+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.schemes;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertTrue;
-import jalview.datamodel.Profile;
-import jalview.datamodel.ProfileI;
-import jalview.datamodel.Profiles;
+import jalview.datamodel.Alignment;
+import jalview.datamodel.AlignmentAnnotation;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.AnnotatedCollectionI;
+import jalview.datamodel.Annotation;
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
import jalview.gui.JvOptionPane;
-
-import java.awt.Color;
+import jalview.io.TCoffeeScoreFile;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class ResidueColourSchemeTest
{
+ @BeforeClass(alwaysRun = true)
+ public void setUp()
+ {
+
+ }
@BeforeClass(alwaysRun = true)
public void setUpJvOptionPane()
}
@Test(groups = "Functional")
- public void testAboveThreshold()
+ public void testIsApplicableTo()
{
+ SequenceI pep1 = new Sequence("pep1", "APQTWLS");
+ SequenceI pep2 = new Sequence("pep2", "AILFQYG");
+ SequenceI dna1 = new Sequence("dna1", "ACTGAC");
+ SequenceI dna2 = new Sequence("dna2", "TCCAAG");
+ AlignmentI peptide = new Alignment(new SequenceI[] { pep1, pep2 });
+ AlignmentI nucleotide = new Alignment(new SequenceI[] { dna1, dna2 });
+
/*
- * make up profiles for this alignment:
- * AR-Q
- * AR--
- * SR-T
- * SR-T
+ * peptide-specific colour schemes
*/
- ProfileI[] profiles = new ProfileI[4];
- profiles[0] = new Profile(4, 0, 2, "AS");
- profiles[1] = new Profile(4, 0, 4, "R");
- profiles[2] = new Profile(4, 4, 0, "");
- profiles[3] = new Profile(4, 1, 2, "T");
- ResidueColourScheme rcs = new ResidueColourScheme();
- rcs.setConsensus(new Profiles(profiles));
-
+ assertTrue(new ClustalxColourScheme(peptide, null)
+ .isApplicableTo(peptide));
+ assertFalse(new ClustalxColourScheme(nucleotide, null)
+ .isApplicableTo(nucleotide));
+ assertTrue(new Blosum62ColourScheme().isApplicableTo(peptide));
+ assertFalse(new Blosum62ColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new BuriedColourScheme().isApplicableTo(peptide));
+ assertFalse(new BuriedColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new HelixColourScheme().isApplicableTo(peptide));
+ assertFalse(new HelixColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new HydrophobicColourScheme().isApplicableTo(peptide));
+ assertFalse(new HydrophobicColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new StrandColourScheme().isApplicableTo(peptide));
+ assertFalse(new StrandColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new TaylorColourScheme().isApplicableTo(peptide));
+ assertFalse(new TaylorColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new TurnColourScheme().isApplicableTo(peptide));
+ assertFalse(new TurnColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new ZappoColourScheme().isApplicableTo(peptide));
+ assertFalse(new ZappoColourScheme().isApplicableTo(nucleotide));
+
+ /*
+ * nucleotide-specific colour schemes
+ */
+ assertFalse(new NucleotideColourScheme().isApplicableTo(peptide));
+ assertTrue(new NucleotideColourScheme().isApplicableTo(nucleotide));
+ assertFalse(new PurinePyrimidineColourScheme().isApplicableTo(peptide));
+ assertTrue(new PurinePyrimidineColourScheme()
+ .isApplicableTo(nucleotide));
+ assertFalse(new RNAInteractionColourScheme().isApplicableTo(peptide));
+ assertTrue(new RNAInteractionColourScheme().isApplicableTo(nucleotide));
+
/*
- * no threshold
+ * indifferent
*/
- rcs.setThreshold(0, true);
- assertTrue(rcs.aboveThreshold('a', 0));
- assertTrue(rcs.aboveThreshold('S', 0));
- assertFalse(rcs.aboveThreshold('W', 0));
- assertTrue(rcs.aboveThreshold('R', 1));
- assertFalse(rcs.aboveThreshold('W', 2));
- assertTrue(rcs.aboveThreshold('t', 3));
- assertFalse(rcs.aboveThreshold('Q', 3));
+ assertTrue(new UserColourScheme().isApplicableTo(peptide));
+ assertTrue(new UserColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new ScoreColourScheme(new int[] {}, new double[] {}, 0, 0d)
+ .isApplicableTo(peptide));
+ assertTrue(new ScoreColourScheme(new int[] {}, new double[] {}, 0, 0d)
+ .isApplicableTo(nucleotide));
+ ResidueColourScheme rcs = new PIDColourScheme();
+ assertTrue(rcs.isApplicableTo(peptide));
+ assertTrue(rcs.isApplicableTo(nucleotide));
+ assertTrue(new PIDColourScheme().isApplicableTo(peptide));
+ assertTrue(new PIDColourScheme().isApplicableTo(nucleotide));
+ assertTrue(new FollowerColourScheme().isApplicableTo(peptide));
+ assertTrue(new FollowerColourScheme().isApplicableTo(nucleotide));
/*
- * with threshold, include gaps
+ * TCoffee colour requires the presence of TCoffee score annotation
*/
- rcs.setThreshold(60, false);
- assertFalse(rcs.aboveThreshold('a', 0));
- assertFalse(rcs.aboveThreshold('S', 0));
- assertTrue(rcs.aboveThreshold('R', 1));
- assertFalse(rcs.aboveThreshold('W', 2));
- assertFalse(rcs.aboveThreshold('t', 3)); // 50% < 60%
+ assertFalse(new TCoffeeColourScheme(peptide).isApplicableTo(peptide));
+ assertFalse(new TCoffeeColourScheme(nucleotide)
+ .isApplicableTo(nucleotide));
+ AlignmentAnnotation aa = new AlignmentAnnotation("T-COFFEE", "", null);
+ aa.setCalcId(TCoffeeScoreFile.TCOFFEE_SCORE);
+ peptide.addAnnotation(aa);
+ aa = new AlignmentAnnotation("T-COFFEE", "", null);
+ aa.setCalcId(TCoffeeScoreFile.TCOFFEE_SCORE);
+ nucleotide.addAnnotation(aa);
+ assertTrue(new TCoffeeColourScheme(peptide).isApplicableTo(peptide));
+ assertTrue(new TCoffeeColourScheme(nucleotide)
+ .isApplicableTo(nucleotide));
/*
- * with threshold, ignore gaps
+ * RNAHelices requires the presence of rna secondary structure
*/
- rcs.setThreshold(60, true);
- assertFalse(rcs.aboveThreshold('a', 0));
- assertFalse(rcs.aboveThreshold('S', 0));
- assertTrue(rcs.aboveThreshold('R', 1));
- assertFalse(rcs.aboveThreshold('W', 2));
- assertTrue(rcs.aboveThreshold('t', 3)); // 67% > 60%
+ assertFalse(new RNAHelicesColour(peptide).isApplicableTo(peptide));
+ assertFalse(new RNAHelicesColour(nucleotide).isApplicableTo(nucleotide));
+ // add secondary structure (small but perfectly formed)
+ Annotation[] ss = new Annotation[2];
+ ss[0] = new Annotation("", "", '{', 0f);
+ ss[1] = new Annotation("", "", '}', 0f);
+ nucleotide.addAnnotation(new AlignmentAnnotation("SS", "", ss));
+ assertTrue(new RNAHelicesColour(nucleotide).isApplicableTo(nucleotide));
}
- /**
- * Test colour bleaching based on conservation score and conservation slider.
- * Scores of 10 or 11 should leave colours unchanged. Gap is always white.
- */
@Test(groups = "Functional")
- public void testApplyConservation()
+ public void testIsApplicableTo_dynamicColourScheme()
{
- ResidueColourScheme rcs = new ResidueColourScheme();
-
- // no conservation present - no fading
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 12));
-
- // cheat by setting conservation sequence directly
- // rather than calculating it - good enough for this test
- String consensus = "0123456789+*-";
- rcs.conservation = consensus.toCharArray();
-
- // column out of range:
- assertEquals(Color.RED,
- rcs.applyConservation(Color.RED, consensus.length()));
-
+ SequenceI pep1 = new Sequence("pep1", "APQTWLS");
+ SequenceI pep2 = new Sequence("pep2", "AILFQYG");
+ AlignmentI peptide = new Alignment(new SequenceI[] { pep1, pep2 });
+
/*
- * with 100% threshold, 'fade factor' is
- * (11-score)/10 * 100/20 = (11-score)/2
- * which is >= 1 for all scores i.e. all fade to white except +, *
+ * demonstrate that we can 'plug in' a colour scheme with specified
+ * criteria for applicability; here, that there are more than 2 sequences
*/
- rcs.setConservationInc(100);
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 0));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 1));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 2));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 3));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 4));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 5));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 6));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 7));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 8));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 9));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 10));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 11));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 12));
+ ColourSchemeI cs = new UserColourScheme()
+ {
+ @Override
+ public boolean isApplicableTo(AnnotatedCollectionI ac)
+ {
+ AlignmentI al = ac.getContext() == null ? (AlignmentI) ac
+ : (AlignmentI) ac.getContext();
+ return al.getSequences().size() > 2;
+ }
+ };
+ assertFalse(cs.isApplicableTo(peptide));
+ peptide.addSequence(pep1);
+ assertTrue(cs.isApplicableTo(peptide));
+ }
- /*
- * with 0% threshold, there should be no fading
- */
- rcs.setConservationInc(0);
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 0));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 1));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 2));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 3));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 4));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 5));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 6));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 7));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 8));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 9));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 10));
- assertEquals(Color.RED, rcs.applyConservation(Color.RED, 11));
- assertEquals(Color.WHITE, rcs.applyConservation(Color.RED, 12)); // gap
+ @Test(groups = "Functional")
+ public void testGetName()
+ {
+ SequenceI pep1 = new Sequence("pep1", "APQTWLS");
+ AlignmentI peptide = new Alignment(new SequenceI[] { pep1 });
- /*
- * with 40% threshold, 'fade factor' is
- * (11-score)/10 * 40/20 = (11-score)/5
- * which is {>1, >1, >1, >1, >1, >1, 1, 0.8, 0.6, 0.4} for score 0-9
- * e.g. score 7 colour fades 80% of the way to white (255, 255, 255)
- */
- rcs.setConservationInc(40);
- Color colour = new Color(155, 105, 55);
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 0));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 1));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 2));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 3));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 4));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 5));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 6));
- assertEquals(new Color(235, 225, 215), rcs.applyConservation(colour, 7));
- assertEquals(new Color(215, 195, 175), rcs.applyConservation(colour, 8));
- assertEquals(new Color(195, 165, 135), rcs.applyConservation(colour, 9));
- assertEquals(colour, rcs.applyConservation(colour, 10));
- assertEquals(colour, rcs.applyConservation(colour, 11));
- assertEquals(Color.WHITE, rcs.applyConservation(colour, 12));
+ assertEquals("Blosum62", new Blosum62ColourScheme().getSchemeName());
+ assertEquals("Buried Index", new BuriedColourScheme().getSchemeName());
+ assertEquals("Helix Propensity", new HelixColourScheme().getSchemeName());
+ assertEquals("Hydrophobic", new HydrophobicColourScheme().getSchemeName());
+ assertEquals("Strand Propensity", new StrandColourScheme().getSchemeName());
+ assertEquals("Taylor", new TaylorColourScheme().getSchemeName());
+ assertEquals("Turn Propensity", new TurnColourScheme().getSchemeName());
+ assertEquals("Zappo", new ZappoColourScheme().getSchemeName());
+ assertEquals("Nucleotide", new NucleotideColourScheme().getSchemeName());
+ assertEquals("Purine/Pyrimidine",
+ new PurinePyrimidineColourScheme().getSchemeName());
+ assertEquals("RNA Interaction type",
+ new RNAInteractionColourScheme().getSchemeName());
+ assertEquals("User Defined", new UserColourScheme().getSchemeName());
+ assertEquals("Score", new ScoreColourScheme(new int[] {},
+ new double[] {}, 0, 0d).getSchemeName());
+ assertEquals("% Identity", new PIDColourScheme().getSchemeName());
+ assertEquals("Follower", new FollowerColourScheme().getSchemeName());
+ assertEquals("T-Coffee Scores",
+ new TCoffeeColourScheme(peptide).getSchemeName());
+ assertEquals("RNA Helices",
+ new RNAHelicesColour(peptide).getSchemeName());
}
}