From e7e30586dd28a35ab2b4d6bc87b7d453bdded8ed Mon Sep 17 00:00:00 2001
From: George Marchment <georgemarchment@yahoo.fr>
Date: Tue, 1 Apr 2025 11:08:51 +0200
Subject: [PATCH] Update the "get_code" fnction for operations ->  when the
 option 'get_OG' is true -> it remove the added "e:" or "t:" + updated the
 detection of the duplicates to only consider operations (since calls are
 renamed anyway)

---
 src/main.py      | 8 +++++---
 src/operation.py | 5 +++++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/main.py b/src/main.py
index 7f1f38b..ac73acc 100644
--- a/src/main.py
+++ b/src/main.py
@@ -20,8 +20,9 @@ class Main(Nextflow_Building_Blocks):
         pos = {}
         for e in executors:
             code = e.get_code(get_OG = True)
-            if(code in seen):
-                raise BioFlowInsightError(f'Executor "{code}" appears twice in the workflow in the exact same way. BioFlow-Insight cannot rewrite the workflow then, try slighly changing how one of the executors is defined')
+            #We don't have to check the calls -> since there are renamed with their ids when we rewrite the code -> so it solve the issue
+            if(code in seen and e.get_type()=="Operation"):
+                raise BioFlowInsightError(f'Operation "{code}" appears twice in the workflow in the exact same way. BioFlow-Insight cannot rewrite the workflow then, try slighly changing how one of the executors is defined')
             seen[code] = ''
             pos[e] = e.get_position_in_main(e)
         #TODO add sort here
@@ -54,12 +55,13 @@ 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(remove_emit_and_take = True, replace_calls = False)
+                old = exe.get_code(get_OG = True, remove_emit_and_take = True, replace_calls = False)
                 new = exe.simplify_code(return_tab = False)
                 if(new!=old):
                     temp = code
                     code = code.replace(old, new, 1)
                     if(temp==code):
+                        print(exe)
                         print(code)
                         print("- old", f'"{old}"')
                         print("- new", f'"{new}"')
diff --git a/src/operation.py b/src/operation.py
index ea2188b..42ddcf3 100644
--- a/src/operation.py
+++ b/src/operation.py
@@ -698,10 +698,15 @@ class Operation(Executor):
 
 
     def get_code(self, replace_calls = True, clean_pipe = False, get_OG=False, remove_emit_and_take = False):
+        #exe.get_code(remove_emit_and_take = True, replace_calls = False)
         code = self.code.get_code()
         if(get_OG):
             if(self.OG_code!=""):
                 code = self.OG_code
+            if(code[:3] in ["e: ", "t: "] and self.get_artificial_status()):
+                #print("-", code)
+                code = code[3:]
+                code = code.strip()
             return code
             
         if(clean_pipe):
-- 
GitLab