X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Frenderer%2Fseqfeatures%2FFeatureColourFinderTest.java;h=c0095fe55de459cc5c64b4ef6e2973202e34c12a;hb=b5667f39acdf309cd92881b73edfda591e0acaf4;hp=a7f228972b19800a39f3a032f42cc6cb2ccdd393;hpb=5adae4008da23589cee57f638dfe02095e1840fd;p=jalview.git diff --git a/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java b/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java index a7f2289..c0095fe 100644 --- a/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java +++ b/test/jalview/renderer/seqfeatures/FeatureColourFinderTest.java @@ -2,22 +2,26 @@ package jalview.renderer.seqfeatures; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import jalview.api.AlignViewportI; import jalview.api.FeatureColourI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; -import jalview.gui.AlignViewport; import jalview.gui.FeatureRenderer; import jalview.io.DataSourceType; import jalview.io.FileLoader; import jalview.schemes.FeatureColour; +import jalview.viewmodel.seqfeatures.FeatureRendererModel.FeatureSettingsBean; import java.awt.Color; +import java.util.List; -import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; +import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; /** @@ -39,7 +43,7 @@ import org.testng.annotations.Test; */ public class FeatureColourFinderTest { - private AlignViewport av; + private AlignViewportI av; private SequenceI seq; @@ -49,7 +53,7 @@ public class FeatureColourFinderTest private FeatureRenderer fr; - @BeforeClass(alwaysRun = true) + @BeforeTest(alwaysRun = true) public void setUp() { // aligned column 8 is sequence position 6 @@ -63,18 +67,16 @@ 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() { - SequenceFeature[] sfs = seq.getSequenceFeatures(); - if (sfs != null) + List sfs = seq.getSequenceFeatures(); + for (SequenceFeature sf : sfs) { - for (SequenceFeature sf : sfs) - { - seq.deleteFeature(sf); - } + seq.deleteFeature(sf); } fr.findAllFeatures(true); @@ -85,6 +87,9 @@ public class FeatureColourFinderTest { fr.setGroupVisibility(group, true); } + + fr.clearRenderOrder(); + av.setShowSequenceFeatures(true); } @Test(groups = "Functional") @@ -122,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() { @@ -131,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") @@ -164,9 +173,9 @@ public class FeatureColourFinderTest * - currently no way other than mimicking reordering of * table in Feature Settings */ - Object[][] data = new Object[2][]; - data[0] = new Object[] { "Metal", red, true }; - data[1] = new Object[] { "Domain", green, true }; + FeatureSettingsBean[] data = new FeatureSettingsBean[2]; + data[0] = new FeatureSettingsBean("Metal", red, null, true); + data[1] = new FeatureSettingsBean("Domain", green, null, true); fr.setFeaturePriority(data); c = finder.findFeatureColour(Color.blue, seq, 10); assertEquals(c, Color.red); @@ -174,7 +183,7 @@ public class FeatureColourFinderTest /* * ..and turn off display of Metal */ - data[0][2] = false; + data[0] = new FeatureSettingsBean("Metal", red, null, false); fr.setFeaturePriority(data); c = finder.findFeatureColour(Color.blue, seq, 10); assertEquals(c, Color.green); @@ -208,8 +217,8 @@ public class FeatureColourFinderTest /* * turn off display of Metal - is this the easiest way to do it?? */ - Object[][] data = new Object[1][]; - data[0] = new Object[] { "Metal", red, false }; + FeatureSettingsBean[] data = new FeatureSettingsBean[1]; + data[0] = new FeatureSettingsBean("Metal", red, null, false); fr.setFeaturePriority(data); c = finder.findFeatureColour(Color.blue, seq, 10); assertEquals(c, Color.blue); @@ -217,7 +226,7 @@ public class FeatureColourFinderTest /* * turn display of Metal back on */ - data[0] = new Object[] { "Metal", red, true }; + data[0] = new FeatureSettingsBean("Metal", red, null, true); fr.setFeaturePriority(data); c = finder.findFeatureColour(Color.blue, seq, 10); assertEquals(c, Color.red); @@ -278,6 +287,28 @@ public class FeatureColourFinderTest } @Test(groups = "Functional") + public void testFindFeatureAtEnd() + { + /* + * terminal residue feature + */ + seq.addSequenceFeature(new SequenceFeature("PDBRESNUM", "pdb res 1", + seq.getEnd(), seq.getEnd(), Float.NaN, "1seq.pdb")); + fr.setColour("PDBRESNUM", new FeatureColour(Color.red)); + fr.featuresAdded(); + av.setShowSequenceFeatures(true); + + /* + * final column should have PDBRESNUM feature, the others not + */ + Color c = finder.findFeatureColour(Color.blue, seq, + seq.getLength() - 2); + assertNotEquals(c, Color.red); + c = finder.findFeatureColour(Color.blue, seq, seq.getLength() - 1); + assertEquals(c, Color.red); + } + + @Test(groups = "Functional") public void testFindFeatureColour_graduatedFeatureColour() { seq.addSequenceFeature(new SequenceFeature("kd", "hydrophobicity", 2, @@ -292,7 +323,7 @@ public class FeatureColourFinderTest */ Color min = new Color(100, 50, 150); Color max = new Color(200, 0, 100); - FeatureColourI fc = new FeatureColour(min, max, 0, 10); + FeatureColourI fc = new FeatureColour(null, min, max, null, 0, 10); fr.setColour("kd", fc); fr.featuresAdded(); av.setShowSequenceFeatures(true); @@ -369,9 +400,9 @@ public class FeatureColourFinderTest * 1) 0.6 * green(0, 255, 0) + 0.4 * cyan(0, 255, 255) = (0, 255, 102) * 2) 0.6* red(255, 0, 0) + 0.4 * (0, 255, 102) = (153, 102, 41) rounded */ - Object[][] data = new Object[2][]; - data[0] = new Object[] { "Metal", red, true }; - data[1] = new Object[] { "Domain", green, true }; + FeatureSettingsBean[] data = new FeatureSettingsBean[2]; + data[0] = new FeatureSettingsBean("Metal", red, null, true); + data[1] = new FeatureSettingsBean("Domain", green, null, true); fr.setFeaturePriority(data); c = finder.findFeatureColour(Color.cyan, seq, 10); assertEquals(c, new Color(153, 102, 41)); @@ -381,7 +412,7 @@ public class FeatureColourFinderTest * Domain (green) above background (pink) * 0.6 * green(0, 255, 0) + 0.4 * pink(255, 175, 175) = (102, 223, 70) */ - data[0][2] = false; + data[0] = new FeatureSettingsBean("Metal", red, null, false); fr.setFeaturePriority(data); c = finder.findFeatureColour(Color.pink, seq, 10); assertEquals(c, new Color(102, 223, 70)); @@ -397,9 +428,10 @@ public class FeatureColourFinderTest /* * add a feature - * it will be automatically set visible but the viewport - * is still configured not to show features + * 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); @@ -416,8 +448,8 @@ public class FeatureColourFinderTest /* * turn off display of Metal */ - Object[][] data = new Object[1][]; - data[0] = new Object[] { "Metal", red, false }; + FeatureSettingsBean[] data = new FeatureSettingsBean[1]; + data[0] = new FeatureSettingsBean("Metal", red, null, false); fr.setFeaturePriority(data); assertTrue(finder.noFeaturesDisplayed()); @@ -433,5 +465,93 @@ public class FeatureColourFinderTest */ 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() + { + String kdFeature = "kd"; + String metalFeature = "Metal"; + seq.addSequenceFeature(new SequenceFeature(kdFeature, "hydrophobicity", 2, + 2, 0f, "KdGroup")); + seq.addSequenceFeature(new SequenceFeature(kdFeature, "hydrophobicity", 4, + 4, 5f, "KdGroup")); + seq.addSequenceFeature(new SequenceFeature(metalFeature, "Fe", 4, 4, + 5f, "MetalGroup")); + seq.addSequenceFeature(new SequenceFeature(kdFeature, "hydrophobicity", 7, + 7, 10f, "KdGroup")); + + /* + * kd feature has 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(null, min, max, null, 0, 10); + fc.setAboveThreshold(true); + fc.setThreshold(5f); + fr.setColour(kdFeature, fc); + FeatureColour green = new FeatureColour(Color.green); + fr.setColour(metalFeature, green); + fr.featuresAdded(); + + /* + * render order is kd above Metal + */ + FeatureSettingsBean[] data = new FeatureSettingsBean[2]; + data[0] = new FeatureSettingsBean(kdFeature, fc, null, true); + data[1] = new FeatureSettingsBean(metalFeature, green, null, true); + fr.setFeaturePriority(data); + + 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 + * should return Green (colour of Metal feature) + */ + c = finder.findFeatureColour(Color.blue, seq, 3); + assertEquals(c, Color.green); + + /* + * 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 + * should return Green (colour of Metal feature) + */ + c = finder.findFeatureColour(Color.blue, seq, 3); + assertEquals(c, Color.green); + + /* + * position 7, column 9, score 10 - above threshold - default colour + */ + c = finder.findFeatureColour(Color.blue, seq, 9); + assertEquals(c, Color.blue); } }