From e5b0b0777ad14638801378f660c21febb6492046 Mon Sep 17 00:00:00 2001
From: George Marchment <georgemarchment@yahoo.fr>
Date: Wed, 26 Mar 2025 09:59:11 +0100
Subject: [PATCH] Small updates

---
 src/channel.py      |  2 +-
 src/outils_graph.py | 30 ++++++++++++++++++++-----
 src/process.py      | 53 ++++++++++++++++++++++++++-------------------
 3 files changed, 56 insertions(+), 29 deletions(-)

diff --git a/src/channel.py b/src/channel.py
index bcd76de..7ca4387 100644
--- a/src/channel.py
+++ b/src/channel.py
@@ -22,7 +22,7 @@ class Channel(Nextflow_Building_Blocks):
         for m in self.get_modules_defined():
             to_call.append(m.get_alias())
         if(self.name in to_call):
-            raise BioFlowInsightError(f"'{self.name}' is trying to be created as a channel{self.get_string_line(self.origin.get_code())}. It already exists as a process or a subworkflow in the nextflow file.", num = 4, origin=self)
+            raise BioFlowInsightError(f"'{self.name}' is trying to be created as a channel{self.get_string_line(self.origin.get_code())}. It already exists as a process, a function or a subworkflow in the nextflow file.", num = 4, origin=self)
         
 
 
diff --git a/src/outils_graph.py b/src/outils_graph.py
index eee7ab3..54cec76 100644
--- a/src/outils_graph.py
+++ b/src/outils_graph.py
@@ -1168,14 +1168,32 @@ def check_if_equal(dicoA, dicoB):
         translated["subworkflows"] = {}
         rewrite(dico, translated)
         return translated
-        
+    
+    translated_new, translated_original = translate_dico(dicoA), translate_dico(dicoB)
     #TO do that we rewrite the structure using a commun language (without using the ids) -> then just check if the translated structures are the same
-    equal = translate_dico(dicoA) ==translate_dico(dicoB)
+    equal = translated_new == translated_original
     if(not equal):
         #TODO -> make a better affichage des differences
-        print(translate_dico(dicoA))
-        print(translate_dico(dicoB))
-        print()
+        if(translated_new['nodes']!=translated_original["nodes"]):
+            diff = list(set(translated_original['nodes']) - set(translated_new['nodes']))
+            if(diff!=[]):
+                print(f"The processes {diff} are missing from the new workflow")
+            diff = list(set(translated_new['nodes']) - set(translated_original['nodes']))
+            if(diff!=[]):
+                print(f"The processes {diff} have been added to the new workflow")
+
+        if(translated_new['edges']!=translated_original["edges"]):
+            edges_new, edges_original = [], []
+            for e in translated_original['edges']:
+                edges_original.append(str(e))
+            for e in translated_new['edges']:
+                edges_new.append(str(e))
+            diff = list(set(edges_original) - set(edges_new))
+            if(diff!=[]):
+                print(f"The edges {diff} are missing from the new workflow")
+            diff = list(set(edges_new) - set(edges_original))
+            if(diff!=[]):
+                print(f"The edges {diff} have been added to the new workflow")
     return equal
 
 #This function removes the artificial nodes from the dico
@@ -1212,7 +1230,7 @@ def remove_artificial_nodes(param_dico):
             if(e["A"]==node_id):
                 links["sink"].append({"sink": e["B"], "label": e["label"]})
                 to_remove.append(e)
-            if(e["B"]==node_id):
+            elif(e["B"]==node_id):
                 links["source"].append({"source": e["A"], "label": e["label"]})
                 to_remove.append(e)
         for e in to_remove:
diff --git a/src/process.py b/src/process.py
index f54bbd0..d4edcb6 100644
--- a/src/process.py
+++ b/src/process.py
@@ -33,6 +33,7 @@ class Process(Nextflow_Building_Blocks):
         self.called_by = []#List of calls
         self.initialised = False
         self.number_times_copied = 0
+        self.initialise_name()
 
 
     def copy(self):
@@ -208,29 +209,37 @@ class Process(Nextflow_Building_Blocks):
 
         positions = [publishDir_pos, input_pos, output_pos, when_pos, script_pos]
         variables_index = ['pusblishDir', 'input', 'output', 'when', 'script']
-        positions, variables_index = sort_and_filter(positions, variables_index)
+        if(positions!=[(0, 0), (0, 0), (0, 0), (0, 0), (0, 0)]):
+            positions, variables_index = sort_and_filter(positions, variables_index)
         
 
-        for i in range(len(positions)):
-            temp_code = ""
-            if(i==len(positions)-1):
-                temp_code =  code[positions[i][1]:code.rfind('}')].strip()
-            else:
-                temp_code =  code[positions[i][1]:positions[i+1][0]].strip()
-            
-            if(variables_index[i]=='input'):
-                self.input_code = temp_code
-            elif(variables_index[i]=='output'):
-                self.output_code = temp_code
-            elif(variables_index[i]=='pusblishDir'):
-                self.pusblishDir_code = temp_code
-            elif(variables_index[i]=='when'):
-                self.when_code = temp_code
-            elif(variables_index[i]=='script'):
-                self.script_code = temp_code
-                #self.extract_tools()
-            else:
-                raise Exception("This shoudn't happen!")
+            for i in range(len(positions)):
+                temp_code = ""
+                if(i==len(positions)-1):
+                    temp_code =  code[positions[i][1]:code.rfind('}')].strip()
+                else:
+                    temp_code =  code[positions[i][1]:positions[i+1][0]].strip()
+                
+                if(variables_index[i]=='input'):
+                    self.input_code = temp_code
+                elif(variables_index[i]=='output'):
+                    self.output_code = temp_code
+                elif(variables_index[i]=='pusblishDir'):
+                    self.pusblishDir_code = temp_code
+                elif(variables_index[i]=='when'):
+                    self.when_code = temp_code
+                elif(variables_index[i]=='script'):
+                    self.script_code = temp_code
+                    #self.extract_tools()
+                else:
+                    raise Exception("This shoudn't happen!")
+        else:
+            self.input_code = ""
+            self.output_code = ""
+            self.pusblishDir_code = ""
+            self.when_code = ""
+            self.script_code = ""
+
 
 
     #Method that returns the input part of the process code
@@ -449,7 +458,7 @@ class Process(Nextflow_Building_Blocks):
     def initialise(self):
         if(not self.initialised):
             self.initialised = True
-            self.initialise_name()
+            
             self.initialise_parts()
             self.initialise_inputs_outputs()
 
-- 
GitLab