Skip to content

Commit 1aec6b0

Browse files
authored
add rna_copy_counts (qiita-spots#3351)
* add rna_copy_counts * RNA -> Calculate RNA * v != '*' * v != '*' : fix conditional * prep job only display if success * allowing for multiple inputs in workflow * fix error * just one element * rollback add_default_workflow * simplify add_default_workflow
1 parent 58e15a4 commit 1aec6b0

File tree

3 files changed

+109
-110
lines changed

3 files changed

+109
-110
lines changed

qiita_db/metadata_template/prep_template.py

Lines changed: 103 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,7 @@ def _get_node_info(workflow, node):
793793
def _get_predecessors(workflow, node):
794794
# recursive method to get predecessors of a given node
795795
pred = []
796+
796797
for pnode in workflow.graph.predecessors(node):
797798
pred = _get_predecessors(workflow, pnode)
798799
cxns = {x[0]: x[2]
@@ -864,15 +865,17 @@ def _get_predecessors(workflow, node):
864865
if wk_params['sample']:
865866
df = ST(self.study_id).to_dataframe(samples=list(self))
866867
for k, v in wk_params['sample'].items():
867-
if k not in df.columns or v not in df[k].unique():
868+
if k not in df.columns or (v != '*' and v not in
869+
df[k].unique()):
868870
reqs_satisfied = False
869871
else:
870872
total_conditions_satisfied += 1
871873

872874
if wk_params['prep']:
873875
df = self.to_dataframe()
874876
for k, v in wk_params['prep'].items():
875-
if k not in df.columns or v not in df[k].unique():
877+
if k not in df.columns or (v != '*' and v not in
878+
df[k].unique()):
876879
reqs_satisfied = False
877880
else:
878881
total_conditions_satisfied += 1
@@ -890,117 +893,112 @@ def _get_predecessors(workflow, node):
890893

891894
# let's just keep one, let's give it preference to the one with the
892895
# most total_conditions_satisfied
893-
workflows = sorted(workflows, key=lambda x: x[0], reverse=True)[:1]
896+
_, wk = sorted(workflows, key=lambda x: x[0], reverse=True)[0]
894897
missing_artifacts = dict()
895-
for _, wk in workflows:
896-
missing_artifacts[wk] = dict()
897-
for node, degree in wk.graph.out_degree():
898-
if degree != 0:
899-
continue
900-
mscheme = _get_node_info(wk, node)
901-
if mscheme not in merging_schemes:
902-
missing_artifacts[wk][mscheme] = node
903-
if not missing_artifacts[wk]:
904-
del missing_artifacts[wk]
898+
for node, degree in wk.graph.out_degree():
899+
if degree != 0:
900+
continue
901+
mscheme = _get_node_info(wk, node)
902+
if mscheme not in merging_schemes:
903+
missing_artifacts[mscheme] = node
905904
if not missing_artifacts:
906905
# raises option b.
907906
raise ValueError('This preparation is complete')
908907

909908
# 3.
910-
for wk, wk_data in missing_artifacts.items():
911-
previous_jobs = dict()
912-
for ma, node in wk_data.items():
913-
predecessors = _get_predecessors(wk, node)
914-
predecessors.reverse()
915-
cmds_to_create = []
916-
init_artifacts = None
917-
for i, (pnode, cnode, cxns) in enumerate(predecessors):
918-
cdp = cnode.default_parameter
919-
cdp_cmd = cdp.command
920-
params = cdp.values.copy()
921-
922-
icxns = {y: x for x, y in cxns.items()}
923-
reqp = {x: icxns[y[1][0]]
924-
for x, y in cdp_cmd.required_parameters.items()}
925-
cmds_to_create.append([cdp_cmd, params, reqp])
926-
927-
info = _get_node_info(wk, pnode)
928-
if info in merging_schemes:
929-
if set(merging_schemes[info]) >= set(cxns):
930-
init_artifacts = merging_schemes[info]
931-
break
932-
if init_artifacts is None:
933-
pdp = pnode.default_parameter
934-
pdp_cmd = pdp.command
935-
params = pdp.values.copy()
936-
# verifying that the workflow.artifact_type is included
937-
# in the command input types or raise an error
938-
wkartifact_type = wk.artifact_type
939-
reqp = dict()
940-
for x, y in pdp_cmd.required_parameters.items():
941-
if wkartifact_type not in y[1]:
942-
raise ValueError(f'{wkartifact_type} is not part '
943-
'of this preparation and cannot '
944-
'be applied')
945-
reqp[x] = wkartifact_type
946-
947-
cmds_to_create.append([pdp_cmd, params, reqp])
948-
949-
if starting_job is not None:
950-
init_artifacts = {
951-
wkartifact_type: f'{starting_job.id}:'}
952-
else:
953-
init_artifacts = {wkartifact_type: self.artifact.id}
954-
955-
cmds_to_create.reverse()
956-
current_job = None
957-
loop_starting_job = starting_job
958-
for i, (cmd, params, rp) in enumerate(cmds_to_create):
959-
if loop_starting_job is not None:
960-
previous_job = loop_starting_job
961-
loop_starting_job = None
962-
else:
963-
previous_job = current_job
964-
if previous_job is None:
965-
req_params = dict()
966-
for iname, dname in rp.items():
967-
if dname not in init_artifacts:
968-
msg = (f'Missing Artifact type: "{dname}" in '
969-
'this preparation; this might be due '
970-
'to missing steps or not having the '
971-
'correct raw data.')
972-
# raises option c.
973-
raise ValueError(msg)
974-
req_params[iname] = init_artifacts[dname]
975-
else:
976-
req_params = dict()
977-
connections = dict()
978-
for iname, dname in rp.items():
979-
req_params[iname] = f'{previous_job.id}{dname}'
980-
connections[dname] = iname
981-
params.update(req_params)
982-
job_params = qdb.software.Parameters.load(
983-
cmd, values_dict=params)
984-
985-
if params in previous_jobs.values():
986-
for x, y in previous_jobs.items():
987-
if params == y:
988-
current_job = x
909+
previous_jobs = dict()
910+
for ma, node in missing_artifacts.items():
911+
predecessors = _get_predecessors(wk, node)
912+
predecessors.reverse()
913+
cmds_to_create = []
914+
init_artifacts = None
915+
for i, (pnode, cnode, cxns) in enumerate(predecessors):
916+
cdp = cnode.default_parameter
917+
cdp_cmd = cdp.command
918+
params = cdp.values.copy()
919+
920+
icxns = {y: x for x, y in cxns.items()}
921+
reqp = {x: icxns[y[1][0]]
922+
for x, y in cdp_cmd.required_parameters.items()}
923+
cmds_to_create.append([cdp_cmd, params, reqp])
924+
925+
info = _get_node_info(wk, pnode)
926+
if info in merging_schemes:
927+
if set(merging_schemes[info]) >= set(cxns):
928+
init_artifacts = merging_schemes[info]
929+
break
930+
if init_artifacts is None:
931+
pdp = pnode.default_parameter
932+
pdp_cmd = pdp.command
933+
params = pdp.values.copy()
934+
# verifying that the workflow.artifact_type is included
935+
# in the command input types or raise an error
936+
wkartifact_type = wk.artifact_type
937+
reqp = dict()
938+
for x, y in pdp_cmd.required_parameters.items():
939+
if wkartifact_type not in y[1]:
940+
raise ValueError(f'{wkartifact_type} is not part '
941+
'of this preparation and cannot '
942+
'be applied')
943+
reqp[x] = wkartifact_type
944+
945+
cmds_to_create.append([pdp_cmd, params, reqp])
946+
947+
if starting_job is not None:
948+
init_artifacts = {
949+
wkartifact_type: f'{starting_job.id}:'}
950+
else:
951+
init_artifacts = {wkartifact_type: self.artifact.id}
952+
953+
cmds_to_create.reverse()
954+
current_job = None
955+
loop_starting_job = starting_job
956+
for i, (cmd, params, rp) in enumerate(cmds_to_create):
957+
if loop_starting_job is not None:
958+
previous_job = loop_starting_job
959+
loop_starting_job = None
960+
else:
961+
previous_job = current_job
962+
if previous_job is None:
963+
req_params = dict()
964+
for iname, dname in rp.items():
965+
if dname not in init_artifacts:
966+
msg = (f'Missing Artifact type: "{dname}" in '
967+
'this preparation; this might be due '
968+
'to missing steps or not having the '
969+
'correct raw data.')
970+
# raises option c.
971+
raise ValueError(msg)
972+
req_params[iname] = init_artifacts[dname]
973+
else:
974+
req_params = dict()
975+
connections = dict()
976+
for iname, dname in rp.items():
977+
req_params[iname] = f'{previous_job.id}{dname}'
978+
connections[dname] = iname
979+
params.update(req_params)
980+
job_params = qdb.software.Parameters.load(
981+
cmd, values_dict=params)
982+
983+
if params in previous_jobs.values():
984+
for x, y in previous_jobs.items():
985+
if params == y:
986+
current_job = x
987+
else:
988+
if workflow is None:
989+
PW = qdb.processing_job.ProcessingWorkflow
990+
workflow = PW.from_scratch(user, job_params)
991+
current_job = [
992+
j for j in workflow.graph.nodes()][0]
989993
else:
990-
if workflow is None:
991-
PW = qdb.processing_job.ProcessingWorkflow
992-
workflow = PW.from_scratch(user, job_params)
993-
current_job = [
994-
j for j in workflow.graph.nodes()][0]
994+
if previous_job is None:
995+
current_job = workflow.add(
996+
job_params, req_params=req_params)
995997
else:
996-
if previous_job is None:
997-
current_job = workflow.add(
998-
job_params, req_params=req_params)
999-
else:
1000-
current_job = workflow.add(
1001-
job_params, req_params=req_params,
1002-
connections={previous_job: connections})
1003-
previous_jobs[current_job] = params
998+
current_job = workflow.add(
999+
job_params, req_params=req_params,
1000+
connections={previous_job: connections})
1001+
previous_jobs[current_job] = params
10041002

10051003
return workflow
10061004

qiita_db/processing_job.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ def submit(self, parent_job_id=None, dependent_jobs_list=None):
10201020
# names to know if it should be executed differently and the
10211021
# plugin should let Qiita know that a specific command should be ran
10221022
# as job array or not
1023-
cnames_to_skip = {'Calculate Cell Counts'}
1023+
cnames_to_skip = {'Calculate Cell Counts', 'Calculate RNA Copy Counts'}
10241024
if 'ENVIRONMENT' in plugin_env_script and cname not in cnames_to_skip:
10251025
# the job has to be in running state so the plugin can change its`
10261026
# status

qiita_pet/handlers/study_handlers/prep_template.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,12 @@ def get(self):
8181
res['creation_job_filename'] = fp['filename']
8282
res['creation_job_filename_body'] = fp['body']
8383
summary = None
84-
if res['creation_job'].outputs:
85-
summary = relpath(
84+
if res['creation_job'].status == 'success':
85+
if res['creation_job'].outputs:
8686
# [0] is the id, [1] is the filepath
87-
res['creation_job'].outputs['output'].html_summary_fp[1],
88-
qiita_config.base_data_dir)
87+
_file = res['creation_job'].outputs[
88+
'output'].html_summary_fp[1]
89+
summary = relpath(_file, qiita_config.base_data_dir)
8990
res['creation_job_artifact_summary'] = summary
9091

9192
self.render('study_ajax/prep_summary.html', **res)

0 commit comments

Comments
 (0)