X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fcontroller%2FAlignViewController.java;h=d1d61d23bb960d31693ec8aa59e521aca7d51e3c;hb=53ff06f7f5e6f8c6d1f594f19a3df90153ead765;hp=7d60dc8d62b2045362190d2409fc9a9ff89b9612;hpb=8b27085fa7fc5f2877e078421284c2636b85b8c6;p=jalview.git diff --git a/src/jalview/controller/AlignViewController.java b/src/jalview/controller/AlignViewController.java index 7d60dc8..d1d61d2 100644 --- a/src/jalview/controller/AlignViewController.java +++ b/src/jalview/controller/AlignViewController.java @@ -238,62 +238,65 @@ public class AlignViewController implements AlignViewControllerI int nseq = 0; for (SequenceI sq : seqs) { - boolean sequenceHasFeature = false; if (sq != null) { - SequenceFeature[] sfs = sq.getSequenceFeatures(); - if (sfs != null) + int ist = sq.findPosition(sqcol.getStartRes()); + int iend = sq.findPosition(sqcol.getEndRes()); // see JAL-2526 + List sfs = sq.getFeatures().findFeatures(ist, + iend, featureType); + boolean overlap = false; + for (SequenceFeature sf : sfs) { - /* - * 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) + // future functionality - featureType == null means mark columns + // containing all displayed features + if (sf != null && (featureType.equals(sf.getType()))) { - // sequence not in region - continue; - } - for (SequenceFeature sf : sfs) - { - // future functionality - featureType == null means mark columns - // containing all displayed features - if (sf != null && (featureType.equals(sf.getType()))) - { - // optimisation - could consider 'spos,apos' like cursor argument - // - findIndex wastes time by starting from first character and - // counting + int sfStartCol = sq.findIndex(sf.getBegin()); + int sfEndCol = sq.findIndex(sf.getEnd()); // inefficient - JAL-2526 - int i = sq.findIndex(sf.getBegin()); - int j = sq.findIndex(sf.getEnd()); - if (j < startPosition || i > endPosition) - { - // feature is outside selected region - continue; - } - sequenceHasFeature = true; - if (i < startPosition) - { - i = startPosition; - } - if (i < ist) - { - i = ist; - } - if (j > endPosition) + if (sf.isContactFeature()) + { + /* + * 'contact' feature - check for 'start' or 'end' + * position within the selected region + */ + if (sfStartCol >= startPosition && sfStartCol <= endPosition) { - j = endPosition; + bs.set(sfStartCol - 1); + overlap = true; } - for (; i <= j; i++) + if (sfEndCol >= startPosition && sfEndCol <= endPosition) { - bs.set(i - 1); // convert to base 0 + bs.set(sfEndCol - 1); + overlap = true; } + continue; + } + + /* + * contiguous feature - select feature positions (if any) + * within the selected region + */ + if (sfStartCol < startPosition) + { + sfStartCol = startPosition; + } + if (sfStartCol < ist) + { + sfStartCol = ist; + } + if (sfEndCol > endPosition) + { + sfEndCol = endPosition; + } + for (; sfStartCol <= sfEndCol; sfStartCol++) + { + bs.set(sfStartCol - 1); // convert to base 0 + overlap = true; } } } - - if (sequenceHasFeature) + if (overlap) { nseq++; } @@ -382,4 +385,66 @@ public class AlignViewController implements AlignViewControllerI return featuresFile; } + + @Override + public boolean markHighlightedColumns(boolean invert, + boolean extendCurrent, boolean toggle) + { + if (!viewport.hasSearchResults()) + { + // do nothing if no selection exists + return false; + } + // JBPNote this routine could also mark rows, not just columns. + BitSet bs = new BitSet(); + SequenceCollectionI sqcol = (viewport.getSelectionGroup() == null || extendCurrent) ? viewport + .getAlignment() : viewport.getSelectionGroup(); + + // this could be a lambda... - the remains of the method is boilerplate, + // except for the different messages for reporting selection. + int nseq = viewport.getSearchResults().markColumns(sqcol, bs); + + ColumnSelection cs = viewport.getColumnSelection(); + if (cs == null) + { + cs = new ColumnSelection(); + } + + if (bs.cardinality() > 0 || invert) + { + boolean changed = cs.markColumns(bs, sqcol.getStartRes(), + sqcol.getEndRes(), invert, extendCurrent, toggle); + if (changed) + { + viewport.setColumnSelection(cs); + alignPanel.paintAlignment(true); + int columnCount = invert ? (sqcol.getEndRes() - sqcol.getStartRes() + 1) + - bs.cardinality() + : bs.cardinality(); + avcg.setStatus(MessageManager.formatMessage( + "label.view_controller_toggled_marked", + new String[] { + toggle ? MessageManager.getString("label.toggled") + : MessageManager.getString("label.marked"), + String.valueOf(columnCount), + invert ? MessageManager + .getString("label.not_containing") + : MessageManager.getString("label.containing"), + "Highlight", Integer.valueOf(nseq).toString() })); + return true; + } + } + else + { + avcg.setStatus(MessageManager + .formatMessage("No highlighted regions marked")); + if (!extendCurrent) + { + cs.clear(); + alignPanel.paintAlignment(true); + } + } + return false; + } + }