PSOT 3.1 KB
Newer Older
1
2
#!/usr/bin/env python3
import argparse
3
import os
4
from config import load_config
5
import copy
6
from nextflow import setup_execution_directory, execute_analysis
7

8
9
def main():
    parser = argparse.ArgumentParser(description='Make bioinformatic observations on aminoacid sequences')
10

11
12
13
14
15
16
17
18
19
20
    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')
21
    analyze_parser.add_argument('--live', '-l', action='store_true', help='Report results as they are computed, not only at the end of the computation')
22
23
24
25
    analyze_parser.add_argument('--config', '-c', help='The config to use')
    analyze_parser.set_defaults(func=analyze)

    args = parser.parse_args()
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
    config = load_config()
    args.func(args, config)


def info(args, config):
    show_analyses(config)

def analyze(args, config):
    execution = generate_execution(config, args)
    setup_execution_directory(execution)
    execute_analysis(execution)

def generate_execution(config, args):
    execution = {}
    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)
    execution['directory'] = 'tmp' # TODO replace by random tmp directory or make it configurable (cli option)
45
    execution['modules'] = generate_execution_modules_for_profile(config, args.profile)
46
    return execution
47
    
48
def generate_execution_modules_for_profile(config, profile):
49
50
    # find profile by name
    p = [x for x in config['profiles'] if x['name'] == profile][0]
51
    modules = copy.deepcopy(p['modules'])
52
    # generate unique ids for each module
53
54
    for module in modules:
        module['id'] = module['name']
55
        module['params'] = generate_params_string(module['parameters'])
56
57
    return modules

Lukas Jelonek's avatar
Lukas Jelonek committed
58
59
60
61
62
63
64
65
66
67
68
69
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

70

71
def show_analyses(config):
72
73
74
75
76
77
78
79
80
81
82
83
    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))

    print()
    print('Available modules for custom profile:')
    for module in config['modules']:
        print('   {0:<20} - {1}'.format(module['name'], module['info']))

84
85
if __name__ == "__main__":
    main()