2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.schemes;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertFalse;
25 import static org.testng.AssertJUnit.assertTrue;
27 import jalview.datamodel.Alignment;
28 import jalview.datamodel.AlignmentAnnotation;
29 import jalview.datamodel.AlignmentI;
30 import jalview.datamodel.AnnotatedCollectionI;
31 import jalview.datamodel.Annotation;
32 import jalview.datamodel.Sequence;
33 import jalview.datamodel.SequenceI;
34 import jalview.gui.JvOptionPane;
35 import jalview.io.TCoffeeScoreFile;
37 import org.testng.annotations.BeforeClass;
38 import org.testng.annotations.Test;
40 public class ResidueColourSchemeTest
42 @BeforeClass(alwaysRun = true)
48 @BeforeClass(alwaysRun = true)
49 public void setUpJvOptionPane()
51 JvOptionPane.setInteractiveMode(false);
52 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
55 @Test(groups = "Functional")
56 public void testIsApplicableTo()
58 SequenceI pep1 = new Sequence("pep1", "APQTWLS");
59 SequenceI pep2 = new Sequence("pep2", "AILFQYG");
60 SequenceI dna1 = new Sequence("dna1", "ACTGAC");
61 SequenceI dna2 = new Sequence("dna2", "TCCAAG");
62 AlignmentI peptide = new Alignment(new SequenceI[] { pep1, pep2 });
63 AlignmentI nucleotide = new Alignment(new SequenceI[] { dna1, dna2 });
66 * peptide-specific colour schemes
68 assertTrue(new ClustalxColourScheme(peptide, null)
69 .isApplicableTo(peptide));
70 assertFalse(new ClustalxColourScheme(nucleotide, null)
71 .isApplicableTo(nucleotide));
72 assertTrue(new Blosum62ColourScheme().isApplicableTo(peptide));
73 assertFalse(new Blosum62ColourScheme().isApplicableTo(nucleotide));
74 assertTrue(new BuriedColourScheme().isApplicableTo(peptide));
75 assertFalse(new BuriedColourScheme().isApplicableTo(nucleotide));
76 assertTrue(new HelixColourScheme().isApplicableTo(peptide));
77 assertFalse(new HelixColourScheme().isApplicableTo(nucleotide));
78 assertTrue(new HydrophobicColourScheme().isApplicableTo(peptide));
79 assertFalse(new HydrophobicColourScheme().isApplicableTo(nucleotide));
80 assertTrue(new StrandColourScheme().isApplicableTo(peptide));
81 assertFalse(new StrandColourScheme().isApplicableTo(nucleotide));
82 assertTrue(new TaylorColourScheme().isApplicableTo(peptide));
83 assertFalse(new TaylorColourScheme().isApplicableTo(nucleotide));
84 assertTrue(new TurnColourScheme().isApplicableTo(peptide));
85 assertFalse(new TurnColourScheme().isApplicableTo(nucleotide));
86 assertTrue(new ZappoColourScheme().isApplicableTo(peptide));
87 assertFalse(new ZappoColourScheme().isApplicableTo(nucleotide));
90 * nucleotide-specific colour schemes
92 assertFalse(new NucleotideColourScheme().isApplicableTo(peptide));
93 assertTrue(new NucleotideColourScheme().isApplicableTo(nucleotide));
94 assertFalse(new PurinePyrimidineColourScheme().isApplicableTo(peptide));
96 new PurinePyrimidineColourScheme().isApplicableTo(nucleotide));
97 assertFalse(new RNAInteractionColourScheme().isApplicableTo(peptide));
98 assertTrue(new RNAInteractionColourScheme().isApplicableTo(nucleotide));
103 assertTrue(new UserColourScheme().isApplicableTo(peptide));
104 assertTrue(new UserColourScheme().isApplicableTo(nucleotide));
105 assertTrue(new ScoreColourScheme(new int[] {}, new double[] {}, 0, 0d)
106 .isApplicableTo(peptide));
107 assertTrue(new ScoreColourScheme(new int[] {}, new double[] {}, 0, 0d)
108 .isApplicableTo(nucleotide));
109 ResidueColourScheme rcs = new PIDColourScheme();
110 assertTrue(rcs.isApplicableTo(peptide));
111 assertTrue(rcs.isApplicableTo(nucleotide));
112 assertTrue(new PIDColourScheme().isApplicableTo(peptide));
113 assertTrue(new PIDColourScheme().isApplicableTo(nucleotide));
114 assertTrue(new FollowerColourScheme().isApplicableTo(peptide));
115 assertTrue(new FollowerColourScheme().isApplicableTo(nucleotide));
118 * TCoffee colour requires the presence of TCoffee score annotation
120 assertFalse(new TCoffeeColourScheme(peptide).isApplicableTo(peptide));
122 new TCoffeeColourScheme(nucleotide).isApplicableTo(nucleotide));
123 AlignmentAnnotation aa = new AlignmentAnnotation("T-COFFEE", "", null);
124 aa.setCalcId(TCoffeeScoreFile.TCOFFEE_SCORE);
125 peptide.addAnnotation(aa);
126 aa = new AlignmentAnnotation("T-COFFEE", "", null);
127 aa.setCalcId(TCoffeeScoreFile.TCOFFEE_SCORE);
128 nucleotide.addAnnotation(aa);
129 assertTrue(new TCoffeeColourScheme(peptide).isApplicableTo(peptide));
131 new TCoffeeColourScheme(nucleotide).isApplicableTo(nucleotide));
134 * RNAHelices requires the presence of rna secondary structure
136 assertFalse(new RNAHelicesColour(peptide).isApplicableTo(peptide));
138 new RNAHelicesColour(nucleotide).isApplicableTo(nucleotide));
139 // add secondary structure (small but perfectly formed)
140 Annotation[] ss = new Annotation[2];
141 ss[0] = new Annotation("", "", '{', 0f);
142 ss[1] = new Annotation("", "", '}', 0f);
143 nucleotide.addAnnotation(new AlignmentAnnotation("SS", "", ss));
144 assertTrue(new RNAHelicesColour(nucleotide).isApplicableTo(nucleotide));
147 @Test(groups = "Functional")
148 public void testIsApplicableTo_dynamicColourScheme()
150 SequenceI pep1 = new Sequence("pep1", "APQTWLS");
151 SequenceI pep2 = new Sequence("pep2", "AILFQYG");
152 AlignmentI peptide = new Alignment(new SequenceI[] { pep1, pep2 });
155 * demonstrate that we can 'plug in' a colour scheme with specified
156 * criteria for applicability; here, that there are more than 2 sequences
158 ColourSchemeI cs = new UserColourScheme()
161 public boolean isApplicableTo(AnnotatedCollectionI ac)
163 AlignmentI al = ac.getContext() == null ? (AlignmentI) ac
164 : (AlignmentI) ac.getContext();
165 return al.getSequences().size() > 2;
168 assertFalse(cs.isApplicableTo(peptide));
169 peptide.addSequence(pep1);
170 assertTrue(cs.isApplicableTo(peptide));
173 @Test(groups = "Functional")
174 public void testGetName()
176 SequenceI pep1 = new Sequence("pep1", "APQTWLS");
177 AlignmentI peptide = new Alignment(new SequenceI[] { pep1 });
179 assertEquals("Blosum62", new Blosum62ColourScheme().getSchemeName());
180 assertEquals("Buried Index", new BuriedColourScheme().getSchemeName());
181 assertEquals("Helix Propensity",
182 new HelixColourScheme().getSchemeName());
183 assertEquals("Hydrophobic",
184 new HydrophobicColourScheme().getSchemeName());
185 assertEquals("Strand Propensity",
186 new StrandColourScheme().getSchemeName());
187 assertEquals("Taylor", new TaylorColourScheme().getSchemeName());
188 assertEquals("Turn Propensity", new TurnColourScheme().getSchemeName());
189 assertEquals("Zappo", new ZappoColourScheme().getSchemeName());
190 assertEquals("Nucleotide",
191 new NucleotideColourScheme().getSchemeName());
192 assertEquals("Purine/Pyrimidine",
193 new PurinePyrimidineColourScheme().getSchemeName());
194 assertEquals("RNA Interaction type",
195 new RNAInteractionColourScheme().getSchemeName());
196 assertEquals("User Defined", new UserColourScheme().getSchemeName());
197 assertEquals("Score",
198 new ScoreColourScheme(new int[] {}, new double[] {}, 0, 0d)
200 assertEquals("% Identity", new PIDColourScheme().getSchemeName());
201 assertEquals("Follower", new FollowerColourScheme().getSchemeName());
202 assertEquals("T-Coffee Scores",
203 new TCoffeeColourScheme(peptide).getSchemeName());
204 assertEquals("RNA Helices",
205 new RNAHelicesColour(peptide).getSchemeName());