X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fcontroller%2FAlignViewController.java;h=d992e4e6a804f0f83fa6272a4cfa537bd91c1ddf;hb=61e7d354202ba56bd3768ebf5f790deec26a6475;hp=24fc18194708981efe7c6d1c19162905308e2743;hpb=3d0101179759ef157b088ea135423cd909512d9f;p=jalview.git diff --git a/src/jalview/controller/AlignViewController.java b/src/jalview/controller/AlignViewController.java index 24fc181..d992e4e 100644 --- a/src/jalview/controller/AlignViewController.java +++ b/src/jalview/controller/AlignViewController.java @@ -52,29 +52,20 @@ public class AlignViewController implements AlignViewControllerI */ private AlignViewControllerGuiI avcg; - @Override - protected void finalize() throws Throwable - { - viewport = null; - alignPanel = null; - avcg = null; - }; - 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 @@ -190,7 +181,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() @@ -215,7 +206,7 @@ public class AlignViewController implements AlignViewControllerI if (!extendCurrent) { cs.clear(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } } return false; @@ -223,102 +214,87 @@ 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) { - final int startPosition = sqcol.getStartRes() + 1; // converted to base 1 - final int endPosition = sqcol.getEndRes() + 1; + 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(); 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()); + List sfs = sq.findFeatures(startColumn, + endColumn, featureType); + + boolean found = false; + for (SequenceFeature sf : sfs) { - int ist = sq.findIndex(sq.getStart()); - int iend = sq.findIndex(sq.getEnd()); - if (iend < startPosition || ist > endPosition) + if (fr.getColour(sf) == null) { - // sequence not in region continue; } - for (SequenceFeature sf : sfs) + if (!found) { - // future functionality - featureType == null means mark columns - // containing all displayed features - if (sf != null && (featureType.equals(sf.getType()))) + nseq++; + } + found = true; + + 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 >= startColumn && sfStartCol <= endColumn) + { + bs.set(sfStartCol - 1); + } + if (sfEndCol >= startColumn && sfEndCol <= endColumn) { - // 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()); - - 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 (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 - } + bs.set(sfEndCol - 1); } + continue; } - } - if (sequenceHasFeature) - { - nseq++; + /* + * contiguous feature - select feature positions (if any) + * within the selected region + */ + if (sfStartCol < startColumn) + { + sfStartCol = startColumn; + } + // not sure what the point of this is + // if (sfStartCol < ist) + // { + // sfStartCol = ist; + // } + if (sfEndCol > endColumn) + { + sfEndCol = endColumn; + } + for (; sfStartCol <= sfEndCol; sfStartCol++) + { + bs.set(sfStartCol - 1); // convert to base 0 + } } } } @@ -362,7 +338,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); } @@ -376,34 +352,34 @@ 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 featuresFile; + return featuresAdded; } @@ -439,7 +415,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() @@ -463,7 +439,7 @@ public class AlignViewController implements AlignViewControllerI if (!extendCurrent) { cs.clear(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } } return false;