@@ -726,13 +726,15 @@ def modification_timestamp(self):
726
726
def max_samples ():
727
727
return qdb .util .max_preparation_samples ()
728
728
729
- def add_default_workflow (self , user ):
730
- """The modification timestamp of the prep information
729
+ def add_default_workflow (self , user , workflow = None ):
730
+ """Adds the commands of the default workflow to this preparation
731
731
732
732
Parameters
733
733
----------
734
734
user : qiita_db.user.User
735
735
The user that requested to add the default workflows
736
+ workflow : qiita_db.processing_job.ProcessingWorkflow, optional
737
+ The workflow to add the default processing
736
738
737
739
Returns
738
740
-------
@@ -745,6 +747,13 @@ def add_default_workflow(self, user):
745
747
a. If this preparation doesn't have valid workflows
746
748
b. This preparation has been fully processed (no new steps needed)
747
749
c. If there is no valid initial artifact to start the workflow
750
+
751
+ Notes
752
+ -----
753
+ This method adds the commands in a default workflow (definition) to
754
+ the preparation, if a workflow (object) is passed it will add the
755
+ commands to the last artifact in that workflow but if it's None it will
756
+ create a new workflow (default)
748
757
"""
749
758
# helper functions to avoid duplication of code
750
759
@@ -806,9 +815,14 @@ def _get_predecessors(workflow, node):
806
815
# workflow
807
816
808
817
# 1.
809
- prep_jobs = [j for c in self .artifact .descendants .nodes ()
810
- for j in c .jobs (show_hidden = True )
811
- if j .command .software .type == 'artifact transformation' ]
818
+ # let's assume that if there is a workflow, there are no jobs
819
+ if workflow is not None :
820
+ prep_jobs = []
821
+ else :
822
+ prep_jobs = [j for c in self .artifact .descendants .nodes ()
823
+ for j in c .jobs (show_hidden = True )
824
+ if j .command .software .type ==
825
+ 'artifact transformation' ]
812
826
merging_schemes = {
813
827
qdb .archive .Archive .get_merging_scheme_from_job (j ): {
814
828
x : y .id for x , y in j .outputs .items ()}
@@ -821,7 +835,14 @@ def _get_predecessors(workflow, node):
821
835
822
836
# 2.
823
837
pt_dt = self .data_type ()
824
- pt_artifact = self .artifact .artifact_type
838
+ # if there is a workflow, we would need to get the artifact_type from
839
+ # the job
840
+ if workflow is not None :
841
+ starting_job = list (workflow .graph .nodes ())[0 ]
842
+ pt_artifact = starting_job .parameters .values ['artifact_type' ]
843
+ else :
844
+ starting_job = None
845
+ pt_artifact = self .artifact .artifact_type
825
846
workflows = [wk for wk in qdb .software .DefaultWorkflow .iter ()
826
847
if wk .artifact_type == pt_artifact and
827
848
pt_dt in wk .data_type ]
@@ -846,7 +867,6 @@ def _get_predecessors(workflow, node):
846
867
raise ValueError ('This preparation is complete' )
847
868
848
869
# 3.
849
- workflow = None
850
870
for wk , wk_data in missing_artifacts .items ():
851
871
previous_jobs = dict ()
852
872
for ma , node in wk_data .items ():
@@ -886,12 +906,20 @@ def _get_predecessors(workflow, node):
886
906
887
907
cmds_to_create .append ([pdp_cmd , params , reqp ])
888
908
889
- init_artifacts = {wkartifact_type : self .artifact .id }
909
+ if starting_job is not None :
910
+ init_artifacts = {
911
+ wkartifact_type : f'{ starting_job .id } :' }
912
+ else :
913
+ init_artifacts = {wkartifact_type : self .artifact .id }
890
914
891
915
cmds_to_create .reverse ()
892
916
current_job = None
893
917
for i , (cmd , params , rp ) in enumerate (cmds_to_create ):
894
- previous_job = current_job
918
+ if starting_job is not None :
919
+ previous_job = starting_job
920
+ starting_job = None
921
+ else :
922
+ previous_job = current_job
895
923
if previous_job is None :
896
924
req_params = dict ()
897
925
for iname , dname in rp .items ():
0 commit comments