-
Notifications
You must be signed in to change notification settings - Fork 0
/
finder.py
68 lines (59 loc) · 2.2 KB
/
finder.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
#!/usr/bin/env python3
import os
import sys
import argparse
import libs.fformat as ff
import libs.flib as fl
def main():
# handle command line options
parser = argparse.ArgumentParser(description = "Program to find all occurences of queries in template sequences.",
usage = "python3 finder.py -t ./data/template.fa -q ./data/query.fa --mismatch 2")
parser.add_argument("-t", "--target", help = "Path to your target fasta file")
parser.add_argument("-q", "--query", help = "Path to your query fasta file")
parser.add_argument("-m", "--mismatch", default = 0, help = "Number of mismatches allowed")
parser.add_argument("-o", "--output", help = "Path to your output directory")
parser.add_argument("-s", "--save", action='store_true', help = "Save output to file?")
parser.add_argument("-r", "--rev", action='store_true', help = "Look in reverse complement strand?")
args = parser.parse_args()
# check if necessary filepaths are provided
# check targets and queries
if args.target:
if args.query:
pass
else:
print(f"[ {ff.Colors.ERROR}ERROR{mf.Colors.NC} ] Please provide a valid path for your query file.")
sys.exit(0)
else:
print(f"[ {ff.Colors.ERROR}ERROR{mf.Colors.NC} ] Please provide a valid path for your target file.")
sys.exit(0)
# check output
if args.output:
out_dir = args.output
else:
out_dir = os.getcwd()
# set output
out_mapping = os.path.join(out_dir, "mapping.txt").replace("\\", "/")
out_report = os.path.join(out_dir, "summary.txt").replace("\\", "/")
# set number of mismatches allowed
mismatch = args.mismatch
# run
print(f'{ff.now()}\tSearch for motifs')
print(f'{"-" * 50}\n')
matches = fl.Seek(args.target, args.query).search(args.mismatch, args.rev)
if args.save:
if os.path.isfile(out_report):
os.remove(out_report)
with open(out_report, "a") as out:
for match in matches:
out.write(f"{match}\n")
# save output
# TODO: save mapping in html report
print(f'{ff.now()}\tSave output in project folder')
else:
for match in matches:
print(match)
print(f'\n{"-" * 50}')
print(f'{ff.now()}\tRun finished')
print(f'[ {ff.Colors.OK}OK{ff.Colors.NC} ] Results successfully stored in: {out_dir}')
if __name__ == "__main__":
main()