JAL-2791 select columns by _visible_ features
[jalview.git] / src / jalview / controller / AlignViewController.java
index 460c2b3..7bb295e 100644 (file)
@@ -36,6 +36,7 @@ import jalview.datamodel.SequenceI;
 import jalview.io.DataSourceType;
 import jalview.io.FeaturesFile;
 import jalview.util.MessageManager;
+import jalview.viewmodel.seqfeatures.FeatureRendererModel;
 
 import java.awt.Color;
 import java.util.BitSet;
@@ -215,17 +216,22 @@ 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)
   {
+    FeatureRendererModel fr = alignPanel == null ? null
+            : (FeatureRendererModel) alignPanel.getFeatureRenderer();
+    List<String> visibleFeatures = fr.getDisplayedFeatureTypes();
+
     final int startColumn = sqcol.getStartRes() + 1; // converted to base 1
     final int endColumn = sqcol.getEndRes() + 1;
     List<SequenceI> seqs = sqcol.getSequences();
@@ -238,13 +244,22 @@ public class AlignViewController implements AlignViewControllerI
         List<SequenceFeature> sfs = sq.findFeatures(startColumn,
                 endColumn, featureType);
 
-        if (!sfs.isEmpty())
-        {
-          nseq++;
-        }
-
+        boolean found = false;
         for (SequenceFeature sf : sfs)
         {
+          {
+            if (!visibleFeatures.contains(sf.getType())
+                    || fr.getColour(sf) == null) // could pull up getColour to
+                                                 // FeatureRenderer interface
+            {
+              continue;
+            }
+          }
+          if (!found)
+          {
+            nseq++;
+          }
+          found = true;
           int sfStartCol = sq.findIndex(sf.getBegin());
           int sfEndCol = sq.findIndex(sf.getEnd());