JAL-2253 pull up constant, additional unit test bug/JAL-2253
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 20 Oct 2017 13:05:40 +0000 (14:05 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 20 Oct 2017 13:05:40 +0000 (14:05 +0100)
src/jalview/ext/ensembl/EnsemblGenomes.java
src/jalview/ext/ensembl/EnsemblLookup.java
src/jalview/ext/ensembl/EnsemblRestClient.java
src/jalview/ext/ensembl/EnsemblSymbol.java
src/jalview/ext/ensembl/EnsemblXref.java
test/jalview/ext/ensembl/EnsemblGeneTest.java

index 5a390f2..b40df50 100644 (file)
@@ -44,6 +44,7 @@ public class EnsemblGenomes extends EnsemblGene
     return "EnsemblGenomes";
   }
 
+  private String Wrong[];
   @Override
   public String getTestQuery()
   {
index 6e824cc..31da9c0 100644 (file)
@@ -94,7 +94,7 @@ public class EnsemblLookup extends EnsemblRestClient
   protected URL getUrl(String identifier)
   {
     String url = getDomain() + "/lookup/id/" + identifier
-            + "?content-type=application/json";
+            + CONTENT_TYPE_JSON;
     try
     {
       return new URL(url);
index 17f9986..6384120 100644 (file)
@@ -74,6 +74,8 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
 
   private final static long VERSION_RETEST_INTERVAL = 1000L * 3600; // 1 hr
 
+  protected static final String CONTENT_TYPE_JSON = "?content-type=application/json";
+
   static
   {
     domainData = new HashMap<String, EnsemblInfo>();
@@ -164,8 +166,7 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
     {
       // 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");
+      URL ping = new URL(getDomain() + "/info/ping" + CONTENT_TYPE_JSON);
 
       /*
        * expect {"ping":1} if ok
@@ -455,8 +456,7 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
     URL url = null;
     try
     {
-      url = new URL(
-              getDomain() + "/info/rest?content-type=application/json");
+      url = new URL(getDomain() + "/info/rest" + CONTENT_TYPE_JSON);
       BufferedReader br = getHttpResponse(url, null);
       if (br == null)
       {
@@ -522,8 +522,7 @@ abstract class EnsemblRestClient extends EnsemblSequenceFetcher
     URL url = null;
     try
     {
-      url = new URL(
-              getDomain() + "/info/data?content-type=application/json");
+      url = new URL(getDomain() + "/info/data" + CONTENT_TYPE_JSON);
       BufferedReader br = getHttpResponse(url, null);
       if (br != null)
       {
index 671bfec..7862fce 100644 (file)
@@ -42,6 +42,10 @@ import org.json.simple.parser.ParseException;
  */
 public class EnsemblSymbol extends EnsemblXref
 {
+  private static final String GENE = "gene";
+  private static final String TYPE = "type";
+  private static final String ID = "id";
+
   /**
    * Constructor given the target domain to fetch data from
    * 
@@ -73,9 +77,9 @@ public class EnsemblSymbol extends EnsemblXref
       while (rvals.hasNext())
       {
         JSONObject val = (JSONObject) rvals.next();
-        String id = val.get("id").toString();
-        String type = val.get("type").toString();
-        if (id != null && "gene".equals(type))
+        String id = val.get(ID).toString();
+        String type = val.get(TYPE).toString();
+        if (id != null && GENE.equals(type))
         {
           result = id;
           break;
@@ -105,7 +109,7 @@ public class EnsemblSymbol extends EnsemblXref
     StringBuilder sb = new StringBuilder();
     sb.append(getDomain()).append("/xrefs/symbol/")
             .append(species.toString()).append("/").append(id)
-            .append("?content-type=application/json");
+            .append(CONTENT_TYPE_JSON);
     for (String t : type)
     {
       sb.append("&object_type=").append(t);
@@ -143,13 +147,14 @@ public class EnsemblSymbol extends EnsemblXref
         {
           if (taxon.isModelOrganism())
           {
-            URL url = getUrl(query, taxon, "gene");
+            URL url = getUrl(query, taxon, GENE);
             if (url != null)
             {
               br = getHttpResponse(url, ids);
               if (br != null)
               {
                 String geneId = parseSymbolResponse(br);
+                System.out.println(url + " returned " + geneId);
                 if (geneId != null && !result.contains(geneId))
                 {
                   result.add(geneId);
index 9634ad3..bf77cd0 100644 (file)
@@ -211,7 +211,7 @@ class EnsemblXref extends EnsemblRestClient
   protected URL getUrl(String identifier)
   {
     String url = getDomain() + "/xrefs/id/" + identifier
-            + "?content-type=application/json&all_levels=1";
+            + CONTENT_TYPE_JSON + "&all_levels=1";
     try
     {
       return new URL(url);
index a8c491c..5920b89 100644 (file)
@@ -296,4 +296,28 @@ public class EnsemblGeneTest
     assertEquals(-1, fc.compare("coding_exon", "feature_variant"));
     assertEquals(1f, fc.getTransparency());
   }
+
+  @Test(groups = "Network")
+  public void testGetGeneIds()
+  {
+    /*
+     * ENSG00000158828 gene id PINK1 human
+     * ENST00000321556 transcript for the same gene - should not be duplicated
+     * P30419 Uniprot identifier for ENSG00000136448
+     * ENST00000592782 transcript for Uniprot gene - should not be duplicated
+     * BRAF - gene name resolvabe (at time of writing) for 6 model species
+     */
+    String ids = "ENSG00000158828 ENST00000321556 P30419 ENST00000592782 BRAF";
+    EnsemblGene testee = new EnsemblGene();
+    List<String> geneIds = testee.getGeneIds(ids);
+    assertEquals(8, geneIds.size());
+    assertTrue(geneIds.contains("ENSG00000158828"));
+    assertTrue(geneIds.contains("ENSG00000136448"));
+    assertTrue(geneIds.contains("ENSG00000157764")); // BRAF human
+    assertTrue(geneIds.contains("ENSMUSG00000002413")); // mouse
+    assertTrue(geneIds.contains("ENSRNOG00000010957")); // rat
+    assertTrue(geneIds.contains("ENSXETG00000004845")); // xenopus
+    assertTrue(geneIds.contains("ENSDARG00000017661")); // zebrafish
+    assertTrue(geneIds.contains("ENSGALG00000012865")); // chicken
+  }
 }