-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathampfinder
172 lines (136 loc) · 6.8 KB
/
ampfinder
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
from settings import *
from AMP import*
from progress.bar import Bar
import argparse
class MainBase(object):
def __init__(self, api=False):
# """
self.cpu_count = os.cpu_count()
USAGE = '''%(prog)s <command> [<args>]
commands are:
---------------------------------------------------------------------------------------
'''
parser = argparse.ArgumentParser(prog="amp", description='{} - {}'.format(APP_NAME, SOFTWARE_VERSION),
epilog=SOFTWARE_SUMMARY, usage=USAGE)
parser.add_argument('command', choices=['main', 'tab', 'parser', 'load', 'clean'], help='Subcommand to run')
def main(self):
parser = self.main_args()
args = parser.parse_args(sys.argv[2:])
print(args)
self.main_run(args)
def main_args(self):
parser = argparse.ArgumentParser(prog="amp main",
description="{} - {} - Main".format(APP_NAME, SOFTWARE_VERSION))
parser.add_argument('-i', '--input_sequence', dest="input_sequence", required=True, \
help='input file must be in either FASTA (contig and protein) or gzip format! e.g myFile.fasta, myFasta.fasta.gz')
parser.add_argument('-o', '--output_file', dest="output_file", required=True,
help="output folder and base filename")
parser.add_argument('-t', '--input_type', dest="input_type",
type=str.lower,
default="contig", choices=['contig', 'protein'],
required=False,
help='specify data input type (default = contig)')
parser.add_argument('-a', '--alignment_tool', dest="aligner",
type=str.upper,
choices=['DIAMOND', 'BLAST'],
default="BLAST",
help="specify alignment tool (default = BLAST)")
parser.add_argument('-n', '--num_threads', dest="threads", type=int,
default=self.cpu_count,
help="number of threads (CPUs) to use in the BLAST search (default={})".format(
self.cpu_count))
parser.add_argument('-c', '--tax_class', dest="tax_class",
default="all",
choices=['Arc', 'Bac','Euk','Fgl','Vir','all'],
help="choose tax_class")
parser.add_argument('--clean', dest="clean", action="store_true", help="removes temporary files")
parser.add_argument('-v', '--version', action='version', version="{}".format(SOFTWARE_VERSION),
help="prints software version number")
return parser
def main_run(self, args):
amp_obj = AMP(**vars(args))
amp_obj.run()
'''
def load(self):
parser = self.load_args()
args = parser.parse_args(sys.argv[2:])
self.load_run(args)
def load_args(self):
parser = app.load.create_parser()
return parser
def load_run(self, args):
app.load.main(args)
def card_annotation(self):
parser = self.card_annotation_args()
args = parser.parse_args(sys.argv[2:])
self.card_annotation_run(args)
def card_annotation_args(self):
parser = app.card_annotation.create_parser()
return parser
def card_annotation_run(self, args):
app.card_annotation.main(args)
def clean(self):
parser = self.clean_args()
args = parser.parse_args(sys.argv[2:])
self.clean_run(args)
def clean_args(self):
parser = app.clean.create_parser()
return parser
def clean_run(self, args):
app.clean.main(args)
def database(self):
parser = self.database_args()
args = parser.parse_args(sys.argv[2:])
print(self.database_run(args))
def database_args(self):
parser = argparse.ArgumentParser(prog="amp database",
description="{} - {} - Database".format(APP_NAME, SOFTWARE_VERSION))
parser.add_argument('-v', '--version', action='store_true', required=True, help="prints data version number")
parser.add_argument('--local', dest="local_database", action='store_true',
help="use local database (default: uses database in executable directory)")
parser.add_argument('--all', action='store_true',
help="data version number used for `rgi bwt` and `rgi main` (default: rgi main)")
return parser
def database_run(self, args):
data_version = ""
# path to loaded database files
if args.local_database:
db = LOCAL_DATABASE
# error if it doesn't exist
if not os.path.exists(LOCAL_DATABASE):
print("Error: missing local directory: {}".format(LOCAL_DATABASE))
print("Please run `rgi load --local -i <path to card.json>` to create local database.")
print("See `rgi load --help` to upload the card.json to rgi application.\n".format(
os.path.abspath(LOCAL_DATABASE)))
exit()
else:
db = data_path
indecies_directory = os.path.join(db, "loaded_databases.json")
if os.path.isfile(indecies_directory) == True:
with open(indecies_directory) as json_file:
json_data = json.load(json_file)
if args.all == True:
kmers_str = ",".join(json_data["card_kmers"]["kmer_sizes"])
if kmers_str == "":
kmers_str = "N/A"
data_version = ("card_canonical: {} | card_variants: {} | kmer_sizes: {}".format(
json_data["card_canonical"]["data_version"],
json_data["card_variants"]["data_version"],
kmers_str
)
)
else:
data_version = json_data["card_canonical"]["data_version"]
else:
print('\nError: no databases found in data path: {}. \nSee `rgi load --help`\n'.format(os.path.abspath(db)))
exit()
if data_version == "":
print('\nError: no databases found in data path: {}. \nSee `rgi load --help`\n'.format(os.path.abspath(db)))
return data_version
'''
if __name__ == '__main__':
time_start = time.time()
m = MainBase()
m.main()
time_end = time.time()
print('totally cost',time_end-time_start)