Commit d8983f62 authored by Lukas Jelonek's avatar Lukas Jelonek
Browse files

Restructure project to not mix packages, scripts and executables (Fixes #21)

parent 068a357a
#!/usr/bin/env python3
import argparse
import os
from config import load_config
import copy
import shutil
from nextflow import setup_execution_directory, execute_analysis
import tempfile
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
def main():
parser = argparse.ArgumentParser(description='Make bioinformatic observations on aminoacid sequences')
parser.set_defaults(func=help)
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('--live', '-l', action='store_true', help='Report results as they are computed, not only at the end of the computation. The live results will be available in the $output/live.')
analyze_parser.add_argument('--config', '-c', help='The config to use')
analyze_parser.add_argument('--debug', '-d', action='store_true', help='Debug mode, computation directory will not be removed after computation')
analyze_parser.add_argument('--execution_dir', '-e', help='Use the specified execution directory and do not delete it after the computation')
analyze_parser.set_defaults(func=analyze)
args = parser.parse_args()
config = load_config()
args.parser = parser
args.func(args, config)
def help(args, config):
args.parser.print_help()
def info(args, config):
show_analyses(config)
def analyze(args, config):
execution = generate_execution(config, args)
if args.debug:
print(execution)
setup_execution_directory(execution)
execute_analysis(execution)
cleanup(execution)
def cleanup(execution):
if not execution['debug']:
shutil.rmtree(execution['directory'])
def generate_execution(config, args):
execution = {}
execution['debug'] = args.debug
execution['mode'] = 'live' if args.live else 'complete'
execution['bin_path'] = config['app']['bin_path']
execution['fasta'] = os.path.abspath(args.fasta)
execution['output'] = os.path.abspath(args.output)
if args.execution_dir:
execution['directory'] = os.path.abspath(args.execution_dir)
else:
execution['directory'] = tempfile.mkdtemp()
execution['modules'] = generate_execution_modules_for_profile(config, args.profile)
return execution
def generate_execution_modules_for_profile(config, profile):
# find profile by name
p = [x for x in config['profiles'] if x['name'] == profile][0]
modules = copy.deepcopy(p['modules'])
# generate unique ids for each module
for module in modules:
module['id'] = module['name']
module['analysis']['params'] = generate_params_string(module['analysis']['parameters'])
module['converter']['params'] = generate_params_string(module['converter']['parameters'])
return modules
def generate_params_string(options):
params = ''
if options:
l = []
for k in options:
if options[k]:
l.append('--' + k + " '" + options[k] + "'")
else:
l.append('--' + k)
params = ' '.join(l)
return params
def show_analyses(config):
print('Profiles:')
for profile in config['profiles']:
print(' {0:<20} - {1}'.format(profile['name'], profile['info']))
if 'modules' in profile:
for module in profile['modules']:
print(' {0:<20}'.format(module['name']))
print()
print('Available modules for custom profile:')
for key in config['modules']:
module = config['modules'][key]
print(' {0:<20} - {1}'.format(module['name'], module['info']))
if __name__ == "__main__":
main()
from psot.main import main
main()
#!/usr/bin/env python3
import argparse
import os
from psot.config import load_config
import copy
import shutil
from psot.nextflow import setup_execution_directory, execute_analysis
import tempfile
def main():
parser = argparse.ArgumentParser(description='Make bioinformatic observations on aminoacid sequences')
parser.set_defaults(func=help)
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('--live', '-l', action='store_true', help='Report results as they are computed, not only at the end of the computation. The live results will be available in the $output/live.')
analyze_parser.add_argument('--config', '-c', help='The config to use')
analyze_parser.add_argument('--debug', '-d', action='store_true', help='Debug mode, computation directory will not be removed after computation')
analyze_parser.add_argument('--execution_dir', '-e', help='Use the specified execution directory and do not delete it after the computation')
analyze_parser.set_defaults(func=analyze)
args = parser.parse_args()
config = load_config()
args.parser = parser
args.func(args, config)
def help(args, config):
args.parser.print_help()
def info(args, config):
show_analyses(config)
def analyze(args, config):
execution = generate_execution(config, args)
if args.debug:
print(execution)
setup_execution_directory(execution)
execute_analysis(execution)
cleanup(execution)
def cleanup(execution):
if not execution['debug']:
shutil.rmtree(execution['directory'])
def generate_execution(config, args):
execution = {}
execution['debug'] = args.debug
execution['mode'] = 'live' if args.live else 'complete'
execution['bin_path'] = config['app']['bin_path']
execution['script_path'] = os.path.abspath(os.path.join(os.path.dirname(config['app']['bin_path']), 'scripts'))
execution['psot_path'] = os.path.abspath(os.path.join(os.path.dirname(config['app']['bin_path']), 'psot'))
execution['fasta'] = os.path.abspath(args.fasta)
execution['output'] = os.path.abspath(args.output)
if args.execution_dir:
execution['directory'] = os.path.abspath(args.execution_dir)
else:
execution['directory'] = tempfile.mkdtemp()
execution['modules'] = generate_execution_modules_for_profile(config, args.profile)
return execution
def generate_execution_modules_for_profile(config, profile):
# find profile by name
p = [x for x in config['profiles'] if x['name'] == profile][0]
modules = copy.deepcopy(p['modules'])
# generate unique ids for each module
for module in modules:
module['id'] = module['name']
module['analysis']['params'] = generate_params_string(module['analysis']['parameters'])
module['converter']['params'] = generate_params_string(module['converter']['parameters'])
return modules
def generate_params_string(options):
params = ''
if options:
l = []
for k in options:
if options[k]:
l.append('--' + k + " '" + options[k] + "'")
else:
l.append('--' + k)
params = ' '.join(l)
return params
def show_analyses(config):
print('Profiles:')
for profile in config['profiles']:
print(' {0:<20} - {1}'.format(profile['name'], profile['info']))
if 'modules' in profile:
for module in profile['modules']:
print(' {0:<20}'.format(module['name']))
print()
print('Available modules for custom profile:')
for key in config['modules']:
module = config['modules'][key]
print(' {0:<20} - {1}'.format(module['name'], module['info']))
if __name__ == "__main__":
main()
......@@ -119,8 +119,10 @@ def setup_execution_directory(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')
if not os.path.exists(directory + '/bin'):
os.symlink(execution['script_path'], directory + '/bin')
if not os.path.exists(directory + '/psot'):
os.symlink(execution['psot_path'], directory + '/psot')
def execute_analysis(execution):
old_cwd = os.getcwd()
......
#!/usr/bin/env python3
import os
import sys
# add psot libraries to module search path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import argparse
import config
from psot import config
from os import system
blastp_tool = config.load_config()['tools'].get('blastp', 'blastp')
......@@ -19,7 +24,7 @@ if args.use_accession:
format += ' saccver'
else:
format += ' sseqid'
format += ' pident qstart qend sstart send evalue bitscore'
format += ' pident qstart qend sstart send slen evalue bitscore'
if args.alignment:
format += ' btop'
......
#!/usr/bin/env python3
import os
import sys
# add psot libraries to module search path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import argparse
import config
import re
from os import system,makedirs
from psot import config
import subprocess
import json
......
#!/usr/bin/env python3
import os
import sys
# add psot libraries to module search path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import argparse
import config
from psot import config
from os import system, makedirs
hmmscan_tool = config.load_config()['tools'].get('hmmscan', 'hmmscan')
......
#!/usr/bin/env python3
import argparse
import config
import re
from os import system,makedirs
from os import system
import subprocess
import json
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')
......
#!/usr/bin/env python3
import os
import sys
# add psot libraries to module search path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import argparse
import config
from psot import config
from os import system
signalp_tool = config.load_config()['tools'].get('signalp', 'signalp')
......
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