Skip to content

Commit b2a65be

Browse files
committed
fix #3158
1 parent fed8550 commit b2a65be

File tree

7 files changed

+73
-23
lines changed

7 files changed

+73
-23
lines changed

qiita_db/metadata_template/prep_template.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -858,12 +858,20 @@ def _get_predecessors(workflow, node):
858858
pdp = pnode.default_parameter
859859
pdp_cmd = pdp.command
860860
params = pdp.values.copy()
861-
reqp = {x: y[1][0]
862-
for x, y in pdp_cmd.required_parameters.items()}
861+
# verifying that the workflow.artifact_type is included
862+
# in the command input types or raise an error
863+
wkartifact_type = wk.artifact_type
864+
reqp = dict()
865+
for x, y in pdp_cmd.required_parameters.items():
866+
if wkartifact_type not in y[1]:
867+
raise ValueError(f'{wkartifact_type} is not part '
868+
'of this preparation and cannot '
869+
'be applied')
870+
reqp[x] = wkartifact_type
871+
863872
cmds_to_create.append([pdp_cmd, params, reqp])
864873

865-
init_artifacts = {
866-
self.artifact.artifact_type: self.artifact.id}
874+
init_artifacts = {wkartifact_type: self.artifact.id}
867875

868876
cmds_to_create.reverse()
869877
current_job = None
@@ -874,8 +882,9 @@ def _get_predecessors(workflow, node):
874882
for iname, dname in rp.items():
875883
if dname not in init_artifacts:
876884
msg = (f'Missing Artifact type: "{dname}" in '
877-
'this preparation; are you missing a '
878-
'step to start?')
885+
'this preparation; this might be due '
886+
'to missing steps or not having the '
887+
'correct raw data.')
879888
# raises option c.
880889
raise ValueError(msg)
881890
req_params[iname] = init_artifacts[dname]

qiita_db/metadata_template/test/test_prep_template.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,13 +1412,13 @@ def test_artifact_setter(self):
14121412
pt.add_default_workflow(qdb.user.User('test@foo.bar'))
14131413

14141414
# now let's test that an error is raised when there is no valid initial
1415-
# input data; this moves the data type from FASTQ to taxa_summary
1415+
# input data; this moves the data type from FASTQ to taxa_summary for
1416+
# the default_workflow_id = 1
14161417
qdb.sql_connection.perform_as_transaction(
1417-
'UPDATE qiita.artifact SET artifact_type_id = 10 WHERE '
1418-
f'artifact_id = {pt.artifact.id}')
1419-
with self.assertRaisesRegex(ValueError, 'Missing Artifact type: '
1420-
'"FASTQ" in this preparation; are you '
1421-
'missing a step to start?'):
1418+
'UPDATE qiita.default_workflow SET artifact_type_id = 10 WHERE '
1419+
'default_workflow_id = 1')
1420+
with self.assertRaisesRegex(ValueError, 'taxa_summary is not part of '
1421+
'this preparation and cannot be applied'):
14221422
pt.add_default_workflow(qdb.user.User('test@foo.bar'))
14231423

14241424
# cleaning

qiita_db/software.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,6 +1946,23 @@ def data_type(self):
19461946
qdb.sql_connection.TRN.add(sql, [self.id])
19471947
return qdb.sql_connection.TRN.execute_fetchflatten()
19481948

