-
Notifications
You must be signed in to change notification settings - Fork 0
/
hmm_wrapper.py
76 lines (52 loc) · 2.19 KB
/
hmm_wrapper.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
import os
import argparse
from multiprocessing import Manager, Pool
from tqdm import tqdm
from jakomics import hmm, utilities, colors, file
import jak_utils
# OPTIONS #####################################################################
parser = argparse.ArgumentParser(description='XXX', formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--in_dir',
help="Directory with faa files",
required=False,
default="")
parser.add_argument('-f', '--files',
help="Paths to individual faa files",
nargs='*',
required=False,
default=[])
parser.add_argument('--out_dir',
help="Directory to write results to",
required=True)
parser.add_argument('-d', '--database',
help="HMM database",
required=True)
args = parser.parse_args()
# manager = Manager()
# result_files = manager.list()
hmm_file = file.FILE(args.database)
# FUNCTIONS ###################################################################
def main(file):
global hmm_file
file.temp_files['temp_log'] = file.id + '.log'
file.results_file = file.short_name + '.hmm.txt'
hmm.run_hmmsearch(file.file_path,
file.temp_files['temp_log'],
os.path.join(args.out_dir, file.short_name + '.' + hmm_file.short_name + '.txt'),
hmm_file.file_path,
echo=False, run=True)
# cleanup
file.remove_temp()
## MAIN LOOP ###################################################################
if __name__ == "__main__":
jak_utils.header()
# make output directory if it doesn't exist
args.out_dir = os.path.abspath(args.out_dir) + '/'
if not os.path.exists(args.out_dir):
print("\nCreating directory " + args.out_dir)
os.makedirs(args.out_dir)
genome_list = utilities.get_files(args.files, args.in_dir, ["faa", "feature_protein.fasta"])
pool = Pool(processes=4)
for _ in tqdm(pool.imap_unordered(main, genome_list), total=len(genome_list), desc="Finished", unit=" files"):
pass
pool.close()