+
+ @Test(groups = { "Functional" })
+ public void testFilterAnnotations()
+ {
+ ColumnSelection cs = new ColumnSelection();
+ AlignmentAnnotation alann = new AlignmentAnnotation("dummy",
+ "dummyDesc", null);
+
+ /*
+ * filter with no conditions clears the selection
+ */
+ Annotation[] anns = new Annotation[] { null };
+ AnnotationFilterParameter filter = new AnnotationFilterParameter();
+ cs.addElement(3);
+ alann.annotations = anns;
+ int added = cs.filterAnnotations(alann, filter);
+ assertEquals(0, added);
+ assertTrue(cs.isEmpty());
+
+ /*
+ * select on description (regex)
+ */
+ filter.setRegexString("w.rld");
+ filter.addRegexSearchField(SearchableAnnotationField.DESCRIPTION);
+ Annotation helix = new Annotation("(", "hello", '<', 2f);
+ Annotation sheet = new Annotation("(", "world", '<', 2f);
+ alann.annotations = new Annotation[] { null, helix, sheet };
+ added = cs.filterAnnotations(alann, filter);
+ assertEquals(1, added);
+ assertTrue(cs.contains(2));
+
+ /*
+ * select on label (invalid regex, exact match)
+ */
+ filter = new AnnotationFilterParameter();
+ filter.setRegexString("(");
+ filter.addRegexSearchField(SearchableAnnotationField.DISPLAY_STRING);
+ alann.annotations = new Annotation[] { null, helix, sheet };
+ added = cs.filterAnnotations(alann, filter);
+ assertEquals(2, added);
+ assertTrue(cs.contains(1));
+ assertTrue(cs.contains(2));
+
+ /*
+ * select Helix (secondary structure symbol H)
+ */
+ filter = new AnnotationFilterParameter();
+ filter.setFilterAlphaHelix(true);
+ helix = new Annotation("x", "desc", 'H', 0f);
+ sheet = new Annotation("x", "desc", 'E', 1f);
+ Annotation turn = new Annotation("x", "desc", 'S', 2f);
+ Annotation ann4 = new Annotation("x", "desc", 'Y', 3f);
+ alann.annotations = new Annotation[] { null, helix, sheet, turn, ann4 };
+ added = cs.filterAnnotations(alann, filter);
+ assertEquals(1, added);
+ assertTrue(cs.contains(1));
+
+ /*
+ * select Helix and Sheet (E)
+ */
+ filter.setFilterBetaSheet(true);
+ alann.annotations = new Annotation[] { null, helix, sheet, turn, ann4 };
+ added = cs.filterAnnotations(alann, filter);
+ assertEquals(2, added);
+ assertTrue(cs.contains(1));
+ assertTrue(cs.contains(2));
+
+ /*
+ * select Sheet and Turn (S)
+ */
+ filter.setFilterAlphaHelix(false);
+ filter.setFilterTurn(true);
+ alann.annotations = new Annotation[] { null, helix, sheet, turn, ann4 };
+ added = cs.filterAnnotations(alann, filter);
+ assertEquals(2, added);
+ assertTrue(cs.contains(2));
+ assertTrue(cs.contains(3));
+
+ /*
+ * select value < 2f (ann1, ann2)
+ */
+ filter = new AnnotationFilterParameter();
+ filter.setThresholdType(ThresholdType.BELOW_THRESHOLD);
+ filter.setThresholdValue(2f);
+ alann.annotations = new Annotation[] { null, helix, sheet, turn, ann4 };
+ added = cs.filterAnnotations(alann, filter);
+ assertEquals(2, added);
+ assertTrue(cs.contains(1));
+ assertTrue(cs.contains(2));
+
+ /*
+ * select value > 2f (ann4 only)
+ */
+ filter.setThresholdType(ThresholdType.ABOVE_THRESHOLD);
+ alann.annotations = new Annotation[] { null, helix, sheet, turn, ann4 };
+ added = cs.filterAnnotations(alann, filter);
+ assertEquals(1, added);
+ assertTrue(cs.contains(4));
+
+ /*
+ * select >2f or Helix
+ */
+ filter.setFilterAlphaHelix(true);
+ alann.annotations = new Annotation[] { null, helix, sheet, turn, ann4 };
+ added = cs.filterAnnotations(alann, filter);
+ assertEquals(2, added);
+ assertTrue(cs.contains(1));
+ assertTrue(cs.contains(4));
+
+ /*
+ * select < 1f or Helix; one annotation matches both
+ * return value should only count it once
+ */
+ filter.setThresholdType(ThresholdType.BELOW_THRESHOLD);
+ filter.setThresholdValue(1f);
+ alann.annotations = new Annotation[] { null, helix, sheet, turn, ann4 };
+ added = cs.filterAnnotations(alann, filter);
+ assertEquals(1, added);
+ assertTrue(cs.contains(1));
+ }