Merge branch 'develop' into feature_29/JAL-1372_referenceseq
[jalview.git] / src / jalview / datamodel / ColumnSelection.java
index f1c6cc4..6acca32 100644 (file)
 package jalview.datamodel;
 
 import jalview.util.ShiftList;
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Vector;
@@ -477,16 +480,13 @@ public class ColumnSelection
   }
 
   /**
-   * This Method is used to return all the HiddenColumn regions less than the
-   * given index.
-   * 
-   * @param end
-   *          int
-   * @return Vector
+   * This Method is used to return all the HiddenColumn regions
+   * @return empty list or List of hidden column intervals
    */
   public List<int[]> getHiddenColumns()
   {
-    return hiddenColumns;
+    return hiddenColumns == null ? Arrays.asList(new int[]
+    {}) : hiddenColumns;
   }
 
   /**
@@ -1283,6 +1283,15 @@ public class ColumnSelection
   {
     return hiddenColumns != null && hiddenColumns.size() > 0;
   }
+  
+  /**
+   * 
+   * @return true if there are more than one set of columns hidden
+   */
+  public boolean hasManyHiddenColumns()
+  {
+    return hiddenColumns != null && hiddenColumns.size() > 1;
+  }
 
   /**
    * mark the columns corresponding to gap characters as hidden in the column
@@ -1298,4 +1307,89 @@ public class ColumnSelection
       hideColumns(r[0], r[1]);
     }
   }
+  
+  public boolean filterAnnotations(Annotation[] annotations,
+          AnnotationFilterParameter filterParams)
+  {
+    this.revealAllHiddenColumns();
+    this.clear();
+    int count = 0;
+    do
+    {
+      if (annotations[count] != null)
+      {
+
+        boolean itemMatched = false;
+
+        if (filterParams.getThresholdType() == AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD
+                && annotations[count].value >= filterParams
+                        .getThresholdValue())
+        {
+          itemMatched = true;
+        }
+        if (filterParams.getThresholdType() == AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD
+                && annotations[count].value <= filterParams
+                        .getThresholdValue())
+        {
+          itemMatched = true;
+        }
+
+        if (filterParams.isFilterAlphaHelix()
+                && annotations[count].secondaryStructure == 'H')
+        {
+          itemMatched = true;
+        }
+
+        if (filterParams.isFilterBetaSheet()
+                && annotations[count].secondaryStructure == 'E')
+        {
+          itemMatched = true;
+        }
+
+        if (filterParams.isFilterTurn()
+                && annotations[count].secondaryStructure == 'S')
+        {
+          itemMatched = true;
+        }
+
+        String regexSearchString = filterParams.getRegexString();
+        if (regexSearchString != null
+                && !filterParams.getRegexSearchFields().isEmpty())
+        {
+          List<SearchableAnnotationField> fields = filterParams
+                  .getRegexSearchFields();
+          try
+          {
+            if (fields.contains(SearchableAnnotationField.DISPLAY_STRING)
+                    && annotations[count].displayCharacter
+                            .matches(regexSearchString))
+            {
+              itemMatched = true;
+            }
+          } catch (java.util.regex.PatternSyntaxException pse)
+          {
+            if (annotations[count].displayCharacter
+                    .equals(regexSearchString))
+            {
+              itemMatched = true;
+            }
+          }
+          if (fields.contains(SearchableAnnotationField.DESCRIPTION)
+                  && annotations[count].description != null
+                  && annotations[count].description
+                          .matches(regexSearchString))
+          {
+            itemMatched = true;
+          }
+        }
+
+        if (itemMatched)
+        {
+          this.addElement(count);
+        }
+      }
+      count++;
+    } while (count < annotations.length);
+    return false;
+  }
 }