Package obitools :: Package seqdb :: Package genbank :: Module ncbi
[hide private]
[frames] | no frames]

Source Code for Module obitools.seqdb.genbank.ncbi

 1  from urllib2 import urlopen 
 2  import sys 
 3  import re 
 4   
 5  import cStringIO 
 6   
 7  from obitools.eutils import EFetch 
 8  from parser import genbankParser,genpepParser 
 9  from parser import genbankIterator,genpepIterator 
10   
11  from obitools.utils import CachedDB 
12   
13   
14 -class NCBIGenbank(EFetch):
15 - def __init__(self):
16 EFetch.__init__(self,db='nucleotide', 17 rettype='gbwithparts')
18
19 - def __getitem__(self,ac):
20 if isinstance(ac,str): 21 text = self.get(id=ac) 22 seq = genbankParser(text) 23 return seq 24 else: 25 query = ','.join([x for x in ac]) 26 data = cStringIO.StringIO(self.get(id=query)) 27 return genbankIterator(data)
28 29 30 31
32 -class NCBIGenpep(EFetch):
33 - def __init__(self):
34 EFetch.__init__(self,db='protein', 35 rettype='gbwithparts')
36
37 - def __getitem__(self,ac):
38 if isinstance(ac,str): 39 text = self.get(id=ac) 40 seq = genpepParser(text) 41 return seq 42 else: 43 query = ','.join([x for x in ac]) 44 data = cStringIO.StringIO(self.get(id=query)) 45 return genpepIterator(data)
46
47 -class NCBIAccession(EFetch):
48 49 _matchACS = re.compile(' +accession +"([^"]+)"') 50
51 - def __init__(self):
52 EFetch.__init__(self,db='nucleotide', 53 rettype='seqid')
54
55 - def __getitem__(self,ac):
56 if isinstance(ac,str): 57 text = self.get(id=ac) 58 rep = NCBIAccession._matchACS.search(text).group(1) 59 return rep 60 else: 61 query = ','.join([x for x in ac]) 62 text = self.get(id=query) 63 rep = (ac.group(1) for ac in NCBIAccession._matchACS.finditer(text)) 64 return rep
65
66 -def Genbank(cache=None):
67 gb = NCBIGenbank() 68 if cache is not None: 69 gb = CachedDB(cache, gb) 70 return gb
71 72
73 -def Genpep(cache=None):
74 gp = NCBIGenpep() 75 if cache is not None: 76 gp = CachedDB(cache, gp) 77 return gp
78