Commit 176b0270 authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

[WIP] nextflow script generation

parent 6578edd8
......@@ -2,13 +2,87 @@
import argparse
from config import load_config
parser = argparse.ArgumentParser(description='Make bioinformatic observations on aminoacid sequences')
parser.add_argument('--fasta', '-f', help='A fasta file with aminoacid sequences')
parser.add_argument('--listanalyses', '-l', action='store_true', help='Show available analysis steps')
config = load_config()
args = parser.parse_args()
def main():
parser = argparse.ArgumentParser(description='Make bioinformatic observations on aminoacid sequences')
config = load_config()
subparsers = parser.add_subparsers()
info_parser = subparsers.add_parser('info')
info_parser.add_argument('--listanalyses', '-l', action='store_true', help='Show available analysis steps')
info_parser.set_defaults(func=info)
analyze_parser = subparsers.add_parser('analyze')
analyze_parser.add_argument('--fasta', '-f', required=True, help='A fasta file with aminoacid sequences')
analyze_parser.add_argument('--output', '-o', required=True, help='The output directory for the json documents')
analyze_parser.add_argument('--profile', '-p', default='fast', help='The profile to use')
analyze_parser.add_argument('--config', '-c', help='The config to use')
analyze_parser.set_defaults(func=analyze)
args = parser.parse_args()
args.func(args)
def info(args):
show_analyses()
def analyze(args):
print()
modules = get_modules_for_profile(args.profile)
generate_nextflow_script(modules)
def get_modules_for_profile(profile):
# find profile by name
p = [x for x in config['profiles'] if x['name'] == profile][0]
# find all modules for profile from modules config section
m = [x for x in config['modules'] if x['name'] in p['modules']]
import copy
modules = copy.deepcopy(m)
# generate unique ids for module
for module in modules:
module['id'] = module['name']
return modules
def generate_nextflow_script(modules):
print('''params.file = "example/proteins.fas"
Channel.fromPath(param.file).set{fasta}''')
target_channels = ["for_"+m['id'] for m in modules]
print('fasta.join{'+';'.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
"""
}
''')
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:
print(analysis_template.substitute(m))
print(convert_template.substitute(m))
def show_analyses():
print('Profiles:')
......@@ -22,8 +96,6 @@ def show_analyses():
print('Available modules for custom profile:')
for module in config['modules']:
print(' {0:<20} - {1}'.format(module['name'], module['info']))
exit(0)
if args.listanalyses:
show_analyses()
if __name__ == "__main__":
main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment