From 095f0d92cb343875bd0f76f833c1eaa8614c22cd Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 21 Nov 2016 11:35:44 +0000 Subject: [PATCH] JAL-2333 corrected select columns with 'contact' feature --- src/jalview/controller/AlignViewController.java | 51 ++++++++++++++------ .../controller/AlignViewControllerTest.java | 27 +++++++++++ 2 files changed, 63 insertions(+), 15 deletions(-) diff --git a/src/jalview/controller/AlignViewController.java b/src/jalview/controller/AlignViewController.java index f508bc3..806e9a5 100644 --- a/src/jalview/controller/AlignViewController.java +++ b/src/jalview/controller/AlignViewController.java @@ -243,10 +243,6 @@ public class AlignViewController implements AlignViewControllerI SequenceFeature[] sfs = sq.getSequenceFeatures(); if (sfs != null) { - /* - * check whether the feature start/end (base 1) - * overlaps the selection start/end - */ int ist = sq.findIndex(sq.getStart()); int iend = sq.findIndex(sq.getEnd()); if (iend < startPosition || ist > endPosition) @@ -264,29 +260,54 @@ public class AlignViewController implements AlignViewControllerI // - findIndex wastes time by starting from first character and // counting - int i = sq.findIndex(sf.getBegin()); - int j = sq.findIndex(sf.getEnd()); - if (j < startPosition || i > endPosition) + int sfStartCol = sq.findIndex(sf.getBegin()); + int sfEndCol = sq.findIndex(sf.getEnd()); + + if (sf.isContactFeature()) + { + /* + * 'contact' feature - check for 'start' or 'end' + * position within the selected region + */ + if (sfStartCol >= startPosition + && sfStartCol <= endPosition) + { + bs.set(sfStartCol - 1); + sequenceHasFeature = true; + } + if (sfEndCol >= startPosition && sfEndCol <= endPosition) + { + bs.set(sfEndCol - 1); + sequenceHasFeature = true; + } + continue; + } + + /* + * contiguous feature - select feature positions (if any) + * within the selected region + */ + if (sfStartCol > endPosition || sfEndCol < startPosition) { // feature is outside selected region continue; } sequenceHasFeature = true; - if (i < startPosition) + if (sfStartCol < startPosition) { - i = startPosition; + sfStartCol = startPosition; } - if (i < ist) + if (sfStartCol < ist) { - i = ist; + sfStartCol = ist; } - if (j > endPosition) + if (sfEndCol > endPosition) { - j = endPosition; + sfEndCol = endPosition; } - for (; i <= j; i++) + for (; sfStartCol <= sfEndCol; sfStartCol++) { - bs.set(i - 1); // convert to base 0 + bs.set(sfStartCol - 1); // convert to base 0 } } } diff --git a/test/jalview/controller/AlignViewControllerTest.java b/test/jalview/controller/AlignViewControllerTest.java index 7fd8965..d7f7acb 100644 --- a/test/jalview/controller/AlignViewControllerTest.java +++ b/test/jalview/controller/AlignViewControllerTest.java @@ -53,6 +53,9 @@ public class AlignViewControllerTest null)); seq3.addSequenceFeature(new SequenceFeature("Metal", "desc", 11, 15, 0f, null)); + // disulfide bond is a 'contact feature' - only select its 'start' and 'end' + seq3.addSequenceFeature(new SequenceFeature("disulfide bond", "desc", 8, 12, + 0f, null)); /* * select the first three columns --> Metal in seq1 2-3 @@ -107,6 +110,30 @@ public class AlignViewControllerTest assertEquals(0, bs.cardinality()); /* + * columns 9-11 should not match disulfide bond at 8/12 + */ + sg.setStartRes(8); + sg.setEndRes(10); + bs.clear(); + seqCount = AlignViewController.findColumnsWithFeature("disulfide bond", + sg, bs); + assertEquals(0, seqCount); + assertEquals(0, bs.cardinality()); + + /* + * columns 6-14 should match disulfide bond at 8/12 + */ + sg.setStartRes(5); + sg.setEndRes(13); + bs.clear(); + seqCount = AlignViewController.findColumnsWithFeature("disulfide bond", + sg, bs); + assertEquals(1, seqCount); + assertEquals(2, bs.cardinality()); + assertTrue(bs.get(7)); + assertTrue(bs.get(11)); + + /* * look for a feature that isn't there */ sg.setStartRes(0); -- 1.7.10.2