JAL-2316 Updated to use identifiers jalview service
authorkiramt <k.mourao@dundee.ac.uk>
Thu, 26 Jan 2017 11:27:08 +0000 (11:27 +0000)
committerkiramt <k.mourao@dundee.ac.uk>
Thu, 26 Jan 2017 11:27:08 +0000 (11:27 +0000)
src/jalview/bin/Cache.java
src/jalview/urls/IdentifiersUrlProvider.java
test/jalview/urls/DesktopUrlProviderFactoryTest.java
test/jalview/urls/IdentifiersUrlProviderTest.java
test/jalview/urls/UrlLinkTableModelTest.java
test/jalview/urls/UrlProviderTest.java

index 6764430..0dfd0d5 100755 (executable)
@@ -184,6 +184,8 @@ import org.apache.log4j.SimpleLayout;
  * <li>STRUCTURE_DISPLAY choose from JMOL (default) or CHIMERA for 3D structure
  * display</li>
  * <li>CHIMERA_PATH specify full path to Chimera program (if non-standard)</li>
+ * <li>ID_ORG_HOSTURL location of jalview service providing identifiers.org urls
+ * </li>
  * 
  * </ul>
  * Deprecated settings:
@@ -241,9 +243,7 @@ public class Cache
    * Identifiers.org download settings
    */
   private static final String ID_ORG_FILE = System.getProperty("user.home")
