From 96d9a7176ea026e88060f32b3befc3ae0e73c4ad Mon Sep 17 00:00:00 2001
From: George Marchment <georgemarchment@yahoo.fr>
Date: Wed, 19 Mar 2025 15:58:41 +0100
Subject: [PATCH] Fixed problem with the remove spaces between \. and the jump
 lines -> it only worked in the case of a single line

---
 src/call.py      |  2 +-
 src/code_.py     |  2 +-
 src/main.py      |  7 +++++--
 src/operation.py | 20 ++++++++------------
 4 files changed, 15 insertions(+), 16 deletions(-)

diff --git a/src/call.py b/src/call.py
index 6361913..604564b 100644
--- a/src/call.py
+++ b/src/call.py
@@ -52,7 +52,7 @@ class Call(Executor):
     def get_parameters(self):
         return self.parameters
 
-    def get_code(self, clean_pipe = False, get_OG=False):
+    def get_code(self, clean_pipe = False, get_OG=False, remove_emit_and_take = False):
         if(get_OG):
             if(self.OG_code==''):
                 return self.code.get_code()
diff --git a/src/code_.py b/src/code_.py
index 7d734dc..f9ea145 100644
--- a/src/code_.py
+++ b/src/code_.py
@@ -152,7 +152,7 @@ class Code:
         return code
 
     def rewrite_jump_dot(self, code):
-        pattern = r"\n *\."
+        pattern = r"(\n *)+\."
         code = re.sub(pattern, '.', code)
         return code
 
diff --git a/src/main.py b/src/main.py
index 0239858..0cec5f5 100644
--- a/src/main.py
+++ b/src/main.py
@@ -50,13 +50,16 @@ class Main(Nextflow_Building_Blocks):
         
         for exe in sorted_executor_2_length:
             if(exe.get_type()=="Call" or exe.get_type()=="Operation"):
-                old = exe.get_code(get_OG = True)
+                old = exe.get_code(get_OG = True, remove_emit_and_take = True)
                 new = exe.simplify_code()
                 if(new!=old):
                     temp = code
                     code = code.replace(exe.get_code(get_OG = True), exe.simplify_code(), 1)
                     if(temp==code):
-                        raise Exception("This shouldn't happen the Exeutor was not replaced")
+                        print(code)
+                        print("- old", f'"{old}"')
+                        print("- new", f'"{new}"')
+                        raise Exception("This shouldn't happen the Executor was not replaced")
             else:
                 raise Exception("This shouldn't happen")
         return code
diff --git a/src/operation.py b/src/operation.py
index 62a1a97..46fa2c1 100644
--- a/src/operation.py
+++ b/src/operation.py
@@ -689,22 +689,22 @@ class Operation(Executor):
         file.close()
 
 
-    def get_code(self, replace_calls = True, clean_pipe = False, get_OG=False):
+    def get_code(self, replace_calls = True, clean_pipe = False, get_OG=False, remove_emit_and_take = False):
         code = self.code.get_code()
         if(get_OG):
             if(self.OG_code!=""):
-                return self.OG_code
-            else:
-                return code
-
-        
-
+                code = self.OG_code
         if(clean_pipe):
             code, self.dico_OG_call_2_new_call = self.clean_pipe_operator(code)
   
         if(replace_calls):
             for call in self.calls:
                 code = code.replace(self.calls[call].get_code(), str(call))
+        
+        #Remove "emit:" and "takes:" for the subworkklfow inputs and outputs
+        if(remove_emit_and_take and code[:6] in ["emit: ", "take: "]):
+            code = code[6:]
+            code = code.strip()
             
         return code
     
@@ -923,11 +923,7 @@ class Operation(Executor):
     
     #Method that rewrites operations to simplify it -> decompose it into multiple line -> to be able to manipulate the calls in a easier way
     def simplify_code(self):
-        code = self.get_code(replace_calls =False, clean_pipe=True)
-        #Remove "emit:" and "takes:" for the subworkklfow inputs and outputs
-        if(code[:6] in ["emit: ", "take: "]):
-            code = code[6:]
-            code = code.strip()
+        code = self.get_code(replace_calls =False, clean_pipe=True, remove_emit_and_take=True)
         #code = self.get_code(get_OG=True)
         index = 1
         operation_id = str(self)[-7:-2]
-- 
GitLab