@@ -853,33 +853,32 @@ def _get_predecessors(workflow, node):
853
853
854
854
all_workflows = [wk for wk in qdb .software .DefaultWorkflow .iter ()]
855
855
# are there any workflows with parameters?
856
- check_requirements = False
857
- default_parameters = {'prep' : {}, 'sample' : {}}
858
- if [wk for wk in all_workflows if wk .parameters != default_parameters ]:
859
- check_requirements = True
860
856
ST = qdb .metadata_template .sample_template .SampleTemplate
861
857
workflows = []
862
858
for wk in all_workflows :
863
859
if wk .artifact_type == pt_artifact and pt_dt in wk .data_type :
864
- if check_requirements and wk .parameters == default_parameters :
865
- continue
866
860
wk_params = wk .parameters
867
861
reqs_satisfied = True
862
+ total_conditions_satisfied = 0
868
863
869
864
if wk_params ['sample' ]:
870
865
df = ST (self .study_id ).to_dataframe (samples = list (self ))
871
866
for k , v in wk_params ['sample' ].items ():
872
867
if k not in df .columns or v not in df [k ].unique ():
873
868
reqs_satisfied = False
869
+ else :
870
+ total_conditions_satisfied += 1
874
871
875
872
if wk_params ['prep' ]:
876
873
df = self .to_dataframe ()
877
874
for k , v in wk_params ['prep' ].items ():
878
875
if k not in df .columns or v not in df [k ].unique ():
879
876
reqs_satisfied = False
877
+ else :
878
+ total_conditions_satisfied += 1
880
879
881
880
if reqs_satisfied :
882
- workflows .append (wk )
881
+ workflows .append (( total_conditions_satisfied , wk ) )
883
882
884
883
if not workflows :
885
884
# raises option a.
@@ -888,8 +887,12 @@ def _get_predecessors(workflow, node):
888
887
'could be due to required parameters, please check the '
889
888
'available workflows.' )
890
889
raise ValueError (msg )
890
+
891
+ # let's just keep one, let's give it preference to the one with the
892
+ # most total_conditions_satisfied
893
+ workflows = sorted (workflows , key = lambda x : x [0 ], reverse = True )[:1 ]
891
894
missing_artifacts = dict ()
892
- for wk in workflows :
895
+ for _ , wk in workflows :
893
896
missing_artifacts [wk ] = dict ()
894
897
for node , degree in wk .graph .out_degree ():
895
898
if degree != 0 :
0 commit comments