X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Frenderer%2FResidueShaderTest.java;h=78f00c80ce16a07a3f6009050f785c0a4d69db5e;hb=5a352aa2f3330ae269d9b70c4a7374c2518bfb2e;hp=26d4b159b9a93cc3ddae7c98a7e378b1bbef28a7;hpb=991d2210e8e086bde29a90bdf21979261442d889;p=jalview.git diff --git a/test/jalview/renderer/ResidueShaderTest.java b/test/jalview/renderer/ResidueShaderTest.java index 26d4b15..78f00c8 100644 --- a/test/jalview/renderer/ResidueShaderTest.java +++ b/test/jalview/renderer/ResidueShaderTest.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.renderer; import static org.testng.AssertJUnit.assertEquals; @@ -8,12 +28,15 @@ import jalview.analysis.Conservation; import jalview.datamodel.Profile; import jalview.datamodel.ProfileI; import jalview.datamodel.Profiles; +import jalview.datamodel.ProfilesI; +import jalview.datamodel.ResidueCount; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceI; import jalview.schemes.ColourSchemeI; import jalview.schemes.PIDColourScheme; import jalview.schemes.ResidueProperties; import jalview.schemes.UserColourScheme; +import jalview.schemes.ZappoColourScheme; import java.awt.Color; import java.util.Collections; @@ -158,28 +181,38 @@ public class ResidueShaderTest assertEquals(Color.WHITE, ccs.applyConservation(colour, 4)); assertEquals(Color.WHITE, ccs.applyConservation(colour, 5)); assertEquals(Color.WHITE, ccs.applyConservation(colour, 6)); - assertEquals(new Color(235, 225, 215), ccs.applyConservation(colour, 7)); - assertEquals(new Color(215, 195, 175), ccs.applyConservation(colour, 8)); - assertEquals(new Color(195, 165, 135), ccs.applyConservation(colour, 9)); + assertEquals(new Color(235, 225, 215), + ccs.applyConservation(colour, 7)); + assertEquals(new Color(215, 195, 175), + ccs.applyConservation(colour, 8)); + assertEquals(new Color(195, 165, 135), + ccs.applyConservation(colour, 9)); assertEquals(colour, ccs.applyConservation(colour, 10)); assertEquals(colour, ccs.applyConservation(colour, 11)); assertEquals(Color.WHITE, ccs.applyConservation(colour, 12)); } - /** - * A custom gap colour should not be affected by Colour by Conservation - */ @Test(groups = "Functional") public void testFindColour_gapColour() { + /* + * normally, a gap is coloured white + */ + ResidueShader rs = new ResidueShader(new ZappoColourScheme()); + assertEquals(Color.white, rs.findColour(' ', 7, null)); + + /* + * a User Colour Scheme may specify a bespoke gap colour + */ Color[] colours = new Color[ResidueProperties.maxProteinIndex + 1]; colours[5] = Color.blue; // Q colour colours[23] = Color.red; // gap colour ColourSchemeI cs = new UserColourScheme(colours); - ResidueShader ccs = new ResidueShader(cs); - - assertEquals(Color.red, ccs.findColour(' ', 7, null)); - + rs = new ResidueShader(cs); + + assertEquals(Color.red, rs.findColour(' ', 7, null)); + assertEquals(Color.blue, rs.findColour('Q', 7, null)); + /* * stub Conservation to return a given consensus string */ @@ -193,33 +226,134 @@ public class ResidueShaderTest return new Sequence("seq", consSequence); } }; - ccs.setConservation(cons); - + rs.setConservation(cons); + /* * with 0% threshold, there should be no fading */ - ccs.setConservationInc(0); - assertEquals(Color.red, ccs.findColour(' ', 7, null)); - assertEquals(Color.blue, ccs.findColour('Q', 7, null)); - + rs.setConservationInc(0); + assertEquals(Color.red, rs.findColour(' ', 7, null)); + assertEquals(Color.blue, rs.findColour('Q', 7, null)); + /* * with 40% threshold, 'fade factor' is * (11-score)/10 * 40/20 = (11-score)/5 * so position 7, score 7 fades 80% of the way to white (255, 255, 255) */ - ccs.setConservationInc(40); + rs.setConservationInc(40); /* * gap colour is unchanged for Conservation */ - assertEquals(Color.red, ccs.findColour(' ', 7, null)); + assertEquals(Color.red, rs.findColour(' ', 7, null)); + assertEquals(Color.red, rs.findColour('-', 7, null)); + assertEquals(Color.red, rs.findColour('.', 7, null)); /* * residue colour is faded 80% of the way from * blue(0, 0, 255) to white(255, 255, 255) * making (204, 204, 255) */ - assertEquals(new Color(204, 204, 255), ccs.findColour('Q', 7, null)); + assertEquals(new Color(204, 204, 255), rs.findColour('Q', 7, null)); + + /* + * turn off By Conservation, apply Above Identity Threshold + * providing a stub Consensus that has modal residue "Q" with pid 60% + */ + rs.setConservationApplied(false); + ProfilesI consensus = getStubConsensus("Q", 60f); + rs.setConsensus(consensus); + + // with consensus pid (60) above threshold (50), colours are unchanged + rs.setThreshold(50, false); + assertEquals(Color.blue, rs.findColour('Q', 7, null)); + assertEquals(Color.red, rs.findColour('-', 7, null)); + + // with consensus pid (60) below threshold (70), + // residue colour becomes white, gap colour is unchanged + rs.setThreshold(70, false); + assertEquals(Color.white, rs.findColour('Q', 7, null)); + assertEquals(Color.red, rs.findColour('-', 7, null)); } + /** + * @param modalResidue + * @param pid + * @return + */ + protected ProfilesI getStubConsensus(final String modalResidue, + final float pid) + { + ProfilesI consensus = new ProfilesI() + { + + @Override + public ProfileI get(int i) + { + return new ProfileI() + { + @Override + public void setCounts(ResidueCount residueCounts) + { + } + + @Override + public float getPercentageIdentity(boolean ignoreGaps) + { + return pid; + } + + @Override + public ResidueCount getCounts() + { + return null; + } + + @Override + public int getHeight() + { + return 0; + } + + @Override + public int getGapped() + { + return 0; + } + + @Override + public int getMaxCount() + { + return 0; + } + + @Override + public String getModalResidue() + { + return modalResidue; + } + + @Override + public int getNonGapped() + { + return 0; + } + }; + } + + @Override + public int getStartColumn() + { + return 0; + } + + @Override + public int getEndColumn() + { + return 0; + } + + }; + return consensus; + } }