Package obitools :: Package obo :: Package go :: Module parser
[hide private]
[frames] | no frames]

Source Code for Module obitools.obo.go.parser

 1  from obitools.obo.parser import OBOTerm 
 2  from obitools.obo.parser import OBOEntry 
 3  from obitools.obo.parser import stanzaIterator 
 4  from logging import debug 
 5   
6 -class GOEntry(OBOEntry):
7 ''' 8 An entry of a GeneOntology .obo file. It can be a header (without a stanza name) or 9 a stanza (with a stanza name between brackets). It inherits from the class dict. 10 '''
11 12
13 -class GOTerm(OBOTerm):
14 15 ''' 16 A stanza named 'Term'. It inherits from the class OBOTerm. 17 ''' 18
19 - def __init__(self,stanza):
20 21 ## use of the OBOEntry constructor. 22 OBOTerm.__init__(self, stanza) 23 24 assert 'namespace' in self and len(self['namespace'])==1, "An OBOTerm must belong to one of the cell_component, molecular_function or biological_process namespace"
25 26
27 -def GOEntryFactory(stanza):
28 ''' 29 Dispatcher of stanza. 30 31 @param stanza: a stanza composed of several lines. 32 @type stanza: text 33 34 @return: an C{OBOTerm} | C{OBOEntry} instance 35 36 @note: The dispatcher treats differently the stanza which are OBO "Term" 37 and the others. 38 ''' 39 40 stanzaType = OBOEntry.parseStanzaName(stanza) 41 42 if stanzaType=="Term": 43 return GOTerm(stanza) 44 else: 45 return OBOEntry(stanza)
46 47
48 -def GOEntryIterator(file):
49 entries = stanzaIterator(file) 50 for e in entries: 51 debug(e) 52 yield GOEntryFactory(e)
53