From: gmungoc Date: Mon, 5 Sep 2016 14:07:52 +0000 (+0100) Subject: JAL-2106 corrections to DBRefEntry.isPrimary code and tests X-Git-Tag: Release_2_10_0~47^2~4^2~13 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d240900df4c81bd7b054afc0f569c7a75d4e1751;p=jalview.git JAL-2106 corrections to DBRefEntry.isPrimary code and tests --- diff --git a/src/jalview/api/DBRefEntryI.java b/src/jalview/api/DBRefEntryI.java index 701acb6..a4ec575 100644 --- a/src/jalview/api/DBRefEntryI.java +++ b/src/jalview/api/DBRefEntryI.java @@ -72,23 +72,20 @@ public interface DBRefEntryI public boolean updateFrom(DBRefEntryI otherEntry); /** - * Method to distinguish between direct and indirect database references - * - * primary references indicate the local sequence data directly corresponds - * with the database record. All other references are secondary. direct + * Method to distinguish between direct and indirect database references.
+ * Primary references indicate the local sequence data directly corresponds + * with the database record. All other references are secondary. Direct * references indicate that part or all of the local sequence data can be * mapped with another sequence, enabling annotation transfer. - * cross-references indicate the local sequence data can be corresponded to - * some other linear coordinate system via a transformation. - * + * Cross-references indicate the local sequence data can be corresponded to + * some other linear coordinate system via a transformation.
* This method is also sufficient to distinguish direct DBRefEntry mappings * from other relationships - e.g. coding relationships (imply a 1:3/3:1 * mapping), but not transcript relationships, which imply a (possibly - * non-contiguous) 1:1 mapping - * + * non-contiguous) 1:1 mapping.
* The only way a dbref's mappings can be fully verified is via the local * sequence frame, so rather than use isPrimary directly, please use - * SequenceI.getPrimaryDbRefs() + * SequenceI.getPrimaryDbRefs(). * * @return true if this reference provides a primary accession for the * associated sequence object diff --git a/src/jalview/datamodel/DBRefEntry.java b/src/jalview/datamodel/DBRefEntry.java index 11e77d8..143a4d2 100755 --- a/src/jalview/datamodel/DBRefEntry.java +++ b/src/jalview/datamodel/DBRefEntry.java @@ -23,6 +23,7 @@ package jalview.datamodel; import jalview.api.DBRefEntryI; import java.util.Arrays; +import java.util.List; public class DBRefEntry implements DBRefEntryI { @@ -297,12 +298,15 @@ public class DBRefEntry implements DBRefEntryI { return false; } - // check map is really 1:1, no shifts allowed. - if (map.getMap().getFromHighest() != map.getMap().getToHighest() - && map.getMap().getFromLowest() != map.getMap().getToLowest() - && !Arrays.equals( - map.getMap().getFromRanges().toArray(new int[0][]), - map.getMap().getToRanges().toArray(new int[0][]))) + // check map is really 1:1, between identical single ranges + List fromRanges = map.getMap().getFromRanges(); + List toRanges = map.getMap().getToRanges(); + if (fromRanges.size() != 1 || toRanges.size() != 1) + { + return false; + } + if (fromRanges.get(0)[0] != toRanges.get(0)[0] + || fromRanges.get(0)[1] != toRanges.get(0)[1]) { return false; } diff --git a/test/jalview/datamodel/DBRefEntryTest.java b/test/jalview/datamodel/DBRefEntryTest.java index 09d9df1..ee0bd41 100644 --- a/test/jalview/datamodel/DBRefEntryTest.java +++ b/test/jalview/datamodel/DBRefEntryTest.java @@ -144,12 +144,37 @@ public class DBRefEntryTest { DBRefEntry dbr = new DBRefEntry(DBRefSource.UNIPROT, "", "Q12345"); assertTrue(dbr.isPrimary()); + /* - * 1:1 mapping + * 1:1 mapping - ok */ dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 1, 3 }, 1, 1)); assertTrue(dbr.isPrimary()); + + /* + * 1:1 mapping of identical split ranges - not ok + */ + dbr.setMap(new Mapping(null, new int[] { 1, 3, 6, 9 }, new int[] { 1, + 3, 6, 9 }, 1, 1)); + assertFalse(dbr.isPrimary()); + + /* + * 1:1 mapping of different ranges - not ok + */ + dbr.setMap(new Mapping(null, new int[] { 1, 4 }, new int[] { 2, 5 }, 1, + 1)); + assertFalse(dbr.isPrimary()); + + /* + * 1:1 mapping of 'isoform' ranges - not ok + */ + dbr.setMap(new Mapping(null, new int[] { 1, 2, 6, 9 }, new int[] { 1, + 3, 7, 9 }, 1, 1)); + assertFalse(dbr.isPrimary()); + dbr.setMap(null); + assertTrue(dbr.isPrimary()); + /* * Version string is prefixed with another dbref source string (fail) */ @@ -163,11 +188,12 @@ public class DBRefEntryTest assertTrue(dbr.isPrimary()); /* - * 1:1 mapping with shift (fail) + * null version string can't be primary ref */ - dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 2, 4 }, 1, - 1)); + dbr.setVersion(null); assertFalse(dbr.isPrimary()); + dbr.setVersion(""); + assertTrue(dbr.isPrimary()); /* * 1:1 mapping and sequenceRef (fail) @@ -182,18 +208,12 @@ public class DBRefEntryTest dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 1, 3 }, 1, 3)); assertFalse(dbr.isPrimary()); + /* * 2:2 mapping with shift (expected fail, but maybe use case for a pass) */ - dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 1, 3 }, 2, + dbr.setMap(new Mapping(null, new int[] { 1, 4 }, new int[] { 1, 4 }, 2, 2)); assertFalse(dbr.isPrimary()); - - /* - * Version string is prefixed with another dbref source string - */ - dbr.setVersion(DBRefSource.EMBL + ":0"); - assertFalse(dbr.isPrimary()); - } }