1 package uk.ac.ebi.intenz.domain.constants;
2
3 import uk.ac.ebi.intenz.domain.exceptions.DomainException;
4
5 import java.util.*;
6
7
8
9
10
11
12
13
14
15 public class XrefDatabaseConstant implements Comparable<XrefDatabaseConstant> {
16 private String databaseCode;
17
18 private String displayName;
19
20 private String url;
21
22 private boolean isXref;
23
24 public static final XrefDatabaseConstant UNDEF = new XrefDatabaseConstant("UNDEF", "UNDEFINED",
25 "", false);
26
27
28
29
30
31
32 public static final XrefDatabaseConstant BRENDA = new XrefDatabaseConstant(
33 "BRENDA", "BRENDA",
34 "http://www.brenda-enzymes.info/php/result_flat.php4?ecno=", true);
35
36 public static final XrefDatabaseConstant METACYC = new XrefDatabaseConstant(
37 "MCYC", "MetaCyc",
38 "http://biocyc.org/META/NEW-IMAGE?type=REACTION&object=", true);
39
40
41
42
43 public static final XrefDatabaseConstant CAS = new XrefDatabaseConstant("CAS", "CAS", "", false);
44
45
46
47
48
49 public static final XrefDatabaseConstant ENZYME =
50 new XrefDatabaseConstant("EXPASY", "ENZYME@ExPASy",
51 "http://enzyme.expasy.org/EC/", false);
52
53
54
55
56 public static final XrefDatabaseConstant NC_IUBMB = new XrefDatabaseConstant("NCIUBMB", "NC-IUBMB",
57 "http://www.chem.qmul.ac.uk/iubmb/enzyme/EC", false);
58
59
60
61
62
63
64 public static final XrefDatabaseConstant GO = new XrefDatabaseConstant("GO", "GO",
65 "http://www.ebi.ac.uk/ego/DisplayGoTerm?id=", true);
66
67
68
69
70
71 public static final XrefDatabaseConstant CSA = new XrefDatabaseConstant("CSA", "CSA",
72 "http://www.ebi.ac.uk/thornton-srv/databases/cgi-bin/CSA/CSA_Show_EC_List.pl?", false);
73
74
75
76
77
78 public static final XrefDatabaseConstant NIST74 = new XrefDatabaseConstant("NIST74", "NIST 74",
79 "http://xpdb.nist.gov/enzyme_thermodynamics/enzyme_compose_query.pl?EC=", false);
80
81
82
83
84
85 public static final XrefDatabaseConstant KEGG = new XrefDatabaseConstant("KEGG", "KEGG",
86 "http://www.genome.ad.jp/dbget-bin/www_bget?ec:", false);
87
88
89
90
91 public static final XrefDatabaseConstant MEROPS = new XrefDatabaseConstant("MEROPS", "MEROPS", "", false);
92
93
94
95
96 public static final XrefDatabaseConstant MIM = new XrefDatabaseConstant("MIM", "OMIM", "http://www.ncbi.nlm.nih.gov/entrez/dispomim.cgi?id=", true);
97
98
99
100
101
102 public static final XrefDatabaseConstant PROSITE = new XrefDatabaseConstant("PROSITE", "PROSITE",
103 "http://www.expasy.org/prosite/", true);
104
105
106
107
108 public static final XrefDatabaseConstant SWISSPROT = new XrefDatabaseConstant("SWISSPROT", "Swiss-Prot",
109 "http://www.uniprot.org/uniprot/", true);
110
111
112
113
114
115
116
117
118 public static final XrefDatabaseConstant UMBBD = new XrefDatabaseConstant("UMBBD", "UM-BBD",
119 "http://umbbd.ethz.ch/servlets/pageservlet?ptype=e&ECcode=", false);
120
121 public static final XrefDatabaseConstant DIAGRAM = new XrefDatabaseConstant("DIAGR", "DIAGRAM",
122 "", true);
123
124
125
126
127
128 public static final XrefDatabaseConstant ERGO = new XrefDatabaseConstant("ERGO", "ERGO",
129 "http://www.ergo-light.com/ERGO/CGI/fr.cgi?org=&user=&fr=", false);
130
131
132
133
134 public static final XrefDatabaseConstant WIT = new XrefDatabaseConstant("WIT", "WIT",
135 "http://www.ergo-light.com/ERGO/CGI/fr.cgi?org=&user=&fr=", false);
136
137
138
139
140 public static final XrefDatabaseConstant PDB = new XrefDatabaseConstant("PDB", "EC2PDB", "http://www.ebi.ac.uk/thornton-srv/databases/cgi-bin/enzymes/GetPage.pl?ec_number=", false);
141
142 private static XrefDatabaseConstant[] PRIVATE_LINK_SOURCES = {
143 UNDEF,
144 BRENDA,
145 CAS,
146 ENZYME,
147 NC_IUBMB,
148 GO,
149 NIST74,
150 KEGG,
151 MEROPS,
152 METACYC,
153 MIM,
154 PROSITE,
155 SWISSPROT,
156 UMBBD,
157 ERGO,
158 WIT,
159 DIAGRAM,
160 PDB,
161 CSA
162 };
163
164 private static XrefDatabaseConstant[] PRIVATE_UNIQUE_LINK_SOURCES = {
165 BRENDA,
166 ENZYME,
167 NC_IUBMB,
168 GO,
169 METACYC,
170 NIST74,
171 KEGG,
172
173 UMBBD,
174 ERGO,
175 WIT
176 };
177
178
179
180
181 public static final List<XrefDatabaseConstant> LINK_SOURCE_CONSTANTS =
182 Collections.unmodifiableList(Arrays.asList(PRIVATE_LINK_SOURCES));
183
184
185
186
187 public static final Set<XrefDatabaseConstant> UNIQUE_LINK_SOURCES =
188 Collections.unmodifiableSet(new HashSet<XrefDatabaseConstant>(Arrays.asList(PRIVATE_UNIQUE_LINK_SOURCES)));
189
190
191
192
193
194
195
196
197 private XrefDatabaseConstant(String sourceCode, String displayName, String url, boolean isXref) {
198 this.databaseCode = sourceCode;
199 this.displayName = displayName;
200 this.url = url;
201 this.isXref = isXref;
202 }
203
204 public static XrefDatabaseConstant valueOf(String sourceCode) throws DomainException {
205 if (sourceCode == null) throw new NullPointerException("Parameter 'databaseCode' must not be null.");
206 if (sourceCode.equals("")) throw new IllegalArgumentException("Parameter 'databaseCode' must not be empty.");
207 for (Iterator<XrefDatabaseConstant> it = LINK_SOURCE_CONSTANTS.iterator(); it.hasNext();) {
208 XrefDatabaseConstant xrefDatabaseConstant = it.next();
209 if (xrefDatabaseConstant.getDatabaseCode().equals(sourceCode)) return xrefDatabaseConstant;
210 }
211 throw new DomainException("org.apache.struts.action.GLOBAL_MESSAGE", "errors.application.xrefs.source_code");
212 }
213
214 public int compareTo(XrefDatabaseConstant linkSourceConstant) {
215 return this.getDatabaseCode().compareTo(linkSourceConstant.getDatabaseCode());
216 }
217
218
219
220
221
222
223
224
225 public static boolean contains(String sourceCode) {
226 if (sourceCode == null) throw new NullPointerException("Parameter 'databaseCode' must not be null.");
227 for (Iterator<XrefDatabaseConstant> it = LINK_SOURCE_CONSTANTS.iterator(); it.hasNext();) {
228 XrefDatabaseConstant sourceConstant = it.next();
229 if (sourceCode.equals(sourceConstant.getDatabaseCode())) return true;
230 }
231 return false;
232 }
233
234 public static boolean isUniqueXrefDatabaseName(String databaseName) {
235 if (databaseName == null) throw new NullPointerException("Parameter 'databaseName' must not be null.");
236 String databaseCode = getDatabaseCodeOf(databaseName);
237 return isUniqueXrefDatabaseCode(databaseCode);
238 }
239
240 public static boolean isUniqueXrefDatabaseCode(String databaseCode) {
241 if (databaseCode == null) throw new NullPointerException("Parameter 'databaseCode' must not be null.");
242 if (!XrefDatabaseConstant.contains(databaseCode)) throw new IllegalArgumentException("The databaseCode paramter is invalid.");
243 for (Iterator<XrefDatabaseConstant> it = UNIQUE_LINK_SOURCES.iterator(); it.hasNext();) {
244 XrefDatabaseConstant xrefDatabaseConstant = it.next();
245 if (xrefDatabaseConstant.databaseCode.equals(databaseCode)) return true;
246 }
247 return false;
248 }
249
250
251
252
253
254
255
256
257
258
259
260 public static boolean isXref(String sourceCode) {
261 if (sourceCode == null) throw new NullPointerException();
262 if (!XrefDatabaseConstant.contains(sourceCode)) throw new IllegalArgumentException("The databaseCode paramter is invalid.");
263 for (Iterator<XrefDatabaseConstant> it = LINK_SOURCE_CONSTANTS.iterator(); it.hasNext();) {
264 XrefDatabaseConstant sourceConstant = it.next();
265 if (sourceCode.equals(sourceConstant.getDatabaseCode())) return sourceConstant.isXref();
266 }
267 return false;
268 }
269
270
271
272
273
274
275
276 public boolean equals(Object o) {
277 if (this == o) return true;
278 if (!(o instanceof XrefDatabaseConstant)) return false;
279
280 final XrefDatabaseConstant xrefDatabaseConstant = (XrefDatabaseConstant) o;
281
282 if (databaseCode != null ? !databaseCode.equals(xrefDatabaseConstant.databaseCode) : xrefDatabaseConstant.databaseCode !=
283 null) return false;
284 if (url != null ? !url.equals(xrefDatabaseConstant.url) : xrefDatabaseConstant.url != null) return false;
285
286 return true;
287 }
288
289
290
291
292
293
294 public int hashCode() {
295 int result;
296 result = (databaseCode != null ? databaseCode.hashCode() : 0);
297 result = 29 * result + (url != null ? url.hashCode() : 0);
298 return result;
299 }
300
301
302
303
304
305
306 public String toString() {
307 return displayName;
308 }
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323 public static String getUrlOf(String sourceCode) {
324 if (sourceCode == null) throw new NullPointerException("Parameter 'databaseCode' must not be null.");
325 if (!XrefDatabaseConstant.contains(sourceCode)) throw new IllegalArgumentException("The 'databaseCode' paramter is invalid.");
326 for (Iterator<XrefDatabaseConstant> it = LINK_SOURCE_CONSTANTS.iterator(); it.hasNext();) {
327 XrefDatabaseConstant sourceConstant = it.next();
328 if (sourceCode.equals(sourceConstant.getDatabaseCode())) return sourceConstant.getUrl();
329 }
330 return "";
331 }
332
333
334
335
336
337
338
339
340 public static String getDisplayNameOf(String sourceCode) {
341 if (sourceCode == null) throw new NullPointerException("Parameter 'databaseCode' must not be null.");
342 if (!XrefDatabaseConstant.contains(sourceCode)) throw new IllegalArgumentException("The 'databaseCode' paramter is invalid.");
343 for (Iterator<XrefDatabaseConstant> it = LINK_SOURCE_CONSTANTS.iterator(); it.hasNext();) {
344 XrefDatabaseConstant sourceConstant = it.next();
345 if (sourceCode.equals(sourceConstant.getDatabaseCode())) return sourceConstant.getDisplayName();
346 }
347 return "";
348 }
349
350 public static String getDatabaseCodeOf(String databaseName) {
351 if (databaseName == null) throw new NullPointerException("Parameter 'databaseName' must not be null.");
352 for (Iterator<XrefDatabaseConstant> it = LINK_SOURCE_CONSTANTS.iterator(); it.hasNext();) {
353 XrefDatabaseConstant sourceConstant = it.next();
354 if (databaseName.equals(sourceConstant.getDisplayName())) return sourceConstant.getDatabaseCode();
355 }
356 throw new IllegalArgumentException("The 'databaseName' parameter is invalid:" + databaseName);
357 }
358
359 public String getDatabaseCode() {
360 return databaseCode;
361 }
362
363 public String getDisplayName() {
364 return displayName;
365 }
366
367 public String getUrl() {
368 return url;
369 }
370
371 public boolean isXref() {
372 return isXref;
373 }
374
375 }
376
377