Skip to content

Commit dfc80d4

Browse files
authored
Merge 0f27dda into b8206e4
2 parents b8206e4 + 0f27dda commit dfc80d4

File tree

2 files changed

+62
-11
lines changed

2 files changed

+62
-11
lines changed

qiita_pet/handlers/software.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def _default_parameters_parsing(node):
7474
# for easy look up and merge of output_names
7575
main_nodes = dict()
7676
not_used_nodes = {n.id: n for n in graph.nodes}
77+
standalone_input = None
7778
for i, (x, y) in enumerate(graph.edges):
7879
if x.id in not_used_nodes:
7980
del not_used_nodes[x.id]
@@ -89,10 +90,16 @@ def _default_parameters_parsing(node):
8990
if i == 0:
9091
# we are in the first element so we can specifically select
9192
# the type we are looking for
92-
if at in input_x[0][1]:
93+
if input_x and at in input_x[0][1]:
9394
input_x[0][1] = at
94-
else:
95+
elif input_x:
9596
input_x[0][1] = '** WARNING, NOT DEFINED **'
97+
else:
98+
# if we get to this point it means that the workflow has a
99+
# multiple commands starting from the main single input,
100+
# thus is fine to link them to the same raw data
101+
standalone_input = vals_x[0]
102+
input_x = [['', at]]
96103

97104
name_x = vals_x[0]
98105
name_y = vals_y[0]
@@ -106,6 +113,8 @@ def _default_parameters_parsing(node):
106113
name = inputs[b]
107114
else:
108115
name = 'input_%s_%s' % (name_x, b)
116+
if standalone_input is not None:
117+
standalone_input = name
109118
vals = [name, a, b]
110119
if vals not in nodes:
111120
inputs[b] = name
@@ -149,21 +158,25 @@ def _default_parameters_parsing(node):
149158

150159
wparams = w.parameters
151160

152-
# adding nodes without edges
153-
# as a first step if not_used_nodes is not empty we'll confirm that
154-
# nodes/edges are empty; in theory we should never hit this
155-
if not_used_nodes and (nodes or edges):
156-
raise ValueError(
157-
'Error, please check your workflow configuration')
161+
# This case happens when a workflow has 2 commands from the initial
162+
# artifact and one of them has more processing after
163+
if not_used_nodes and (nodes or edges) and standalone_input is None:
164+
standalone_input = edges[0][0]
158165

159166
# note that this block is similar but not identical to adding connected
160167
# nodes
161168
for i, (_, x) in enumerate(not_used_nodes.items()):
162169
vals_x, input_x, output_x = _default_parameters_parsing(x)
163-
if at in input_x[0][1]:
170+
if input_x and at in input_x[0][1]:
164171
input_x[0][1] = at
165-
else:
172+
elif input_x:
166173
input_x[0][1] = '** WARNING, NOT DEFINED **'
174+
else:
175+
# if we get to this point it means that these are "standalone"
176+
# commands, thus is fine to link them to the same raw data
177+
if standalone_input is None:
178+
standalone_input = vals_x[0]
179+
input_x = [['', at]]
167180

168181
name_x = vals_x[0]
169182
if vals_x not in (nodes):
@@ -173,7 +186,14 @@ def _default_parameters_parsing(node):
173186
name = inputs[b]
174187
else:
175188
name = 'input_%s_%s' % (name_x, b)
176-
nodes.append([name, a, b])
189+
# if standalone_input == name_x then this is the first time
190+
# we are processing a standalone command so we need to add
191+
# the node and store the name of the node for future usage
192+
if standalone_input == name_x:
193+
nodes.append([name, a, b])
194+
standalone_input = name
195+
else:
196+
name = standalone_input
177197
edges.append([name, vals_x[0]])
178198
for a, b in output_x:
179199
name = 'output_%s_%s' % (name_x, b)

qiita_pet/test/test_software.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,37 @@ def test_get(self):
5757
self.assertIn('FASTA upstream workflow', body)
5858
DefaultWorkflow(2).active = True
5959

60+
def test_retrive_workflows_standalone(self):
61+
# let's create a new workflow, add 2 commands, and make parameters not
62+
# required: two standalone commands
63+
with TRN:
64+
# 5 per_sample_FASTQ
65+
sql = """INSERT INTO qiita.default_workflow
66+
(name, artifact_type_id, description, parameters)
67+
VALUES ('', 5, '', '{"prep": {}, "sample": {}}')
68+
RETURNING default_workflow_id"""
69+
TRN.add(sql)
70+
wid = TRN.execute_fetchlast()
71+
# 11 & 12 are per-sample-FASTQ split libraries commands
72+
sql = """INSERT INTO qiita.default_workflow_node
73+
(default_workflow_id, default_parameter_set_id)
74+
VALUES (%s, 11), (%s, 12)
75+
RETURNING default_workflow_node_id"""
76+
TRN.add(sql, [wid, wid])
77+
nid = TRN.execute_fetchflatten()
78+
sql = """UPDATE qiita.command_parameter SET required = false"""
79+
TRN.add(sql)
80+
TRN.execute()
81+
82+
obs = _retrive_workflows(True)[-1]
83+
exp_value = f'input_params_{nid[0]}_per_sample_FASTQ'
84+
# there should be a single "input" node
85+
self.assertEqual(1, len(
86+
[x for x in obs['nodes'] if x[0] == exp_value]))
87+
# and 2 edges
88+
self.assertEqual(2, len(
89+
[x for x in obs['edges'] if x[0] == exp_value]))
90+
6091
def test_retrive_workflows(self):
6192
# we should see all 3 workflows
6293
DefaultWorkflow(2).active = False

0 commit comments

Comments
 (0)