From: gmungoc Date: Fri, 1 Apr 2016 10:33:33 +0000 (+0100) Subject: JAL-2037 set DBRefEntry.version to "0" not "" in EMBL xrefs X-Git-Tag: Release_2_10_0~270^2~1^2~9 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=2a797f80d895583822b5945a311069ee2566210f;p=jalview.git JAL-2037 set DBRefEntry.version to "0" not "" in EMBL xrefs --- diff --git a/src/jalview/datamodel/xdb/embl/EmblFile.java b/src/jalview/datamodel/xdb/embl/EmblFile.java index e0b5ede..69870b6 100644 --- a/src/jalview/datamodel/xdb/embl/EmblFile.java +++ b/src/jalview/datamodel/xdb/embl/EmblFile.java @@ -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"); + } + } + } + } + } + } + } } diff --git a/test/jalview/datamodel/xdb/embl/EmblFileTest.java b/test/jalview/datamodel/xdb/embl/EmblFileTest.java index d7fd7e4..c6a94d7 100644 --- a/test/jalview/datamodel/xdb/embl/EmblFileTest.java +++ b/test/jalview/datamodel/xdb/embl/EmblFileTest.java @@ -41,6 +41,7 @@ public class EmblFileTest + "Chicken LDH-A mRNA for lactate dehydrogenase A chain (EC 1.1.1.27)" + "L-lactate dehydrogenasechutney" + "" + + "" + "" + "L-lactate dehydrogenase A-chainpickle" + "MSLKDHLIHNKeith" @@ -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()); } }