JAL-2754 Sequence.findFeatures(fromCol, toCol)
[jalview.git] / src / jalview / controller / AlignViewController.java
index d1d61d2..5c1f403 100644 (file)
@@ -232,73 +232,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<SequenceI> seqs = sqcol.getSequences();
     int nseq = 0;
     for (SequenceI sq : seqs)
     {
       if (sq != null)
       {
-        int ist = sq.findPosition(sqcol.getStartRes());
-        int iend = sq.findPosition(sqcol.getEndRes()); // see JAL-2526
-        List<SequenceFeature> sfs = sq.getFeatures().findFeatures(ist,
-                iend, featureType);
-        boolean overlap = false;
-        for (SequenceFeature sf : sfs)
+        // int ist = sq.findPosition(sqcol.getStartRes());
+        List<SequenceFeature> sfs = sq.findFeatures(startColumn,
+                endColumn, featureType);
+
+        if (!sfs.isEmpty())
         {
-          // future functionality - featureType == null means mark columns
-          // containing all displayed features
-          if (sf != null && (featureType.equals(sf.getType())))
-          {
-            int sfStartCol = sq.findIndex(sf.getBegin());
-            int sfEndCol = sq.findIndex(sf.getEnd()); // inefficient - JAL-2526
+          nseq++;
+        }
 
-            if (sf.isContactFeature())
-            {
-              /*
-               * 'contact' feature - check for 'start' or 'end'
-               * position within the selected region
-               */
-              if (sfStartCol >= startPosition && sfStartCol <= endPosition)
-              {
-                bs.set(sfStartCol - 1);
-                overlap = true;
-              }
-              if (sfEndCol >= startPosition && sfEndCol <= endPosition)
-              {
-                bs.set(sfEndCol - 1);
-                overlap = true;
-              }
-              continue;
-            }
+        for (SequenceFeature sf : sfs)
+        {
+          int sfStartCol = sq.findIndex(sf.getBegin());
+          int sfEndCol = sq.findIndex(sf.getEnd());
 
+          if (sf.isContactFeature())
+          {
             /*
-             * contiguous feature - select feature positions (if any) 
-             * within the selected region
+             * 'contact' feature - check for 'start' or 'end'
+             * position within the selected region
              */
-            if (sfStartCol < startPosition)
-            {
-              sfStartCol = startPosition;
-            }
-            if (sfStartCol < ist)
+            if (sfStartCol >= startColumn && sfStartCol <= endColumn)
             {
-              sfStartCol = ist;
+              bs.set(sfStartCol - 1);
             }
-            if (sfEndCol > endPosition)
+            if (sfEndCol >= startColumn && sfEndCol <= endColumn)
             {
-              sfEndCol = endPosition;
-            }
-            for (; sfStartCol <= sfEndCol; sfStartCol++)
-            {
-              bs.set(sfStartCol - 1); // convert to base 0
-              overlap = true;
+              bs.set(sfEndCol - 1);
             }
+            continue;
+          }
+
+          /*
+           * 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
           }
-        }
-        if (overlap)
-        {
-          nseq++;
         }
       }
     }