X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fcontroller%2FAlignViewController.java;fp=src%2Fjalview%2Fcontroller%2FAlignViewController.java;h=bc7f21269a8e46c0b34ee604a8227ea8509d7a34;hb=2595e9d4ee0dbbd3406a98c4e49a61ccde806479;hp=f508bc360dcdb96707fa2354a1484ec9eb27708d;hpb=e20075ba805d744d7cc4976e2b8d5e5840fb0a8d;p=jalview.git diff --git a/src/jalview/controller/AlignViewController.java b/src/jalview/controller/AlignViewController.java index f508bc3..bc7f212 100644 --- a/src/jalview/controller/AlignViewController.java +++ b/src/jalview/controller/AlignViewController.java @@ -33,6 +33,7 @@ import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; import jalview.datamodel.SequenceI; +import jalview.io.DataSourceType; import jalview.io.FeaturesFile; import jalview.util.MessageManager; @@ -243,10 +244,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 +261,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 } } } @@ -349,7 +371,7 @@ public class AlignViewController implements AlignViewControllerI } @Override - public boolean parseFeaturesFile(String file, String protocol, + public boolean parseFeaturesFile(String file, DataSourceType protocol, boolean relaxedIdMatching) { boolean featuresFile = false; @@ -381,4 +403,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; + } + }