Clover icon

Coverage Report

  1. Project Clover database Thu Nov 28 2024 18:06:40 GMT
  2. Package jalview.schemes

File ClustalxColourSchemeTest.java

 

Code metrics

0
31
3
1
163
67
3
0.1
10.33
3
1

Classes

Class Line # Actions
ClustalxColourSchemeTest 34 31 3
0.8823529588.2%
 

Contributing tests

This file is covered by 2 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.Assert.assertEquals;
24   
25    import jalview.datamodel.AlignmentI;
26    import jalview.gui.AlignFrame;
27    import jalview.io.DataSourceType;
28    import jalview.io.FileLoader;
29   
30    import java.awt.Color;
31   
32    import org.testng.annotations.Test;
33   
 
34    public class ClustalxColourSchemeTest
35    {
36    // @formatter:off
37    private static final String FASTA =
38    ">seq1\nAAANNNRQ\n" +
39    ">seq2\nAAANNNRQ\n" +
40    ">seq3\nAAANNNRQ\n" +
41    ">seq4\nAAANNNRQ\n" +
42    ">seq5\nAAANYYKQ\n" +
43    ">seq6\nAAANYYKQ\n" +
44    ">seq7\nAVKWYYKQ\n" +
45    ">seq8\nKKKWYYQQ\n" +
46    ">seq9\nKKKWWYQQ\n" +
47    ">seq0\nKKKWWWQW\n";
48    // @formatter:on
49   
 
50  1 toggle @Test(groups = "Functional")
51    public void testFindColour()
52    {
53  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(FASTA,
54    DataSourceType.PASTE);
55  1 AlignmentI al = af.getViewport().getAlignment();
56  1 ClustalxColourScheme cs = new ClustalxColourScheme(al, null);
57   
58    /*
59    * column 1 is 70% A which is above Clustalx threshold of 60%
60    */
61  1 Color clustalBlue = new Color(0.5f, 0.7f, 0.9f);
62  1 assertEquals(cs.findColour('A', 0, al.getSequenceAt(0)), clustalBlue);
63   
64    /*
65    * column 2 is 70% A or V which is above Clustalx threshold for group
66    */
67  1 assertEquals(cs.findColour('A', 0, al.getSequenceAt(1)), clustalBlue);
68   
69    /*
70    * column 3 is 60% A which is not above Clustalx threshold
71    * the Ks in the other rows are not in the same Clustalx group
72    */
73  1 assertEquals(cs.findColour('A', 2, al.getSequenceAt(1)), Color.white);
74   
75    /*
76    * column 4 is 60% N which is above Clustalx threshold of 50%
77    */
78  1 Color clustalGreen = new Color(0.1f, 0.8f, 0.1f);
79  1 assertEquals(cs.findColour('N', 3, al.getSequenceAt(1)), clustalGreen);
80   
81    /*
82    * column 5 is 40% N and 40% Y which fails to pass the threshold of
83    * 50% N or 85% either
84    */
85  1 assertEquals(cs.findColour('N', 4, al.getSequenceAt(1)), Color.white);
86   
87    /*
88    * column 6 is 40% N and 50% Y which fails to pass the threshold of
89    * 85% for either
90    */
91  1 assertEquals(cs.findColour('N', 5, al.getSequenceAt(1)), Color.white);
92   
93    /*
94    * column 7 is 40% R and 30% K which combine to make > 60%
95    */
96  1 Color clustalRed = new Color(0.9f, 0.2f, 0.1f);
97  1 assertEquals(cs.findColour('R', 6, al.getSequenceAt(1)), clustalRed);
98  1 assertEquals(cs.findColour('K', 6, al.getSequenceAt(7)), clustalRed);
99   
100    /*
101    * column 8 is >85% Q which qualifies K and R to be red
102    */
103  1 assertEquals(cs.findColour('R', 7, al.getSequenceAt(1)), clustalRed);
104  1 assertEquals(cs.findColour('K', 7, al.getSequenceAt(1)), clustalRed);
105   
106    // TODO more test cases; check if help documentation matches implementation
107    }
108   
109    // @formatter:on
110   
111    /**
112    * Test for colour calculation when the consensus percentage ignores gapped
113    * sequences
114    */
 
115  1 toggle @Test(groups = "Functional")
116    public void testFindColour_ignoreGaps()
117    {
118    /*
119    * CCC
120    * CCC
121    * -CC
122    * first column is 66% C (blue) including gaps
123    * or 100% C ignoring gaps
124    */
125  1 String fasta = ">seq1\nCCC\n>seq2\nccc\n>seq3\n-CC\n";
126  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(fasta,
127    DataSourceType.PASTE);
128  1 AlignmentI al = af.getViewport().getAlignment();
129  1 ClustalxColourScheme cs = new ClustalxColourScheme(al, null);
130   
131    /*
132    * column 1 is 66% C which is above Clustalx threshold of 60%
133    */
134  1 Color clustalBlue = ClustalxColourScheme.ClustalColour.BLUE.colour;
135  1 assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalBlue);
136   
137    /*
138    * set directly to ignore gaps
139    */
140  1 cs.setIncludeGaps(false);
141  1 Color clustalPink = ClustalxColourScheme.ClustalColour.PINK.colour;
142  1 assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalPink);
143   
144    /*
145    * set ignore gaps on the viewport...
146    */
147  1 cs.setIncludeGaps(true);
148  1 assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalBlue);
149  1 af.getViewport().setIgnoreGapsConsensus(true, af.alignPanel);
150    // next test fails: colour scheme does not read ignore gaps flag from
151    // viewport
152    // assertEquals(cs.findColour('C', 0, al.getSequenceAt(0)), clustalPink);
153    }
154   
 
155  0 toggle @Test
156    public void testDocString()
157    {
158    /* verify we have some sort of useful output */
159  0 ClustalxColourScheme x = new ClustalxColourScheme();
160  0 String out = x.toRuleRep();
161  0 System.out.print(out);
162    }
163    }