Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BioFlow-Insight
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
shareFAIR
BioFlow-Insight
Commits
7b6d83dc
Commit
7b6d83dc
authored
6 months ago
by
George Marchment
Browse files
Options
Downloads
Patches
Plain Diff
updated function "remove_empty_conditions_place_anker"
parent
c06e5e04
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#14437
failed
6 months ago
Stage: test
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/outils.py
+19
-2
19 additions, 2 deletions
src/outils.py
src/workflow.py
+7
-57
7 additions, 57 deletions
src/workflow.py
with
26 additions
and
59 deletions
src/outils.py
+
19
−
2
View file @
7b6d83dc
...
...
@@ -1343,9 +1343,9 @@ def get_channels_to_add_in_false_conditions(body, emitted_channels):
return
body
#This function removes the empty conditions
-> while keeping the anker_clusters -> if it's orignally in a condtion
#This function removes the empty conditions
def
remove_empty_conditions
(
code
):
pattern
=
r
"
(if *\(.+\)|else)\s*{(\s*
|\s*\/\/Anker_clusters\s*
)}
"
pattern
=
r
"
(if *\(.+\)|else)\s*{(\s*)}
"
def
replace
(
text
,
pattern
):
def
replacer
(
match
):
return
match
.
group
(
0
).
replace
(
match
.
group
(
0
),
match
.
group
(
2
))
...
...
@@ -1357,4 +1357,21 @@ def remove_empty_conditions(code):
code
=
replace
(
code
,
pattern
)
return
code
#This function removes the empty conditions -> while keeping the anker_clusters -> if it's orignally in a condtion
def
remove_empty_conditions_place_anker
(
code
):
conditions
=
extract_conditions
(
code
)
OG_anker
=
"
//Anker_clusters
"
pos
=
code
.
find
(
OG_anker
)
conditions_containing_anker
=
[]
for
condition
in
conditions
:
start
,
end
=
conditions
[
condition
]
if
(
start
<=
pos
and
pos
<=
end
):
conditions_containing_anker
.
append
(
condition
.
split
(
'
$$__$$
'
)[
0
])
new_anker
=
OG_anker
for
condition
in
conditions_containing_anker
:
new_anker
=
f
"
\n
}}
\n
{
new_anker
}
\n
if(
{
condition
}
) {{
\n
"
code
=
code
.
replace
(
OG_anker
,
new_anker
)
code
=
remove_empty_conditions
(
code
)
return
code
This diff is collapsed.
Click to expand it.
src/workflow.py
+
7
−
57
View file @
7b6d83dc
...
...
@@ -3,7 +3,7 @@
from
.nextflow_file
import
Nextflow_File
from
.ro_crate
import
RO_Crate
from
.
import
constant
from
.outils
import
is_git_directory
,
format_with_tabs
,
replace_thing_by_call
,
replace_group1
,
group_together_ifs
,
extract_curly
,
remove_extra_jumps
,
get_channels_to_add_in_false_conditions
,
extract_conditions
,
remove_empty_conditions
from
.outils
import
is_git_directory
,
format_with_tabs
,
replace_thing_by_call
,
replace_group1
,
group_together_ifs
,
extract_curly
,
remove_extra_jumps
,
get_channels_to_add_in_false_conditions
,
extract_conditions
,
remove_empty_conditions
_place_anker
from
.outils_graph
import
get_flatten_dico
,
initia_link_dico_rec
,
get_number_cycles
,
generate_graph
from
.outils_annotate
import
get_tools_commands_from_user_for_process
from
.bioflowinsighterror
import
BioFlowInsightError
...
...
@@ -838,10 +838,11 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
last_executor_in_cluster
=
get_last_executor_in_cluster
(
executors_in_order
,
clusters
)
if
(
last_executor_in_cluster
.
get_type
()
==
"
Process
"
):
call
=
last_executor_in_cluster
.
get_call
()
code
=
code
.
replace
(
call
.
get_code
(
get_OG
=
True
),
"
//Anker_clusters
"
)
code
=
code
.
replace
(
call
.
get_code
(
get_OG
=
True
),
"
\n
//Anker_clusters
\n
"
)
elif
(
last_executor_in_cluster
.
get_type
()
==
"
Operation
"
):
if
(
not
last_executor_in_cluster
.
get_artificial_status
()):
code
=
code
.
replace
(
last_executor_in_cluster
.
get_code
(
get_OG
=
True
),
"
//Anker_clusters
"
,
1
)
print
(
last_executor_in_cluster
.
get_code
(
get_OG
=
True
))
code
=
code
.
replace
(
last_executor_in_cluster
.
get_code
(
get_OG
=
True
),
"
\n
//Anker_clusters
\n
"
,
1
)
else
:
raise
Exception
(
"
This shoudn
'
t happen
"
)
else
:
...
...
@@ -863,7 +864,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
raise
Exception
(
"
This shoudn
'
t happen
"
)
#Remove the empty conditions left in the code
code
=
remove_empty_conditions
(
code
)
code
=
remove_empty_conditions
_place_anker
(
code
)
#Add the subworkflow defintions
...
...
@@ -884,6 +885,7 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
subworkflow_clusters_to_add
,
subworkflow_cluster_calls_to_add
=
[],
[]
index_cluster
=
len
(
clusters
)
#We replace the last clusters first -> this is cause the outputs of the last clusters aren't used anywhere else in the workflow by definition
for
elements
in
list
(
reversed
(
clusters
)):
channels_to_replace_outside_of_cluster
=
[]
...
...
@@ -1088,58 +1090,6 @@ George Marchment, Bryan Brancotte, Marie Schmit, Frédéric Lemoine, Sarah Cohen
"""
#TODO -> rmoving the conditions which are problematic
#This might not be the probleme -> when rerunnung the analysis isn
'
t totally robust
still_simplifying_conditions = True
while(still_simplifying_conditions):
still_simplifying_conditions = False
to_replace, anker1, anker2 =
""
,
""
,
""
#Replace if/else
for match in re.finditer(r
"
if\s*\([^\{]+\{\s*(\/\/Anker_cluster\d|\s)\s*\}\s*else\s*\{\s*(\/\/Anker_cluster\d|\s)\s*\}
"
, code):
to_replace = match.group(0)
anker1, anker2 = match.group(1), match.group(2)
still_simplifying_conditions = True
break
#Replace empty if on its own
if(not still_simplifying_conditions):
for match in re.finditer(r
"
(if\s*\([^\{]+\{\s*(\/\/Anker_cluster\d|\s)\s*\})\s*[^e]
"
, code):
to_replace = match.group(1)
anker1 = match.group(2)
still_simplifying_conditions = True
break
if(still_simplifying_conditions):
code = code.replace(to_replace, f
"
{anker1}
\n
{anker2}
"
)
#Replace the ankers by the calls of the subworkflows
for i in range(len(subworkflow_clusters_to_add)):
#Extracting the conditions in the code
conditions_in_code = extract_conditions(code)
anker = f
"
//Anker_cluster{i}
"
pos_anker = code.find(anker)
#For each anker get the condition in which it is called
#Cause we do not want the call of the subworkflows to be done in a condition
#So around the call we place
""
}} call if(){if(){
""
-> so it
'
s executed ouside of a condition
conditions_for_anker = []
for c in conditions_in_code:
if(conditions_in_code[c][0]<pos_anker and pos_anker <conditions_in_code[c][1]):
conditions_for_anker.append(c.split(
"
$$__$$
"
)[0])
#Placing the extract curlies around it
subworkflow_call = subworkflow_cluster_calls_to_add[i]
for c in conditions_for_anker:
subworkflow_call = f
"
\n
}}
\n
{subworkflow_call}
\n
if({c}){{
\n
"
code = code.replace(anker, subworkflow_call)
for old, new in channels_to_replace_outside_of_cluster:
pattern= fr
"
[ \(,]({re.escape(old)})[^\w]
"
code = replace_group1(code, pattern, new)
#code = code.replace(old, new)
"""
#Putting || back
code
=
code
.
replace
(
"
$OR$
"
,
"
||
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment