Commit 3fd9f365 authored by Marc's avatar Marc
Browse files

Raise exception when profile is not found; Add error propagation to nextflow call

parent d7af2120
#!/usr/bin/env python3
import argparse
from os import system
parser = argparse.ArgumentParser(description='Script that returns the fasta as it is inserted. Can be used for modules that have no actual analysis.')
parser.add_argument('--fasta', '-f', required=True, help='A fasta file with aminoacid sequences')
parser.add_argument('--output', '-o', required=True, help='The result directory. Will contain info.json and results.tsv.')
args = parser.parse_args()
print('cp ' + args.fasta + " " + args.output)
print('cp -p ' + args.fasta + " " + args.output)
......@@ -55,8 +55,9 @@ def analyze(args, config):
if args.debug:
print(json.dumps(execution, indent=2))
setup_execution_directory(execution)
execute_analysis(execution)
error_code = execute_analysis(execution)
cleanup(execution)
exit(error_code)
def cleanup(execution):
if not execution['debug']:
......@@ -88,7 +89,10 @@ def generate_execution(config, args):
def generate_execution_modules_for_profile(config, profile):
# find profile by name
p = [x for x in config['profiles'] if x['name'] == profile][0]
profiles = [x for x in config['profiles'] if x['name'] == profile]
if len(profiles) < 1:
raise Exception("Profile not found " + profile)
p = profiles[0]
modules = copy.deepcopy(p['modules'])
# generate unique ids for each module
for module in modules:
......
......@@ -4,6 +4,8 @@ import os
import subprocess
from copy import deepcopy
import collections
import sys
# taken from https://stackoverflow.com/questions/6027558/flatten-nested-python-dictionaries-compressing-keys
def flatten(d, parent_key='', sep='_'):
......@@ -270,8 +272,14 @@ def setup_execution_directory(execution):
def execute_analysis(execution):
old_cwd = os.getcwd()
os.chdir(execution['directory'])
os.system('nextflow run ' + execution['directory'] + '/main.nf --fasta ' + execution['fasta'] + ' --output ' + execution['output'])
command = 'nextflow run ' + execution['directory'] + '/main.nf --fasta ' + execution['fasta'] + ' --output ' + execution['output']
retcode = 1
try:
retcode = subprocess.call(command, shell= True)
except OSError as e:
print("Execution failed: ", e, file=sys.stderr)
os.chdir(old_cwd)
return retcode
def generate_nextflow_script(execution):
modules = execution['modules']
......
Markdown is supported
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