1 package uk.ac.ebi.intenz.domain.constants;
2
3 import java.util.*;
4
5 import uk.ac.ebi.intenz.domain.exceptions.DomainException;
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://www.metacyc.org/META/NEW-IMAGE?type=EC-NUMBER&object=EC-", 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/CSA_NEW/SearchResults_EC.php?ECID=", 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
129 @Deprecated
130 public static final XrefDatabaseConstant ERGO = new XrefDatabaseConstant("ERGO", "ERGO",
131 "http://www.ergo-light.com/ERGO/CGI/fr.cgi?org=&user=&fr=", false);
132
133
134
135
136 public static final XrefDatabaseConstant WIT = new XrefDatabaseConstant("WIT", "WIT",
137 "http://www.ergo-light.com/ERGO/CGI/fr.cgi?org=&user=&fr=", false);
138
139
140
141
142 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);
143
144
145
146
147 public static final XrefDatabaseConstant EXPLORENZ = new XrefDatabaseConstant(
148 "EXP", "ExplorEnz", "http://www.enzyme-database.org/query.php?ec=", false);
149
150 public static final XrefDatabaseConstant UNIPATHWAY =
151 new XrefDatabaseConstant("UP", "UniPathway",
152 "http://www.unipathway.org/enzyme/entry?ec=", false);
153
154 private static XrefDatabaseConstant[] PRIVATE_LINK_SOURCES = {
155 NC_IUBMB,
156 BRENDA,
157 DIAGRAM,
158 ENZYME,
159 ERGO,
160 EXPLORENZ,
161 GO,
162 KEGG,
163 MEROPS,
164 METACYC,
165 MIM,
166 NIST74,
167 PROSITE,
168 SWISSPROT,
169 UMBBD,
170 UNIPATHWAY,
171 WIT,
172 CSA,
173 PDB,
174 CAS,
175 UNDEF
176 };
177
178 private static XrefDatabaseConstant[] PRIVATE_UNIQUE_LINK_SOURCES = {
179 NC_IUBMB,
180 BRENDA,
181 ENZYME,
182 EXPLORENZ,
183 GO,
184 KEGG,
185 METACYC,
186 NIST74,
187 UMBBD,
188 UNIPATHWAY,
189 WIT
190 };
191
192
193
194
195 public static final List<XrefDatabaseConstant> LINK_SOURCE_CONSTANTS =
196 Collections.unmodifiableList(Arrays.asList(PRIVATE_LINK_SOURCES));
197
198
199
200
201 public static final Set<XrefDatabaseConstant> UNIQUE_LINK_SOURCES =
202 Collections.unmodifiableSet(new HashSet<XrefDatabaseConstant>(Arrays.asList(PRIVATE_UNIQUE_LINK_SOURCES)));
203
204
205
206
207
208
209
210
211 private XrefDatabaseConstant(String sourceCode, String displayName, String url, boolean isXref) {
212 this.databaseCode = sourceCode;
213 this.displayName = displayName;
214 this.url = url;
215 this.isXref = isXref;
216 }
217
218 public static XrefDatabaseConstant valueOf(String sourceCode) throws DomainException {
219 if (sourceCode == null) throw new NullPointerException("Parameter 'databaseCode' must not be null.");
220 if (sourceCode.equals("")) throw new IllegalArgumentException("Parameter 'databaseCode' must not be empty.");
221 for (Iterator<XrefDatabaseConstant> it = LINK_SOURCE_CONSTANTS.iterator(); it.hasNext();) {
222 XrefDatabaseConstant xrefDatabaseConstant = it.next();
223 if (xrefDatabaseConstant.getDatabaseCode().equals(sourceCode)) return xrefDatabaseConstant;
224 }
225 throw new DomainException("org.apache.struts.action.GLOBAL_MESSAGE", "errors.application.xrefs.source_code");
226 }
227
228 public int compareTo(XrefDatabaseConstant linkSourceConstant) {
229 return this.getDatabaseCode().compareTo(linkSourceConstant.getDatabaseCode());
230 }
231
232
233
234
235
236
237
238
239 public static boolean contains(String sourceCode) {
240 if (sourceCode == null) throw new NullPointerException("Parameter 'databaseCode' must not be null.");
241 for (Iterator<XrefDatabaseConstant> it = LINK_SOURCE_CONSTANTS.iterator(); it.hasNext();) {
242 XrefDatabaseConstant sourceConstant = it.next();
243 if (sourceCode.equals(sourceConstant.getDatabaseCode())) return true;
244 }
245 return false;
246 }
247
248 public static boolean isUniqueXrefDatabaseName(String databaseName) {
249 if (databaseName == null) throw new NullPointerException("Parameter 'databaseName' must not be null.");
250 String databaseCode = getDatabaseCodeOf(databaseName);
251 return isUniqueXrefDatabaseCode(databaseCode);
252 }
253
254 public static boolean isUniqueXrefDatabaseCode(String databaseCode) {
255 if (databaseCode == null) throw new NullPointerException("Parameter 'databaseCode' must not be null.");
256 if (!XrefDatabaseConstant.contains(databaseCode)) throw new IllegalArgumentException("The databaseCode paramter is invalid.");
257 for (Iterator<XrefDatabaseConstant> it = UNIQUE_LINK_SOURCES.iterator(); it.hasNext();) {
258 XrefDatabaseConstant xrefDatabaseConstant = it.next();
259 if (xrefDatabaseConstant.databaseCode.equals(databaseCode)) return true;
260 }
261 return false;
262 }
263
264
265
266
267
268
269
270
271
272
273
274 public static boolean isXref(String sourceCode) {
275 if (sourceCode == null) throw new NullPointerException();
276 if (!XrefDatabaseConstant.contains(sourceCode)) throw new IllegalArgumentException("The databaseCode paramter is invalid.");
277 for (Iterator<XrefDatabaseConstant> it = LINK_SOURCE_CONSTANTS.iterator(); it.hasNext();) {
278 XrefDatabaseConstant sourceConstant = it.next();
279 if (sourceCode.equals(sourceConstant.getDatabaseCode())) return sourceConstant.isXref();
280 }
281 return false;
282 }
283
284
285
286
287
288
289
290 public boolean equals(Object o) {
291 if (this == o) return true;
292 if (!(o instanceof XrefDatabaseConstant)) return false;
293
294 final XrefDatabaseConstant xrefDatabaseConstant = (XrefDatabaseConstant) o;
295
296 if (databaseCode != null ? !databaseCode.equals(xrefDatabaseConstant.databaseCode) : xrefDatabaseConstant.databaseCode !=
297 null) return false;
298 if (url != null ? !url.equals(xrefDatabaseConstant.url) : xrefDatabaseConstant.url != null) return false;
299
300 return true;
301 }
302
303
304
305
306
307
308 public int hashCode() {
309 int result;
310 result = (databaseCode != null ? databaseCode.hashCode() : 0);
311 result = 29 * result + (url != null ? url.hashCode() : 0);
312 return result;
313 }
314
315
316
317
318
319
320 public String toString() {
321 return displayName;
322 }
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337 public static String getUrlOf(String sourceCode) {
338 if (sourceCode == null) throw new NullPointerException("Parameter 'databaseCode' must not be null.");
339 if (!XrefDatabaseConstant.contains(sourceCode)) throw new IllegalArgumentException("The 'databaseCode' paramter is invalid.");
340 for (Iterator<XrefDatabaseConstant> it = LINK_SOURCE_CONSTANTS.iterator(); it.hasNext();) {
341 XrefDatabaseConstant sourceConstant = it.next();
342 if (sourceCode.equals(sourceConstant.getDatabaseCode())) return sourceConstant.getUrl();
343 }
344 return "";
345 }
346
347
348
349
350
351
352
353
354 public static String getDisplayNameOf(String sourceCode) {
355 if (sourceCode == null) throw new NullPointerException("Parameter 'databaseCode' must not be null.");
356 if (!XrefDatabaseConstant.contains(sourceCode)) throw new IllegalArgumentException("The 'databaseCode' paramter is invalid.");
357 for (Iterator<XrefDatabaseConstant> it = LINK_SOURCE_CONSTANTS.iterator(); it.hasNext();) {
358 XrefDatabaseConstant sourceConstant = it.next();
359 if (sourceCode.equals(sourceConstant.getDatabaseCode())) return sourceConstant.getDisplayName();
360 }
361 return "";
362 }
363
364 public static String getDatabaseCodeOf(String databaseName) {
365 if (databaseName == null) throw new NullPointerException("Parameter 'databaseName' must not be null.");
366 for (Iterator<XrefDatabaseConstant> it = LINK_SOURCE_CONSTANTS.iterator(); it.hasNext();) {
367 XrefDatabaseConstant sourceConstant = it.next();
368 if (databaseName.equals(sourceConstant.getDisplayName())) return sourceConstant.getDatabaseCode();
369 }
370 throw new IllegalArgumentException("The 'databaseName' parameter is invalid:" + databaseName);
371 }
372
373 public String getDatabaseCode() {
374 return databaseCode;
375 }
376
377 public String getDisplayName() {
378 return displayName;
379 }
380
381 public String getUrl() {
382 return url;
383 }
384
385 public boolean isXref() {
386 return isXref;
387 }
388
389 }
390
391