1 package uk.ac.ebi.intenz.domain.enzyme;
2
3 import java.util.Map;
4 import java.util.StringTokenizer;
5 import java.util.TreeMap;
6
7 import uk.ac.ebi.intenz.domain.constants.EnzymeSourceConstant;
8 import uk.ac.ebi.intenz.domain.constants.EnzymeViewConstant;
9 import uk.ac.ebi.intenz.domain.constants.XrefDatabaseConstant;
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 public class EnzymeLink implements Comparable<EnzymeLink>, Commented, Viewable {
29
30
31
32 public static final EnzymeLink BRENDA =
33 new EnzymeLink(XrefDatabaseConstant.BRENDA, XrefDatabaseConstant.BRENDA.getUrl(),
34 "", "BRENDA", EnzymeSourceConstant.INTENZ, EnzymeViewConstant.INTENZ);
35
36
37
38
39 public static final EnzymeLink METACYC =
40 new EnzymeLink(XrefDatabaseConstant.METACYC, XrefDatabaseConstant.METACYC.getUrl(),
41 "", "MetaCyc", EnzymeSourceConstant.INTENZ, EnzymeViewConstant.INTENZ);
42
43
44
45
46 public static final EnzymeLink KEGG =
47 new EnzymeLink(XrefDatabaseConstant.KEGG, XrefDatabaseConstant.KEGG.getUrl(),
48 "", "", EnzymeSourceConstant.INTENZ, EnzymeViewConstant.INTENZ);
49
50
51
52
53 public static final EnzymeLink EXPASY =
54 new EnzymeLink(XrefDatabaseConstant.ENZYME, XrefDatabaseConstant.ENZYME.getUrl(),
55 "", "", EnzymeSourceConstant.INTENZ, EnzymeViewConstant.INTENZ);
56
57
58
59
60 public static final EnzymeLink NC_IUBMB =
61 new EnzymeLink(XrefDatabaseConstant.NC_IUBMB, XrefDatabaseConstant.NC_IUBMB.getUrl(),
62 "", "", EnzymeSourceConstant.IUBMB, EnzymeViewConstant.INTENZ);
63
64
65
66
67
68 @Deprecated
69 public static final EnzymeLink ERGO =
70 new EnzymeLink(XrefDatabaseConstant.ERGO, XrefDatabaseConstant.ERGO.getUrl(),
71 "", "ERGO", EnzymeSourceConstant.INTENZ, EnzymeViewConstant.INTENZ);
72
73
74
75
76 public static final EnzymeLink WIT =
77 new EnzymeLink(XrefDatabaseConstant.WIT, XrefDatabaseConstant.WIT.getUrl(),
78 "", "", EnzymeSourceConstant.INTENZ, EnzymeViewConstant.INTENZ);
79
80
81
82
83 public static final EnzymeLink GO =
84 new EnzymeLink(XrefDatabaseConstant.GO, XrefDatabaseConstant.GO.getUrl(),
85 "", "", EnzymeSourceConstant.INTENZ, EnzymeViewConstant.INTENZ);
86
87
88
89
90 public static final EnzymeLink NIST74 =
91 new EnzymeLink(XrefDatabaseConstant.NIST74, XrefDatabaseConstant.NIST74.getUrl(),
92 "", "", EnzymeSourceConstant.INTENZ, EnzymeViewConstant.INTENZ);
93
94
95
96
97 public static final EnzymeLink UMBBD =
98 new EnzymeLink(XrefDatabaseConstant.UMBBD, XrefDatabaseConstant.UMBBD.getUrl(),
99 "", "", EnzymeSourceConstant.INTENZ, EnzymeViewConstant.INTENZ);
100
101
102
103
104 public static final EnzymeLink PDB =
105 new EnzymeLink(XrefDatabaseConstant.PDB, XrefDatabaseConstant.PDB.getUrl(),
106 "", "", EnzymeSourceConstant.INTENZ, EnzymeViewConstant.INTENZ);
107
108
109
110
111 public static final EnzymeLink CSA =
112 new EnzymeLink(XrefDatabaseConstant.CSA, XrefDatabaseConstant.CSA.getUrl(),
113 "", "", EnzymeSourceConstant.INTENZ, EnzymeViewConstant.INTENZ);
114
115 public static final EnzymeLink EXPLORENZ = new EnzymeLink(
116 XrefDatabaseConstant.EXPLORENZ,
117 XrefDatabaseConstant.EXPLORENZ.getUrl(),
118 "", "", EnzymeSourceConstant.IUBMB, EnzymeViewConstant.INTENZ);
119
120 public static final EnzymeLink UNIPATHWAY = new EnzymeLink(
121 XrefDatabaseConstant.UNIPATHWAY,
122 XrefDatabaseConstant.UNIPATHWAY.getUrl(),
123 "", "", EnzymeSourceConstant.INTENZ, EnzymeViewConstant.INTENZ);
124
125 private static Map<XrefDatabaseConstant, EnzymeLink> STATIC_LINKS;
126
127 static {
128 STATIC_LINKS = new TreeMap<XrefDatabaseConstant, EnzymeLink>();
129 STATIC_LINKS.put(BRENDA.getXrefDatabaseConstant(), BRENDA);
130 STATIC_LINKS.put(METACYC.getXrefDatabaseConstant(), METACYC);
131 STATIC_LINKS.put(KEGG.getXrefDatabaseConstant(), KEGG);
132 STATIC_LINKS.put(EXPASY.getXrefDatabaseConstant(), EXPASY);
133 STATIC_LINKS.put(EXPLORENZ.getXrefDatabaseConstant(), EXPLORENZ);
134 STATIC_LINKS.put(NIST74.getXrefDatabaseConstant(), NIST74);
135 STATIC_LINKS.put(UMBBD.getXrefDatabaseConstant(), UMBBD);
136 STATIC_LINKS.put(UNIPATHWAY.getXrefDatabaseConstant(), UNIPATHWAY);
137 STATIC_LINKS.put(CSA.getXrefDatabaseConstant(), CSA);
138 STATIC_LINKS.put(PDB.getXrefDatabaseConstant(), PDB);
139 }
140
141
142
143
144 private XrefDatabaseConstant xrefDatabaseConstant;
145
146
147
148
149 private String specificUrl;
150
151
152
153
154 private String accession;
155
156
157
158
159 private String name;
160
161 private EnzymeSourceConstant source;
162
163
164
165
166 private EnzymeViewConstant view;
167
168 private String dataComment;
169
170
171
172
173
174
175
176
177
178 private EnzymeLink(XrefDatabaseConstant xrefDatabaseConstant, String specificUrl, String accession, String name,
179 EnzymeSourceConstant source, EnzymeViewConstant view) {
180 this.xrefDatabaseConstant = xrefDatabaseConstant;
181 this.specificUrl = specificUrl;
182 this.accession = accession;
183 this.name = name;
184 this.source = source;
185 this.view = view;
186 }
187
188
189
190
191
192
193
194
195
196
197
198
199 public static EnzymeLink valueOf(XrefDatabaseConstant xrefDatabaseConstant,
200 String specificUrl, String accession, String name,
201 EnzymeSourceConstant source, EnzymeViewConstant view) {
202 if (xrefDatabaseConstant == null) throw new NullPointerException("Parameter 'xrefDatabaseConstant' must not be null.");
203 if (source == null) throw new NullPointerException("Parameter 'source' must not be null.");
204 if (view == null) throw new NullPointerException("Parameter 'view' must not be null.");
205
206
207
208
209 if (STATIC_LINKS.containsKey(xrefDatabaseConstant)){
210 if (accession == null){
211 return STATIC_LINKS.get(xrefDatabaseConstant);
212 } else {
213
214 return new EnzymeLink(xrefDatabaseConstant,
215 xrefDatabaseConstant.getUrl(),
216 accession, accession, source, view);
217 }
218 }
219
220 if ((specificUrl == null || specificUrl.equals("")) && (accession == null || accession.equals("")) &&
221 (name == null || name.equals("")))
222 throw new IllegalArgumentException("Either parameter specificUrl, accession or name must contain a value.");
223
224 return new EnzymeLink(xrefDatabaseConstant, specificUrl, accession, name, source, view);
225 }
226
227
228
229
230
231
232
233
234
235
236
237
238 public static EnzymeLink valueOf(XrefDatabaseConstant xrefDatabaseConstant, String specificUrl, String accession, String name,
239 EnzymeSourceConstant source, EnzymeViewConstant view, String dataComment){
240 EnzymeLink el = EnzymeLink.valueOf(xrefDatabaseConstant, specificUrl, accession, name, source, view);
241 el.setDataComment(dataComment);
242 return el;
243 }
244
245
246
247
248
249
250
251
252 public static boolean isStaticLink(XrefDatabaseConstant databaseConstant) {
253 if (databaseConstant == null) throw new NullPointerException("Parameter 'databaseConstant' must not be null.");
254 return STATIC_LINKS.containsKey(databaseConstant);
255 }
256
257 public static EnzymeLink getStaticLink(XrefDatabaseConstant databaseConstant) {
258 if (databaseConstant == null) throw new NullPointerException("Parameter 'databaseConstant' must not be null.");
259 return STATIC_LINKS.get(databaseConstant);
260 }
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276 public int compareTo(EnzymeLink link) {
277 if (xrefDatabaseConstant == link.getXrefDatabaseConstant()) {
278 if (name.equals(link.getName())) {
279 if (accession.equals(link.getAccession())) {
280 return specificUrl.compareTo(link.getSpecificUrl());
281 }
282 return accession.compareTo(link.getAccession());
283 }
284 return name.compareTo(link.getName());
285 }
286
287 return xrefDatabaseConstant.equals(XrefDatabaseConstant.NC_IUBMB)?
288 -1 : link.getXrefDatabaseConstant().equals(XrefDatabaseConstant.NC_IUBMB)?
289 1 : xrefDatabaseConstant.compareTo(link.getXrefDatabaseConstant());
290 }
291
292
293
294
295
296
297
298 public boolean equals(Object o) {
299 if (this == o) return true;
300 if (!(o instanceof EnzymeLink)) return false;
301
302 final EnzymeLink enzymeLink = (EnzymeLink) o;
303
304 if (accession != null ? !accession.equals(enzymeLink.accession) : enzymeLink.accession != null) return false;
305 if (name != null ? !name.equals(enzymeLink.name) : enzymeLink.name != null) return false;
306 if (source != null ? !source.equals(enzymeLink.source) : enzymeLink.source != null) return false;
307 if (specificUrl != null ? !specificUrl.equals(enzymeLink.specificUrl) : enzymeLink.specificUrl != null) return false;
308 if (view != null ? !view.equals(enzymeLink.view) : enzymeLink.view != null) return false;
309 if (xrefDatabaseConstant != null ? !xrefDatabaseConstant.equals(enzymeLink.xrefDatabaseConstant) : enzymeLink.xrefDatabaseConstant !=
310 null)
311 return false;
312
313 return true;
314 }
315
316
317
318
319
320
321 public int hashCode() {
322 int result;
323 result = (xrefDatabaseConstant != null ? xrefDatabaseConstant.hashCode() : 0);
324 result = 29 * result + (specificUrl != null ? specificUrl.hashCode() : 0);
325 result = 29 * result + (accession != null ? accession.hashCode() : 0);
326 result = 29 * result + (name != null ? name.hashCode() : 0);
327 result = 29 * result + (source != null ? source.hashCode() : 0);
328 result = 29 * result + (view != null ? view.hashCode() : 0);
329 return result;
330 }
331
332
333
334
335
336
337 public String toString() {
338 StringBuffer output = new StringBuffer();
339 output.append(this.xrefDatabaseConstant);
340 output.append(", ");
341 output.append(this.specificUrl);
342 output.append(", ");
343 output.append(this.accession);
344 output.append(", ");
345 output.append(this.name);
346 output.append(", ");
347 output.append(this.view.toString());
348 output.append(", ");
349 output.append(this.source.toString());
350
351 return output.toString();
352 }
353
354
355
356
357
358
359
360
361
362
363
364 public String getListOrderCriterion() {
365 if (xrefDatabaseConstant == XrefDatabaseConstant.SWISSPROT ||
366 xrefDatabaseConstant == XrefDatabaseConstant.PROSITE ||
367 xrefDatabaseConstant == XrefDatabaseConstant.CAS) {
368 return accession;
369 }
370
371 if (xrefDatabaseConstant == XrefDatabaseConstant.MEROPS || xrefDatabaseConstant == XrefDatabaseConstant.UMBBD) return specificUrl;
372
373 if (xrefDatabaseConstant == XrefDatabaseConstant.DIAGRAM) return name;
374
375 return xrefDatabaseConstant.getDatabaseCode();
376 }
377
378
379
380
381
382
383
384
385 public String getFullUrl(String ec) {
386 if (ec == null) throw new NullPointerException();
387 if (STATIC_LINKS.keySet().contains(xrefDatabaseConstant)){
388 boolean withAccession = EnzymeCommissionNumber.isPreliminary(ec)
389 && accession != null && accession.length() > 0;
390 return specificUrl + (withAccession? accession : ec);
391 }
392 if (xrefDatabaseConstant == XrefDatabaseConstant.PROSITE ||
393 xrefDatabaseConstant == XrefDatabaseConstant.SWISSPROT ||
394 xrefDatabaseConstant == XrefDatabaseConstant.MIM ||
395 xrefDatabaseConstant == XrefDatabaseConstant.PDB ||
396 xrefDatabaseConstant == XrefDatabaseConstant.GO ||
397 xrefDatabaseConstant == XrefDatabaseConstant.BRENDA ||
398 xrefDatabaseConstant == XrefDatabaseConstant.METACYC){
399 StringBuffer sb = new StringBuffer(xrefDatabaseConstant.getUrl());
400 sb.append(accession);
401 return sb.toString();
402 }
403 if (xrefDatabaseConstant == XrefDatabaseConstant.NC_IUBMB){
404 StringTokenizer st = new StringTokenizer(ec, ".");
405 StringBuffer sb = new StringBuffer(xrefDatabaseConstant.getUrl());
406 sb.append(st.nextToken()).append('/')
407 .append(st.nextToken()).append('/')
408 .append(st.nextToken()).append('/')
409 .append(st.nextToken()).append(".html");
410 return sb.toString();
411 }
412 return specificUrl;
413 }
414
415 public XrefDatabaseConstant getXrefDatabaseConstant() {
416 return xrefDatabaseConstant;
417 }
418
419 public String getSpecificUrl() {
420 return specificUrl;
421 }
422
423 public String getAccession() {
424 return accession;
425 }
426
427 public String getName() {
428 return name;
429 }
430
431 public EnzymeViewConstant getView() {
432 return view;
433 }
434
435 public EnzymeSourceConstant getSource() {
436 return source;
437 }
438
439 public String getDataComment() {
440 return dataComment;
441 }
442
443 public void setDataComment(String comment) {
444 dataComment = comment;
445 }
446 }