Package biana :: Package BianaParser :: Module gooboParser
[hide private]
[frames] | no frames]

Source Code for Module biana.BianaParser.gooboParser

  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   
27 -class GOOBOParser(BianaParser):
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
38 - def __init__(self):
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
46 - def parse_database(self):
47 """ 48 Method that implements the specific operations of go obo parser 49 """ 50 51 52 # Add the attributes specifics in GO database 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 # IMPORTANT: As we have added new types and attributes that are not in the default BIANA distribution, we must execute the follwing command: 63 self.biana_access.refresh_database_information() 64 65 66 67 # Add the possibility to transfer taxonomy name and taxonomy category using taxID as a key 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 # Start variables 77 term_id = None 78 term_name = None 79 term_def = None 80 81 # GO OBO specific 82 term_namespace = None 83 #term_synonyms = [] 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 # Adding a dummy relation to let the database know that go_name attribute is also a possible relation attribute 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 # New term 99 if term_id is not None: 100 # insert previous 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 # Restart variables 126 term_id = None 127 term_name = None 128 term_def = None 129 # GO OBO specific 130 term_namespace = None 131 #term_synonyms = [] 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 #print "??:", line # malformation --> is_a: regulates ! regulates 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 # Set the ontology hierarch and insert elements to ontology 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