import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.fail;
-import jalview.analysis.AlignmentGenerator;
-import jalview.gui.JvOptionPane;
-
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import jalview.analysis.AlignmentGenerator;
+import jalview.gui.JvOptionPane;
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter;
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField;
+import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.ThresholdType;
+
public class ColumnSelectionTest
{
cs.removeElement(1);
List<Integer> sel = cs.getSelected();
assertEquals(2, sel.size());
- assertEquals(new Integer(2), sel.get(0));
- assertEquals(new Integer(5), sel.get(1));
+ assertEquals(Integer.valueOf(2), sel.get(0));
+ assertEquals(Integer.valueOf(5), sel.get(1));
// removing an element in the list removes it
cs.removeElement(2);
assertEquals(1, sel.size());
sel = cs.getSelected();
assertEquals(1, sel.size());
- assertEquals(new Integer(5), sel.get(0));
+ assertEquals(Integer.valueOf(5), sel.get(0));
}
/**
*/
@Test(
groups = "Functional",
- expectedExceptions = { ConcurrentModificationException.class })
+ expectedExceptions =
+ { ConcurrentModificationException.class })
public void testGetSelected_concurrentModification()
{
ColumnSelection cs = new ColumnSelection();
assertEquals("[3, 1]", cs2.getSelected().toString());
}
-
@Test(groups = { "Functional" })
public void testStretchGroup_expand()
{
assertEquals(sg.getStartRes(), 10);
assertEquals(sg.getEndRes(), 19);
}
+
+ @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));
+ }
}