From 40d33aae8d7249422c61c7932ba41a10848def22 Mon Sep 17 00:00:00 2001
From: George Marchment <georgemarchment@yahoo.fr>
Date: Wed, 6 Mar 2024 09:37:55 +0100
Subject: [PATCH] fix minor bugs

---
 src/bioflowinsighterror.py |  1 +
 src/constant.py            |  2 +-
 src/operation.py           |  7 ++++++-
 src/outils.py              | 16 ++++++++++++++++
 src/process.py             |  6 +++++-
 src/workflow.py            |  3 ++-
 6 files changed, 31 insertions(+), 4 deletions(-)

diff --git a/src/bioflowinsighterror.py b/src/bioflowinsighterror.py
index d76b296..dd222bb 100644
--- a/src/bioflowinsighterror.py
+++ b/src/bioflowinsighterror.py
@@ -42,6 +42,7 @@ class BioFlowInsightError(Exception):
 #* [3] -> unkonwn thing in a pipe operator  
 #* [5] -> A ternary conditional operator was used with an tuple   
 #* [7] -> Tuple with emit (ch1, ch2) = emit.out 
+#* [9] -> Tuple with call (ch1, ch2) = wf()
         
 
 
diff --git a/src/constant.py b/src/constant.py
index 5c11ebc..a53afee 100644
--- a/src/constant.py
+++ b/src/constant.py
@@ -108,7 +108,7 @@ DOUBLE_DOT_TUPLE = r"\(\s*\w+\s*(,\s*\w+\s*)+\)\s*=\s*([^\?\n]+)\s*\?([^\n]+)"
 END_OPERATOR = r' *(\(|{)'
 ILLEGAL_CHARCTER_BEFORE_POTENTIAL_CHANNELS = r"\w|\'|\"|\."
 ILLEGAL_CHARCTER_AFTER_POTENTIAL_CHANNELS = r"\w"
-MERGE_OPERATIONS = r'\.\s*((merge|mix|concat|spread|join|phase|cross|combine|fromList|collect|fromPath|value|from)\s*(\(|\{))'
+MERGE_OPERATIONS = r'\.\s*((merge|mix|concat|spread|join|phase|cross|combine|fromList|collect|fromPath|value|from|map)\s*(\(|\{))'#I've added map to this list cause channels can appear in map can concatenating channels -> it's a strange way of doing it
 OPERATOR_IN_PIPE = r"\w+ *{[^}]*}|\w+ *\([^\)]*\)|\w+"
 SET_OPERATORS = ["choice", "separate", "tap", "into", "set"]
 TUPLE_EQUALS = r'\( *\w+( *, *\w+)+ *\) *=\s*(\w+)\s*\.'
diff --git a/src/operation.py b/src/operation.py
index b5e0da1..8f7b1e5 100644
--- a/src/operation.py
+++ b/src/operation.py
@@ -247,10 +247,15 @@ class Operation(Executor):
         #================================
         #Case channel1
         #================================
-        if(bool(re.fullmatch(constant.WORD, operation))):
+        if(bool(re.fullmatch(constant.WORD, operation.strip()))):
             self.add_origin(operation)
 
 
+        #Case tupel with call -> this is not supported by BioFlow-Insight -> try calling first then using the emits
+        if(bool(re.fullmatch(r"\( *\w+ *(\, *\w+)+ *\) *= *Call_\d+", operation.strip()))):
+            raise BioFlowInsightError(f"A tuple is associated with an call{self.get_string_line(self.get_code(get_OG= True))}. BioFlow-Insight doesn't support this (see specification list), try defining the operation in a different way.", num=9, origin=self)
+
+
         case_operation_starts_with_emit = False
         #---------------------------
         #Check emits
diff --git a/src/outils.py b/src/outils.py
index 8fa3780..a8082d4 100644
--- a/src/outils.py
+++ b/src/outils.py
@@ -683,6 +683,22 @@ def remove_jumps_inbetween_parentheses(code):
     code = re.sub(r", *\n", ", ", code)
     return code
 
+def remove_jumps_inbetween_curlies(code):
+    code = re.sub(',\s*\n\s*', ', ', code)
+    code = re.sub(';\s*\n\s*', '; ', code)
+    code = list(code)
+    curly_count = 0
+    for i in range(len(code)):
+        if(code[i]=="{"):
+            curly_count+=1
+        elif(code[i]=="}"):
+            curly_count-=1
+        elif(code[i]=="\n" and curly_count!=0):
+            code[i] = " "
+    code = "".join(code)
+    code = re.sub(r", *\n", ", ", code)
+    return code
+
 #def check_if_parameter_is_given_pipe(code, OG_start, OG_end):
 #    char, end = get_next_element_caracter(code, OG_end-1)
 #    start = OG_end
diff --git a/src/process.py b/src/process.py
index ca7d81b..51acddc 100644
--- a/src/process.py
+++ b/src/process.py
@@ -2,7 +2,7 @@ import re
 
 from .code_ import Code
 from .nextflow_building_blocks import Nextflow_Building_Blocks
-from .outils import remove_jumps_inbetween_parentheses, sort_and_filter, get_dico_from_tab_from_id, check_if_element_in_tab_rocrate
+from .outils import remove_jumps_inbetween_parentheses, remove_jumps_inbetween_curlies, sort_and_filter, get_dico_from_tab_from_id, check_if_element_in_tab_rocrate
 from .bioflowinsighterror import BioFlowInsightError
 
 from . import constant
@@ -151,6 +151,7 @@ class Process(Nextflow_Building_Blocks):
     def initialise_inputs_DSL1(self):
         code = "\n"+self.get_input_code()+"\n"
         code = remove_jumps_inbetween_parentheses(code)
+        code = remove_jumps_inbetween_curlies(code)
         #Simplying the inputs -> when there is a jump line '.' -> it turns it to '.'
         code = re.sub(constant.JUMP_DOT, '.', code)
 
@@ -191,6 +192,7 @@ class Process(Nextflow_Building_Blocks):
     def initialise_inputs_DSL2(self):
         code = self.get_input_code()
         code = remove_jumps_inbetween_parentheses(code)
+        code = remove_jumps_inbetween_curlies(code)
         for input in code.split("\n"):
             input = input.strip()
             if(input!=""):
@@ -208,6 +210,7 @@ class Process(Nextflow_Building_Blocks):
     def initialise_outputs_DSL1(self):
         code = self.get_output_code()
         code = remove_jumps_inbetween_parentheses(code)
+        code = remove_jumps_inbetween_curlies(code)
         def add_channel(name):
             from .channel import Channel
             output = Channel(name=name, origin=self.origin)
@@ -235,6 +238,7 @@ class Process(Nextflow_Building_Blocks):
     def initialise_outputs_DSL2(self):
         code = self.get_output_code()
         code = remove_jumps_inbetween_parentheses(code)
+        code = remove_jumps_inbetween_curlies(code)
         for output in code.split("\n"):
             output = output.strip()
             if(output!=""):
diff --git a/src/workflow.py b/src/workflow.py
index b29ea75..290a427 100644
--- a/src/workflow.py
+++ b/src/workflow.py
@@ -70,8 +70,9 @@ class Workflow:
             with open(f'temp_dico_{id(self)}.json') as json_file:
                 self.dico = json.load(json_file)
             os.system(f"rm temp_dico_{id(self)}.json")
+            
         except:
-            None
+            _ = os.system(f"rm temp_dico_{id(self)}.json")
         os.chdir(current_directory)
     
 
-- 
GitLab