X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fcontroller%2FAlignViewController.java;h=aac78014d50cfec0617b87109e75dc6b8b07f482;hb=83be20f1d8274aa0044acc72c427abef766d8dd1;hp=e44c32dee9f45a37794e4e55a40d4c0994986813;hpb=82b053436b1d354d5b09ab419cac65ca032aea94;p=jalview.git diff --git a/src/jalview/controller/AlignViewController.java b/src/jalview/controller/AlignViewController.java index e44c32d..aac7801 100644 --- a/src/jalview/controller/AlignViewController.java +++ b/src/jalview/controller/AlignViewController.java @@ -29,6 +29,7 @@ import jalview.api.FeatureRenderer; import jalview.commands.OrderCommand; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; +import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceCollectionI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; @@ -38,6 +39,7 @@ import jalview.io.FeaturesFile; import jalview.util.MessageManager; import java.awt.Color; +import java.util.ArrayList; import java.util.BitSet; import java.util.List; @@ -53,20 +55,19 @@ public class AlignViewController implements AlignViewControllerI private AlignViewControllerGuiI avcg; public AlignViewController(AlignViewControllerGuiI alignFrame, - AlignViewportI viewport, AlignmentViewPanel alignPanel) + AlignViewportI vp, AlignmentViewPanel ap) { this.avcg = alignFrame; - this.viewport = viewport; - this.alignPanel = alignPanel; + this.viewport = vp; + this.alignPanel = ap; } @Override - public void setViewportAndAlignmentPanel(AlignViewportI viewport, - AlignmentViewPanel alignPanel) + public void setViewportAndAlignmentPanel(AlignViewportI vp, + AlignmentViewPanel ap) { - this.alignPanel = alignPanel; - this.viewport = viewport; - + this.alignPanel = ap; + this.viewport = vp; } @Override @@ -182,7 +183,7 @@ public class AlignViewController implements AlignViewControllerI if (changed) { viewport.setColumnSelection(cs); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); int columnCount = invert ? (sqcol.getEndRes() - sqcol.getStartRes() + 1) - bs.cardinality() @@ -207,7 +208,7 @@ public class AlignViewController implements AlignViewControllerI if (!extendCurrent) { cs.clear(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } } return false; @@ -215,17 +216,21 @@ public class AlignViewController implements AlignViewControllerI /** * Sets a bit in the BitSet for each column (base 0) in the sequence - * collection which includes the specified feature type. Returns the number of - * sequences which have the feature in the selected range. + * collection which includes a visible feature of the specified feature type. + * Returns the number of sequences which have the feature visible in the + * selected range. * * @param featureType * @param sqcol * @param bs * @return */ - static int findColumnsWithFeature(String featureType, + int findColumnsWithFeature(String featureType, SequenceCollectionI sqcol, BitSet bs) { + FeatureRenderer fr = alignPanel == null ? null : alignPanel + .getFeatureRenderer(); + final int startColumn = sqcol.getStartRes() + 1; // converted to base 1 final int endColumn = sqcol.getEndRes() + 1; List seqs = sqcol.getSequences(); @@ -238,13 +243,19 @@ public class AlignViewController implements AlignViewControllerI List sfs = sq.findFeatures(startColumn, endColumn, featureType); - if (!sfs.isEmpty()) - { - nseq++; - } - + boolean found = false; for (SequenceFeature sf : sfs) { + if (fr.getColour(sf) == null) + { + continue; + } + if (!found) + { + nseq++; + } + found = true; + int sfStartCol = sq.findIndex(sf.getBegin()); int sfEndCol = sq.findIndex(sf.getEnd()); @@ -329,7 +340,7 @@ public class AlignViewController implements AlignViewControllerI AlignmentSorter.sortByFeature(typ, gps, start, stop, al, method); avcg.addHistoryItem(new OrderCommand(methodText, oldOrder, viewport.getAlignment())); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, false); } @@ -343,35 +354,136 @@ public class AlignViewController implements AlignViewControllerI public boolean parseFeaturesFile(String file, DataSourceType protocol, boolean relaxedIdMatching) { - boolean featuresFile = false; + boolean featuresAdded = false; + FeatureRenderer fr = alignPanel.getFeatureRenderer(); try { - featuresFile = new FeaturesFile(false, file, protocol).parse( - viewport.getAlignment().getDataset(), - alignPanel.getFeatureRenderer().getFeatureColours(), false, - relaxedIdMatching); + featuresAdded = new FeaturesFile(false, file, protocol).parse( + viewport.getAlignment().getDataset(), fr.getFeatureColours(), + fr.getFeatureFilters(), false, relaxedIdMatching); } catch (Exception ex) { ex.printStackTrace(); } - if (featuresFile) + if (featuresAdded) { avcg.refreshFeatureUI(true); - if (alignPanel.getFeatureRenderer() != null) + if (fr != null) { // update the min/max ranges where necessary - alignPanel.getFeatureRenderer().findAllFeatures(true); + fr.findAllFeatures(true); } if (avcg.getFeatureSettingsUI() != null) { avcg.getFeatureSettingsUI().discoverAllFeatureData(); } - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); + } + + return featuresAdded; + + } + + /** + * + * Add highlighted sequences to selected rows. Exclude highlighted sequences + * from selected rows. toggle inclusion or exclusion of highlighted sequences. + * or add/exclude/toggle for sequences not highlighted. + * + * @param invert + * - when true, sequences that are not highlighted are added/removed + * from selection + * @param extendCurrent + * - normally true , the current selected group is modified. + * Otherwise a new selection is created + * @param toggle + * - toggle selection status for highlighted/not highlighted sequence + * @return + */ + public boolean selectHighlightedSequences(boolean invert, + boolean extendCurrent, boolean toggle) + { + List results = alignPanel.getAlignViewport() + .getHighlightedSeqs(); + + SequenceGroup sq = (extendCurrent + && viewport.getSelectionGroup() != null) + ? viewport.getSelectionGroup() + : new SequenceGroup(); + + SearchResultsI searchResults = viewport.getSearchResults(); + if (invert) + { + List nothighlighted = new ArrayList(); + for (SequenceI seq : alignPanel.getAlignViewport().getAlignment() + .getSequences()) + { + if (!results.contains(seq) && (searchResults == null + || !searchResults.involvesSequence(seq))) + { + nothighlighted.add(seq); + } + } + results = nothighlighted; + } + else + { + // copy list and add in search results + results = new ArrayList(results); + if (searchResults != null) + { + for (SequenceI seq : alignPanel.getAlignViewport().getAlignment() + .getSequences()) + { + if (searchResults.involvesSequence(seq)) + { + results.add(seq); + } + } + } + } + + if (results == null || results.size() == 0) + { + // do nothing if no selection exists + // unless toggle ?? + return false; + } + + boolean changed = false; + + for (SequenceI seq : results) + { + int size = sq.getSize(); + if (toggle) + { + sq.addOrRemove(seq, false); + } + else + { + sq.addSequence(seq, false); + } + changed |= size != sq.getSize(); + } + + if (sq.getSize() == 0) + { + viewport.setSelectionGroup(null); + } + else + { + if (sq != viewport.getSelectionGroup()) + { + sq.setStartRes(0); + sq.setEndRes(viewport.getRanges().getAbsoluteAlignmentWidth()); + } + viewport.setSelectionGroup(sq); } - return featuresFile; + alignPanel.paintAlignment(false, false); + return changed; } @Override @@ -406,7 +518,7 @@ public class AlignViewController implements AlignViewControllerI if (changed) { viewport.setColumnSelection(cs); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); int columnCount = invert ? (sqcol.getEndRes() - sqcol.getStartRes() + 1) - bs.cardinality() @@ -430,7 +542,7 @@ public class AlignViewController implements AlignViewControllerI if (!extendCurrent) { cs.clear(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } } return false;