JAL-2885 uniprot now https, uniprot/ensembl/pfam/xfam configurable
[jalview.git] / src / jalview / ext / ensembl / EnsemblSequenceFetcher.java
index f1b96e2..2f642b5 100644 (file)
@@ -1,5 +1,26 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.ext.ensembl;
 
+import jalview.bin.Cache;
 import jalview.datamodel.DBRefSource;
 import jalview.ws.seqfetcher.DbSourceProxyImpl;
 
@@ -9,13 +30,33 @@ import com.stevesoft.pat.Regex;
  * A base class for Ensembl sequence fetchers
  * 
  * @author gmcarstairs
- *
  */
-public abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl
+abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl
 {
+  // domain properties lookup keys:
+  protected static final String ENSEMBL_DOMAIN = "ENSEMBL_DOMAIN";
+  protected static final String ENSEMBL_GENOMES_DOMAIN = "ENSEMBL_GENOMES_DOMAIN";
+
+  // domain properties default values:
+  protected static final String DEFAULT_ENSEMBL_DOMAIN = "http://rest.ensembl.org";
+  protected static final String DEFAULT_ENSEMBL_GENOMES_DOMAIN = "http://rest.ensemblgenomes.org";
+
   /*
-   * possible values for the 'feature' parameter of the REST overlap endpoint
-   * @see 
+   * accepts ENSG/T/E/P with 11 digits
+   * or ENSMUSP or similar for other species
+   * or CCDSnnnnn.nn with at least 3 digits
+   */
+  private static final Regex ACCESSION_REGEX = new Regex(
+          "(ENS([A-Z]{3}|)[GTEP]{1}[0-9]{11}$)" + "|"
+                  + "(CCDS[0-9.]{3,}$)");
+
+  protected final String ensemblGenomesDomain;
+
+  protected final String ensemblDomain;
+
+  /*
+   * possible values for the 'feature' parameter of the /overlap REST service
+   * @see http://rest.ensembl.org/documentation/info/overlap_id
    */
   protected enum EnsemblFeatureType
   {
@@ -24,17 +65,32 @@ public abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl
     constrained, regulatory
   }
 
-  @Override
-  public String getDbSource()
+  private String domain;
+
+  /**
+   * Constructor
+   */
+  public EnsemblSequenceFetcher()
   {
-    // NB ensure Uniprot xrefs are canonicalised from "Ensembl" to "ENSEMBL"
-    return DBRefSource.ENSEMBL; // "ENSEMBL"
+    /*
+     * the default domain names may be overridden in .jalview_properties;
+     * this allows an easy change from http to https in future if needed
+     */
+    ensemblDomain = Cache.getDefault(ENSEMBL_DOMAIN, DEFAULT_ENSEMBL_DOMAIN);
+    ensemblGenomesDomain = Cache.getDefault(ENSEMBL_GENOMES_DOMAIN,
+            DEFAULT_ENSEMBL_GENOMES_DOMAIN);
+    domain = ensemblDomain;
   }
 
   @Override
-  public String getDbVersion()
+  public String getDbSource()
   {
-    return "0";
+    // NB ensure Uniprot xrefs are canonicalised from "Ensembl" to "ENSEMBL"
+    if (ensemblGenomesDomain.equals(getDomain()))
+    {
+      return DBRefSource.ENSEMBLGENOMES;
+    }
+    return DBRefSource.ENSEMBL;
   }
 
   @Override
@@ -43,10 +99,16 @@ public abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl
     return " ";
   }
 
+  /**
+   * Ensembl accession are ENST + 11 digits for human transcript, ENSG for human
+   * gene. Other species insert 3 letters e.g. ENSMUST..., ENSMUSG...
+   * 
+   * @see http://www.ensembl.org/Help/View?id=151
+   */
   @Override
   public Regex getAccessionValidator()
   {
-    return new Regex("((ENSP|ENST|ENSG|CCDS)[0-9.]{3,})");
+    return ACCESSION_REGEX;
   }
 
   @Override
@@ -77,4 +139,20 @@ public abstract class EnsemblSequenceFetcher extends DbSourceProxyImpl
   {
     return true;
   }
+
+  /**
+   * Returns the domain name to query e.g. http://rest.ensembl.org or
+   * http://rest.ensemblgenomes.org
+   * 
+   * @return
+   */
+  protected String getDomain()
+  {
+    return domain;
+  }
+
+  protected void setDomain(String d)
+  {
+    domain = d;
+  }
 }