Package biana :: Package BianaObjects :: Module ExternalEntityRelation'
[hide private]
[frames] | no frames]

Source Code for Module biana.BianaObjects.ExternalEntityRelation'

  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   
 21  # Each participant in the relation can have different attributes: role, detection method,... 
 22  import ExternalEntity 
 23  import sets 
 24   
 25   
26 -class ExternalEntityRelation(ExternalEntity.ExternalEntity):
27 """ 28 This general object represents an entry represeting a relation between external entities in an external database 29 30 An external Entity Relation is a relation of any type between two or more external entities 31 32 It can contain several attributes. 33 """ 34 35
36 - def __init__(self, source_database, relation_type, id=None):
37 """ 38 "source_databas_id" is the source database id where this entity is described 39 40 "relation_type" indicates the type of externalEntityRelation 41 42 "id" is the UNIQUE identifier in the database for this external entity 43 """ 44 45 self.participants = {} # This is a dictionary with the following format: 46 # key: externalEntityID for the participant 47 # values: dictionary with its attributes (role, detection method,...) 48 49 self.relation_type = relation_type 50 51 ExternalEntity.ExternalEntity.__init__(self, source_database = source_database, type="relation", id=id)
52 53
54 - def add_participant(self, externalEntityID):
55 """ 56 Adds a participant to this relation 57 58 "externalEntityID" externalEntityID corresponding to the participant 59 """ 60 61 if self.participants.has_key(externalEntityID): 62 return 63 else: 64 self.participants[externalEntityID] = {}
65 66 67 68
70 """ 71 Returns a list with all the externalEntityIds of the participants 72 """ 73 return self.participants.keys()
74 75 76 77
78 - def get_participant_attributes(self, participantExternalEntityID):
79 """ 80 Returns a list of [(attribute_name, fieldValues dictionary)] 81 """ 82 return self.participants[participantExternalEntityID]
83 84 85
86 - def get_participant_attribute(self, participantExternalEntityID, attribute_identifier):
87 """ 88 """ 89 try: 90 return self.participants[participantExternalEntityID][attribute_identifier.lower()] 91 except: 92 return []
93 94 95
96 - def add_participant_attribute(self, externalEntityID, participantAttribute ):
97 """ 98 Adds an attribute to a participant in the relation 99 100 If the participant didn't exist previously, it gives error. It is necessary to insert previously the participant! 101 """ 102 103 if self.participants.has_key(externalEntityID): 104 try: 105 self.participants[externalEntityID][participantAttribute.attribute_identifier.lower()].append(participantAttribute) 106 except KeyError: 107 self.participants[externalEntityID][participantAttribute.attribute_identifier.lower()] = [participantAttribute] 108 else: 109 raise ValueError("Trying to add attributes to an unexisting participant. Participant: %s" %externalEntityID)
110 111 112 113
114 - def get_relation_type(self):
115 """ 116 Returns the type of this relation (interaction, reaction...) 117 """ 118 return self.relation_type
119 120 121 122
123 - def get_valid_relation_types(biana_database):
124 """ 125 Static method 126 127 Returns a list with all available relation types 128 """ 129 return biana_database.VALID_EXTERNAL_ENTITY_RELATION_TYPES_DICT.values()
130 131 get_valid_relation_types = staticmethod(get_valid_relation_types) 132 133 134 135 136
137 - def isValidType(type, biana_database):
138 139 return type.lower() in ExternalEntityRelation.VALID_EXTERNAL_ENTITY_RELATION_TYPES_DICT
140 141 isValidType = staticmethod(isValidType)
142