From 65fac4819a313c8e9600229b998f0f842f32942a Mon Sep 17 00:00:00 2001
From: George Marchment <georgemarchment@yahoo.fr>
Date: Tue, 11 Feb 2025 13:38:57 +0100
Subject: [PATCH] Fixing some minors bugs

---
 src/emitted.py       | 2 +-
 src/include.py       | 2 +-
 src/nextflow_file.py | 1 +
 src/operation.py     | 6 +++++-
 src/workflow.py      | 6 +++++-
 5 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/emitted.py b/src/emitted.py
index 55142b0..c3534ad 100644
--- a/src/emitted.py
+++ b/src/emitted.py
@@ -45,7 +45,7 @@ class Emitted(Channel):
                         self.emits = o
         
         if(self.emits==None):
-            raise Exception(f"No emitted matched with '{name}' (in file '{self.get_file_address()}'). Should match with emittes from '{self.emitted_by.get_name()}' (in file '{self.emitted_by.get_file_address()}'")
+            raise Exception(f"No emitted matched with '{name}' (in file '{self.get_file_address()}'). Should match with emittes from '{self.emitted_by.get_first_element_called().get_name()}' (in file '{self.emitted_by.get_file_address()}'")
 
     def set_emits(self, input):
         thing_which_emits = self.emitted_by.get_first_element_called()
diff --git a/src/include.py b/src/include.py
index bfced50..fa11136 100644
--- a/src/include.py
+++ b/src/include.py
@@ -79,7 +79,7 @@ class Include(Nextflow_Building_Blocks):
                 found_file = True
 
         if(not found_file and os.path.isfile(address[:-3]+"/main.nf")):
-            self.nextflow_file = Nextflow_File(address[:-3]+"/main.nf", origin=self)
+            self.nextflow_file = Nextflow_File(address[:-3]+"/main.nf", workflow = self.nextflow_file_origin.get_workflow())
         
         #TODO -> check if the nextflow_file is defined somewhere else? 
         #In the cas the nextflow file is imported multiple times
diff --git a/src/nextflow_file.py b/src/nextflow_file.py
index 6095fd0..8a5ab63 100644
--- a/src/nextflow_file.py
+++ b/src/nextflow_file.py
@@ -25,6 +25,7 @@ class Nextflow_File(Nextflow_Building_Blocks):
         self.address = address 
         self.workflow = workflow
         self.first_file = first_file
+        self.main = None
         self.workflow.add_nextflow_file_2_workflow(self)
         self.includes = []
         self.processes = []
diff --git a/src/operation.py b/src/operation.py
index 96087ff..29d383f 100644
--- a/src/operation.py
+++ b/src/operation.py
@@ -500,7 +500,11 @@ class Operation(Executor):
                     emited = self.check_is_emit(name)
                     if(not emited):
                         #TODO -> check at what extend this is used
-                        channels = self.get_channels_same_level()+self.get_channels_above_level()+self.get_channels_inside_level()+self.get_channels_from_other_blocks_on_same_level()
+                        #This is just a trick so i don't have to specifically define the methods for subworkflows
+                        thing = self
+                        if(self.origin.get_type()=="Subworkflow"):
+                            thing = self.origin.root
+                        channels = thing.get_channels_same_level()+thing.get_channels_above_level()+thing.get_channels_inside_level()+thing.get_channels_from_other_blocks_on_same_level()
                         for c in channels:
                             if(c.get_name() in name):
                                 pos = [m.start() for m in re.finditer(c.get_name(), operation)]
diff --git a/src/workflow.py b/src/workflow.py
index 5faf0d6..cf52871 100644
--- a/src/workflow.py
+++ b/src/workflow.py
@@ -161,7 +161,11 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
         if(self.get_DSL() == "DSL1"):
             return self.get_structure_DSL1(dico=dico)
         elif(self.get_DSL() == "DSL2"):
-            return self.get_workflow_main().get_structure(dico)
+            main = self.get_workflow_main()
+            if(main!=None):
+                return self.get_workflow_main().get_structure(dico)
+            else:
+                return dico
             #return self.get_structure_DSL2(dico=dico, start = True)
         else:
             raise Exception(f"The workflow's DSL is '{self.DSL}' -> I don't know what this is!")
-- 
GitLab