JAL-3116 Uniprot XML unmarshalled using JAXB not Castor
[jalview.git] / src / jalview / datamodel / xdb / embl / EmblFile.java
index 54aab8b..8a32c13 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9.0b2)
- * Copyright (C) 2015 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
  * 
  * This file is part of Jalview.
  * 
@@ -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;
@@ -43,6 +46,8 @@ public class EmblFile
 
   Vector<EmblError> errors;
 
+  String text;
+
   /**
    * @return the entries
    */
@@ -116,8 +121,9 @@ public class EmblFile
       try
       {
         // uncomment to DEBUG EMBLFile reading
-        if (jalview.bin.Cache.getDefault(jalview.bin.Cache.CASTORLOGLEVEL,
-                "debug").equalsIgnoreCase("DEBUG"))
+        if (jalview.bin.Cache
+                .getDefault(jalview.bin.Cache.CASTORLOGLEVEL, "debug")
+                .equalsIgnoreCase("DEBUG"))
         {
           unmar.setDebug(jalview.bin.Cache.log.isDebugEnabled());
         }
@@ -129,6 +135,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 +145,59 @@ 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)
+  {
+    if (record.getEntries() == null)
+    {
+      return;
+    }
+    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");
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+
+  public String getText()
+  {
+    return text;
+  }
+
+  public void setText(String text)
+  {
+    this.text = text;
+  }
 }