forked from DaehwanKimLab/hisat-genotype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hisatgenotype_toolkit
executable file
·103 lines (92 loc) · 4.4 KB
/
hisatgenotype_toolkit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
# --------------------------------------------------------------------------- #
# Copyright 2017, Daehwan Kim <[email protected]> #
# #
# This file is part of HISAT-genotype. Its purpose is as a wrapper for #
# secondary and individual scripts in HISATgenotype #
# #
# HISAT-genotype is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# HISAT-genotype is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with HISAT-genotype. If not, see <http://www.gnu.org/licenses/>. #
# --------------------------------------------------------------------------- #
import sys
import os
import subprocess
import re
import resource
import inspect
import random
import math
from datetime import datetime, date, time
from argparse import ArgumentParser, FileType
import hisatgenotype_typing_common as typing_common
# --------------------------------------------------------------------------- #
# Main function for wrapper that contains all functions #
# --------------------------------------------------------------------------- #
if __name__ == '__main__':
# This step is critical for finding the scripts to run
path = '/'.join(os.path.realpath(__file__).split('/')[:-1])
path += '/hisatgenotype_tools/'
if not os.path.exists(path):
print('Error! Toolkit Directory not found at %s' % path,
file=sys.stderr)
exit(1)
scripts = []
sfiles = sorted(os.listdir(path))
for script in sfiles:
if script.startswith('.'):
continue
scripts.append(script)
parser = ArgumentParser(
description='HISAT-genotype Toolkit')
parser.add_argument('--see-script',
dest='see_script',
action='store_true',
help='Prints the exact script and options being run')
subparser = parser.add_subparsers(title='Tools',
dest='script',
help='HISAT-genotype tools and \
individual scripts')
subparsers = []
script_key = {}
for itr in range(len(scripts)):
# Need to strip the file name and get the core of the script name
name = scripts[itr]\
.replace('hisatgenotype_', '')\
.replace('run_', '')\
.replace('_', '-')\
.split('.')[0]
script = scripts[itr]
script_key.update({ name : script })
subparsers.append(subparser.add_parser(name,
help=script,
add_help=False))
subparsers[itr].add_argument('-h', '--help',
dest='script_help',
action='store_true'
)
args, additional = parser.parse_known_args()
cmd = [path]
cmd[0] += script_key[args.script]
if additional and not args.script_help:
cmd += additional
elif args.script_help:
cmd += additional + ['--help']
elif args.script not in ['conc-results']:
print("Please provide options for tool selected",
file=sys.stderr)
exit(1)
if args.see_script:
print(cmd)
code = subprocess.call(cmd)
if code != 0:
print('Script exited with error %d' % code)