From c2123ddde2f035fa9ef27acb8dbc0d408ddc017f Mon Sep 17 00:00:00 2001
From: George Marchment <georgemarchment@yahoo.fr>
Date: Tue, 19 Mar 2024 12:12:21 +0100
Subject: [PATCH] update

---
 README.md            |  2 +-
 src/call.py          |  3 +++
 src/main_DSL2.py     | 11 +++++++++++
 src/nextflow_file.py | 19 +++++++++++++++++--
 src/operation.py     |  5 +++++
 src/workflow.py      | 25 +++++++++++++++++++++++++
 6 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 3596897..42dbd76 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
 # BioFlow-Insight
 
 
-[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-green.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Version 1.0](https://img.shields.io/badge/version-v1.0-yellow)]() [![Zenodo doi badge](https://img.shields.io/badge/DOI-10.5281%2Fzenodo.10818333-blue.svg)](https://zenodo.org/uploads/10818333) 
+[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-green.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Version 1.0](https://img.shields.io/badge/version-v1.0-yellow)]()
 
 
 
diff --git a/src/call.py b/src/call.py
index 826778d..0ae3d38 100644
--- a/src/call.py
+++ b/src/call.py
@@ -53,6 +53,9 @@ class Call(Executor):
         for para in self.parameters:
             if(para.get_type()=="Call"):
                 tab = para.get_elements_called(tab_input = tab.copy(), first_call = False)
+            elif(para.get_type()=="Operation"):
+                tab += para.get_elements_called(tab = tab.copy())
+
         temp = list(set(tab))
         #del tab
         return temp
diff --git a/src/main_DSL2.py b/src/main_DSL2.py
index cb82f41..e882493 100644
--- a/src/main_DSL2.py
+++ b/src/main_DSL2.py
@@ -42,6 +42,17 @@ class Main_DSL2(Nextflow_Building_Blocks):
     def get_process_from_name(self, name):
         return self.origin.get_process_from_name(name)
     
+    def get_processes_called(self, tab = []):
+
+        for c in self.get_all_called():
+            if(c.get_type()=="Process"):
+                tab.append(c)
+            elif(c.get_type()=="Subworkflow"):
+                tab+=c.get_processes_called()
+        
+        return list(set(tab))
+
+
     def get_function_from_name(self, name):
         return self.origin.get_function_from_name(name) 
     
diff --git a/src/nextflow_file.py b/src/nextflow_file.py
index 740bd4e..f23e39a 100644
--- a/src/nextflow_file.py
+++ b/src/nextflow_file.py
@@ -295,8 +295,23 @@ class Nextflow_File(Nextflow_Building_Blocks):
         return None
         raise Exception(f"Process '{name}' couldn't be found in '{self.get_file_address()}'")
 
-    def get_number_processes(self):
-        return len(self.processes)
+
+    def get_processes_defined(self, tab = []):
+        tab+= super().get_processes()
+        for include in self.includes:
+            tab+=include.get_file().get_processes_defined()
+        return list(set(tab))
+
+
+    def get_processes_called(self, tab = []):
+        if(self.get_DSL()=="DSL1"):
+            return self.get_processes()
+        elif(self.get_DSL()=="DSL2"):
+            return self.main.get_processes_called()
+        else:
+            raise Exception("This shouldn't happen!")
+
+
 
 
     #----------------------
diff --git a/src/operation.py b/src/operation.py
index 8f7b1e5..8927f0b 100644
--- a/src/operation.py
+++ b/src/operation.py
@@ -62,6 +62,11 @@ class Operation(Executor):
     def add_channel(self, channel):
         self.origin.add_channel(channel)   
 
+    def get_elements_called(self, tab = []):
+        for o in self.origins:
+            if(o.get_type()=="Call"):
+                tab+=o.get_elements_called()
+        return tab
 
 
     def add_origin_channel(self, name):
diff --git a/src/workflow.py b/src/workflow.py
index db2d7a3..f458b40 100644
--- a/src/workflow.py
+++ b/src/workflow.py
@@ -7,6 +7,10 @@ import os
 import re
 import json
 from pathlib import Path
+import glob
+
+from .bioflowinsighterror import BioFlowInsightError
+
 
 
 class Workflow:
@@ -15,6 +19,19 @@ class Workflow:
                  license = None, creativeWorkStatus = None, authors = None, 
                  version = None, keywords = None, producer = None,
                  publisher = None, processes_2_remove = None):
+        print("here")
+        if(not os.path.isfile(file)):
+            nextflow_files = glob.glob(f'{file}/*.nf')
+            if(len(nextflow_files)==0):
+                raise BioFlowInsightError("No Nextflow files ('.nf') are in the directory!", num = -1)
+            try:
+                file = '/'.join(nextflow_files[0].split('/')[:-1])+"/main.nf"
+                with open(file, 'r') as f:
+                        txt= f.read()
+            except:
+                file =nextflow_files[0]
+
+
         self.nextflow_file = Nextflow_File(
             file,
             duplicate=duplicate,
@@ -207,6 +224,14 @@ class Workflow:
     def add_2_rocrate(self, dico):
         self.nextflow_file.add_2_rocrate(dico)
 
+    def get_processes_defined(self):
+        return self.nextflow_file.get_processes_defined()
+    
+    def get_processes_called(self):
+        return self.nextflow_file.get_processes_called()
+
+
+
     def initialise_rocrate(self):
         self.rocrate = RO_Crate(self)
         self.rocrate.initialise()
-- 
GitLab