X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=test%2Fjalview%2Fio%2FFeaturesFileTest.java;h=32ca8412fb61d7fb173f54f5cd48a3b900bdfa0a;hb=7c6dc8ce96f205c9330592ac18d5e9e6ef9407e0;hp=45340d91a3da4ee885462bcb6a49bd0430ecaaf8;hpb=136c0793b90b72b928c4d77dc109dd5c644e00d3;p=jalview.git diff --git a/test/jalview/io/FeaturesFileTest.java b/test/jalview/io/FeaturesFileTest.java index 45340d9..32ca841 100644 --- a/test/jalview/io/FeaturesFileTest.java +++ b/test/jalview/io/FeaturesFileTest.java @@ -23,7 +23,9 @@ package jalview.io; import static org.testng.AssertJUnit.assertEquals; import static org.testng.AssertJUnit.assertFalse; import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.AssertJUnit.assertSame; import static org.testng.AssertJUnit.assertTrue; +import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals; import jalview.api.FeatureColourI; import jalview.api.FeatureRenderer; @@ -32,9 +34,17 @@ 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; import java.awt.Color; import java.io.File; @@ -42,14 +52,28 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; public class FeaturesFileTest { + private static String simpleGffFile = "examples/testdata/simpleGff3.gff"; + + @AfterClass(alwaysRun = true) + public void tearDownAfterClass() + { + /* + * remove any sequence mappings created so they don't pollute other tests + */ + StructureSelectionManager ssm = StructureSelectionManager + .getStructureSelectionManager(Desktop.instance); + ssm.resetAll(); + } @BeforeClass(alwaysRun = true) public void setUpJvOptionPane() @@ -58,8 +82,6 @@ public class FeaturesFileTest JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); } - private static String simpleGffFile = "examples/testdata/simpleGff3.gff"; - @Test(groups = { "Functional" }) public void testParse() throws Exception { @@ -79,9 +101,13 @@ public class FeaturesFileTest * updated - JAL-1904), and verify (some) feature group colours */ colours = af.getFeatureRenderer().getFeatureColours(); - assertEquals("26 feature group colours not found", 26, colours.size()); + assertEquals("27 feature group colours not found", 27, colours.size()); assertEquals(colours.get("Cath").getColour(), new Color(0x93b1d1)); assertEquals(colours.get("ASX-MOTIF").getColour(), new Color(0x6addbb)); + FeatureColourI kdColour = colours.get("kdHydrophobicity"); + assertTrue(kdColour.isGraduatedColour()); + assertTrue(kdColour.isAboveThreshold()); + assertEquals(-2f, kdColour.getThreshold()); /* * verify (some) features on sequences @@ -450,10 +476,10 @@ public class FeaturesFileTest */ FeatureRenderer fr = af.alignPanel.getFeatureRenderer(); Map visible = fr.getDisplayedFeatureCols(); - List visibleGroups = new ArrayList( + List visibleGroups = new ArrayList<>( Arrays.asList(new String[] {})); String exported = featuresFile.printJalviewFormat( - al.getSequencesArray(), visible, visibleGroups, false); + al.getSequencesArray(), visible, null, visibleGroups, false); String expected = "No Features Visible"; assertEquals(expected, exported); @@ -462,7 +488,7 @@ public class FeaturesFileTest */ visibleGroups.add("uniprot"); exported = featuresFile.printJalviewFormat(al.getSequencesArray(), - visible, visibleGroups, true); + visible, null, visibleGroups, true); expected = "Cath\tFER_CAPAA\t-1\t0\t0\tDomain\t0.0\n" + "desc1\tFER_CAPAN\t-1\t0\t0\tPfam\t1.3\n" + "desc3\tFER1_SOLLC\t-1\t0\t0\tPfam\n" // NaN is not output @@ -476,9 +502,9 @@ public class FeaturesFileTest fr.setVisible("GAMMA-TURN"); visible = fr.getDisplayedFeatureCols(); exported = featuresFile.printJalviewFormat(al.getSequencesArray(), - visible, visibleGroups, false); + 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" @@ -491,13 +517,13 @@ public class FeaturesFileTest fr.setVisible("Pfam"); visible = fr.getDisplayedFeatureCols(); exported = featuresFile.printJalviewFormat(al.getSequencesArray(), - visible, visibleGroups, false); + visible, null, visibleGroups, false); /* * features are output within group, ordered by sequence and by type */ 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" @@ -522,8 +548,8 @@ public class FeaturesFileTest */ FeaturesFile featuresFile = new FeaturesFile(); FeatureRenderer fr = af.alignPanel.getFeatureRenderer(); - Map visible = new HashMap(); - List visibleGroups = new ArrayList( + Map visible = new HashMap<>(); + List visibleGroups = new ArrayList<>( Arrays.asList(new String[] {})); String exported = featuresFile.printGffFormat(al.getSequencesArray(), visible, visibleGroups, false); @@ -606,4 +632,79 @@ public class FeaturesFileTest + "FER_CAPAN\tUniprot\tPfam\t20\t20\t0.0\t+\t2\tx=y;black=white\n"; assertEquals(expected, exported); } + + /** + * Test for parsing of feature filters as represented in a Jalview features + * file + * + * @throws Exception + */ + @Test(groups = { "Functional" }) + public void testParseFilters() throws Exception + { + Map filters = new HashMap<>(); + String text = "sequence_variant\tCSQ:PolyPhen NotContains 'damaging'\n" + + "missense_variant\t(label contains foobar) and (Score lt 1.3)"; + FeaturesFile featuresFile = new FeaturesFile(text, + DataSourceType.PASTE); + featuresFile.parseFilters(filters); + assertEquals(filters.size(), 2); + + FeatureMatcherSetI fm = filters.get("sequence_variant"); + assertNotNull(fm); + Iterator matchers = fm.getMatchers().iterator(); + FeatureMatcherI matcher = matchers.next(); + assertFalse(matchers.hasNext()); + String[] attributes = matcher.getAttribute(); + assertArrayEquals(attributes, new String[] { "CSQ", "PolyPhen" }); + assertSame(matcher.getMatcher().getCondition(), Condition.NotContains); + assertEquals(matcher.getMatcher().getPattern(), "damaging"); + + fm = filters.get("missense_variant"); + assertNotNull(fm); + matchers = fm.getMatchers().iterator(); + matcher = matchers.next(); + assertTrue(matcher.isByLabel()); + assertSame(matcher.getMatcher().getCondition(), Condition.Contains); + assertEquals(matcher.getMatcher().getPattern(), "foobar"); + matcher = matchers.next(); + assertTrue(matcher.isByScore()); + assertSame(matcher.getMatcher().getCondition(), Condition.LT); + assertEquals(matcher.getMatcher().getPattern(), "1.3"); + assertEquals(matcher.getMatcher().getFloatValue(), 1.3f); + + assertFalse(matchers.hasNext()); + } + + @Test(groups = { "Functional" }) + public void testOutputFeatureFilters() + { + FeaturesFile ff = new FeaturesFile(); + StringBuilder sb = new StringBuilder(); + Map visible = new HashMap<>(); + visible.put("pfam", new FeatureColour(Color.red)); + Map 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()); + } }