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 sets
21
22
24 """
25 Class to represent a condition of unification
26 """
27
28 - def __init__(self, externalDatabaseID_A, externalDatabaseID_B, externalAttribute, field_conditions_A=[], field_conditions_B=[],
29 field_cross_references = ["value"]):
30 """
31 "externalDatabaseID_A" and "externalDatabaseID_B" are the databaseIntegers that identify the databases we want to crossreference
32 externalDatabaseID_A must be lower or equal to externalDatabaseID_B. If not, they will be flipped
33
34 "externalAttribute" is the attribute that we want to cross-reference
35 It can be a list of attributes if they have to be taken into account together (for example, ["sequence","taxID"]
36
37 "fields_A" and "fields_B" is a list with the fields we want to cross-reference (for example, ["value","type"]
38
39 "field_conditions_A" and "field_conditions_B" is optional, and they must be a dictionary with restricted fields { "field": "restricted_value" }
40
41 "field_cross_references" is a list of the fields that have to be cross-referenced. By default, it takes the value [ "value" ]
42 """
43
44
45 if externalDatabaseID_A > externalDatabaseID_B:
46 self.externalDatabaseID_A = externalDatabaseID_B
47 self.externalDatabaseID_B = externalDatabaseID_A
48 self.field_conditions_A = field_conditions_B
49 self.field_conditions_B = field_conditions_A
50 else:
51 self.externalDatabaseID_A = externalDatabaseID_A
52 self.externalDatabaseID_B = externalDatabaseID_B
53 self.field_conditions_A = field_conditions_A
54 self.field_conditions_B = field_conditions_B
55
56 self.field_cross_references = field_cross_references
57
58 if (isinstance(externalAttribute,list) ):
59 self.externalAttribute = [ x.lower() for x in externalAttribute ]
60 else:
61 self.externalAttribute = [externalAttribute.lower()]
62
63
64
65
66
67
68 self.field_cross_references.sort()
69 self.field_conditions_A.sort()
70 self.field_conditions_B.sort()
71
72
74 """
75 String representation of the class
76 """
77
78 return_list = ["Unification atom"]
79 return_list.append("Cross databases: %s - %s" %(self.get_externalDatabaseID_A(),self.get_externalDatabaseID_B()))
80 return_list.append("Using external attribute: %s" %self.get_external_attribute_list())
81 return_list.append("Field cross_references: %s" %self.field_cross_references)
82
83 return "%s" %("\n\t".join(return_list))
84
85
87 """
88 returns a tuple with both database identifiers
89 """
90 return (self.externalDatabaseID_A, self.externalDatabaseID_B)
91
93 return self.externalDatabaseID_A
94
96 return self.externalDatabaseID_B
97
99 return self.externalAttribute
100
102 """
103 gets a list of tuples with the following format: (field,value)
104 """
105 return [ (x,self.field_conditions_A[x]) for x in self.field_conditions_A ]
106
107
109 """
110 gets a list of tuples with the following format: (field,value)
111 """
112 return [ (x,self.field_conditions_B[x]) for x in self.field_conditions_B ]
113
114
116
117 return self.field_cross_references
118
119
131
132
133
135 """
136 Class to represent
137 """
138
139
140 - def __init__(self, description, BianaDatabaseVersion, id=None):
141 """
142 """
143
144 self.unification_atom_elements = []
145
146 self.description = description
147 self.databaseVersion = BianaDatabaseVersion
148
149 self.id = id
150
151 self.use_databases = sets.Set()
152
153
155
156 self.use_databases.add(externalDatabaseID)
157
159 """
160 Returns a set with the database ids it contains
161 """
162
163 return self.use_databases
164
165
167 """
168 Adds a crossreference condition
169 """
170 self.unification_atom_elements.append(unificationAtomElement)
171 self.use_databases.add(unificationAtomElement.externalDatabaseID_A)
172 self.use_databases.add(unificationAtomElement.externalDatabaseID_B)
173
175 return self.unification_atom_elements
176
177
180
181
184
185
189