Skip to content

Commit b626871

Browse files
authored
add analysis id to validate parameters (#3497)
* add analysis id to validate parameters * adding artifacts to job creation * add analysis to release * mv up pvals * artifacs -> artifacts * rm counts * rewrite scenarios * fix analysis error * no prep_template, parents or analysis provided * data_type * rm parents * params=None * overwrite_lock
1 parent 74ad1ba commit b626871

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

qiita_db/analysis.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,17 +847,21 @@ def _lock_samples(self):
847847
"Can't add/remove samples from this analysis"
848848
)
849849

850-
def add_samples(self, samples):
850+
def add_samples(self, samples, overwrite_lock=False):
851851
"""Adds samples to the analysis
852852
853853
Parameters
854854
----------
855855
samples : dictionary of lists
856856
samples and the artifact id they come from in form
857857
{artifact_id: [sample1, sample2, ...], ...}
858+
overwrite_lock : bool, optional
859+
if True it will ignore the sample-lock and will allow adding
860+
samples to a non-default analysis
858861
"""
859862
with qdb.sql_connection.TRN:
860-
self._lock_samples()
863+
if not overwrite_lock:
864+
self._lock_samples()
861865

862866
for aid, samps in samples.items():
863867
# get previously selected samples for aid and filter them out

qiita_db/processing_job.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,16 +1217,16 @@ def release(self):
12171217

12181218
provenance = loads(self.parameters.values["provenance"])
12191219
job = ProcessingJob(provenance["job"])
1220+
pvals = job.parameters.values
12201221
if "data_type" in a_info:
12211222
# This job is resulting from a private job
12221223
parents = None
12231224
params = None
12241225
name = None
12251226
data_type = a_info["data_type"]
1226-
pvals = job.parameters.values
12271227
if "analysis" in pvals:
12281228
cmd_out_id = None
1229-
analysis = qdb.analysis.Analysis(job.parameters.values["analysis"])
1229+
analysis = qdb.analysis.Analysis(pvals["analysis"])
12301230
else:
12311231
cmd_out_id = provenance["cmd_out_id"]
12321232
analysis = None
@@ -1237,8 +1237,31 @@ def release(self):
12371237
params = job.parameters
12381238
cmd_out_id = provenance["cmd_out_id"]
12391239
name = provenance["name"]
1240-
analysis = None
12411240
data_type = None
1241+
if "analysis" in pvals:
1242+
analysis = qdb.analysis.Analysis(pvals["analysis"])
1243+
if "artifacts" in pvals:
1244+
# as this is going to be the first artifact of an analysis, we
1245+
# need to provide the data type so we are going to make sure all
1246+
# the parents data_types are the same and assigning that one; note
1247+
# that (1) we are doing this to be stringent but it should be responsability
1248+
# of the plugin creating this artifact, and (2) to keep the same functionality
1249+
# we are going to make sure that params is not set as it shouldn't be passed when
1250+
# assiging to an analysis
1251+
params = None
1252+
data_type = set(
1253+
[
1254+
qdb.artifact.Artifact(aid).data_type
1255+
for aid in pvals["artifacts"]
1256+
]
1257+
)
1258+
if len(data_type) != 1:
1259+
raise ValueError(
1260+
f"Not valid parents data_types: {data_type}"
1261+
)
1262+
data_type = data_type.pop()
1263+
else:
1264+
analysis = None
12421265

12431266
# Create the artifact
12441267
atype = a_info["artifact_type"]
@@ -1470,6 +1493,7 @@ def _complete_artifact_transformation(self, artifacts_data):
14701493
validator_jobs = []
14711494
with qdb.sql_connection.TRN:
14721495
cmd_id = self.command.id
1496+
parameters = self.parameters.values
14731497
for out_name, a_data in artifacts_data.items():
14741498
# Correct the format of the filepaths parameter so we can
14751499
# create a validate job
@@ -1506,6 +1530,12 @@ def _complete_artifact_transformation(self, artifacts_data):
15061530
# belong to the same analysis, so we can just ask the
15071531
# first artifact for the analysis that it belongs to
15081532
analysis = self.input_artifacts[0].analysis.id
1533+
elif "analysis" in parameters:
1534+
# if we made it this far in the if/elif block it means that
1535+
# we are dealing with a job that was generated to link study/template
1536+
# artifacts and an analysis; thus, using the analysis parameter from
1537+
# the job itself
1538+
analysis = parameters["analysis"]
15091539

15101540
# Once the validate job completes, it needs to know if it has
15111541
# been generated from a command (and how) or if it has been
@@ -1521,11 +1551,10 @@ def _complete_artifact_transformation(self, artifacts_data):
15211551
cmd_out_id = qdb.sql_connection.TRN.execute_fetchlast()
15221552
naming_params = self.command.naming_order
15231553
if naming_params:
1524-
params = self.parameters.values
15251554
art_name = "%s %s" % (
15261555
out_name,
15271556
" ".join(
1528-
[str(params[p]).split("/")[-1] for p in naming_params]
1557+
[str(parameters[p]).split("/")[-1] for p in naming_params]
15291558
),
15301559
)
15311560
else:

0 commit comments

Comments
 (0)