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

Source Code for Module biana.BianaParser.MyDataParser

 1  from bianaParser import * 
 2                       
3 -class MyDataParser(BianaParser):
4 """ 5 MyData Parser Class 6 7 Parses data in the following format (meaining Uniprot_id1 interacts with Uniprot_id2 and some scores are associated with both the participants and the interaction): 8 9 Uniprot_id1 Description1 Participant_score1 Uniprot_id2 Description2 Participant_score2 Interaction_Affinity_score 10 """ 11 12 name = "mydata" 13 description = "This file implements a program that fills up tables in BIANA database from data in MyData format" 14 external_entity_definition = "An external entity represents a protein" 15 external_entity_relations = "An external relation represents an interaction with given affinity" 16
17 - def __init__(self):
18 """ 19 Start with the default values 20 """ 21 BianaParser.__init__(self, default_db_description = "MyData parser", 22 default_script_name = "MyDataParser.py", 23 default_script_description = MyDataParser.description, 24 additional_compulsory_arguments = [])
25
26 - def parse_database(self):
27 """ 28 Method that implements the specific operations of a MyData formatted file 29 """ 30 # Add affinity score as a valid external entity relation since it is not recognized by BIANA 31 self.biana_access.add_valid_external_entity_attribute_type( name = "AffinityScore", 32 data_type = "double", 33 category = "eE numeric attribute") 34 35 # Add score as a valid external entity relation participant attribute since it is not recognized by BIANA 36 # (Do not confuse with external entity/relation score attribute, participants can have their attributes as well) 37 self.biana_access.add_valid_external_entity_relation_participant_attribute_type( name = "Score", data_type = "float unsigned" ) 38 39 # Since we have added new attributes that are not in the default BIANA distribution, we execute the following command 40 self.biana_access.refresh_database_information() 41 42 self.input_file_fd = open(self.input_file, 'r') 43 self.external_entity_ids_dict = {} 44 45 for line in self.input_file_fd: 46 (id1, desc1, score1, id2, desc2, score2, score_int) = line.strip().split() 47 # Create an external entity corresponding to Uniprot_id1 in database (if it is not already created) 48 if not self.external_entity_ids_dict.has_key(id1): 49 new_external_entity = ExternalEntity( source_database = self.database, type = "protein" ) 50 # Annotate it as Uniprot_id1 51 new_external_entity.add_attribute( ExternalEntityAttribute( attribute_identifier= "Uniprot", value=id1, type="cross-reference") ) 52 # Associate its description 53 new_external_entity.add_attribute( ExternalEntityAttribute( attribute_identifier= "Description", value=desc1) ) 54 # Insert this external entity into database 55 self.external_entity_ids_dict[id1] = self.biana_access.insert_new_external_entity( externalEntity = new_external_entity ) 56 # Create an external entity corresponding to Uniprot_id2 in database (if it is not already created) 57 if not self.external_entity_ids_dict.has_key(id2): 58 new_external_entity = ExternalEntity( source_database = self.database, type = "protein" ) 59 # Annotate it as Uniprot_id2 60 new_external_entity.add_attribute( ExternalEntityAttribute( attribute_identifier= "Uniprot", value=id2, type="cross-reference") ) 61 # Associate its description 62 new_external_entity.add_attribute( ExternalEntityAttribute( attribute_identifier= "Description", value=desc2) ) 63 # Insert this external entity into database 64 self.external_entity_ids_dict[id2] = self.biana_access.insert_new_external_entity( externalEntity = new_external_entity ) 65 66 # Create an external entity relation corresponding to interaction between Uniprot_id1 and Uniprot_id2 in database 67 new_external_entity_relation = ExternalEntityRelation( source_database = self.database, relation_type = "interaction" ) 68 # Associate Uniprot_id1 as the first participant in this interaction 69 new_external_entity_relation.add_participant( externalEntityID = self.external_entity_ids_dict[id1] ) 70 # Associate Uniprot_id2 as the second participant in this interaction 71 new_external_entity_relation.add_participant( externalEntityID = self.external_entity_ids_dict[values[1]] ) 72 # Associate score of first participant Uniprot_id1 with this interaction 73 new_external_entity_relation.add_participant_attributes( externalEntityID = self.external_entity_ids_dict[id1], participantAttribute = ExternalEntityRelationParticipantAttribute( attribute_identifier = "Score", value = score1 ) ) 74 # Associate score of second participant Uniprot_id2 with this interaction 75 new_external_entity_relation.add_participant_attributes( externalEntityID = self.external_entity_ids_dict[id2], participantAttribute = ExternalEntityRelationParticipantAttribute( attribute_identifier = "Score", value = score2 ) ) 76 # Associate the score of the interaction with this interaction 77 new_external_entity_relation.add_attribute( ExternalEntityRelationAttribute( attribute_identifier = "AffinityScore", 78 value = score_int ) ) 79 # Insert this external entity realtion into database 80 self.biana_access.insert_new_external_entity( externalEntity = new_external_entity_relation ) 81 82 input_file_fd.close()
83