Merge branch 'releases/Release_2_11_3_Branch'
[jalview.git] / src / jalview / datamodel / ColumnSelection.java
index 309aabf..b427739 100644 (file)
@@ -278,6 +278,27 @@ public class ColumnSelection
   }
 
   /**
+   * add a series of start,end (inclusive) ranges to the column selection
+   * 
+   * @param rng
+   *          [start_0, end_0, start_1, end_1, ... ]
+   * @param baseOne
+   *          - when true, ranges are base 1 and will be mapped to base 0
+   */
+  public void addRangeOfElements(int[] rng, boolean baseOne)
+  {
+    int base = baseOne ? -1 : 0;
+    for (int c = 0; c < rng.length; c += 2)
+    {
+      for (int p = rng[c]; p <= rng[c + 1]; p++)
+      {
+        selection.add(base + p);
+      }
+    }
+
+  }
+
+  /**
    * clears column selection
    */
   public void clear()
@@ -319,10 +340,12 @@ public class ColumnSelection
 
   /**
    * Returns a read-only view of the (possibly empty) list of selected columns
+   * (base 1)
    * <p>
-   * The list contains no duplicates but is not necessarily ordered. It also may
-   * include columns hidden from the current view. To modify (for example sort)
-   * the list, you should first make a copy.
+   * The list contains no duplicates but is not necessarily ordered. Columns are
+   * reported in alignment coordinates (base 1), so may also include columns
+   * hidden from the current view. To modify (for example sort) the list, you
+   * should first make a copy.
    * <p>
    * The list is not thread-safe: iterating over it could result in
    * ConcurrentModificationException if it is modified by another thread.
@@ -566,6 +589,45 @@ public class ColumnSelection
     // JBPNote - this method needs to be refactored to become independent of
     // viewmodel package
     this.clear();
+
+    if (ann_row.graph == AlignmentAnnotation.CONTACT_MAP && (filterParams
+            .getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
+            || filterParams
+                    .getThresholdType() == AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD))
+    {
+      float tVal = filterParams.getThresholdValue();
+      if (ann_row.sequenceRef != null)
+      {
+        // TODO - get ContactList from AlignmentView for non-seq-ref associatd
+        for (int column = 0; column < annotations.length; column++)
+        {
+          if (ann_row.annotations[column] == null)
+          {
+            continue;
+          }
+
+          int cpos = ann_row.sequenceRef.findPosition(column) - 1;
+          ContactListI clist = ann_row.sequenceRef
+                  .getContactListFor(ann_row, cpos);
+          for (int row = column + 8, rowEnd = clist
+                  .getContactHeight(); row < rowEnd; row++)
+          {
+            if (filterParams
+                    .getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
+                            ? (clist.getContactAt(row) > tVal)
+                            : (clist.getContactAt(row) < tVal))
+            {
+              addElement(column);
+              break;
+              // int column_forrowpos = ann_row.sequenceRef.findIndex(row + 1);
+              // addElement(column_forrowpos);
+            }
+          }
+        }
+      }
+      return selection.size();
+    }
+
     int addedCount = 0;
     int column = 0;
     do
@@ -580,19 +642,6 @@ public class ColumnSelection
          * filter may have multiple conditions - 
          * these are or'd until a match is found
          */
-        if (ann_row.graph == AlignmentAnnotation.CUSTOMRENDERER)
-        {
-          if (ann_row.sequenceRef != null)
-          {
-            int cpos = ann_row.sequenceRef.findPosition(column) - 1;
-            ContactListI clist = ann_row.sequenceRef
-                    .getContactListFor(ann_row, cpos);
-            ContactRange crange = clist.getRangeFor(0,
-                    clist.getContactHeight());
-            value = (float) crange.getMean();
-          }
-        }
-
         if (filterParams
                 .getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
                 && value > filterParams.getThresholdValue())