-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathKazusaSPSUMHandler.py
More file actions
95 lines (62 loc) · 2.05 KB
/
KazusaSPSUMHandler.py
File metadata and controls
95 lines (62 loc) · 2.05 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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
'''
Created on 07.02.2015
@author: david
'''
from os import listdir
from os.path import join
from CUTable import CUTable
class KazusaSPSUMHandler(object):
'''
classdocs
'''
def __init__(self, path=""):
'''
Constructor
'''
self.taxidToCodonUsage = dict()
self.descToTaxidAndNCDS = dict()
if not path:
pass
else:
self.loadSPSUMFromPath(path)
def loadSPSUMFromPath(self, path):
'''
'''
files = listdir(path)
for f in files:
if f.endswith(".spsum"):
self.readSPSUMFile(join(path, f))
elif f == "SPSUM_LABEL":
self.readSPSUM_LABEL(join(path, f))
def readSPSUMFile(self, file):
fd = open(file)
while True:
descLine = fd.readline()
if not descLine: break
cu = fd.readline()
# split into taxid:desc:nrCDS
taxid = descLine.split(":", 1)[0].strip()
desc = descLine.split(":", 1)[1].strip()
ncds = desc.rsplit(":", 1)[1].strip()
desc = desc.rsplit(":", 1)[0].strip()
self.taxidToCodonUsage[taxid] = cu.strip()
self.descToTaxidAndNCDS[desc] = (taxid, ncds)
fd.close()
def readSPSUM_LABEL(self, file):
fd = open(file)
fd.readline() # omit first line
self.SPSUM_LABEL = fd.readline().strip()
fd.close()
def search(self, query):
'''
'''
res = dict()
for desc, taxidNCS in self.descToTaxidAndNCDS.items():
if desc.find(query) != -1:
res[desc] = taxidNCS
return res
def getCUTable(self, taxid):
'''
'''
res = CUTable(self.SPSUM_LABEL, self.taxidToCodonUsage[taxid])
return res