JAL-2446 merged to spike branch
[jalview.git] / src / jalview / controller / AlignViewController.java
index 9451c3b..5c1f403 100644 (file)
@@ -33,6 +33,7 @@ import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.io.DataSourceType;
 import jalview.io.FeaturesFile;
 import jalview.util.MessageManager;
 
@@ -231,70 +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)
     {
-      boolean sequenceHasFeature = false;
       if (sq != null)
       {
-        SequenceFeature[] sfs = sq.getSequenceFeatures();
-        if (sfs != null)
+        // int ist = sq.findPosition(sqcol.getStartRes());
+        List<SequenceFeature> sfs = sq.findFeatures(startColumn,
+                endColumn, featureType);
+
+        if (!sfs.isEmpty())
+        {
+          nseq++;
+        }
+
+        for (SequenceFeature sf : sfs)
         {
+          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)
+            {
+              bs.set(sfEndCol - 1);
+            }
+            continue;
+          }
+
           /*
-           * check whether the feature start/end (base 1) 
-           * overlaps the selection start/end
+           * contiguous feature - select feature positions (if any) 
+           * within the selected region
            */
-          int ist = sq.findIndex(sq.getStart());
-          int iend = sq.findIndex(sq.getEnd());
-          if (iend < startPosition || ist > endPosition)
+          if (sfStartCol < startColumn)
           {
-            // sequence not in region
-            continue;
+            sfStartCol = startColumn;
           }
-          for (SequenceFeature sf : sfs)
+          // not sure what the point of this is
+          // if (sfStartCol < ist)
+          // {
+          // sfStartCol = ist;
+          // }
+          if (sfEndCol > endColumn)
           {
-            // future functionality - featureType == null means mark columns
-            // containing all displayed features
-            if (sf != null && (featureType.equals(sf.getType())))
-            {
-              // optimisation - could consider 'spos,apos' like cursor argument
-              // - findIndex wastes time by starting from first character and
-              // counting
-
-              int i = sq.findIndex(sf.getBegin());
-              int j = sq.findIndex(sf.getEnd());
-              if (j < startPosition || i > endPosition)
-              {
-                // feature is outside selected region
-                continue;
-              }
-              sequenceHasFeature = true;
-              if (i < startPosition)
-              {
-                i = startPosition;
-              }
-              if (i < ist)
-              {
-                i = ist;
-              }
-              if (j > endPosition)
-              {
-                j = endPosition;
-              }
-              for (; i <= j; i++)
-              {
-                bs.set(i - 1); // convert to base 0
-              }
-            }
+            sfEndCol = endColumn;
+          }
+          for (; sfStartCol <= sfEndCol; sfStartCol++)
+          {
+            bs.set(sfStartCol - 1); // convert to base 0
           }
-        }
-
-        if (sequenceHasFeature)
-        {
-          nseq++;
         }
       }
     }
@@ -349,7 +346,7 @@ public class AlignViewController implements AlignViewControllerI
   }
 
   @Override
-  public boolean parseFeaturesFile(String file, String protocol,
+  public boolean parseFeaturesFile(String file, DataSourceType protocol,
           boolean relaxedIdMatching)
   {
     boolean featuresFile = false;