From 9a0e53e18ba1280658e1424c5e08b90e7beeebde Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 24 Aug 2016 16:47:35 +0100 Subject: [PATCH] JAL-2106 stricter check for 1:1 mapping (same numbering on both sides, and word size == 1) --- src/jalview/datamodel/DBRefEntry.java | 9 +++++++ test/jalview/datamodel/DBRefEntryTest.java | 37 ++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/jalview/datamodel/DBRefEntry.java b/src/jalview/datamodel/DBRefEntry.java index e2ee195..11e77d8 100755 --- a/src/jalview/datamodel/DBRefEntry.java +++ b/src/jalview/datamodel/DBRefEntry.java @@ -297,6 +297,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][]))) + { + return false; + } } if (version == null) { diff --git a/test/jalview/datamodel/DBRefEntryTest.java b/test/jalview/datamodel/DBRefEntryTest.java index 8cc31e0..09d9df1 100644 --- a/test/jalview/datamodel/DBRefEntryTest.java +++ b/test/jalview/datamodel/DBRefEntryTest.java @@ -145,32 +145,53 @@ public class DBRefEntryTest DBRefEntry dbr = new DBRefEntry(DBRefSource.UNIPROT, "", "Q12345"); assertTrue(dbr.isPrimary()); /* - * 1:1 mapping with shift + * 1:1 mapping */ - dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 5, 9 }, 1, + dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 1, 3 }, 1, 1)); assertTrue(dbr.isPrimary()); + /* + * Version string is prefixed with another dbref source string (fail) + */ + dbr.setVersion(DBRefSource.EMBL + ":0"); + assertFalse(dbr.isPrimary()); + + /* + * Version string is alphanumeric + */ + dbr.setVersion("0.1.b"); + assertTrue(dbr.isPrimary()); /* - * 1:1 mapping with shift and sequenceRef + * 1:1 mapping with shift (fail) + */ + dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 2, 4 }, 1, + 1)); + assertFalse(dbr.isPrimary()); + + /* + * 1:1 mapping and sequenceRef (fail) */ dbr.setMap(new Mapping(new Sequence("foo", "ASDF"), new int[] { 1, 3 }, - new int[] { 5, 9 }, 1, 1)); + new int[] { 1, 3 }, 1, 1)); assertFalse(dbr.isPrimary()); /* - * 1:3 mapping with shift (fail) + * 1:3 mapping (fail) */ - dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 5, 9 }, 1, + 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 not realistic) + * 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[] { 5, 9 }, 2, + dbr.setMap(new Mapping(null, new int[] { 1, 3 }, new int[] { 1, 3 }, 2, 2)); assertFalse(dbr.isPrimary()); + /* + * Version string is prefixed with another dbref source string + */ dbr.setVersion(DBRefSource.EMBL + ":0"); assertFalse(dbr.isPrimary()); -- 1.7.10.2