JAL-1705 include stop codons in derived CDS; support ensemblgenomes
[jalview.git] / src / jalview / ext / ensembl / EnsemblRestClient.java
index 297f71b..1c47373 100644 (file)
@@ -23,10 +23,9 @@ import com.stevesoft.pat.Regex;
  */
 abstract class EnsemblRestClient extends EnsemblSequenceFetcher
 {
-  protected final static String ENSEMBL_REST = "http://rest.ensembl.org";
+  private final static String ENSEMBL_REST = "http://rest.ensembl.org";
 
-  protected static final String SEQUENCE_ID_URL = ENSEMBL_REST
-          + "/sequence/id";
+  protected final static String ENSEMBL_GENOMES_REST = "http://rest.ensemblgenomes.org";
 
   // @see https://github.com/Ensembl/ensembl-rest/wiki/Output-formats
   private static final String PING_URL = "http://rest.ensembl.org/info/ping.json";
@@ -39,18 +38,48 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
   private static final Regex GENE_REGEX = new Regex(
             "(ENS)([A-Z]{3}|)G[0-9]{11}$");
 
+  private String domain = ENSEMBL_REST;
+
   private static boolean ensemblRestAvailable = false;
 
   private static long lastCheck = -1;
 
   protected volatile boolean inProgress = false;
 
-  public static boolean isTranscriptIdentifier(String query)
+  /**
+   * Default constructor to use rest.ensembl.org
+   */
+  public EnsemblRestClient()
+  {
+    this(ENSEMBL_REST);
+  }
+
+  /**
+   * Constructor given the target domain to fetch data from
+   * 
+   * @param d
+   */
+  public EnsemblRestClient(String d)
+  {
+    domain = d;
+  }
+
+  String getDomain()
+  {
+    return domain;
+  }
+
+  void setDomain(String d)
+  {
+    domain = d;
+  }
+
+  public boolean isTranscriptIdentifier(String query)
   {
     return query == null ? false : TRANSCRIPT_REGEX.search(query);
   }
 
-  public static boolean isGeneIdentifier(String query)
+  public boolean isGeneIdentifier(String query)
   {
     return query == null ? false : GENE_REGEX.search(query);
   }
@@ -112,7 +141,10 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
   {
     try
     {
-      URL ping = new URL(PING_URL);
+      // note this format works for both ensembl and ensemblgenomes
+      // info/ping.json works for ensembl only (March 2016)
+      URL ping = new URL(getDomain()
+              + "/info/ping?content-type=application/json");
       HttpURLConnection conn = (HttpURLConnection) ping.openConnection();
       int rc = conn.getResponseCode();
       conn.disconnect();