From: gmungoc Date: Sat, 24 Jun 2017 12:06:12 +0000 (+0100) Subject: JAL-2547 fix case of gap followed by enclosing contact feature position X-Git-Tag: Release_2_10_3b1~190 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=d8d9dadb23ea69882877e511b5fb62352bc9ed63;p=jalview.git JAL-2547 fix case of gap followed by enclosing contact feature position --- diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 96a2fa1..a01d185 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -1821,12 +1821,11 @@ public class Sequence extends ASequence implements SequenceI endPos, types); /* - * if the start or end column is gapped, startPos or endPos may be to the - * left or right, and we may have included adjacent or enclosing features; - * remove any that are not enclosing features + * if end column is gapped, endPos may be to the right, + * and we may have included adjacent or enclosing features; + * remove any that are not enclosing, non-contact features */ - if (endPos > this.end || Comparison.isGap(sequence[fromColumn - 1]) - || Comparison.isGap(sequence[toColumn - 1])) + if (endPos > this.end || Comparison.isGap(sequence[toColumn - 1])) { ListIterator it = result.listIterator(); while (it.hasNext()) @@ -1847,6 +1846,13 @@ public class Sequence extends ASequence implements SequenceI { it.remove(); } + else if (featureEndColumn > toColumn && sf.isContactFeature()) + { + /* + * remove an enclosing feature if it is a contact feature + */ + it.remove(); + } } } } diff --git a/test/jalview/datamodel/SequenceTest.java b/test/jalview/datamodel/SequenceTest.java index d1f4290..2f824ca 100644 --- a/test/jalview/datamodel/SequenceTest.java +++ b/test/jalview/datamodel/SequenceTest.java @@ -1343,23 +1343,21 @@ public class SequenceTest null); sq.addSequenceFeature(sf0); // add feature on BCD - SequenceFeature sf1 = new SequenceFeature("Cath", "desc", 9, 11, 2f, + SequenceFeature sfBCD = new SequenceFeature("Cath", "desc", 9, 11, 2f, null); - sq.addSequenceFeature(sf1); + sq.addSequenceFeature(sfBCD); // add feature on DE - SequenceFeature sf2 = new SequenceFeature("Cath", "desc", 11, 12, 2f, + SequenceFeature sfDE = new SequenceFeature("Cath", "desc", 11, 12, 2f, null); - sq.addSequenceFeature(sf2); + sq.addSequenceFeature(sfDE); // add contact feature at [B, H] - SequenceFeature sf3 = new SequenceFeature("Disulphide bond", "desc", 9, - 15, 2f, - null); - sq.addSequenceFeature(sf3); + SequenceFeature sfContactBH = new SequenceFeature("Disulphide bond", + "desc", 9, 15, 2f, null); + sq.addSequenceFeature(sfContactBH); // add contact feature at [F, G] - SequenceFeature sf4 = new SequenceFeature("Disulfide Bond", "desc", 13, - 14, 2f, - null); - sq.addSequenceFeature(sf4); + SequenceFeature sfContactFG = new SequenceFeature("Disulfide Bond", + "desc", 13, 14, 2f, null); + sq.addSequenceFeature(sfContactFG); // no features in columns 1-2 (-A) List found = sq.findFeatures(1, 2); @@ -1368,20 +1366,24 @@ public class SequenceTest // columns 1-6 (-ABC--) includes BCD and B/H feature but not DE found = sq.findFeatures(1, 6); assertEquals(2, found.size()); - assertTrue(found.contains(sf1)); - assertTrue(found.contains(sf3)); + assertTrue(found.contains(sfBCD)); + assertTrue(found.contains(sfContactBH)); // columns 5-6 (--) includes (enclosing) BCD but not (contact) B/H feature found = sq.findFeatures(5, 6); assertEquals(1, found.size()); - assertTrue(found.contains(sf1)); + assertTrue(found.contains(sfBCD)); // columns 7-10 (DEF-) includes BCD, DE, F/G but not B/H feature found = sq.findFeatures(7, 10); assertEquals(3, found.size()); - assertTrue(found.contains(sf1)); - assertTrue(found.contains(sf2)); - assertTrue(found.contains(sf4)); + assertTrue(found.contains(sfBCD)); + assertTrue(found.contains(sfDE)); + assertTrue(found.contains(sfContactFG)); + + // columns 10-11 (--) should find nothing + found = sq.findFeatures(10, 11); + assertEquals(0, found.size()); } @Test(groups = { "Functional" })