1 from bianaParser import *
2
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
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
27 """
28 Method that implements the specific operations of a MyData formatted file
29 """
30
31 self.biana_access.add_valid_external_entity_attribute_type( name = "AffinityScore",
32 data_type = "double",
33 category = "eE numeric attribute")
34
35
36
37 self.biana_access.add_valid_external_entity_relation_participant_attribute_type( name = "Score", data_type = "float unsigned" )
38
39
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
48 if not self.external_entity_ids_dict.has_key(id1):
49 new_external_entity = ExternalEntity( source_database = self.database, type = "protein" )
50
51 new_external_entity.add_attribute( ExternalEntityAttribute( attribute_identifier= "Uniprot", value=id1, type="cross-reference") )
52
53 new_external_entity.add_attribute( ExternalEntityAttribute( attribute_identifier= "Description", value=desc1) )
54
55 self.external_entity_ids_dict[id1] = self.biana_access.insert_new_external_entity( externalEntity = new_external_entity )
56
57 if not self.external_entity_ids_dict.has_key(id2):
58 new_external_entity = ExternalEntity( source_database = self.database, type = "protein" )
59
60 new_external_entity.add_attribute( ExternalEntityAttribute( attribute_identifier= "Uniprot", value=id2, type="cross-reference") )
61
62 new_external_entity.add_attribute( ExternalEntityAttribute( attribute_identifier= "Description", value=desc2) )
63
64 self.external_entity_ids_dict[id2] = self.biana_access.insert_new_external_entity( externalEntity = new_external_entity )
65
66
67 new_external_entity_relation = ExternalEntityRelation( source_database = self.database, relation_type = "interaction" )
68
69 new_external_entity_relation.add_participant( externalEntityID = self.external_entity_ids_dict[id1] )
70
71 new_external_entity_relation.add_participant( externalEntityID = self.external_entity_ids_dict[values[1]] )
72
73 new_external_entity_relation.add_participant_attributes( externalEntityID = self.external_entity_ids_dict[id1], participantAttribute = ExternalEntityRelationParticipantAttribute( attribute_identifier = "Score", value = score1 ) )
74
75 new_external_entity_relation.add_participant_attributes( externalEntityID = self.external_entity_ids_dict[id2], participantAttribute = ExternalEntityRelationParticipantAttribute( attribute_identifier = "Score", value = score2 ) )
76
77 new_external_entity_relation.add_attribute( ExternalEntityRelationAttribute( attribute_identifier = "AffinityScore",
78 value = score_int ) )
79
80 self.biana_access.insert_new_external_entity( externalEntity = new_external_entity_relation )
81
82 input_file_fd.close()
83