diff --git a/src/call.py b/src/call.py index 99e9f174eeae43224614d92a8ebf3c503e033c30..b117605ca15a89da80ed9ef25f10f0c02b92624e 100644 --- a/src/call.py +++ b/src/call.py @@ -14,11 +14,12 @@ class Call(Executor): def __init__(self, code, origin, OG_code = ''): self.code = Code(code = code, origin = self) self.origin = origin - self.condition = Condition(self) self.called = [] self.first_element_called = None self.parameters = []#These are in the order self.OG_code = OG_code + #It's important this is last + self.condition = Condition(self) def __str__(self): return f"Call_{id(self)}" diff --git a/src/condition.py b/src/condition.py index 22c4884c2d34125fffadc014f23b76695fcc2316..da5da0301ca34a45697ed8bde016bbeff2520940 100644 --- a/src/condition.py +++ b/src/condition.py @@ -9,18 +9,19 @@ class Condition: def initialise(self): - thing_defined = self.origin.get_code() + thing_defined = self.origin.get_code(get_OG=True) code = self.origin.get_workflow_code() #print(f"'{thing_defined}'") #print(f"'{code}'") - conditions_dico = extract_conditions(code) + conditions_dico = self.origin.get_file_conditions() pos = code.find(thing_defined) for c in conditions_dico: condition_extend = conditions_dico[c] if(condition_extend[0]<pos and pos<condition_extend[1]): self.conditions.append(c) + #print(conditions_dico) print(thing_defined, self.conditions) - print() + #print() diff --git a/src/nextflow_building_blocks.py b/src/nextflow_building_blocks.py index 15e7d5d0ffced41e92918274ed0c41d1e6c8a25f..7d82334f88526266f7ade7e918ecb8dc36bd1af6 100644 --- a/src/nextflow_building_blocks.py +++ b/src/nextflow_building_blocks.py @@ -130,6 +130,10 @@ class Nextflow_Building_Blocks: def get_workflow_code(self): return self.origin.get_workflow_code() + + def get_file_conditions(self): + #print(self) + return self.origin.get_file_conditions() #---------------------- #CHANNELS diff --git a/src/nextflow_file.py b/src/nextflow_file.py index 9a7e0b08f972e36bc7cdffadb1c874d7b6bafdb9..e199cf541b3dd6dc8f2ed19fec2f516d9eb38ad0 100644 --- a/src/nextflow_file.py +++ b/src/nextflow_file.py @@ -13,7 +13,7 @@ from . import constant warnings.filterwarnings("ignore") from .nextflow_building_blocks import Nextflow_Building_Blocks -from .outils import extract_curly, get_curly_count, get_parenthese_count, get_dico_from_tab_from_id, check_file_exists +from .outils import extract_curly, get_curly_count, get_parenthese_count, get_dico_from_tab_from_id, check_file_exists, extract_conditions from .bioflowinsighterror import BioFlowInsightError @@ -37,6 +37,7 @@ class Nextflow_File(Nextflow_Building_Blocks): if(self.first_file==True): self.origin.set_DSL(self.which_DSL()) self.graph = None + self.conditions = extract_conditions(self.get_code()) self.added_2_rocrate = False self.check_file_correctness() @@ -45,6 +46,7 @@ class Nextflow_File(Nextflow_Building_Blocks): self.check_file_correctness_after_DSL() self.set_null() + def get_name_file(self): name = self.get_file_address().split('/')[-1] return name[:-3] @@ -52,6 +54,10 @@ class Nextflow_File(Nextflow_Building_Blocks): def get_workflow_code(self): return self.get_code() + def get_file_conditions(self): + return self.conditions + + def check_file_correctness(self): code = self.get_code() if(code.count("{")!=code.count("}")): diff --git a/src/operation.py b/src/operation.py index 8fc7bf44727838e9009b163e1a71e2512502d386..6cdc9556e744c47e1080160cea373c7c27f86ec4 100644 --- a/src/operation.py +++ b/src/operation.py @@ -26,6 +26,8 @@ class Operation(Executor): self.OG_code = OG_code self.show_in_structure = True self.operation_type = None + #It's important this is last + self.condition = Condition(self) def change_code(self, code): self.code = Code(code, origin = self) diff --git a/src/outils.py b/src/outils.py index a207b254f97f63670a67c9d535bd9496dc43a4d7..c4004c6b6090063da174658907b13cac66cefbcd 100644 --- a/src/outils.py +++ b/src/outils.py @@ -988,34 +988,53 @@ def extract_conditions(code): return conditions_dico #Just because there is an 'if' doesn't necessarily mean there is an if bloc found_if_bloc = False + conditions = [] if(code[start:start+2]=="if" and [quote_single, quote_double, triple_single, triple_double]==[False, False, False, False]): + for match in re.finditer(r"if *\((.+)\)\s*\{", code[start:]): if(match.span(0)[0]==0): found_if_bloc = True condition = match.group(1) + conditions.append(condition) end = extract_curly(code, match.span(0)[1]+start)#Here we nedd to add the start index since we're only working on a subpart of code conditions_dico[condition] = (start,end) start_inside, end_inside = match.span(0)[1]+start, end-1 conditions_dico = adding_inside(conditions_dico, code, start_inside, end_inside) break - #Try to find an else corresponding - if(found_if_bloc and code[end:].strip()[:4]=="else"): - #print("corresponding else") - for match in re.finditer(r"else\s*{", code[end:]): - start_else, end_else = match.span(0) - start_else+=end - end_else = extract_curly(code, end_else+end) - conditions_dico[f"neg({condition})"] = (start_else,end_else) - start_inside, end_inside = match.span(0)[1]+start, end_else-1 - conditions_dico = adding_inside(conditions_dico, code, start_inside, end_inside) - #print(code[start_else:end_else]) - break - #Case we need to jump to the end of the else - start = end_else-1 - else: - if(found_if_bloc): - #Case we need to jump to the end of the if - start = end-1 + searching_for_else = True + while(searching_for_else): + searching_for_else = False + #Try to find an else corresponding + if(found_if_bloc and code[end:].strip()[:4]=="else"): + found_else_if = False + #CASE of "else if" + for match in re.finditer(r"else *if *\((.+)\)\s*\{", code[end:]): + found_else_if = True + searching_for_else = True + condition = match.group(1) + conditions.append(condition) + start_else, end_else = match.span(0) + start_else+=end + end_else = extract_curly(code, end_else+end) + conditions_dico[condition] = (start_else,end_else) + start_inside, end_inside = match.span(0)[1]+end, end_else-1 + conditions_dico = adding_inside(conditions_dico, code, start_inside, end_inside) + break + #CASE of "else" + if(not found_else_if): + for match in re.finditer(r"else\s*{", code[end:]): + start_else, end_else = match.span(0) + start_else+=end + end_else = extract_curly(code, end_else+end) + conditions_dico[' && '.join(["neg({})".format(v) for v in conditions])] = (start_else,end_else) + start_inside, end_inside = match.span(0)[1]+end, end_else-1 + conditions_dico = adding_inside(conditions_dico, code, start_inside, end_inside) + #print(code[start_else:end_else]) + break + end = end_else + if(found_if_bloc): + #Case we need to jump to the end of the if + start = end-1 start+=1 return conditions_dico diff --git a/src/process.py b/src/process.py index 464852351c13675f117a60f5ac6e1cd4f5b40203..3de0822144a1e7ad6948704536ab2c1545e3d5a3 100644 --- a/src/process.py +++ b/src/process.py @@ -2,6 +2,7 @@ import re import glob from .code_ import Code +from .condition import Condition from .nextflow_building_blocks import Nextflow_Building_Blocks from .outils import remove_jumps_inbetween_parentheses, remove_jumps_inbetween_curlies, sort_and_filter, get_dico_from_tab_from_id, check_if_element_in_tab_rocrate, get_python_packages, get_R_libraries, get_perl_modules from .bioflowinsighterror import BioFlowInsightError @@ -27,6 +28,8 @@ class Process(Nextflow_Building_Blocks): self.external_scripts = [-1] self.initialise() self.initialised = True + ##It's important this is last + #self.condition = Condition(self) def set_alias(self, alias): self.alias = alias