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

Source Code for Module biana.BianaParser.psimioboParser

  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 PSIMIOBOParser(BianaParser):
28 """ 29 PSI MI OBO Parser Class 30 """ 31 32 name = "psi_mi_obo" 33 description = "This program fills up tables in database biana related with protein interaction 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 = "PSI MI obo", 41 default_script_name = "psimioboParser.py", 42 default_script_description = "This program fills up tables in database piana related to PSI-MI formatted Ontologies")
43 44
45 - def parse_database(self):
46 """ 47 Method that implements the specific operations of psi-mi-obo parser 48 """ 49 50 # Add the possibility to transfer taxonomy name and taxonomy category using taxID as a key 51 self.biana_access._add_transfer_attribute( externalDatabaseID = self.database.get_id(), 52 key_attribute = "Method_id", 53 transfer_attribute="psimi_name" ) 54 self.default_eE_attribute = "psimi_name" 55 56 ontology = Ontology( source_database = self.database, linkedAttribute="Method_id", name="psimiobo", descriptionAttribute="psimi_name" ) 57 58 specific_identifiers_and_parent = {} 59 60 # Start variables 61 term_id = None 62 term_name = None 63 term_def = None 64 65 # PSI-MI OMO specific 66 term_is_a = [] 67 term_part_of = [] 68 term_exact_synonyms = [] 69 term_related_synonyms = [] 70 71 self.initialize_input_file_descriptor() 72 73 # Adding a dummy relation to let the database know that psimi_name attribute is also a possible relation attribute 74 externalEntityRelation = ExternalEntityRelation( source_database = self.database, relation_type = "interaction" ) 75 externalEntityRelation.add_attribute( ExternalEntityRelationAttribute( attribute_identifier = "psimi_name", value = None) ) 76 77 for line in self.input_file_fd: 78 79 if re.search("\[Term\]",line): 80 # New term 81 if term_id is not None: 82 # insert previous 83 externalEntity = ExternalEntity( source_database = self.database, type = "PsiMiOboOntologyElement" ) 84 85 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "Method_id", value = term_id) ) 86 87 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "psimi_name", value = term_name) ) 88 89 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "description", value = term_def) ) 90 91 for current_synonym in term_exact_synonyms: 92 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "psimi_name", 93 value = current_synonym, 94 type = "exact_synonym" ) ) 95 96 for current_synonym in term_related_synonyms: 97 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "psimi_name", 98 value = current_synonym, 99 type = "related_synonym" ) ) 100 101 self.biana_access.insert_new_external_entity( externalEntity ) 102 103 specific_identifiers_and_parent[term_id] = (externalEntity.get_id(),term_is_a,term_part_of) 104 105 106 # Restart variables 107 term_id = None 108 term_name = None 109 term_def = None 110 # PSI-MI OMO specific 111 term_is_a = [] 112 term_part_of = [] 113 term_exact_synonyms = [] 114 term_related_synonyms = [] 115 116 elif re.search("^id\:",line): 117 temp = re.search("MI\:(\d+)",line) 118 119 if temp: 120 term_id = temp.group(1) 121 122 elif re.search("^name\:",line): 123 temp = re.search("name:\s+(.+)",line) 124 term_name = temp.group(1) 125 126 elif re.search("^def\:",line): 127 temp = re.search("\"(.+)\"",line) 128 term_def = temp.group(1) 129 130 # PSI-MI OBO synonyms 131 elif re.search("exact_synonym\:",line): 132 temp = re.search("\"(.+)\"",line) 133 term_exact_synonyms.append(temp.group(1)) 134 135 elif re.search("related_synonym\:",line): 136 temp = re.search("\"(.+)\"",line) 137 term_related_synonyms.append(temp.group(1)) 138 139 elif re.search("is_a\:",line): 140 temp = re.search("MI\:(\d+)",line) 141 if temp is not None: 142 #print "??:", line # malformation --> is_a: regulates ! regulates 143 term_is_a.append(temp.group(1)) 144 145 elif re.search("relationship\:",line): 146 if( re.search("part_of",line) ): 147 temp = re.search("part_of\s+MI\:(\d+)",line) 148 if temp is not None: 149 term_part_of.append(temp.group(1)) 150 151 elif re.search("\[Typedef\]", line): 152 # insert last 153 externalEntity = ExternalEntity( source_database = self.database, type = "PsiMiOboOntologyElement" ) 154 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "Method_id", value = term_id) ) 155 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "psimi_name", value = term_name) ) 156 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "description", value = term_def) ) 157 for current_synonym in term_exact_synonyms: 158 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "psimi_name", 159 value = current_synonym, 160 type = "exact_synonym" ) ) 161 for current_synonym in term_related_synonyms: 162 externalEntity.add_attribute( ExternalEntityAttribute( attribute_identifier = "psimi_name", 163 value = current_synonym, 164 type = "related_synonym" ) ) 165 self.biana_access.insert_new_external_entity( externalEntity ) 166 specific_identifiers_and_parent[term_id] = (externalEntity.get_id(),term_is_a,term_part_of) 167 168 169 # Set the ontology hierarch and insert elements to ontology 170 #print specific_identifiers_and_parent 171 for current_method_id in specific_identifiers_and_parent: 172 #print current_method_id 173 is_a_list = [ specific_identifiers_and_parent[x][0] for x in specific_identifiers_and_parent[current_method_id][1] ] 174 is_part_of_list = [ specific_identifiers_and_parent[x][0] for x in specific_identifiers_and_parent[current_method_id][2] ] 175 ontology.add_element( ontologyElementID = specific_identifiers_and_parent[current_method_id][0], 176 isA = is_a_list, 177 isPartOf = is_part_of_list ) 178 179 self.biana_access.insert_new_external_entity(ontology)
180