-          + File.separatorChar + ".jalview_identifiers";
-
-  private static final String ID_ORG_URL = "http://identifiers.org/rest/collections/";
+          + File.separatorChar + ".identifiers.org.ids.json";
 
   /**
    * Allowed values are PDB or mmCIF
@@ -456,7 +456,7 @@ public class Cache
             "sifts_cache_threshold_in_days",
             DEFAULT_CACHE_THRESHOLD_IN_DAYS));
 
-    IdOrgSettings.setUrl(ID_ORG_URL);
+    IdOrgSettings.setUrl(getProperty("ID_ORG_HOSTURL"));
     IdOrgSettings.setDownloadLocation(ID_ORG_FILE);
 
     System.out
index a966b07..c938666 100644 (file)
@@ -52,6 +52,10 @@ import org.json.simple.parser.ParseException;
 public class IdentifiersUrlProvider extends UrlProviderImpl
 {
 
+  private static final String LOCAL_KEY = "Local";
+
+  private static final String ID_ORG_KEY = "identifiers.org";
+
   // map of string ids to urls
   private HashMap<String, UrlLink> urls;
 
@@ -83,8 +87,24 @@ public class IdentifiersUrlProvider extends UrlProviderImpl
     try
     {
       FileReader reader = new FileReader(idFileName);
+      String key = "";
+      JSONObject obj = (JSONObject) parser.parse(reader);
+      if (obj.containsKey(ID_ORG_KEY))
+      {
+        key = ID_ORG_KEY;
+      }
+      else if (obj.containsKey(LOCAL_KEY))
+      {
+        key = LOCAL_KEY;
+      }
+      else
+      {
+        System.out
+                .println("Unexpected key returned from identifiers jalview service");
+        return idData;
+      }
 
-      JSONArray jsonarray = (JSONArray) parser.parse(reader);
+      JSONArray jsonarray = (JSONArray) obj.get(key);
 
       // loop over each entry in JSON array and build HashMap entry
       for (int i = 0; i < jsonarray.size(); i++)
@@ -100,12 +120,15 @@ public class IdentifiersUrlProvider extends UrlProviderImpl
     } catch (FileNotFoundException e)
     {
       e.printStackTrace();
+      idData.clear();
     } catch (IOException e)
     {
       e.printStackTrace();
+      idData.clear();
     } catch (ParseException e)
     {
       e.printStackTrace();
+      idData.clear();
     }
     return idData;
   }
index 5610ca3..cc55034 100644 (file)
@@ -35,8 +35,7 @@ import org.testng.annotations.Test;
 
 public class DesktopUrlProviderFactoryTest
 {
-  // Test identifiers.org download file
-  private static final String testIdOrgString = "[{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
+  private static final String testIdOrgString = "{\"Local\": [{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
           + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\","
           + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\","
           + "\"pattern\":\"^([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?$\","
@@ -44,7 +43,7 @@ public class DesktopUrlProviderFactoryTest
           + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\","
           + "\"url\":\"http://identifiers.org/interpro\"},"
           + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\""
-          + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]";
+          + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]}";
 
   @BeforeMethod(alwaysRun = true)
   public void setup()
index 9c8c96a..eed58b0 100644 (file)
@@ -38,8 +38,7 @@ import org.testng.annotations.Test;
 
 public class IdentifiersUrlProviderTest
 {
-  // Test identifiers.org download file
-  private static final String testIdOrgFile = "[{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
+  private static final String testIdOrgFile = "{\"Local\": [{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
           + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\","
           + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\","
           + "\"pattern\":\"^([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?$\","
@@ -47,7 +46,7 @@ public class IdentifiersUrlProviderTest
           + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\","
           + "\"url\":\"http://identifiers.org/interpro\"},"
           + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\""
-          + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]";
+          + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]}";
   
   private static final String[] dlinks = {
       "UniProt Knowledgebase|http://identifiers.org/uniprot/$DB_ACCESSION$|uniprot",
index 4b2ea6e..ab190ef 100644 (file)
@@ -52,8 +52,7 @@ public class UrlLinkTableModelTest {
   private static final String notinmenu = "Not1|http://not.in.menu/$DB_ACCESSION$|"
           + "Not2|http://not.in.menu.either/$DB_ACCESSION$";
 
-  // Test identifiers.org download file
-  private static final String testIdOrgString = "[{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
+  private static final String testIdOrgString = "{\"Local\": [{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
           + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\","
           + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\","
           + "\"pattern\":\"^([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?$\","
@@ -61,7 +60,7 @@ public class UrlLinkTableModelTest {
           + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\","
           + "\"url\":\"http://identifiers.org/interpro\"},"
           + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\""
-          + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]";
+          + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]}";
 
   private UrlProviderI prov;
 
index 29327d7..460ebe9 100644 (file)
@@ -18,7 +18,7 @@ import org.testng.annotations.Test;
 public class UrlProviderTest {
   
   // Test identifiers.org download file
-  private static final String testIdOrgString = "[{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
+  private static final String testIdOrgString = "{\"Local\": [{\"id\":\"MIR:00000002\",\"name\":\"ChEBI\",\"pattern\":\"^CHEBI:\\d+$\","
          + "\"definition\":\"Chemical Entities of Biological Interest (ChEBI)\",\"prefix\":\"chebi\","
          + "\"url\":\"http://identifiers.org/chebi\"},{\"id\":\"MIR:00000005\",\"name\":\"UniProt Knowledgebase\","
          + "\"pattern\":\"^([A-N,R-Z][0-9]([A-Z][A-Z, 0-9][A-Z, 0-9][0-9]){1,2})|([O,P,Q][0-9][A-Z, 0-9][A-Z, 0-9][A-Z, 0-9][0-9])(\\.\\d+)?$\","
@@ -26,7 +26,7 @@ public class UrlProviderTest {
          + "{\"id\":\"MIR:00000011\",\"name\":\"InterPro\",\"pattern\":\"^IPR\\d{6}$\",\"definition\":\"InterPro\",\"prefix\":\"interpro\","
          + "\"url\":\"http://identifiers.org/interpro\"},"
          + "{\"id\":\"MIR:00000372\",\"name\":\"ENA\",\"pattern\":\"^[A-Z]+[0-9]+(\\.\\d+)?$\",\"definition\":\"The European Nucleotide Archive (ENA),\""
-         + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]";
+          + "\"prefix\":\"ena.embl\",\"url\":\"http://identifiers.org/ena.embl\"}]}";
 
   private UrlProviderI prov;