Merge branch 'develop' (JAL-4102 2.11.2.6 patch release) into features/r2_11_2_alphaf...
[jalview.git] / src / jalview / datamodel / ColumnSelection.java
index 6f14e21..db83e76 100644 (file)
  */
 package jalview.datamodel;
 
-import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
-import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField;
-
 import java.util.ArrayList;
 import java.util.BitSet;
 import java.util.Collections;
 import java.util.List;
 import java.util.regex.PatternSyntaxException;
 
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField;
+
 /**
  * Data class holding the selected columns and hidden column ranges for a view.
  * Ranges are base 1.
@@ -354,6 +354,22 @@ public class ColumnSelection
   }
 
   /**
+   * 
+   */
+  public boolean intersects(int from, int to)
+  {
+    // TODO: do this in a more efficient bitwise way
+    for (int f = from; f <= to; f++)
+    {
+      if (selection.isSelected(f))
+      {
+        return true;
+      }
+    }
+    return false;
+  }
+
+  /**
    * Answers true if no columns are selected, else false
    */
   public boolean isEmpty()
@@ -543,12 +559,52 @@ public class ColumnSelection
    * @param filterParams
    * @return
    */
-  public int filterAnnotations(Annotation[] annotations,
+  public int filterAnnotations(AlignmentAnnotation ann_row,
           AnnotationFilterParameter filterParams)
   {
+    Annotation[] annotations = ann_row.annotations;
     // JBPNote - this method needs to be refactored to become independent of
     // viewmodel package
     this.clear();
+
+    if (ann_row.graph == AlignmentAnnotation.CUSTOMRENDERER && (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
@@ -556,6 +612,7 @@ public class ColumnSelection
       Annotation ann = annotations[column];
       if (ann != null)
       {
+        float value = ann.value;
         boolean matched = false;
 
         /*
@@ -564,14 +621,14 @@ public class ColumnSelection
          */
         if (filterParams
                 .getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
-                && ann.value > filterParams.getThresholdValue())
+                && value > filterParams.getThresholdValue())
         {
           matched = true;
         }
 
         if (!matched && filterParams
                 .getThresholdType() == AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD
-                && ann.value < filterParams.getThresholdValue())
+                && value < filterParams.getThresholdValue())
         {
           matched = true;
         }