Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 10:11:34 GMT
  2. Package jalview.schemes

File ResidueColourSchemeTest.java

 

Code metrics

2
88
6
1
207
151
7
0.08
14.67
6
1.17

Classes

Class Line # Actions
ResidueColourSchemeTest 40 88 7
0.989583399%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
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.
11    *
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.
16    *
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.
20    */
21    package jalview.schemes;
22   
23    import static org.testng.AssertJUnit.assertEquals;
24    import static org.testng.AssertJUnit.assertFalse;
25    import static org.testng.AssertJUnit.assertTrue;
26   
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;
36   
37    import org.testng.annotations.BeforeClass;
38    import org.testng.annotations.Test;
39   
 
40    public class ResidueColourSchemeTest
41    {
 
42  1 toggle @BeforeClass(alwaysRun = true)
43    public void setUp()
44    {
45   
46    }
47   
 
48  1 toggle @BeforeClass(alwaysRun = true)
49    public void setUpJvOptionPane()
50    {
51  1 JvOptionPane.setInteractiveMode(false);
52  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
53    }
54   
 
55  1 toggle @Test(groups = "Functional")
56    public void testIsApplicableTo()
57    {
58  1 SequenceI pep1 = new Sequence("pep1", "APQTWLS");
59  1 SequenceI pep2 = new Sequence("pep2", "AILFQYG");
60  1 SequenceI dna1 = new Sequence("dna1", "ACTGAC");
61  1 SequenceI dna2 = new Sequence("dna2", "TCCAAG");
62  1 AlignmentI peptide = new Alignment(new SequenceI[] { pep1, pep2 });
63  1 AlignmentI nucleotide = new Alignment(new SequenceI[] { dna1, dna2 });
64   
65    /*
66    * peptide-specific colour schemes
67    */
68  1 assertTrue(new ClustalxColourScheme(peptide, null)
69    .isApplicableTo(peptide));
70  1 assertFalse(new ClustalxColourScheme(nucleotide, null)
71    .isApplicableTo(nucleotide));
72  1 assertTrue(new Blosum62ColourScheme().isApplicableTo(peptide));
73  1 assertFalse(new Blosum62ColourScheme().isApplicableTo(nucleotide));
74  1 assertTrue(new BuriedColourScheme().isApplicableTo(peptide));
75  1 assertFalse(new BuriedColourScheme().isApplicableTo(nucleotide));
76  1 assertTrue(new HelixColourScheme().isApplicableTo(peptide));
77  1 assertFalse(new HelixColourScheme().isApplicableTo(nucleotide));
78  1 assertTrue(new HydrophobicColourScheme().isApplicableTo(peptide));
79  1 assertFalse(new HydrophobicColourScheme().isApplicableTo(nucleotide));
80  1 assertTrue(new StrandColourScheme().isApplicableTo(peptide));
81  1 assertFalse(new StrandColourScheme().isApplicableTo(nucleotide));
82  1 assertTrue(new TaylorColourScheme().isApplicableTo(peptide));
83  1 assertFalse(new TaylorColourScheme().isApplicableTo(nucleotide));
84  1 assertTrue(new TurnColourScheme().isApplicableTo(peptide));
85  1 assertFalse(new TurnColourScheme().isApplicableTo(nucleotide));
86  1 assertTrue(new ZappoColourScheme().isApplicableTo(peptide));
87  1 assertFalse(new ZappoColourScheme().isApplicableTo(nucleotide));
88   
89    /*
90    * nucleotide-specific colour schemes
91    */
92  1 assertFalse(new NucleotideColourScheme().isApplicableTo(peptide));
93  1 assertTrue(new NucleotideColourScheme().isApplicableTo(nucleotide));
94  1 assertFalse(new PurinePyrimidineColourScheme().isApplicableTo(peptide));
95  1 assertTrue(
96    new PurinePyrimidineColourScheme().isApplicableTo(nucleotide));
97  1 assertFalse(new RNAInteractionColourScheme().isApplicableTo(peptide));
98  1 assertTrue(new RNAInteractionColourScheme().isApplicableTo(nucleotide));
99   
100    /*
101    * indifferent
102    */
103  1 assertTrue(new UserColourScheme().isApplicableTo(peptide));
104  1 assertTrue(new UserColourScheme().isApplicableTo(nucleotide));
105  1 assertTrue(new ScoreColourScheme(new int[] {}, new double[] {}, 0, 0d)
106    .isApplicableTo(peptide));
107  1 assertTrue(new ScoreColourScheme(new int[] {}, new double[] {}, 0, 0d)
108    .isApplicableTo(nucleotide));
109  1 ResidueColourScheme rcs = new PIDColourScheme();
110  1 assertTrue(rcs.isApplicableTo(peptide));
111  1 assertTrue(rcs.isApplicableTo(nucleotide));
112  1 assertTrue(new PIDColourScheme().isApplicableTo(peptide));
113  1 assertTrue(new PIDColourScheme().isApplicableTo(nucleotide));
114  1 assertTrue(new FollowerColourScheme().isApplicableTo(peptide));
115  1 assertTrue(new FollowerColourScheme().isApplicableTo(nucleotide));
116   
117    /*
118    * TCoffee colour requires the presence of TCoffee score annotation
119    */
120  1 assertFalse(new TCoffeeColourScheme(peptide).isApplicableTo(peptide));
121  1 assertFalse(
122    new TCoffeeColourScheme(nucleotide).isApplicableTo(nucleotide));
123  1 AlignmentAnnotation aa = new AlignmentAnnotation("T-COFFEE", "", null);
124  1 aa.setCalcId(TCoffeeScoreFile.TCOFFEE_SCORE);
125  1 peptide.addAnnotation(aa);
126  1 aa = new AlignmentAnnotation("T-COFFEE", "", null);
127  1 aa.setCalcId(TCoffeeScoreFile.TCOFFEE_SCORE);
128  1 nucleotide.addAnnotation(aa);
129  1 assertTrue(new TCoffeeColourScheme(peptide).isApplicableTo(peptide));
130  1 assertTrue(
131    new TCoffeeColourScheme(nucleotide).isApplicableTo(nucleotide));
132   
133    /*
134    * RNAHelices requires the presence of rna secondary structure
135    */
136  1 assertFalse(new RNAHelicesColour(peptide).isApplicableTo(peptide));
137  1 assertFalse(
138    new RNAHelicesColour(nucleotide).isApplicableTo(nucleotide));
139    // add secondary structure (small but perfectly formed)
140  1 Annotation[] ss = new Annotation[2];
141  1 ss[0] = new Annotation("", "", '{', 0f);
142  1 ss[1] = new Annotation("", "", '}', 0f);
143  1 nucleotide.addAnnotation(new AlignmentAnnotation("SS", "", ss));
144  1 assertTrue(new RNAHelicesColour(nucleotide).isApplicableTo(nucleotide));
145    }
146   
 
147  1 toggle @Test(groups = "Functional")
148    public void testIsApplicableTo_dynamicColourScheme()
149    {
150  1 SequenceI pep1 = new Sequence("pep1", "APQTWLS");
151  1 SequenceI pep2 = new Sequence("pep2", "AILFQYG");
152  1 AlignmentI peptide = new Alignment(new SequenceI[] { pep1, pep2 });
153   
154    /*
155    * demonstrate that we can 'plug in' a colour scheme with specified
156    * criteria for applicability; here, that there are more than 2 sequences
157    */
158  1 ColourSchemeI cs = new UserColourScheme()
159    {
 
160  2 toggle @Override
161    public boolean isApplicableTo(AnnotatedCollectionI ac)
162    {
163  2 AlignmentI al = ac.getContext() == null ? (AlignmentI) ac
164    : (AlignmentI) ac.getContext();
165  2 return al.getSequences().size() > 2;
166    }
167    };
168  1 assertFalse(cs.isApplicableTo(peptide));
169  1 peptide.addSequence(pep1);
170  1 assertTrue(cs.isApplicableTo(peptide));
171    }
172   
 
173  1 toggle @Test(groups = "Functional")
174    public void testGetName()
175    {
176  1 SequenceI pep1 = new Sequence("pep1", "APQTWLS");
177  1 AlignmentI peptide = new Alignment(new SequenceI[] { pep1 });
178   
179  1 assertEquals("Blosum62", new Blosum62ColourScheme().getSchemeName());
180  1 assertEquals("Buried Index", new BuriedColourScheme().getSchemeName());
181  1 assertEquals("Helix Propensity",
182    new HelixColourScheme().getSchemeName());
183  1 assertEquals("Hydrophobic",
184    new HydrophobicColourScheme().getSchemeName());
185  1 assertEquals("Strand Propensity",
186    new StrandColourScheme().getSchemeName());
187  1 assertEquals("Taylor", new TaylorColourScheme().getSchemeName());
188  1 assertEquals("Turn Propensity", new TurnColourScheme().getSchemeName());
189  1 assertEquals("Zappo", new ZappoColourScheme().getSchemeName());
190  1 assertEquals("Nucleotide",
191    new NucleotideColourScheme().getSchemeName());
192  1 assertEquals("Purine/Pyrimidine",
193    new PurinePyrimidineColourScheme().getSchemeName());
194  1 assertEquals("RNA Interaction type",
195    new RNAInteractionColourScheme().getSchemeName());
196  1 assertEquals("User Defined", new UserColourScheme().getSchemeName());
197  1 assertEquals("Score",
198    new ScoreColourScheme(new int[] {}, new double[] {}, 0, 0d)
199    .getSchemeName());
200  1 assertEquals("% Identity", new PIDColourScheme().getSchemeName());
201  1 assertEquals("Follower", new FollowerColourScheme().getSchemeName());
202  1 assertEquals("T-Coffee Scores",
203    new TCoffeeColourScheme(peptide).getSchemeName());
204  1 assertEquals("RNA Helices",
205    new RNAHelicesColour(peptide).getSchemeName());
206    }
207    }