-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgetfullgenefuncatLATE.py
More file actions
42 lines (32 loc) · 1.29 KB
/
Copy pathgetfullgenefuncatLATE.py
File metadata and controls
42 lines (32 loc) · 1.29 KB
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
import sqlite3
import sys
import operator
from collections import defaultdict
infile = open(sys.argv[1], 'r')
outfile = open(sys.argv[2], 'w')
nohits = open(sys.argv[3], 'w')
con = sqlite3.connect('/users/kiverson/eggNOGproteinaliasesDB3')
c = con.cursor()
catcount = defaultdict(int)
nobact1 = 0
nobact = defaultdict(int)
for line in infile:
line = line.split()
gene = (line[0].strip(),)
c.execute("SELECT cat FROM funccat INNER JOIN bactmembers ON (funccat.NOGmember == bactmembers.NOGmember) WHERE bactmembers.eggNOGid == (SELECT nog FROM lateFull2nog WHERE gene = ?);", gene)
cat = c.fetchall()
try:
catcount[str(cat[0][0])] += int(line[1].strip())
except IndexError:
nobact1 += int(line[1].strip())
nobact[line[0].strip()] += int(line[1].strip())
#for k in catcount:
#outfile.write("%s\t%s\n" % (k, catcount[k]) )
#outfile.write("nomatch: %s\n" % nobact1)
#sortedcats = sorted(catcount.iteritems(), key=operator.itemgetter(1), reverse=True)
#sortednobact = sorted(nobact.iteritems(), key=operator.itemgetter(1), reverse=True)
for cat in sorted(catcount.iterkeys()):
outfile.write("%s\t%s\n" % (cat, catcount[cat]) )
outfile.write("nomatch\t%s\n" % nobact1)
for k in sorted(nobact.iterkeys()):
nohits.write("%s\t%s\n" % (k, nobact[k]) )