Skip to content

Commit 35a051e

Browse files
authored
Fix 3436 (#3440)
* fix #3438 * fix #3436 * self->cls * rm () * adding tests * fix test * fix flake8
1 parent 8c3e342 commit 35a051e

File tree

4 files changed

+63
-5
lines changed

4 files changed

+63
-5
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ Deployed on October 14th, 2024
1414
* `SortMeRNA v4.3.7` superseded `Sortmerna v2.1b`, which relies on Silva 138 and now produced even mates. Thank you @ekopylova and @biocodz for the support.
1515
* `Remove SynDNA reads` superseded `SynDNA Woltka`, which now generates even mates.
1616
* `Woltka v0.1.7, paired-end` superseded `Woltka v0.1.6` in `qp-woltka`; [more information](https://qiita.ucsd.edu/static/doc/html/processingdata/woltka_pairedend.html). Thank you to @qiyunzhu for the benchmarks!
17-
* Other general fixes, like [#3424](https://github.com/qiita-spots/qiita/pull/3424), [#3425](https://github.com/qiita-spots/qiita/pull/3425), [#3439](https://github.com/qiita-spots/qiita/pull/3439).
17+
* Other general fixes, like [#3424](https://github.com/qiita-spots/qiita/pull/3424), [#3425](https://github.com/qiita-spots/qiita/pull/3425), [#3439](https://github.com/qiita-spots/qiita/pull/3439), [#3440](https://github.com/qiita-spots/qiita/pull/3440).
18+
* General SPP improvements, like: [NuQC modified to preserve metadata in fastq files](https://github.com/biocore/mg-scripts/pull/155), [use squeue instead of sacct](https://github.com/biocore/mg-scripts/pull/152), , [job aborts if Qiita study contains sample metadata columns reserved for prep-infos](https://github.com/biocore/mg-scripts/pull/151), [metapool generates OverrideCycles value](https://github.com/biocore/metagenomics_pooling_notebook/pull/225).
19+
1820

1921

2022
Version 2024.07

qiita_db/artifact.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,8 @@ def can_be_submitted_to_ebi(self):
929929
# words has more that one processing step behind it
930930
fine_to_send = []
931931
fine_to_send.extend([pt.artifact for pt in self.prep_templates])
932-
fine_to_send.extend([c for a in fine_to_send for c in a.children])
932+
fine_to_send.extend([c for a in fine_to_send if a is not None
933+
for c in a.children])
933934
if self not in fine_to_send:
934935
return False
935936

qiita_db/metadata_template/prep_template.py

+12
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ def delete(cls, id_):
272272
"Cannot remove prep template %d because it has an artifact"
273273
" associated with it" % id_)
274274

275+
# artifacts that are archived are not returned as part of the code
276+
# above and we need to clean them before moving forward
277+
sql = """SELECT artifact_id
278+
FROM qiita.preparation_artifact
279+
WHERE prep_template_id = %s"""
280+
qdb.sql_connection.TRN.add(sql, args)
281+
archived_artifacts = set(
282+
qdb.sql_connection.TRN.execute_fetchflatten())
283+
if archived_artifacts:
284+
for aid in archived_artifacts:
285+
qdb.artifact.Artifact.delete(aid)
286+
275287
# Delete the prep template filepaths
276288
sql = """DELETE FROM qiita.prep_template_filepath
277289
WHERE prep_template_id = %s"""

qiita_db/test/test_artifact.py

+46-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from tempfile import mkstemp, mkdtemp
1111
from datetime import datetime
1212
from os import close, remove
13-
from os.path import exists, join, basename
13+
from os.path import exists, join, basename, dirname, abspath
1414
from shutil import copyfile
1515
from functools import partial
1616
from json import dumps
@@ -23,6 +23,7 @@
2323
from qiita_core.util import qiita_test_checker
2424
from qiita_core.testing import wait_for_processing_job
2525
import qiita_db as qdb
26+
from qiita_ware.private_plugin import _delete_analysis_artifacts
2627

2728

2829
class ArtifactTestsReadOnly(TestCase):
@@ -1518,15 +1519,57 @@ def test_archive(self):
15181519
'be archived'):
15191520
A.archive(8)
15201521

1521-
for aid in range(4, 7):
1522+
for aid in range(5, 7):
15221523
ms = A(aid).merging_scheme
15231524
A.archive(aid)
15241525
self.assertEqual(ms, A(aid).merging_scheme)
15251526
exp_nodes.remove(A(aid))
15261527
self.assertCountEqual(A(1).descendants.nodes(), exp_nodes)
15271528

15281529
obs_artifacts = len(qdb.util.get_artifacts_information([4, 5, 6, 8]))
1529-
self.assertEqual(1, obs_artifacts)
1530+
self.assertEqual(2, obs_artifacts)
1531+
1532+
# in the tests above we generated and validated archived artifacts
1533+
# so this allows us to add tests to delete a prep-info with archived
1534+
# artifacts. The first bottleneck to do this is that this tests will
1535+
# actually remove files, which we will need for other tests so lets
1536+
# make a copy and then restore them
1537+
mfolder = dirname(dirname(abspath(__file__)))
1538+
mpath = join(mfolder, 'support_files', 'test_data')
1539+
mp = partial(join, mpath)
1540+
fps = [
1541+
mp('processed_data/1_study_1001_closed_reference_otu_table.biom'),
1542+
mp('processed_data/'
1543+
'1_study_1001_closed_reference_otu_table_Silva.biom'),
1544+
mp('raw_data/1_s_G1_L001_sequences.fastq.gz'),
1545+
mp('raw_data/1_s_G1_L001_sequences_barcodes.fastq.gz')]
1546+
for fp in fps:
1547+
copyfile(fp, f'{fp}.bk')
1548+
1549+
PT = qdb.metadata_template.prep_template.PrepTemplate
1550+
QEE = qdb.exceptions.QiitaDBExecutionError
1551+
pt = A(1).prep_templates[0]
1552+
# it should fail as this prep is public and have been submitted to ENA
1553+
with self.assertRaisesRegex(QEE, 'Cannot remove prep template 1'):
1554+
PT.delete(pt.id)
1555+
# now, remove those restrictions + analysis + linked artifacts
1556+
sql = "DELETE FROM qiita.artifact_processing_job"
1557+
qdb.sql_connection.perform_as_transaction(sql)
1558+
sql = "DELETE FROM qiita.ebi_run_accession"
1559+
qdb.sql_connection.perform_as_transaction(sql)
1560+
sql = "UPDATE qiita.artifact SET visibility_id = 1"
1561+
qdb.sql_connection.perform_as_transaction(sql)
1562+
_delete_analysis_artifacts(qdb.analysis.Analysis(1))
1563+
_delete_analysis_artifacts(qdb.analysis.Analysis(2))
1564+
_delete_analysis_artifacts(qdb.analysis.Analysis(3))
1565+
for aid in [3, 2, 1]:
1566+
A.delete(aid)
1567+
1568+
PT.delete(pt.id)
1569+
1570+
# bringing back the filepaths
1571+
for fp in fps:
1572+
copyfile(f'{fp}.bk', fp)
15301573

15311574

15321575
if __name__ == '__main__':

0 commit comments

Comments
 (0)