JAL-2037 set DBRefEntry.version to "0" not "" in EMBL xrefs
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 1 Apr 2016 10:33:33 +0000 (11:33 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 1 Apr 2016 10:33:33 +0000 (11:33 +0100)
src/jalview/datamodel/xdb/embl/EmblFile.java
test/jalview/datamodel/xdb/embl/EmblFileTest.java

index e0b5ede..69870b6 100644 (file)
@@ -20,6 +20,9 @@
  */
 package jalview.datamodel.xdb.embl;
 
+import jalview.datamodel.DBRefEntry;
+import jalview.ws.dbsources.Uniprot;
+
 import java.io.File;
 import java.io.FileReader;
 import java.io.PrintWriter;
@@ -129,6 +132,8 @@ public class EmblFile
       unmar.setMapping(map);
       unmar.setLogWriter(new PrintWriter(System.out));
       record = (EmblFile) unmar.unmarshal(file);
+
+      canonicaliseDbRefs(record);
     } catch (Exception e)
     {
       e.printStackTrace(System.err);
@@ -137,4 +142,45 @@ public class EmblFile
 
     return record;
   }
+
+  /**
+   * Change blank version to "0" in any DBRefEntry, to ensure consistent
+   * comparison with other DBRefEntry in Jalview
+   * 
+   * @param record
+   * @see Uniprot#getDbVersion
+   */
+  static void canonicaliseDbRefs(EmblFile record)
+  {
+    for (EmblEntry entry : record.getEntries())
+    {
+      if (entry.getDbRefs() != null)
+      {
+        for (DBRefEntry dbref : entry.getDbRefs())
+        {
+          if ("".equals(dbref.getVersion()))
+          {
+            dbref.setVersion("0");
+          }
+        }
+      }
+
+      if (entry.getFeatures() != null)
+      {
+        for (EmblFeature feature : entry.getFeatures())
+        {
+          if (feature.getDbRefs() != null)
+          {
+            for (DBRefEntry dbref : feature.getDbRefs())
+            {
+              if ("".equals(dbref.getVersion()))
+              {
+                dbref.setVersion("0");
+              }
+            }
+          }
+        }
+      }
+    }
+  }
 }
index d7fd7e4..c6a94d7 100644 (file)
@@ -41,6 +41,7 @@ public class EmblFileTest
           + "<description>Chicken LDH-A mRNA for lactate dehydrogenase A chain (EC 1.1.1.27)</description>"
           + "<keyword>L-lactate dehydrogenase</keyword><keyword>chutney</keyword>"
           + "<dbreference db=\"EuropePMC\" primary=\"PMC1460223\" secondary=\"9649548\" />"
+          + "<dbreference db=\"MD5\" primary=\"d3b68\" />"
           + "<feature name=\"CDS\"><dbreference db=\"GOA\" primary=\"P00340\" secondary=\"2.1\" /><dbreference db=\"InterPro\" primary=\"IPR001236\" />"
           + "<qualifier name=\"note\"><value>L-lactate dehydrogenase A-chain</value><value>pickle</value></qualifier>"
           + "<qualifier name=\"translation\"><value>MSLKDHLIHN</value><evidence>Keith</evidence></qualifier>"
@@ -79,11 +80,16 @@ public class EmblFileTest
     /*
      * dbrefs
      */
-    assertEquals(1, entry.getDbRefs().size());
+    assertEquals(2, entry.getDbRefs().size());
     DBRefEntry dbref = entry.getDbRefs().get(0);
     assertEquals("EuropePMC", dbref.getSource());
     assertEquals("PMC1460223", dbref.getAccessionId());
     assertEquals("9649548", dbref.getVersion());
+    dbref = entry.getDbRefs().get(1);
+    assertEquals("MD5", dbref.getSource());
+    assertEquals("d3b68", dbref.getAccessionId());
+    // blank version has been converted to "0"
+    assertEquals("0", dbref.getVersion());
 
     /*
      * sequence features
@@ -99,7 +105,8 @@ public class EmblFileTest
     dbref = ef.getDbRefs().get(1);
     assertEquals("InterPro", dbref.getSource());
     assertEquals("IPR001236", dbref.getAccessionId());
-    assertEquals("", dbref.getVersion());
+    // blank version converted to "0":
+    assertEquals("0", dbref.getVersion());
     assertEquals(2, ef.getQualifiers().size());
 
     // feature qualifiers
@@ -142,5 +149,12 @@ public class EmblFileTest
     assertEquals("mRNA", seq.getType());
     assertEquals("2", seq.getVersion());
     assertEquals("GTGACG", seq.getSequence());
+
+    /*
+     * getSequence() converts empty DBRefEntry.version to "0"
+     */
+    assertEquals("0", entry.getDbRefs().get(1).getVersion());
+    assertEquals("0", entry.getFeatures().get(0).getDbRefs().get(1)
+            .getVersion());
   }
 }