Skip to content
Snippets Groups Projects
Commit fec4dbd5 authored by George Marchment's avatar George Marchment
Browse files

Updated the position of subworkflow calls + changed topological order to order...

Updated the position of subworkflow calls + changed topological order to order of definition in the code
parent 964230af
No related branches found
No related tags found
No related merge requests found
Pipeline #14388 failed with stage
in 2 minutes and 28 seconds
...@@ -81,6 +81,13 @@ class Executor(Nextflow_Building_Blocks): ...@@ -81,6 +81,13 @@ class Executor(Nextflow_Building_Blocks):
def get_channels_from_name_all_channels(self, name): def get_channels_from_name_all_channels(self, name):
return self.origin.get_channels_from_name_all_channels(name) return self.origin.get_channels_from_name_all_channels(name)
def get_position_in_main(self, executor):
return self.origin.get_position_in_main(executor)
def get_subworkflow_calls_to_get_here(self, executor):
return self.origin.get_subworkflow_calls_to_get_here(executor)
def get_channels_from_name_other_blocks_on_same_level(self, name): def get_channels_from_name_other_blocks_on_same_level(self, name):
return self.origin.get_channels_from_name_other_blocks_on_same_level(name) return self.origin.get_channels_from_name_other_blocks_on_same_level(name)
......
...@@ -15,6 +15,29 @@ class Main(Nextflow_Building_Blocks): ...@@ -15,6 +15,29 @@ class Main(Nextflow_Building_Blocks):
self.initialised = False self.initialised = False
self.root = None self.root = None
def get_order_execution_executors(self, dico):
executors = self.get_all_executors_in_subworkflow()
pos = {}
for e in executors:
pos[e] = e.get_position_in_main(e)
#TODO add sort here
pos = {k: v for k, v in sorted(pos.items(), key=lambda item: item[1])}
for e in pos:
if(e.get_type()=="Call"):
if(e.get_first_element_called().get_type()=="Subworkflow"):
dico[e] = {}
e.get_first_element_called().get_order_execution_executors(dico[e])
else:
dico[e.get_first_element_called()] = pos[e]
else:
dico[e] = pos[e]
return dico
def get_position_in_main(self, executor):
code = self.get_code()
return code.find(executor.get_code(get_OG = True))
def get_string_line(self, bit_of_code): def get_string_line(self, bit_of_code):
return self.nextflow_file.get_string_line(bit_of_code) return self.nextflow_file.get_string_line(bit_of_code)
......
...@@ -27,6 +27,19 @@ class Root(Nextflow_Building_Blocks): ...@@ -27,6 +27,19 @@ class Root(Nextflow_Building_Blocks):
def get_type(self): def get_type(self):
return "Root" return "Root"
def get_position_in_main(self, executor):
return self.origin.get_position_in_main(executor)
def get_subworkflow_calls_to_get_here(self, executor):
if(self.origin.get_type()=="Main"):
return []
elif(self.origin.get_type() in ["Block", "Root"]):
return self.origin.get_subworkflow_calls_to_get_here(executor)
#Case subworkflow
else:
call = self.origin.get_call()
return [call]+call.get_subworkflow_calls_to_get_here(executor)
def get_blocks(self): def get_blocks(self):
return self.blocks return self.blocks
......
...@@ -398,6 +398,22 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen ...@@ -398,6 +398,22 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
else: else:
raise BioFlowInsightError("Trying to generate random relevant processes however option 'duplicate' is not activated.") raise BioFlowInsightError("Trying to generate random relevant processes however option 'duplicate' is not activated.")
#Method that returns the order of execution for each executor
def get_order_execution_executors(self):
dico = {}
dico = self.get_workflow_main().get_order_execution_executors(dico)
tab = []
def explore_dico(dico):
if(type(dico)!=dict):
None
else:
for val in dico:
tab.append(val)
explore_dico(dico[val])
explore_dico(dico)
return tab
#This method rewrites the entire workflow into one single file #This method rewrites the entire workflow into one single file
def write_workflow_into_one_file(self): def write_workflow_into_one_file(self):
#This tag is used as an identification to safely manipulate the string #This tag is used as an identification to safely manipulate the string
...@@ -723,7 +739,16 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen ...@@ -723,7 +739,16 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
# if(len(c)>1): # if(len(c)>1):
# clusters[i] = self.nextflow_file.graph.get_induced_subgraph(c) # clusters[i] = self.nextflow_file.graph.get_induced_subgraph(c)
#Get the topological order #Get the topological order
clusters = self.graph.get_topogical_order(clusters) executors_in_order = self.get_order_execution_executors()
new_clusters = []
for cluster in clusters:
tab = []
for e in executors_in_order:
if(e in cluster):
tab.append(e)
new_clusters.append(tab)
clusters = new_clusters
#clusters = self.graph.get_topogical_order(clusters)
...@@ -746,6 +771,21 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen ...@@ -746,6 +771,21 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
if(len(elements)>1 and at_least_one_process): if(len(elements)>1 and at_least_one_process):
name, body, take, emit = "", "", "", "" name, body, take, emit = "", "", "", ""
first_element = True first_element = True
def get_last_operation_or_call(elements):
index = -1
while(True):
if(elements[index].get_type()=="Process"):
return elements[index].get_call()
else:
if(not elements[index].get_artificial_status()):
return elements[index]
else:
index = index-1
anker_thing = get_last_operation_or_call(elements).get_code(get_OG = True)
code = code.replace(anker_thing, f"//Anker_cluster{index_cluster}\n\n{anker_thing}")
for ele in elements: for ele in elements:
if(ele.get_type()=="Process"): if(ele.get_type()=="Process"):
...@@ -757,11 +797,11 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen ...@@ -757,11 +797,11 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
call = ele.get_call() call = ele.get_call()
#If first element -> add marker for the subworkflow call #If first element -> add marker for the subworkflow call
if(first_element): #if(first_element):
code = code.replace(call.get_code(get_OG = True), f"//Anker_cluster{index_cluster}") # code = code.replace(call.get_code(get_OG = True), f"//Anker_cluster{index_cluster}")
first_element = False # first_element = False
else: #else:
code = code.replace(call.get_code(get_OG = True), "") code = code.replace(call.get_code(get_OG = True), "")
processes_added.append(call.get_first_element_called()) processes_added.append(call.get_first_element_called())
...@@ -779,12 +819,12 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen ...@@ -779,12 +819,12 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
#TODO -> check this verification there might be some "effet de bord" #TODO -> check this verification there might be some "effet de bord"
if(not ele.get_artificial_status()): if(not ele.get_artificial_status()):
#If first element -> add marker for the subworkflow call ##If first element -> add marker for the subworkflow call
if(first_element): #if(first_element):
code = code.replace(ele.get_code(get_OG = True), f"//Anker_cluster{index_cluster}", 1) # code = code.replace(ele.get_code(get_OG = True), f"//Anker_cluster{index_cluster}", 1)
first_element = False # first_element = False
else: #else:
code = code.replace(ele.get_code(get_OG = True), "", 1) code = code.replace(ele.get_code(get_OG = True), "", 1)
#Ignore these cases #Ignore these cases
#TODO -> you should be able to remove this #TODO -> you should be able to remove this
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment