From b1fd31f132b9fa98a5de11077db794360bbaf67a Mon Sep 17 00:00:00 2001
From: George Marchment <georgemarchment@yahoo.fr>
Date: Mon, 8 Jul 2024 15:46:19 +0200
Subject: [PATCH] fix minor bug

---
 src/operation.py | 26 +++++++++++++++++++++++++-
 src/process.py   |  3 +++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/operation.py b/src/operation.py
index 8927f0b..47a9fd3 100644
--- a/src/operation.py
+++ b/src/operation.py
@@ -739,6 +739,13 @@ class Operation(Executor):
     def check_if_empty_call(self):
         return self.get_code()==""
     
+    #This method returns the element which is defined after the call
+    def get_element_after_call(self, call):
+        for match in re.finditer(str(call)+r"\s*\.\s*(\w+)\s*\.", self.get_code()):
+            return match.group(1)
+
+
+    
 
 
     def initialise_from_call(self):
@@ -806,7 +813,24 @@ class Operation(Executor):
                         if(sub.get_nb_emit()==0):
                             raise BioFlowInsightError(f"The subworkflow '{sub.get_name()}' doesn't emit anything. It is given to an operation{self.get_string_line(call.get_code())}.", num=20, origin=self)
                         elif(sub.get_nb_emit()>1):
-                            raise BioFlowInsightError(f"To much to unpack : The subworkflow '{sub.get_name()}' emits over one channel in a operation{self.get_string_line(call.get_code())}.", num=20, origin=self)
+                            #In the case test().a.view() and test is a subworkflow
+                            added = False
+                            element_after_call = self.get_element_after_call(o)
+                            emits = sub.get_emit()
+                            for e in emits:
+                                if(e.get_gives()==[]):
+                                    for o in e.get_origins():
+                                        if(o.get_code()==element_after_call):
+                                            dico["edges"].append({'A':str(e), 'B':str(self), "label":e.get_code()})
+                                            added =True
+                                else:
+                                    for g in e.get_gives():
+                                        if(g.get_code()==element_after_call):
+                                            dico["edges"].append({'A':str(e), 'B':str(self), "label":e.get_code()})
+                                            added =True
+                            
+                            if(not added):
+                                raise BioFlowInsightError(f"To much to unpack : The subworkflow '{sub.get_name()}' emits over one channel in a operation{self.get_string_line(call.get_code())}.", num=20, origin=self)
                             #TODO recommendation -> try using an emit subworkflow.out
                         else:
                             emit = sub.get_emit()[0]
diff --git a/src/process.py b/src/process.py
index 12b3eea..ef3d222 100644
--- a/src/process.py
+++ b/src/process.py
@@ -31,6 +31,9 @@ class Process(Nextflow_Building_Blocks):
     def get_alias(self):
         return self.alias
     
+    def get_script_code(self):
+        return self.script_code
+    
     def get_name(self):
         return self.name
     
-- 
GitLab