JAL-2843 unit tests for writing filters to Jalview features file
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 9 Jan 2018 16:28:11 +0000 (16:28 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Tue, 9 Jan 2018 16:28:11 +0000 (16:28 +0000)
test/jalview/io/FeaturesFileTest.java

index fd4cad7..32ca841 100644 (file)
@@ -34,12 +34,15 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceDummy;
 import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
+import jalview.datamodel.features.FeatureMatcher;
 import jalview.datamodel.features.FeatureMatcherI;
+import jalview.datamodel.features.FeatureMatcherSet;
 import jalview.datamodel.features.FeatureMatcherSetI;
 import jalview.datamodel.features.SequenceFeatures;
 import jalview.gui.AlignFrame;
 import jalview.gui.Desktop;
 import jalview.gui.JvOptionPane;
+import jalview.schemes.FeatureColour;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.matcher.Condition;
 
@@ -501,7 +504,7 @@ public class FeaturesFileTest
     exported = featuresFile.printJalviewFormat(al.getSequencesArray(),
             visible, null, visibleGroups, false);
     expected = "METAL\tcc9900\n"
-            + "GAMMA-TURN\tff0000|00ffff|20.0|95.0|below|66.0\n"
+            + "GAMMA-TURN\tscore|ff0000|00ffff|noValueMin|20.0|95.0|below|66.0\n"
             + "\nSTARTGROUP\tuniprot\n"
             + "Turn\tFER_CAPAA\t-1\t36\t38\tGAMMA-TURN\t0.0\n"
             + "Iron\tFER_CAPAA\t-1\t39\t39\tMETAL\t0.0\n"
@@ -520,7 +523,7 @@ public class FeaturesFileTest
      */
     expected = "METAL\tcc9900\n"
             + "Pfam\tff0000\n"
-            + "GAMMA-TURN\tff0000|00ffff|20.0|95.0|below|66.0\n"
+            + "GAMMA-TURN\tscore|ff0000|00ffff|noValueMin|20.0|95.0|below|66.0\n"
             + "\nSTARTGROUP\tuniprot\n"
             + "Turn\tFER_CAPAA\t-1\t36\t38\tGAMMA-TURN\t0.0\n"
             + "Iron\tFER_CAPAA\t-1\t39\t39\tMETAL\t0.0\n"
@@ -672,4 +675,36 @@ public class FeaturesFileTest
 
     assertFalse(matchers.hasNext());
   }
+
+  @Test(groups = { "Functional" })
+  public void testOutputFeatureFilters()
+  {
+    FeaturesFile ff = new FeaturesFile();
+    StringBuilder sb = new StringBuilder();
+    Map<String, FeatureColourI> visible = new HashMap<>();
+    visible.put("pfam", new FeatureColour(Color.red));
+    Map<String, FeatureMatcherSetI> featureFilters = new HashMap<>();
+
+    // with no filters, nothing is output
+    ff.outputFeatureFilters(sb, visible, featureFilters);
+    assertEquals("", sb.toString());
+
+    // with filter for not visible features only, nothing is output
+    FeatureMatcherSet filter = new FeatureMatcherSet();
+    filter.and(FeatureMatcher.byLabel(Condition.Present, null));
+    featureFilters.put("foobar", filter);
+    ff.outputFeatureFilters(sb, visible, featureFilters);
+    assertEquals("", sb.toString());
+
+    // with filters for visible feature types
+    FeatureMatcherSet filter2 = new FeatureMatcherSet();
+    filter2.and(FeatureMatcher.byAttribute(Condition.Present, null, "CSQ",
+            "PolyPhen"));
+    filter2.and(FeatureMatcher.byScore(Condition.LE, "-2.4"));
+    featureFilters.put("pfam", filter2);
+    visible.put("foobar", new FeatureColour(Color.blue));
+    ff.outputFeatureFilters(sb, visible, featureFilters);
+    String expected = "\nSTARTFILTERS\nfoobar\tLabel Present\npfam\t(CSQ:PolyPhen Present) AND (Score LE -2.4)\nENDFILTERS\n\n";
+    assertEquals(expected, sb.toString());
+  }
 }