-
Notifications
You must be signed in to change notification settings - Fork 1
/
find_contaminations.py
executable file
·60 lines (54 loc) · 1.87 KB
/
find_contaminations.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
#!/usr/bin/env python
#-*- encoding:utf-8 -*-
import sys
import math
import os
class Usage(Exception):
def __init__(self, msg):
self.msg = msg
def usage():
print("\nUsage: python contaminantFinder.py input output")
sys.exit(-1)
def main():
args = sys.argv[1:]
if len(args) !=2:
usage()
fin = open(sys.argv[1], 'r')
fout = open(sys.argv[2], 'w')
contiglist=[]
contiginfo=[]
notcontaminant = ['Human', 'H.sapiens', 'Homo', 'sapiens', 'troglodytes', 'Gorilla', 'pygmaeus', 'mulatta', 'Rhinopithecus', 'Papio', 'Macaque', 'musculus', 'Callithrix', 'Colobus', 'fascicularis', 'Ailuropoda', 'Aotus', 'abelii', 'Pongo', 'Microcebus', 'Chinchilla', 'Macaca', 'macaque', 'aethiops', 'Mouse', 'canadensis','monkey','squirrel', 'Pig', 'Canadensis', 'Ovis', 'Chlorocebus','Myotis','gallus','Gallus','citb_109_p_11,', 'Methylobacterium','Bos taurus', 'Figure 4.','Cyprinus carpio','Pan','Agkistrodon contortrix','Apteryx australis','']
i=0
line = fin.readline()
while(line!=''):
elems = line.strip().split();
contiginfo=[]
contiginfo.append(elems[1]);
line = fin.readline()
elems = line.strip().split("=");
contiginfo.append(elems[1]);
line = fin.readline()
if line!='':
prev_line = line;
while( line !='' and not(line[0]=="Q" and line[1]=="u" and line[2]=="e" and line[3]=="r" and line[4]=="y")):
elems= line.strip().split();
contiginfo.append(elems[1]+" "+elems[2]);
line = fin.readline()
if(prev_line!= line):
contiglist.append(contiginfo);
for i in range(0,len(contiglist)):
contigel = contiglist[i];
f = 2;
notprint = 0
while f<15 and f < len(contigel):
if(contigel[f].split()[0] in notcontaminant or contigel[f].split()[1] in notcontaminant):
notprint = 1
f+=1
if(notprint==0):
toprint=""
for a in contigel:
toprint+= a+"\t"
fout.write("{0}\n".format(toprint));
fout.close()
if __name__ == "__main__":
sys.exit(main())