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 import sets
22 import biana.biana_globals as BIANA_GLOBALS
23
24
26 """
27 This general object represents an entry in an external database
28
29 It can contain several attributes.
30 """
31
32
33 PROMISCUOUS_EXTERNAL_ENTITY_TYPES_DICT = dict(BIANA_GLOBALS.PROMISCUOUS_EXTERNAL_ENTITY_TYPES_DICT)
34
35
36 - def __init__(self, source_database, type, id=None):
37 """
38 "source_database" is the source database id wbere this entity is described
39
40 "type" indicates the type of externalEntity.It can be:
41 'protein','gene','protein alignment','cluster','structure, SCOPElement'
42
43 "id" is the UNIQUE identifier in the database for this external entity
44 """
45
46 type = type.lower()
47
48 self.id = id
49 self.attributes = {}
50 self.sourceDatabase = source_database
51 self.type = type
52
53 return
54
55
57
58 string = "External Entity ID: %s\n" %self.id
59
60 for current_attribute in self.attributes:
61 string += "%s:\n\t%s\n" %(current_attribute, "\t".join(map(str,self.attributes[current_attribute])))
62
63
64 return string
65
66
67
69
70 return self.id==other.id
71
72
73
75 """
76 Gets the UNIQUE identifier
77 """
78 return self.id
79
80
81
83 """
84 Gets the ExternalDatabase Object where this externalEntity is contained
85 """
86 return self.sourceDatabase
87
88
89
91 """
92 Gets a string representing the type of this externalEntity
93 """
94 return self.type
95
96
97
99 if self.id is None:
100 self.id = id_value
101 else:
102 raise ValueError("Cannot change identifier from externalEntity")
103
104
105
107 """
108 Adds an attribute to this ExternalEntity Object
109
110 "externalEntityAttribute": A valid externalEntityAttribute Object. It cannot contain value None as its value
111 """
112
113 if externalEntityAttribute.value is None:
114 sys.stderr.write("Attribute %s not added because it has None value\n" %(externalEntityAttribute.attribute_identifier))
115 return
116
117 self.attributes.setdefault(externalEntityAttribute.attribute_identifier.lower(),sets.Set([])).add(externalEntityAttribute)
118
119
120
122 """
123 Returns a SET with the externalEntityAttribute objects corresponding to the attribute_identifier associated to this externalEntity.
124
125 If the externalEntity object does not contain any attribute of "attribute_identifier" type, it returns an empty list
126 """
127
128 try:
129 return self.attributes[attribute_identifier.lower()]
130 except KeyError:
131 return sets.Set()
132
133
135 """
136 Returns a dictionary with all the ExternalEntityAttributes associated to this externalEntity.
137
138 Keys correspond to "attribute_identifier" and values to a Set with all external entity objects
139 """
140 return self.attributes
141
142
143
145
146 return type.lower() in biana_database.VALID_EXTERNAL_ENTITY_TYPES_DICT
147
148 isValidType = staticmethod(isValidType)
149
150
151
153
154 return biana_database.VALID_EXTERNAL_ENTITY_TYPES_DICT.values()
155
156 get_valid_external_entity_types = staticmethod(get_valid_external_entity_types)
157