X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fcontroller%2FAlignViewController.java;h=460c2b3eedaf391e1deb1bdbce8cc1dc180aa591;hb=6c118f968f6e8f726fdbb6ce6c24d870b22419bb;hp=bc7f21269a8e46c0b34ee604a8227ea8509d7a34;hpb=7d67fb613ec026dc9a265e351e7fab542e3f1d61;p=jalview.git diff --git a/src/jalview/controller/AlignViewController.java b/src/jalview/controller/AlignViewController.java index bc7f212..460c2b3 100644 --- a/src/jalview/controller/AlignViewController.java +++ b/src/jalview/controller/AlignViewController.java @@ -52,14 +52,6 @@ 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) { @@ -85,10 +77,11 @@ public class AlignViewController implements AlignViewControllerI SequenceGroup[] gps = null; if (sg != null && (cs == null || cs.isEmpty())) { - gps = jalview.analysis.Grouping.makeGroupsFrom(viewport - .getSequenceSelection(), viewport.getAlignmentView(true) - .getSequenceStrings(viewport.getGapCharacter()), viewport - .getAlignment().getGroups()); + gps = jalview.analysis.Grouping.makeGroupsFrom( + viewport.getSequenceSelection(), + viewport.getAlignmentView(true) + .getSequenceStrings(viewport.getGapCharacter()), + viewport.getAlignment().getGroups()); } else { @@ -96,8 +89,8 @@ public class AlignViewController implements AlignViewControllerI { gps = jalview.analysis.Grouping.makeGroupsFromCols( (sg == null) ? viewport.getAlignment().getSequencesArray() - : sg.getSequences().toArray(new SequenceI[0]), cs, - viewport.getAlignment().getGroups()); + : sg.getSequences().toArray(new SequenceI[0]), + cs, viewport.getAlignment().getGroups()); } } if (gps != null) @@ -170,8 +163,9 @@ public class AlignViewController implements AlignViewControllerI // JBPNote this routine could also mark rows, not just columns. // need a decent query structure to allow all types of feature searches BitSet bs = new BitSet(); - SequenceCollectionI sqcol = (viewport.getSelectionGroup() == null || extendCurrent) ? viewport - .getAlignment() : viewport.getSelectionGroup(); + SequenceCollectionI sqcol = (viewport.getSelectionGroup() == null + || extendCurrent) ? viewport.getAlignment() + : viewport.getSelectionGroup(); int nseq = findColumnsWithFeature(featureType, sqcol, bs); @@ -188,15 +182,15 @@ public class AlignViewController implements AlignViewControllerI if (changed) { viewport.setColumnSelection(cs); - alignPanel.paintAlignment(true); - int columnCount = invert ? (sqcol.getEndRes() - sqcol.getStartRes() + 1) - - bs.cardinality() + alignPanel.paintAlignment(false, false); + 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"), + "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") @@ -207,13 +201,13 @@ public class AlignViewController implements AlignViewControllerI } else { - avcg.setStatus(MessageManager.formatMessage( - "label.no_feature_of_type_found", - new String[] { featureType })); + avcg.setStatus(MessageManager + .formatMessage("label.no_feature_of_type_found", new String[] + { featureType })); if (!extendCurrent) { cs.clear(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } } return false; @@ -232,91 +226,66 @@ public class AlignViewController implements AlignViewControllerI static int findColumnsWithFeature(String featureType, SequenceCollectionI sqcol, BitSet bs) { - final int startPosition = sqcol.getStartRes() + 1; // converted to base 1 - final int endPosition = sqcol.getEndRes() + 1; + 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); + + if (!sfs.isEmpty()) { - int ist = sq.findIndex(sq.getStart()); - int iend = sq.findIndex(sq.getEnd()); - if (iend < startPosition || ist > endPosition) - { - // sequence not in region - continue; - } - for (SequenceFeature sf : sfs) + nseq++; + } + + for (SequenceFeature sf : sfs) + { + int sfStartCol = sq.findIndex(sf.getBegin()); + int sfEndCol = sq.findIndex(sf.getEnd()); + + if (sf.isContactFeature()) { - // future functionality - featureType == null means mark columns - // containing all displayed features - if (sf != null && (featureType.equals(sf.getType()))) + /* + * 'contact' feature - check for 'start' or 'end' + * position within the selected region + */ + if (sfStartCol >= startColumn && sfStartCol <= 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(sfStartCol - 1); } + if (sfEndCol >= startColumn && sfEndCol <= endColumn) + { + 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 + } } } } @@ -358,9 +327,9 @@ public class AlignViewController implements AlignViewControllerI } SequenceI[] oldOrder = al.getSequencesArray(); AlignmentSorter.sortByFeature(typ, gps, start, stop, al, method); - avcg.addHistoryItem(new OrderCommand(methodText, oldOrder, viewport - .getAlignment())); - alignPanel.paintAlignment(true); + avcg.addHistoryItem(new OrderCommand(methodText, oldOrder, + viewport.getAlignment())); + alignPanel.paintAlignment(true, false); } @@ -377,9 +346,10 @@ public class AlignViewController implements AlignViewControllerI boolean featuresFile = false; try { - featuresFile = new FeaturesFile(false, file, protocol).parse(viewport - .getAlignment().getDataset(), alignPanel.getFeatureRenderer() - .getFeatureColours(), false, relaxedIdMatching); + featuresFile = new FeaturesFile(false, file, protocol).parse( + viewport.getAlignment().getDataset(), + alignPanel.getFeatureRenderer().getFeatureColours(), false, + relaxedIdMatching); } catch (Exception ex) { ex.printStackTrace(); @@ -397,7 +367,7 @@ public class AlignViewController implements AlignViewControllerI { avcg.getFeatureSettingsUI().discoverAllFeatureData(); } - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(true, true); } return featuresFile; @@ -415,8 +385,9 @@ public class AlignViewController implements AlignViewControllerI } // JBPNote this routine could also mark rows, not just columns. BitSet bs = new BitSet(); - SequenceCollectionI sqcol = (viewport.getSelectionGroup() == null || extendCurrent) ? viewport - .getAlignment() : viewport.getSelectionGroup(); + 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. @@ -435,15 +406,15 @@ public class AlignViewController implements AlignViewControllerI if (changed) { viewport.setColumnSelection(cs); - alignPanel.paintAlignment(true); - int columnCount = invert ? (sqcol.getEndRes() - sqcol.getStartRes() + 1) - - bs.cardinality() + alignPanel.paintAlignment(false, false); + 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"), + "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") @@ -459,7 +430,7 @@ public class AlignViewController implements AlignViewControllerI if (!extendCurrent) { cs.clear(); - alignPanel.paintAlignment(true); + alignPanel.paintAlignment(false, false); } } return false;