1 """GeneOntology id retriver using Entrez and GenBank id --[cyppi]"""
2
3 from Bio import GenBank, Fasta
4
5 class getGoid:
6 """ Get the goid from gid.
7 this class fetch the Genbank document by given gid
8 then parse the document and get goid(s)
9 if not in the document or if there is some errer,
10 this class will return just empty list.
11
12 usage :
13 go = getGoid()
14 golist = go.getgoid(gid='some gid', data='protein')
15 the data is set 'protein' as a default,
16 if the gid is protein, then just put gid without anynotation
17 like
18 golist = go.getgoid('some gid')
19 and if the gid related withe the dna
20 data should be noted like
21 golist = go.getgoid(gid='some gid', data='nucleotide')
22
23
24 """
25 fpser =''
26 ncbi = ''
27 ncbj = ''
28 golist = []
29 def __init__(self):
30 self.fpser = GenBank.FeatureParser()
31 self.ncbi = GenBank.NCBIDictionary(database = 'protein',format='genbank',parser=self.fpser)
32 self.ncbj = GenBank.NCBIDictionary(database = 'nucleotide',format='genbank', parser = self.fpser)
33
34 def getProteinGo(self,gid):
35 try:
36 data = self.ncbi.get(gid)
37 for item in data.features:
38 if item.qualifiers != '' and item.qualifiers.has_key('note'):
39 self.getgoidfromnote(item.qualifiers['note'])
40 except :
41 self.golist = []
42
43 def getDNAGo(self, gid):
44 try:
45 data = self.ncbj.get(gid)
46 for item in data.features:
47 if item.qualifiers != '' and item.qualifiers.has_key('note'):
48 self.getgoidfromnote(item.qualifiers['note'])
49 except:
50 self.golist = []
51
52 def getgoidfromnote(self, note):
53 self.golist = []
54 for item in note:
55 item = item.replace('\n', ' ' )
56 nlist = item.split('goid')
57 if len(nlist) > 0:
58 for item in nlist[1:]:
59 if item[1:8] != ' ':
60
61 self.golist.append(item[1:8])
62
63 def getgoid(self,gid,data='protein'):
64 if data== 'protein':
65 self.getProteinGo(gid)
66 elif data =='nucleotide':
67 self.getDNAGo(gid)
68 return self.golist
69
70
71 if __name__ =='__main__':
72 go = getGoid()
73 go.getgoid('6755536')
74 for item in go.golist:
75 print item