View Javadoc

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    * This class represents an enumeration of all supported link source types.
9    * <p/>
10   * Instances of this class are immutable.
11   *
12   * @author Michael Darsow
13   * @version $Revision: 1.4 $ $Date: 2008/07/09 09:49:05 $
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     * <a href="http://www.brenda.uni-koeln.de/">BRENDA</a> collects functional
29     * data about enzymes. NOTE: this is now considered as xref, as the identifiers
30     * we are linking to are their preliminary EC numbers.
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     * <a href="http://www.cas.org/">CAS</a> is commercial and cannot be linked to.
42     */
43    public static final XrefDatabaseConstant CAS = new XrefDatabaseConstant("CAS", "CAS", "", false);
44  
45    /**
46     * <a href="http://ca.expasy.org/enzyme/">ENZYME</a> is the EXPASY version of the NC-IUBMB Nomenclature containing some
47     * additional information (cofactors, improved comments and additional links).
48     */
49    public static final XrefDatabaseConstant ENZYME =
50  		  new XrefDatabaseConstant("EXPASY", "ENZYME@ExPASy",
51  				  "http://enzyme.expasy.org/EC/", false);
52  
53    /**
54     * Gerry Moss' web pages (Nomenclature Comitee of the IUBMB).
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     * <a href="http://geneontology.org/">GO</a> is the Gene Ontology database.
61     */
62  //  public static final XrefDatabaseConstant GO = new XrefDatabaseConstant("GO", "GO",
63  //                                                                         "http://www.ebi.ac.uk/ego/GSearch?query=", false);
64    public static final XrefDatabaseConstant GO = new XrefDatabaseConstant("GO", "GO",
65            "http://www.ebi.ac.uk/ego/DisplayGoTerm?id=", true);
66  
67    /**
68     * <a href="http://www.ebi.ac.uk/thornton-srv/databases/CSA/">Catalytic Site Atlas</a>
69     * provides catalytic residues details.
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     * <a href="http://wwwbiotech.nist.gov:8030/enzyme/ename.html">NIST74</a> provides further information about the
76     * catalytic activity.
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     * <a href="http://www.genome.ad.jp/kegg/kegg2.html">KEGG</a> comprises several databases storing information
83     * especially related to enzymes (e.g. LIGAND, REACTION) and genes and genomes in general.
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     * <a href="http://merops.sanger.ac.uk/">MEROPS</a> is a resource for peptidases.
90     */
91    public static final XrefDatabaseConstant MEROPS = new XrefDatabaseConstant("MEROPS", "MEROPS", "", false);
92  
93    /**
94     * <a href="http://www.ncbi.nlm.nih.gov/omim/">OMIM</a> stores information about human genetic diseases.
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     * <a href="http://ca.expasy.org/prosite/">PROSITE</a> is located at the SIB and contains information about protein
100    * families and domains.
101    */
102   public static final XrefDatabaseConstant PROSITE = new XrefDatabaseConstant("PROSITE", "PROSITE",
103                                                                               "http://www.expasy.org/prosite/", true);
104 
105   /**
106    * <a href="http://ca.expasy.org/sprot/">Swiss-Prot</a> is THE protein sequence database.
107    */
108   public static final XrefDatabaseConstant SWISSPROT = new XrefDatabaseConstant("SWISSPROT", "Swiss-Prot",
109                                                                                 "http://www.uniprot.org/uniprot/", true);
110 
111   /**
112    * <a href="http://umbbd.ethz.ch">UM-BBD</a> is a comprehensive resource about enzymes also
113    * containing enzymes which haven't got an EC number yet.
114    * <p/>
115    * UM-BBD links can be static (using EC number) or non-static (using UM-BBD identifier). Therefore a UM-BBD link
116    * will not be part of the list of static links.
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    * <a href="http://ca.expasy.org/sprot/">ERGO</a> is a not very reliable enzyme source ... (I couldn't get any
126    * information about it because the server was down).
127    * @deprecated This website does not work any more (if it ever did).
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    * <a href="http://ca.expasy.org/sprot/">ERGO</a> formerly WIT.
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    * Link to the <a href="http://www.rcsb.org/pdb/index.html">Protein Data Bank (PDB)</a>.
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      * Link to ExplorEnz (Dublin's MySQL implementation of NC-IUBMB).
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    * All link sources ordered alphabetically. This set is immutable.
194    */
195   public static final List<XrefDatabaseConstant> LINK_SOURCE_CONSTANTS =
196 	  Collections.unmodifiableList(Arrays.asList(PRIVATE_LINK_SOURCES));
197 
198   /**
199    * This set contains all link which can only occur once in an enzyme entry.
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    * Object cannot be created outside this class.
206    *
207    * @param sourceCode  The line type code.
208    * @param displayName The full name of this source.
209    * @param url         The URL of this link source (if available).
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    * Checks if the given link source code exists in this enumeration.
234    *
235    * @param sourceCode The source code of the link.
236    * @return <code>true</code> if the source code exists.
237    * @throws NullPointerException if <code>databaseCode</code> is <code>null</code>.
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    * Returns <code>true</code> if this link belongs to the XREFS table.
266    * <p/>
267    * If the source code is not a valid source code an exception is thrown (see below).
268    *
269    * @param sourceCode The source code of this link constant.
270    * @return <code>true</code> if this link belongs to the XREFS table.
271    * @throws NullPointerException     if <code>databaseCode</code> is <code>null</code>.
272    * @throws IllegalArgumentException if <code>databaseCode</code> is invalid.
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    * Standard equals method.
286    *
287    * @param o Object to be compared to this one.
288    * @return <code>true</code> if the objects are equal.
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    * Returns the hash code of this object.
305    *
306    * @return the hash code of this object.
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    * Returns the display name.
317    *
318    * @return the display name.
319    */
320   public String toString() {
321     return displayName;
322   }
323 
324 
325   // ----------------  GETTER ------------------
326 
327   /**
328    * Returns the URL of the given source code.
329    * <p/>
330    * If the source code is not a valid source code an exception is thrown (see below).
331    *
332    * @param sourceCode The source code of this link constant.
333    * @return the URL.
334    * @throws NullPointerException     if <code>databaseCode</code> is <code>null</code>.
335    * @throws IllegalArgumentException if <code>databaseCode</code> is invalid.
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    * Returns the display name of the source defined by <code>databaseCode</code>.
349    *
350    * @param sourceCode The source's code.
351    * @return the display name.
352    * @throws NullPointerException if <code>databaseCode</code> is <code>null</code>.
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