From 9f1bffdc1af720c2561942db7bd42c4086c4d0b0 Mon Sep 17 00:00:00 2001 From: George Marchment <georgemarchment@yahoo.fr> Date: Sun, 4 Feb 2024 14:30:07 +0100 Subject: [PATCH] Starting to add Ro-crate support --- src/constant.py | 23 +++++++++++++++++++++++ src/process.py | 8 ++++++++ src/ro_crate.py | 14 ++++++++++++++ src/workflow.py | 25 +++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 src/ro_crate.py create mode 100644 src/workflow.py diff --git a/src/constant.py b/src/constant.py index 9badf13..f41e6ea 100644 --- a/src/constant.py +++ b/src/constant.py @@ -21,6 +21,27 @@ LIST_OPERATORS = ["distinct", "filter", "first", "last", "randomSample", "take", "close","dump","ifEmpty","print","println","set","view", "empty", "of", "fromPath", "fromList", "subscribe", "value", "from"]#This last line is added by me:) +TOOLS = [ + "samtools", + "bcftools", + "fastqc", + "bedtools", + "multiqc", + "gatk", + "bwa", + "minimap2", + "tabix", + "vcf", + "wget", + "bgzip", + "hmmsearch", + "pigz", + "picard", + "star", + "iqtree", + "idxstats", +] + #========================== # PATTERNS @@ -122,3 +143,5 @@ SUBWORKFLOW_HEADER = r'workflow +(\w+|\'[\w ]+\'|\"[\w ]+\") *{' WORKFLOW_HEADER = r"workflow\s*\{" WORKFLOW_HEADER_2 = r'[^\w](workflow\s*{)' + + diff --git a/src/process.py b/src/process.py index 8a94f27..7aee198 100644 --- a/src/process.py +++ b/src/process.py @@ -19,6 +19,7 @@ class Process(Nextflow_Building_Blocks): self.output_code = "" self.when_code = "" self.script_code = "" + self.tools = [] self.initialise() self.initialised = True @@ -71,6 +72,12 @@ class Process(Nextflow_Building_Blocks): def get_nb_outputs(self): return len(self.outputs) + def extract_tools(self): + script = self.script_code.lower() + for tool in constant.TOOLS: + if tool in script: + self.tools.append(tool) + def initialise_parts(self): code = self.get_code() @@ -126,6 +133,7 @@ class Process(Nextflow_Building_Blocks): 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!") diff --git a/src/ro_crate.py b/src/ro_crate.py new file mode 100644 index 0000000..e987fb7 --- /dev/null +++ b/src/ro_crate.py @@ -0,0 +1,14 @@ + + +class RO_Crate: + def __init__(self, workflow): + self.nextflow_file = workflow + self.directroy = '/'.join(workflow.get_file_address().split('/')[:-1]) + self.dico = {} + + def initialise_dico(self): + None + + def initialise(self): + self.initialise_dico() + print("i'm initialised") \ No newline at end of file diff --git a/src/workflow.py b/src/workflow.py new file mode 100644 index 0000000..5f700ae --- /dev/null +++ b/src/workflow.py @@ -0,0 +1,25 @@ + +from .nextflow_file import Nextflow_File +from .ro_crate import RO_Crate + + +class Workflow: + def __init__(self, file, duplicate=False, display_info=True): + self.nextflow_file = Nextflow_File(file, duplicate = duplicate, display_info = display_info) + self.rocrate = None + + + def get_file_address(self): + return self.nextflow_file.get_file_address() + + def initialise_rocrate(self): + self.rocrate = RO_Crate(self) + self.rocrate.initialise() + + + def initialise(self): + self.nextflow_file.initialise() + self.initialise_rocrate() + + def generate_all_graphs(self, render_graphs = True): + self.nextflow_file.generate_all_graphs(render_graphs = render_graphs) -- GitLab