1 """
2 BIANA: Biologic Interactions and Network Analysis
3 Copyright (C) 2009 Javier Garcia-Garcia, Emre Guney, Baldo Oliva
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 """
19
20 import sys
21
22 import re
23
24 from bianaParser import *
25
26
28 """
29 GO OBO 1.2 Parser Class
30 """
31
32 name = "go_obo"
33 description = "This program fills up tables in database biana related with gene ontology"
34 external_entity_definition = "A external entity represents an ontology element"
35 external_entity_relations = ""
36
37
39
40 BianaParser.__init__(self, default_db_description = "GO obo",
41 default_script_name = "gooboParser.py",
42 default_script_description = "This program fills up tables in database biana related to OBO 1.2 formatted Ontologies")
43 self.default_eE_attribute = "go_id"
44
45
47 """
48 Method that implements the specific operations of go obo parser
49 """
50
51
52
53 self.biana_access.add_valid_external_entity_attribute_type( name = "GO_type",
54 data_type = "ENUM(\"universal\",\"molecular_function\",\"cellular_component\",\"biological_process\")",
55 category = "eE attribute")
56
57 self.biana_access.add_valid_external_entity_attribute_type( name = "GO_name",
58 data_type = "varchar(370)",
59 category = "eE identifier attribute")
60
61
62
63 self.biana_access.refresh_database_information()
64
65
66
67
68 self.biana_access._add_transfer_attribute( externalDatabaseID = self.database.get_id(),
69 key_attribute = "GO",
70 transfer_attribute="GO_name" )
71
72 ontology = Ontology( source_database = self.database, linkedAttribute="GO", name="GO", descriptionAttribute="GO_name" )
73
74 specific_identifiers_and_parent = {}
75
76
77 term_id = None
78 term_name = None
79 term_def = None
80
81
82 term_namespace = None
83
84 term_is_a = []
85 term_part_of = []
86 term_exact_synonyms = []
87 term_related_synonyms = []
88
89 self.initialize_input_file_descriptor()
90
91
92 externalEntityRelation = ExternalEntityRelation( source_database = self.database, relation_type = "interaction" )
93 externalEntityRelation.add_attribute( ExternalEntityRelationAttribute( attribute_identifier = "go_name", value = None) )
94
95 for line in self.input_file_fd:
96
97 if re.search("\[Term\]",line):
98
99 if term_id is not None:
100
101 externalEntity = ExternalEntity( source_database = self.database, type = "GOElement" )
102
103 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "GO", value = term_id) )
104
105 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "GO_name", value = term_name, type="unique") )
106
107 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "GO_type", value = term_namespace) )
108
109 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "description", value = term_def) )
110
111 for current_synonym in term_exact_synonyms:
112 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "GO_name",
113 value = current_synonym,
114 type = "exact_synonym" ) )
115
116 for current_synonym in term_related_synonyms:
117 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "GO_name",
118 value = current_synonym,
119 type = "related_synonym" ) )
120
121 self.biana_access.insert_new_external_entity( externalEntity )
122
123 specific_identifiers_and_parent[term_id] = (externalEntity.get_id(), term_is_a, term_part_of)
124
125
126 term_id = None
127 term_name = None
128 term_def = None
129
130 term_namespace = None
131
132 term_is_a = []
133 term_part_of = []
134 term_exact_synonyms = []
135 term_related_synonyms = []
136
137 elif re.search("^id\:",line):
138 temp = re.search("GO\:(\d+)",line)
139
140 if temp:
141 term_id = temp.group(1)
142
143 elif re.search("^name\:",line):
144 temp = re.search("name:\s+(.+)",line)
145 term_name = temp.group(1)
146
147 elif re.search("^namespace\:",line):
148 temp = re.search("namespace:\s+(.+)",line)
149 term_namespace = temp.group(1)
150
151 elif re.search("^def\:",line):
152 temp = re.search("\"(.+)\"",line)
153 term_def = temp.group(1)
154
155 elif re.search("synonym\:",line):
156 temp = re.search("\"(.+)\"\s+(\w+)",line)
157 if temp.group(2) == "EXACT":
158 term_exact_synonyms.append(temp.group(1))
159 elif temp.group(2) == "RELATED":
160 term_related_synonyms.append(temp.group(1))
161
162 elif re.search("is_a\:",line):
163 temp = re.search("GO\:(\d+)",line)
164 if temp is not None:
165
166 term_is_a.append(temp.group(1))
167
168 elif re.search("relationship\:",line):
169 if( re.search("part_of",line) ):
170 temp = re.search("part_of\s+GO\:(\d+)",line)
171 if temp is not None:
172 term_part_of.append(temp.group(1))
173
174
175 for current_method_id in specific_identifiers_and_parent:
176 is_a_list = [ specific_identifiers_and_parent[x][0] for x in specific_identifiers_and_parent[current_method_id][1] ]
177 is_part_of_list = [ specific_identifiers_and_parent[x][0] for x in specific_identifiers_and_parent[current_method_id][2] ]
178 ontology.add_element( ontologyElementID = specific_identifiers_and_parent[current_method_id][0],
179 isA = is_a_list,
180 isPartOf = is_part_of_list )
181
182 self.biana_access.insert_new_external_entity(ontology)
183