From: gmungoc Date: Sun, 3 Jun 2018 11:03:29 +0000 (+0100) Subject: JAL-3010 double-click selects columns for term and sub-terms in Summary View X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=5e26f2eaa826c88dbc29354f67e5c00e7936437a;p=jalview.git JAL-3010 double-click selects columns for term and sub-terms in Summary View --- diff --git a/src/jalview/api/AlignViewControllerI.java b/src/jalview/api/AlignViewControllerI.java index a7ec69e..f7575c3 100644 --- a/src/jalview/api/AlignViewControllerI.java +++ b/src/jalview/api/AlignViewControllerI.java @@ -62,11 +62,11 @@ public interface AlignViewControllerI * @param toggle * - rather than explicitly set, toggle selection state * @param featureType - * - feature type string + * - one or more feature types to match * @return true if operation affected state */ boolean markColumnsContainingFeatures(boolean invert, - boolean extendCurrent, boolean toggle, String featureType); + boolean extendCurrent, boolean toggle, String... featureType); /** * sort the alignment or current selection by average score over the given set diff --git a/src/jalview/controller/AlignViewController.java b/src/jalview/controller/AlignViewController.java index d992e4e..cacde84 100644 --- a/src/jalview/controller/AlignViewController.java +++ b/src/jalview/controller/AlignViewController.java @@ -157,7 +157,7 @@ public class AlignViewController implements AlignViewControllerI @Override public boolean markColumnsContainingFeatures(boolean invert, - boolean extendCurrent, boolean toggle, String featureType) + boolean extendCurrent, boolean toggle, String... featureType) { // JBPNote this routine could also mark rows, not just columns. // need a decent query structure to allow all types of feature searches @@ -166,7 +166,7 @@ public class AlignViewController implements AlignViewControllerI || extendCurrent) ? viewport.getAlignment() : viewport.getSelectionGroup(); - int nseq = findColumnsWithFeature(featureType, sqcol, bs); + int nseq = findColumnsWithFeature(sqcol, bs, featureType); ColumnSelection cs = viewport.getColumnSelection(); if (cs == null) @@ -174,6 +174,9 @@ public class AlignViewController implements AlignViewControllerI cs = new ColumnSelection(); } + String featureTypeString = featureType.length == 1 ? featureType[0] + : featureType.toString(); + if (bs.cardinality() > 0 || invert) { boolean changed = cs.markColumns(bs, sqcol.getStartRes(), @@ -194,7 +197,7 @@ public class AlignViewController implements AlignViewControllerI invert ? MessageManager .getString("label.not_containing") : MessageManager.getString("label.containing"), - featureType, Integer.valueOf(nseq).toString() })); + featureTypeString, Integer.valueOf(nseq).toString() })); return true; } } @@ -202,7 +205,7 @@ public class AlignViewController implements AlignViewControllerI { avcg.setStatus(MessageManager .formatMessage("label.no_feature_of_type_found", new String[] - { featureType })); + { featureTypeString })); if (!extendCurrent) { cs.clear(); @@ -214,17 +217,18 @@ public class AlignViewController implements AlignViewControllerI /** * Sets a bit in the BitSet for each column (base 0) in the sequence - * 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. + * collection which includes a visible feature of the specified feature + * type(s). Returns the number of sequences which have the feature(s) visible + * in the selected range. * - * @param featureType * @param sqcol * @param bs + * @param featureType + * * @return */ - int findColumnsWithFeature(String featureType, - SequenceCollectionI sqcol, BitSet bs) + int findColumnsWithFeature(SequenceCollectionI sqcol, + BitSet bs, String... featureType) { FeatureRenderer fr = alignPanel == null ? null : alignPanel .getFeatureRenderer(); diff --git a/src/jalview/gui/FeatureSettings.java b/src/jalview/gui/FeatureSettings.java index 0c90646..48b623f 100644 --- a/src/jalview/gui/FeatureSettings.java +++ b/src/jalview/gui/FeatureSettings.java @@ -362,8 +362,9 @@ public class FeatureSettings extends JPanel boolean invertSelection = evt.isAltDown(); boolean toggleSelection = Platform.isControlDown(evt); boolean extendSelection = evt.isShiftDown(); + String[] terms = getTermsInScope(type); fr.ap.alignFrame.avc.markColumnsContainingFeatures( - invertSelection, extendSelection, toggleSelection, type); + invertSelection, extendSelection, toggleSelection, terms); } } @@ -392,6 +393,37 @@ public class FeatureSettings extends JPanel }); } + /** + * Answers an array consisting of the given type, and also (if 'Summary View' + * is selected), any child terms in the sequence ontology + * + * @param type + * @return + */ + protected String[] getTermsInScope(String type) + { + if (!summaryView.isSelected()) + { + return new String[] { type }; + } + + List terms = new ArrayList<>(); + terms.add(type); + + OntologyI so = SequenceOntologyFactory.getInstance(); + + Object[][] data = ((FeatureTableModel) table.getModel()).getData(); + for (Object[] row : data) + { + String type2 = (String) row[TYPE_COLUMN]; + if (!type2.equals(type) && so.isA(type2, type)) + { + terms.add(type2); + } + } + return terms.toArray(new String[terms.size()]); + } + protected void popupMenu(final int rowSelected, final String type, final Object typeCol, int x, int y) { diff --git a/src/jalview/workers/ConsensusThread.java b/src/jalview/workers/ConsensusThread.java index 335529c..78c6da2 100644 --- a/src/jalview/workers/ConsensusThread.java +++ b/src/jalview/workers/ConsensusThread.java @@ -118,7 +118,10 @@ public class ConsensusThread extends AlignCalcWorker protected void eraseConsensus(int aWidth) { AlignmentAnnotation consensus = getConsensusAnnotation(); - consensus.annotations = new Annotation[aWidth]; + if (consensus != null) + { + consensus.annotations = new Annotation[aWidth]; + } AlignmentAnnotation gap = getGapAnnotation(); if (gap != null) { diff --git a/test/jalview/controller/AlignViewControllerTest.java b/test/jalview/controller/AlignViewControllerTest.java index efee93b..469481d 100644 --- a/test/jalview/controller/AlignViewControllerTest.java +++ b/test/jalview/controller/AlignViewControllerTest.java @@ -102,7 +102,7 @@ public class AlignViewControllerTest af.alignPanel); BitSet bs = new BitSet(); - int seqCount = avc.findColumnsWithFeature("Metal", sg, bs); + int seqCount = avc.findColumnsWithFeature(sg, bs, "Metal"); assertEquals(1, seqCount); assertEquals(2, bs.cardinality()); assertTrue(bs.get(3)); // base 0 @@ -113,7 +113,7 @@ public class AlignViewControllerTest */ sg.setEndRes(6); bs.clear(); - seqCount = avc.findColumnsWithFeature("Metal", sg, bs); + seqCount = avc.findColumnsWithFeature(sg, bs, "Metal"); assertEquals(2, seqCount); assertEquals(4, bs.cardinality()); assertTrue(bs.get(3)); @@ -127,7 +127,7 @@ public class AlignViewControllerTest sg.setStartRes(13); sg.setEndRes(13); bs.clear(); - seqCount = avc.findColumnsWithFeature("Metal", sg, bs); + seqCount = avc.findColumnsWithFeature(sg, bs, "Metal"); assertEquals(1, seqCount); assertEquals(1, bs.cardinality()); assertTrue(bs.get(13)); @@ -138,7 +138,7 @@ public class AlignViewControllerTest sg.setStartRes(17); sg.setEndRes(19); bs.clear(); - seqCount = avc.findColumnsWithFeature("Metal", sg, bs); + seqCount = avc.findColumnsWithFeature(sg, bs, "Metal"); assertEquals(0, seqCount); assertEquals(0, bs.cardinality()); @@ -154,7 +154,7 @@ public class AlignViewControllerTest sg.setStartRes(0); sg.setEndRes(6); bs.clear(); - seqCount = avc.findColumnsWithFeature("Metal", sg, bs); + seqCount = avc.findColumnsWithFeature(sg, bs, "Metal"); assertEquals(1, seqCount); assertEquals(2, bs.cardinality()); assertTrue(bs.get(5)); @@ -166,7 +166,7 @@ public class AlignViewControllerTest sg.setStartRes(10); sg.setEndRes(12); bs.clear(); - seqCount = avc.findColumnsWithFeature("disulfide bond", sg, bs); + seqCount = avc.findColumnsWithFeature(sg, bs, "disulfide bond"); assertEquals(0, seqCount); assertEquals(0, bs.cardinality()); @@ -176,7 +176,7 @@ public class AlignViewControllerTest sg.setStartRes(5); sg.setEndRes(17); bs.clear(); - seqCount = avc.findColumnsWithFeature("disulfide bond", sg, bs); + seqCount = avc.findColumnsWithFeature(sg, bs, "disulfide bond"); assertEquals(1, seqCount); assertEquals(2, bs.cardinality()); assertTrue(bs.get(8)); @@ -188,7 +188,7 @@ public class AlignViewControllerTest sg.setStartRes(0); sg.setEndRes(19); bs.clear(); - seqCount = avc.findColumnsWithFeature("Pfam", sg, bs); + seqCount = avc.findColumnsWithFeature(sg, bs, "Pfam"); assertEquals(0, seqCount); assertEquals(0, bs.cardinality()); }