X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Frenderer%2Fseqfeatures%2FFeatureColourFinderTest.java;h=4fc079ec119e7e3f4a898cbc748754b7d9a597a6;hb=b4d2b6a2ed131265ed599db27de9b82aaf010400;hp=127b6c2da20a2b517f0581bd4ffa0cc9fafac33c;hpb=846f3f1ad573cad309d41356af68887a4a3348eb;p=jalview.git diff --git a/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java b/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java index 127b6c2..4fc079e 100644 --- a/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java +++ b/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java @@ -1,6 +1,9 @@ package jalview.renderer.seqfeatures; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; import jalview.api.FeatureColourI; import jalview.datamodel.SequenceFeature; @@ -14,8 +17,8 @@ import jalview.schemes.FeatureColour; import java.awt.Color; -import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; /** @@ -47,7 +50,7 @@ public class FeatureColourFinderTest private FeatureRenderer fr; - @BeforeClass(alwaysRun = true) + @BeforeTest(alwaysRun = true) public void setUp() { // aligned column 8 is sequence position 6 @@ -61,7 +64,8 @@ public class FeatureColourFinderTest } /** - * Clear down any sequence features before each test + * Clear down any sequence features before each test (not as easy as it + * sounds...) */ @BeforeMethod(alwaysRun = true) public void setUpBeforeTest() @@ -83,6 +87,9 @@ public class FeatureColourFinderTest { fr.setGroupVisibility(group, true); } + + fr.clearRenderOrder(); + av.setShowSequenceFeatures(true); } @Test(groups = "Functional") @@ -120,6 +127,10 @@ public class FeatureColourFinderTest assertEquals(c, Color.red); } + /** + * feature colour at a gap is null (not white) - a user defined colour scheme + * can then provide a bespoke gap colour if configured to do so + */ @Test(groups = "Functional") public void testFindFeatureColour_gapPosition() { @@ -129,7 +140,7 @@ public class FeatureColourFinderTest fr.featuresAdded(); av.setShowSequenceFeatures(true); Color c = finder.findFeatureColour(null, seq, 6); - assertEquals(c, Color.white); + assertNull(c); } @Test(groups = "Functional") @@ -384,4 +395,124 @@ public class FeatureColourFinderTest c = finder.findFeatureColour(Color.pink, seq, 10); assertEquals(c, new Color(102, 223, 70)); } + + @Test(groups = "Functional") + public void testNoFeaturesDisplayed() + { + /* + * no features on alignment to render + */ + assertTrue(finder.noFeaturesDisplayed()); + + /* + * add a feature + * it will be automatically set visible but we leave + * the viewport configured not to show features + */ + av.setShowSequenceFeatures(false); + seq.addSequenceFeature(new SequenceFeature("Metal", "Metal", 2, 12, + Float.NaN, "MetalGroup")); + FeatureColour red = new FeatureColour(Color.red); + fr.setColour("Metal", red); + fr.featuresAdded(); + assertTrue(finder.noFeaturesDisplayed()); + + /* + * turn on feature display + */ + av.setShowSequenceFeatures(true); + assertFalse(finder.noFeaturesDisplayed()); + + /* + * turn off display of Metal + */ + Object[][] data = new Object[1][]; + data[0] = new Object[] { "Metal", red, false }; + fr.setFeaturePriority(data); + assertTrue(finder.noFeaturesDisplayed()); + + /* + * turn display of Metal back on + */ + fr.setVisible("Metal"); + assertFalse(finder.noFeaturesDisplayed()); + + /* + * turn off MetalGroup - has no effect here since the group of a + * sequence feature instance is independent of its type + */ + fr.setGroupVisibility("MetalGroup", false); + assertFalse(finder.noFeaturesDisplayed()); + + /* + * a finder with no feature renderer + */ + FeatureColourFinder finder2 = new FeatureColourFinder(null); + assertTrue(finder2.noFeaturesDisplayed()); + } + + @Test(groups = "Functional") + public void testFindFeatureColour_graduatedWithThreshold() + { + seq.addSequenceFeature(new SequenceFeature("kd", "hydrophobicity", 2, + 2, 0f, "KdGroup")); + seq.addSequenceFeature(new SequenceFeature("kd", "hydrophobicity", 4, + 4, 5f, "KdGroup")); + seq.addSequenceFeature(new SequenceFeature("kd", "hydrophobicity", 7, + 7, 10f, "KdGroup")); + + /* + * graduated colour from 0 to 10 + * above threshold value of 5 + */ + Color min = new Color(100, 50, 150); + Color max = new Color(200, 0, 100); + FeatureColourI fc = new FeatureColour(min, max, 0, 10); + fc.setAboveThreshold(true); + fc.setThreshold(5f); + fr.setColour("kd", fc); + fr.featuresAdded(); + av.setShowSequenceFeatures(true); + + /* + * position 2, column 1, score 0 - below threshold - default colour + */ + Color c = finder.findFeatureColour(Color.blue, seq, 1); + assertEquals(c, Color.blue); + + /* + * position 4, column 3, score 5 - at threshold - default colour + */ + c = finder.findFeatureColour(Color.blue, seq, 3); + assertEquals(c, Color.blue); + + /* + * position 7, column 9, score 10 - maximum colour in range + */ + c = finder.findFeatureColour(Color.blue, seq, 9); + assertEquals(c, max); + + /* + * now colour below threshold of 5 + */ + fc.setBelowThreshold(true); + + /* + * position 2, column 1, score 0 - min colour + */ + c = finder.findFeatureColour(Color.blue, seq, 1); + assertEquals(c, min); + + /* + * position 4, column 3, score 5 - at threshold - default colour + */ + c = finder.findFeatureColour(Color.blue, seq, 3); + assertEquals(c, Color.blue); + + /* + * position 7, column 9, score 10 - above threshold - default colour + */ + c = finder.findFeatureColour(Color.blue, seq, 9); + assertEquals(c, Color.blue); + } }