From e614041d6153821e06a002a44e372ac357ebf4e4 Mon Sep 17 00:00:00 2001
From: George Marchment <georgemarchment@yahoo.fr>
Date: Thu, 17 Apr 2025 11:10:28 +0200
Subject: [PATCH] Added filter -> i cannot rewrite a workflow in which there is
 a circular loop with the calls : 'ch = call(ch)' or 'call(ch)\n ch =
 call.out'

---
 src/operation.py | 19 +++++++++++++++++++
 src/outils.py    |  4 +++-
 src/workflow.py  |  2 ++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/operation.py b/src/operation.py
index 37c20af..bd5a006 100644
--- a/src/operation.py
+++ b/src/operation.py
@@ -28,6 +28,7 @@ class Operation(Executor):
         self.operation_type = None
         #Artificial means that it is created by the analysis -> it is not native in the code
         self.artificial = False
+        self.create_loop_with_call = False
         #It's important this is last
         #self.condition = Condition(self)
 
@@ -42,6 +43,8 @@ class Operation(Executor):
         return self.artificial
 
 
+    def get_create_loop_with_call_status(self):
+        return self.create_loop_with_call
 
     def add_element_gives(self, ele):
         self.gives.append(ele)
@@ -815,6 +818,21 @@ class Operation(Executor):
         else:
             return False
 
+    #This method is to flag cases of ch = call(ch) or call(ch)\n ch = emit.call.out
+    def check_that_operation_does_not_create_loop_with_call(self):
+        for o in self.origins:
+            if(o.get_type()=='Call' or o.get_type()=='Emitted'):
+                if(o.get_type()=='Emitted'):
+                    call = o.emitted_by
+                else:
+                    call = o
+                for param in call.get_parameters():
+                    for g in self.gives:
+                        if(g.get_code(get_OG = True)==param.get_code(get_OG = True)):
+                            self.create_loop_with_call = True
+                
+
+
     def initialise(self):
         #If the operation is a double dot consition thing
         if(self.check_if_double_dot()):
@@ -825,6 +843,7 @@ class Operation(Executor):
             self.extract_calls()
             self.initialise_origins()
             self.initialise_gives()
+            self.check_that_operation_does_not_create_loop_with_call()
 
         self.write_summary(self.get_output_dir() / "debug/operations.nf")
         
diff --git a/src/outils.py b/src/outils.py
index 83b420f..1cb9190 100644
--- a/src/outils.py
+++ b/src/outils.py
@@ -1355,7 +1355,9 @@ def get_channels_to_add_in_false_conditions(body, emitted_channels):
         #For the remaining condition in the list -> need to create an empty channel in the case of the negation
         for condition in channels_2_conditions[channel]:
             condition = condition.split("$$__$$")[0]
-            body += f"\nif(!({condition})) {{\n{channel} = Channel.empty()\n}}"
+            #TODO -> check this doesn't fuck anything up -> see number 75
+            #Originally it is not commented
+            #body += f"\nif(!({condition})) {{\n{channel} = Channel.empty()\n}}"
     
     return body
 
diff --git a/src/workflow.py b/src/workflow.py
index 27a2fd9..3aacb38 100644
--- a/src/workflow.py
+++ b/src/workflow.py
@@ -1081,6 +1081,8 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
                     tab = []
                     for ele in c:
                         if(ele.get_type()=="Operation"):
+                            if(ele.get_create_loop_with_call_status()):
+                                raise BioFlowInsightError(f'BioFlow-Insight cannot rewrite the workflows since the operation "{ele.get_code(get_OG = True)}" creates the channel on which it depends.', type="Rewrite Error")
                             if(ele.get_artificial_status()==False):
                                 tab.append(ele)
                         else:
-- 
GitLab