From 53f588fd7be9d989ed53805775b6d9a245aedda8 Mon Sep 17 00:00:00 2001
From: George Marchment <georgemarchment@yahoo.fr>
Date: Wed, 19 Feb 2025 09:48:58 +0100
Subject: [PATCH] Fixed: placing the call of a subworkflow outside of
 conditions

---
 src/workflow.py | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/workflow.py b/src/workflow.py
index 0d5cc50..ca17328 100644
--- a/src/workflow.py
+++ b/src/workflow.py
@@ -3,7 +3,7 @@
 from .nextflow_file import Nextflow_File
 from .ro_crate import RO_Crate
 from . import constant
-from .outils import is_git_directory, format_with_tabs, replace_thing_by_call, replace_group1, group_together_ifs, extract_curly, remove_extra_jumps, get_channels_to_add_in_false_conditions
+from .outils import is_git_directory, format_with_tabs, replace_thing_by_call, replace_group1, group_together_ifs, extract_curly, remove_extra_jumps, get_channels_to_add_in_false_conditions, extract_conditions
 from .outils_graph import flatten_dico, initia_link_dico_rec, get_number_cycles
 from .outils_annotate import get_tools_commands_from_user_for_process
 from .bioflowinsighterror import BioFlowInsightError
@@ -978,9 +978,25 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
             
             
         
+
             #Replace the ankers by the calls of the subworkflows  
             for i in range(len(subworkflow_clusters_to_add)):
-                code = code.replace(f"//Anker_cluster{i}", subworkflow_cluster_calls_to_add[i])
+                #Extracting the conditions in the code
+                conditions_in_code = extract_conditions(code)
+                anker = f"//Anker_cluster{i}"
+                pos_anker = code.find(anker)
+                #For each anker get the condition in which it is called
+                #Cause we do not want the call of the subworkflows to be done in a condition
+                #So around the call we place ""}} call if(){if(){"" -> so it's executed ouside of a condition
+                conditions_for_anker = []
+                for c in conditions_in_code:
+                    if(conditions_in_code[c][0]<pos_anker and pos_anker <conditions_in_code[c][1]):
+                        conditions_for_anker.append(c.split("$$__$$")[0])
+                #Placing the extract curlies around it
+                subworkflow_call = subworkflow_cluster_calls_to_add[i]
+                for c in conditions_for_anker:
+                    subworkflow_call = f"\n}}\n{subworkflow_call}\nif({c}){{\n"
+                code = code.replace(anker, subworkflow_call)
             
            
             for old, new in channels_to_replace_outside_of_cluster:
-- 
GitLab