1949+
@property
1950+
def artifact_type(self):
1951+
"""Retrieves artifact_type that the workflow can be applied to
1952+
1953+
Returns
1954+
----------
1955+
str
1956+
The name of the artifact type this workflow can be applied to
1957+
"""
1958+
with qdb.sql_connection.TRN:
1959+
sql = """SELECT artifact_type
1960+
FROM qiita.artifact_type
1961+
LEFT JOIN qiita.default_workflow USING (artifact_type_id)
1962+
WHERE default_workflow_id = %s"""
1963+
qdb.sql_connection.TRN.add(sql, [self.id])
1964+
return qdb.sql_connection.TRN.execute_fetchflatten()[0]
1965+
19491966
@property
19501967
def graph(self):
19511968
"""Returns the graph that represents the workflow

qiita_db/support_files/patches/85.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@ BEGIN
1010
INSERT INTO qiita.command_parameter (command_id, parameter_name, parameter_type, required, default_value)
1111
VALUES (cmd_id, 'categories', 'mchoice', True, NULL);
1212
END $do$;
13+
14+
-- Feb 28, 2022
15+
-- adding a new column to the default_workflow table to keep track of the
16+
-- artifact type that is expecting vs. "guessing"
17+
18+
ALTER TABLE qiita.default_workflow ADD artifact_type_id BIGINT NOT NULL DEFAULT 3;
19+
ALTER TABLE qiita.default_workflow
20+
ADD CONSTRAINT fk_artifact_type_id
21+
FOREIGN KEY (artifact_type_id)
22+
REFERENCES qiita.artifact_type(artifact_type_id)
23+
ON UPDATE CASCADE;

qiita_db/test/test_software.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,9 @@ def test_default_workflows(self):
632632
obs = list(qdb.software.DefaultWorkflow.iter(False))
633633
self.assertEqual(obs, exp)
634634

635+
self.assertEqual(
636+
qdb.software.DefaultWorkflow(1).artifact_type, 'FASTQ')
637+
635638
qdb.software.DefaultWorkflow(1).active = False
636639
obs = list(qdb.software.DefaultWorkflow.iter(False))
637640
self.assertEqual(obs, exp)

qiita_pet/handlers/software.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,23 @@ def _default_parameters_parsing(node):
7272
# output_type: output_node_name}, ...}
7373
# for easy look up and merge of output_names
7474
main_nodes = dict()
75-
for x, y in graph.edges:
75+
for i, (x, y) in enumerate(graph.edges):
7676
connections = []
7777
for a, _, c in graph[x][y]['connections'].connections:
7878
connections.append("%s | %s" % (a, c))
7979

8080
vals_x, input_x, output_x = _default_parameters_parsing(x)
8181
vals_y, input_y, output_y = _default_parameters_parsing(y)
82+
83+
if i == 0:
84+
# we are in the first element so we can specifically select
85+
# the type we are looking for
86+
at = w.artifact_type
87+
if at in input_x[0][1]:
88+
input_x[0][1] = at
89+
else:
90+
input_x[0][1] = '** WARNING, NOT DEFINED **'
91+
8292
name_x = vals_x[0]
8393
name_y = vals_y[0]
8494
if vals_x not in (nodes):

qiita_pet/test/test_software.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def test_retrive_workflows(self):
152152
'sortmerna_coverage': '0.97', 'threads': '1'}],
153153
['output_params_8_OTU table | BIOM', 3, 'OTU table | BIOM']])
154154
exp[0]['edges'].extend([
155-
['input_params_1_FASTQ | per_sample_FASTQ', 'params_7'],
155+
['input_params_1_FASTQ', 'params_7'],
156156
['params_7', 'output_params_7_demultiplexed | Demultiplexed'],
157157
['output_params_7_demultiplexed | Demultiplexed', 'params_8'],
158158
['params_8', 'output_params_8_OTU table | BIOM']])
@@ -180,8 +180,8 @@ def test_retrive_workflows(self):
180180
'rev_comp_mapping_barcodes': 'False', 'rev_comp': 'False',
181181
'phred_quality_threshold': '3', 'barcode_type': 'golay_12',
182182
'max_barcode_errors': '1.5', 'phred_offset': 'auto'}],
183-
['input_params_1_FASTQ | per_sample_FASTQ', 1,
184-
'FASTQ | per_sample_FASTQ'],
183+
['input_params_1_FASTQ', 1,
184+
'FASTQ'],
185185
['output_params_1_demultiplexed | Demultiplexed', 1,
186186
'demultiplexed | Demultiplexed'],
187187
['params_2', 3, 'Pick closed-reference OTUs', 'Defaults', {
@@ -190,7 +190,7 @@ def test_retrive_workflows(self):
190190
'sortmerna_coverage': '0.97', 'threads': '1'}],
191191
['output_params_2_OTU table | BIOM', 3, 'OTU table | BIOM']],
192192
'edges': [
193-
['input_params_1_FASTQ | per_sample_FASTQ', 'params_1'],
193+
['input_params_1_FASTQ', 'params_1'],
194194
['params_1', 'output_params_1_demultiplexed | Demultiplexed'],
195195
['output_params_1_demultiplexed | Demultiplexed', 'params_2'],
196196
['params_2', 'output_params_2_OTU table | BIOM']]},
@@ -206,8 +206,8 @@ def test_retrive_workflows(self):
206206
'qual_score_window': '0', 'disable_primers': 'False',
207207
'reverse_primers': 'disable', 'reverse_primer_mismatches': '0',
208208
'truncate_ambi_bases': 'False'}],
209-
['input_params_3_FASTA | FASTA_Sanger | SFF', 2,
210-
'FASTA | FASTA_Sanger | SFF'],
209+
['input_params_3_** WARNING, NOT DEFINED **', 2,
210+
'** WARNING, NOT DEFINED **'],
211211
['output_params_3_demultiplexed | Demultiplexed', 2,
212212
'demultiplexed | Demultiplexed'],
213213
['params_4', 3, 'Pick closed-reference OTUs', 'Defaults', {
@@ -216,7 +216,7 @@ def test_retrive_workflows(self):
216216
'sortmerna_coverage': '0.97', 'threads': '1'}],
217217
['output_params_4_OTU table | BIOM', 3, 'OTU table | BIOM']],
218218
'edges': [
219-
['input_params_3_FASTA | FASTA_Sanger | SFF', 'params_3'],
219+
['input_params_3_** WARNING, NOT DEFINED **', 'params_3'],
220220
['params_3', 'output_params_3_demultiplexed | Demultiplexed'],
221221
['output_params_3_demultiplexed | Demultiplexed', 'params_4'],
222222
['params_4', 'output_params_4_OTU table | BIOM']]},
@@ -229,8 +229,8 @@ def test_retrive_workflows(self):
229229
'rev_comp_mapping_barcodes': 'False', 'rev_comp': 'False',
230230
'phred_quality_threshold': '3', 'barcode_type': 'not-barcoded',
231231
'max_barcode_errors': '1.5', 'phred_offset': 'auto'}],
232-
['input_params_5_FASTQ | per_sample_FASTQ', 1,
233-
'FASTQ | per_sample_FASTQ'],
232+
['input_params_5_FASTQ', 1,
233+
'FASTQ'],
234234
['output_params_5_demultiplexed | Demultiplexed', 1,
235235
'demultiplexed | Demultiplexed'],
236236
['params_6', 3, 'Pick closed-reference OTUs', 'Defaults', {
@@ -239,7 +239,7 @@ def test_retrive_workflows(self):
239239
'sortmerna_coverage': '0.97', 'threads': '1'}],
240240
['output_params_6_OTU table | BIOM', 3, 'OTU table | BIOM']],
241241
'edges': [
242-
['input_params_5_FASTQ | per_sample_FASTQ', 'params_5'],
242+
['input_params_5_FASTQ', 'params_5'],
243243
['params_5', 'output_params_5_demultiplexed | Demultiplexed'],
244244
['output_params_5_demultiplexed | Demultiplexed', 'params_6'],
245245
['params_6', 'output_params_6_OTU table | BIOM']]}]

0 commit comments

Comments
 (0)