View Javadoc

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    * 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://biocyc.org/META/NEW-IMAGE?type=REACTION&object=", 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/cgi-bin/CSA/CSA_Show_EC_List.pl?", 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    */
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    * <a href="http://ca.expasy.org/sprot/">ERGO</a> formerly WIT.
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    * Link to the <a href="http://www.rcsb.org/pdb/index.html">Protein Data Bank (PDB)</a>.
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     //MIM,
173     UMBBD,
174     ERGO,
175     WIT
176   };
177 
178   /**
179    * All link sources ordered alphabetically. This set is immutable.
180    */
181   public static final List<XrefDatabaseConstant> LINK_SOURCE_CONSTANTS =
182 	  Collections.unmodifiableList(Arrays.asList(PRIVATE_LINK_SOURCES));
183 
184   /**
185    * This set contains all link which can only occur once in an enzyme entry.
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    * Object cannot be created outside this class.
192    *
193    * @param sourceCode  The line type code.
194    * @param displayName The full name of this source.
195    * @param url         The URL of this link source (if available).
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    * Checks if the given link source code exists in this enumeration.
220    *
221    * @param sourceCode The source code of the link.
222    * @return <code>true</code> if the source code exists.
223    * @throws NullPointerException if <code>databaseCode</code> is <code>null</code>.
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    * Returns <code>true</code> if this link belongs to the XREFS table.
252    * <p/>
253    * If the source code is not a valid source code an exception is thrown (see below).
254    *
255    * @param sourceCode The source code of this link constant.
256    * @return <code>true</code> if this link belongs to the XREFS table.
257    * @throws NullPointerException     if <code>databaseCode</code> is <code>null</code>.
258    * @throws IllegalArgumentException if <code>databaseCode</code> is invalid.
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    * Standard equals method.
272    *
273    * @param o Object to be compared to this one.
274    * @return <code>true</code> if the objects are equal.
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    * Returns the hash code of this object.
291    *
292    * @return the hash code of this object.
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    * Returns the display name.
303    *
304    * @return the display name.
305    */
306   public String toString() {
307     return displayName;
308   }
309 
310 
311   // ----------------  GETTER ------------------
312 
313   /**
314    * Returns the URL of the given source code.
315    * <p/>
316    * If the source code is not a valid source code an exception is thrown (see below).
317    *
318    * @param sourceCode The source code of this link constant.
319    * @return the URL.
320    * @throws NullPointerException     if <code>databaseCode</code> is <code>null</code>.
321    * @throws IllegalArgumentException if <code>databaseCode</code> is invalid.
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    * Returns the display name of the source defined by <code>databaseCode</code>.
335    *
336    * @param sourceCode The source's code.
337    * @return the display name.
338    * @throws NullPointerException if <code>databaseCode</code> is <code>null</code>.
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