-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParse_Single.py
41 lines (32 loc) · 1.05 KB
/
Parse_Single.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
"""
Filter blast output to each OTUs top hit
based on score and identity.
If both score and identity are equal the OTU has multiple hits.
"""
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("blast", help="The blast output to filter")
args = parser.parse_args()
ofpath = args.blast + ".parsed"
towrite = ""
blastdict = {}
with open(args.blast) as infile:
for line in infile:
temp = line.strip('\n').split('\t')
OTU = temp[0]
if OTU not in blastdict.keys():
blastdict[OTU] = []
blastdict[OTU].append(line)
else:
comp = blastdict[OTU][0].strip('\n').split('\t')
if temp[11] > comp[11]:
blastdict[OTU][0] = line
elif temp[11] == comp[11] and temp[2] > comp[2]:
blastdict[OTU][0] = line
elif temp[11] == comp[11] and temp[2] == comp[2]:
blastdict[OTU].append(line)
for k, v in blastdict.items():
for i in v:
towrite += i
with open(ofpath, "w+") as outfile:
outfile.write(towrite)