-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun_batch_resfinder.py
executable file
·124 lines (106 loc) · 4.43 KB
/
run_batch_resfinder.py
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
# python3 /home/zack/development/resfinder/run_resfinder.py -ifa 1237-49_S49.raw.fasta -acq -l 0.6 -t 0.9
# !/usr/bin/env python3
import sys
import os
from argparse import ArgumentParser
import time
start_time = time.time()
parser = ArgumentParser(allow_abbrev=False)
# General options
parser.add_argument("-ifd",
help="Input fasta directory.",
default=None)
parser.add_argument("-o",
help="Path to blast output",
default='')
parser.add_argument("-b",
help="Path to blastn",
default='blastn')
parser.add_argument("-k",
help="Path to KMA",
default=None)
parser.add_argument("-s",
help="Species in the sample",
default=None)
parser.add_argument("-l",
help="Minimum (breadth-of) coverage",
type=float,
default=0.60)
parser.add_argument("-t",
help="Threshold for identity",
type=float,
default=0.80)
# Acquired resistance options
parser.add_argument("-db_res",
help="Path to the databases for ResFinder",
default=None)
parser.add_argument("-db_res_kma",
help="Path to the ResFinder databases indexed with KMA. \
Defaults to the 'kma_indexing' directory inside the \
given database directory.",
default=None)
parser.add_argument("-d",
help="Databases chosen to search in - if none is specified\
all is used",
default=None)
parser.add_argument("-acq",
action="store_true",
help="Run resfinder for acquired resistance genes",
default=False)
parser.add_argument("-ao",
help="Genes are allowed to overlap this number of\
nucleotides. Default: 30.",
type=int,
default=30)
# Point resistance option
parser.add_argument("-c",
action="store_true",
help="Run pointfinder for chromosomal mutations",
default=False)
parser.add_argument("-db_point",
help="Path to the databases for PointFinder",
default=None)
parser.add_argument("-g",
nargs='+',
help="Specify genes existing in the database to \
search for - if none is specified all genes are \
included in the search.",
default=None)
parser.add_argument("-u",
action="store_true",
help="Show all mutations found even if in unknown to the\
resistance database",
default=False)
# # Temporary option only available temporary
# parser.add_argument("--pickle",
# action="store_true",
# help="Create a pickle dump of the Isolate object. \
# Currently needed in the CGE webserver. Dependency \
# and this option is being removed.",
# default=False)
args = parser.parse_args()
args_dict = args.__dict__
if not (args.ifd):
sys.exit("ERROR: inputfastadir is required")
inputfastadir = os.path.abspath(args.ifd)
batch_out_path = args.o
fasta_files = [f for f in os.listdir(inputfastadir) if f.endswith('.fasta')]
if not len(fasta_files):
sys.exit("ERROR: no FASTA files found")
run_resfinder = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'run_resfinder.py')
arg_coll = []
for x, y in args_dict.items():
if x not in ['ifd', 'o'] and y is not False and y is not None:
if y is True:
arg_coll.append(f'-{x}')
else:
arg_coll.append(f'-{x} {y}')
arg_str = ' '.join(arg_coll)
for f in fasta_files:
inputfasta = os.path.join(inputfastadir, f)
out_path = os.path.join(batch_out_path, f.replace('.fasta', ''))
print(f'exec python3 {run_resfinder} -ifa {inputfasta} -o {out_path} {arg_str}')
os.system(f'exec python3 {run_resfinder} -ifa {inputfasta} -o {out_path} {arg_str}')
time_taken = time.strftime("%H:%M:%S", time.gmtime(time.time() - start_time))
print(f'Processed {len(fasta_files)} FASTA files (Time taken: {time_taken})')
sys.exit()