Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SOaAS
psot.repository
Commits
ab785538
Commit
ab785538
authored
Feb 28, 2017
by
Lukas Jelonek
Browse files
Refactored nextflow code generation and execution into module. Implemented postprocessing
parent
326b3e1d
Changes
2
Hide whitespace changes
Inline
Side-by-side
bin/PSOT
View file @
ab785538
...
@@ -3,6 +3,7 @@ import argparse
...
@@ -3,6 +3,7 @@ import argparse
import
os
import
os
from
config
import
load_config
from
config
import
load_config
import
copy
import
copy
from
nextflow
import
setup_execution_directory
,
execute_analysis
def
main
():
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'Make bioinformatic observations on aminoacid sequences'
)
parser
=
argparse
.
ArgumentParser
(
description
=
'Make bioinformatic observations on aminoacid sequences'
)
...
@@ -44,24 +45,6 @@ def generate_execution(config, args):
...
@@ -44,24 +45,6 @@ def generate_execution(config, args):
modules
=
generate_execution_modules_for_profile
(
config
,
args
.
profile
)
modules
=
generate_execution_modules_for_profile
(
config
,
args
.
profile
)
execution
[
'modules'
]
=
modules
execution
[
'modules'
]
=
modules
return
execution
return
execution
def
setup_execution_directory
(
execution
):
directory
=
execution
[
'directory'
]
if
not
os
.
path
.
exists
(
directory
):
os
.
mkdir
(
directory
)
if
not
os
.
path
.
isdir
(
directory
):
exit
()
nextflow_script
=
generate_nextflow_script
(
execution
[
'modules'
])
with
open
(
directory
+
'/main.nf'
,
'w'
)
as
script_file
:
script_file
.
write
(
nextflow_script
)
if
not
os
.
path
.
exists
(
directory
+
'/bin'
):
os
.
symlink
(
execution
[
'bin_path'
],
directory
+
'/bin'
)
def
execute_analysis
(
execution
):
os
.
chdir
(
execution
[
'directory'
])
os
.
system
(
'nextflow run main.nf --fasta '
+
execution
[
'fasta'
]
+
' --output '
+
execution
[
'output'
])
def
generate_execution_modules_for_profile
(
config
,
profile
):
def
generate_execution_modules_for_profile
(
config
,
profile
):
# find profile by name
# find profile by name
...
@@ -87,50 +70,6 @@ def generate_params_string(options):
...
@@ -87,50 +70,6 @@ def generate_params_string(options):
params
=
' '
.
join
(
l
)
params
=
' '
.
join
(
l
)
return
params
return
params
def
generate_nextflow_script
(
modules
):
fragments
=
[]
fragments
.
append
(
'''params.fasta = "example/proteins.fas"
Channel.fromPath(params.fasta).set{fasta}'''
)
target_channels
=
[
"for_"
+
m
[
'id'
]
for
m
in
modules
]
fragments
.
append
(
'fasta.into{'
+
';'
.
join
(
target_channels
)
+
';}'
)
from
string
import
Template
analysis_template
=
Template
(
'''
process ${id} {
input:
file fasta from for_${id}
output:
file "$${fasta}.${id}.results" into ${id}_results
script:
"""
${analysis_script} --fasta $$fasta --output $${fasta}.${id}.results ${params}
"""
}
'''
)
convert_template
=
Template
(
'''
process convert_${id}_to_json {
input:
file result from ${id}_results
output:
file "$${result}.json" into ${id}_json
script:
"""
${converter_script} --result $$result --output $${result}.json
"""
}
'''
)
for
m
in
modules
:
fragments
.
append
(
analysis_template
.
substitute
(
m
))
fragments
.
append
(
convert_template
.
substitute
(
m
))
# TODO add postprocessing
nextflow_script
=
'
\n
'
.
join
(
fragments
)
return
nextflow_script
def
show_analyses
(
config
):
def
show_analyses
(
config
):
print
(
'Profiles:'
)
print
(
'Profiles:'
)
...
...
bin/nextflow.py
0 → 100644
View file @
ab785538
from
string
import
Template
import
os.path
import
os
analysis_template
=
Template
(
'''
process ${id} {
input:
file fasta from for_${id}
output:
file "$${fasta}.${id}.results" into ${id}_results
script:
"""
${analysis_script} --fasta $$fasta --output $${fasta}.${id}.results ${params}
"""
}
'''
)
convert_template
=
Template
(
'''
process convert_${id}_to_json {
input:
file result from ${id}_results
output:
file "$${result}.json" into ${id}_json
script:
"""
${converter_script} --result $$result --output $${result}.json
"""
}
'''
)
input_template
=
Template
(
''' file ${id}_result from ${id}_json'''
)
join_jsons_template
=
Template
(
'''
process join_documents {
input:
${inputs}
output:
file "joined.json" into joined_json
script:
"""
join_json_files.py --output joined.json *.json
"""
}
'''
)
split_jsons_template
=
Template
(
'''
process split_documents {
publishDir "${output}", mode: 'copy'
input:
file "input/json.json" from joined_json
output:
file "*.json" into result_documents
script:
"""
split_json_into_separate_files.py --json 'input/json.json' --output .
"""
}
'''
)
def
setup_execution_directory
(
execution
):
directory
=
execution
[
'directory'
]
if
not
os
.
path
.
exists
(
directory
):
os
.
mkdir
(
directory
)
if
not
os
.
path
.
isdir
(
directory
):
exit
()
nextflow_script
=
generate_nextflow_script
(
execution
)
with
open
(
directory
+
'/main.nf'
,
'w'
)
as
script_file
:
script_file
.
write
(
nextflow_script
)
if
not
os
.
path
.
exists
(
directory
+
'/bin'
):
os
.
symlink
(
execution
[
'bin_path'
],
directory
+
'/bin'
)
def
execute_analysis
(
execution
):
os
.
chdir
(
execution
[
'directory'
])
os
.
system
(
'nextflow run main.nf --fasta '
+
execution
[
'fasta'
]
+
' --output '
+
execution
[
'output'
])
def
generate_nextflow_script
(
execution
):
modules
=
execution
[
'modules'
]
fragments
=
[]
fragments
.
append
(
'''params.fasta = "example/proteins.fas"
Channel.fromPath(params.fasta).set{fasta}'''
)
target_channels
=
[
"for_"
+
m
[
'id'
]
for
m
in
modules
]
fragments
.
append
(
'fasta.into{'
+
';'
.
join
(
target_channels
)
+
';}'
)
for
m
in
modules
:
fragments
.
append
(
analysis_template
.
substitute
(
m
))
fragments
.
append
(
convert_template
.
substitute
(
m
))
json_inputs
=
[]
for
m
in
modules
:
json_inputs
.
append
(
input_template
.
substitute
(
m
))
fragments
.
append
(
join_jsons_template
.
substitute
({
'inputs'
:
'
\n
'
.
join
(
json_inputs
)}))
fragments
.
append
(
split_jsons_template
.
substitute
(
execution
))
nextflow_script
=
'
\n
'
.
join
(
fragments
)
return
nextflow_script
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment