1 __docformat__ = 'restructuredtext'
2
3 import re
4 import string
5 import textwrap
6
7
8 from obitools.obo.go.parser import GOEntryIterator
9 from obitools.obo.go.parser import GOTerm
10 from obitools.obo.go.parser import GOEntry
11
12 """
13 go_obo.py : gene_ontology_edit.obo file parser:
14 ----------------------------------------------------
15
16 - OBOFile class: open a flat file and return an entry.
17
18 """
20 """
21 Iterator over all entries of an OBO file
22 """
23
26
29
31 fiche = self.file.next()
32
33 if isinstance(fiche, GOTerm):
34 self.isaterm=True
35 return Term(fiche)
36 elif isinstance(fiche, GOEntry):
37 self.isaterm=False
38 return Entry(fiche)
39 else:
40 self.isaterm=False
41 return Header(fiche)
42
43
44
45
46
48 """
49 Class Xref
50 Xref.db Xref database
51 Xref.id Xref identifier
52 """
53
55 data = description.split(':')
56 self.db = data[0].strip()
57 self.id = data[1].strip()
58
59
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
89 """
90 Class Term
91 representing a GO term.
92 """
93
116
117
118 - def __checkEntry__(self):
119 minimum=(hasattr(self,'goid') )
120 if not minimum:
121 raise AssertionError('Misconstructed GO Term instance %s' % [x for x in dir(self) if x[0]!='_'])
122
123
125 """
126 Extract GO id.
127 """
128 self.goid = self.data.id.value.strip('GO:')
129
131 """
132 Extract GO name.
133 """
134 self.name = self.data.name.value
135
137 """
138 Extract GO synonym(s).
139 """
140 self.list_synonyms = {}
141 if self.data.synonyms:
142 for y in self.data.synonyms:
143 self.list_synonyms[y.value] = y.scope
144
145
154
163
165 """
166 To make the is_a hierarchy
167 """
168 if self.data.is_a != None:
169 self.is_a = set([isa.value.strip('GO:') for isa in self.data.is_a])
170 else:
171 self.is_a = set()
172
174 """
175 To make the part_of hierarchy
176 """
177 self.part_of = set()
178 self.regulates = set()
179 self.negatively_regulates = set()
180 self.positively_regulates = set()
181
182 if self.data.relationship != None:
183 for rel in self.data.relationship:
184 if rel.relationship == "part_of":
185 self.part_of.add(rel.value.strip('GO:'))
186 elif rel.relationship == "regulates":
187 self.regulates.add(rel.value.strip('GO:'))
188 elif rel.relationship == "negatively_regulates":
189 self.negatively_regulates.add(rel.value.strip('GO:'))
190 elif rel.relationship == "positively_regulates":
191 self.positively_regulates.add(rel.value.strip('GO:'))
192
193
206
207
208
209
211 """
212 for each obsolete terms corresponds a set of GO Identifiers
213 so that this GO term is consider as others GO Terms
214 """
215 self.considers = set()
216 self.replaces = set()
217 self.is_obsolete = self.data.is_obsolete
218 if self.data.is_obsolete:
219 if self.data.consider:
220 self.considers = set([considered.value.strip('GO:') for considered in self.data.consider])
221 if self.data.replaced_by:
222 self.replaces = set([replaced.value.strip('GO:') for replaced in self.data.replaced_by])
223
224
226 """
227 alternate(s) id(s) for this term (= alias in the geneontology schema model!)
228 """
229 if self.data.alt_ids:
230 self.alt_ids = set([x.value.strip('GO:') for x in self.data.alt_ids])
231 else:
232 self.alt_ids = set()
233
235 """
236 cross references to other databases
237 """
238 self.xrefs = set()
239 if self.data.xrefs:
240 self.xrefs = set([Xref(x.value.reference) for x in self.data.xrefs])
241
242
250
251
252 -class Entry(object):
253 """
254 a Stanza entry, like [Typedef] for example
255 """
256 - def __init__(self,data=None):
257 self.data=data
258 self.isaterm=False
259 self.isanentry=True
260
261
263 """
264 class representing a GO header.
265 """
266
268 """
269 """
270 self.data=data
271 self.isaterm = False
272