Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 20:42:03 GMT
  2. Package jalview.schemes

File PIDColourSchemeTest.java

 

Code metrics

2
27
2
1
134
58
4
0.15
13.5
2
2

Classes

Class Line # Actions
PIDColourSchemeTest 35 27 4
0.967741996.8%
 

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 java.awt.Color;
26   
27    import org.testng.annotations.Test;
28   
29    import jalview.datamodel.SequenceI;
30    import jalview.gui.AlignFrame;
31    import jalview.gui.AlignViewport;
32    import jalview.io.DataSourceType;
33    import jalview.io.FileLoader;
34   
 
35    public class PIDColourSchemeTest
36    {
37    static final Color white = Color.white;
38   
39    static final Color over40 = new Color(204, 204, 255);
40   
41    static final Color over60 = new Color(153, 153, 255);
42   
43    static final Color over80 = new Color(100, 100, 255);
44   
45    /**
46    * Test findColour for cases:
47    * <ul>
48    * <li>gap: white</li>
49    * <li>no match to consensus: white</li>
50    * <li>match consensus with pid > 80%: 100,100,255</li>
51    * <li>match consensus with pid > 60%: 153, 153, 255</li>
52    * <li>match consensus with pid > 40%: 204, 204, 255</li>
53    * <li>match consensus with pid <= 40%: white</li>
54    * <li>joint consensus matching</li>
55    * <li>case insensitive matching</li>
56    * <ul>
57    */
 
58  1 toggle @Test(groups = "Functional")
59    public void testFindColour()
60    {
61  1 ColourSchemeI scheme = new PIDColourScheme();
62   
63    /*
64    * doesn't use column or sequence
65    * we assume consensus residue is computed as upper case
66    */
67  1 assertEquals(scheme.findColour('A', 0, null, "A", 0f), white);
68  1 assertEquals(scheme.findColour('A', 0, null, "A", 40f), white);
69  1 assertEquals(scheme.findColour('A', 0, null, "A", 40.1f), over40);
70  1 assertEquals(scheme.findColour('A', 0, null, "A", 60f), over40);
71  1 assertEquals(scheme.findColour('A', 0, null, "A", 60.1f), over60);
72  1 assertEquals(scheme.findColour('A', 0, null, "A", 80f), over60);
73  1 assertEquals(scheme.findColour('A', 0, null, "A", 80.1f), over80);
74  1 assertEquals(scheme.findColour('A', 0, null, "A", 100f), over80);
75  1 assertEquals(scheme.findColour('A', 0, null, "KFV", 100f), white);
76   
77  1 assertEquals(scheme.findColour('a', 0, null, "A", 80f), over60);
78  1 assertEquals(scheme.findColour('A', 0, null, "AC", 80f), over60);
79  1 assertEquals(scheme.findColour('A', 0, null, "KCA", 80f), over60);
80    }
81   
82    /**
83    * Test that changing the 'ignore gaps in consensus' in the viewport (an
84    * option on the annotation label popup menu) results in a change to the
85    * colouring
86    */
 
87  1 toggle @Test(groups = "Functional")
88    public void testFindColour_ignoreGaps()
89    {
90    /*
91    * AAAAA
92    * AAAAA
93    * -CCCC
94    * FFFFF
95    *
96    * first column consensus is A
97    * first column PID is 50%, or 67% ignoring gaps
98    */
99  1 String seqs = ">seq1\nAAAAA\n>seq2\nAAAAA\n>seq3\n-CCCC\n>seq4\nFFFFF\n";
100   
101    /*
102    * load data and wait for consensus to be computed
103    */
104  1 AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(seqs,
105    DataSourceType.PASTE);
106  1 AlignViewport viewport = af.getViewport();
107  1 viewport.setIgnoreGapsConsensus(false, af.alignPanel);
108  1 do
109    {
110  1 try
111    {
112  1 Thread.sleep(50);
113    } catch (InterruptedException x)
114    {
115    }
116  1 } while (af.getViewport().getCalcManager().isWorking());
117  1 af.changeColour_actionPerformed(JalviewColourScheme.PID.toString());
118   
119  1 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
120   
121    /*
122    * including gaps, A should be coloured for 50% consensus
123    */
124  1 Color c = viewport.getResidueShading().findColour('A', 0, seq);
125  1 assertEquals(c, over40);
126   
127    /*
128    * now choose to ignore gaps; colour should be for 67%
129    */
130  1 viewport.setIgnoreGapsConsensus(true, af.alignPanel);
131  1 c = viewport.getResidueShading().findColour('A', 0, seq);
132  1 assertEquals(c, over60);
133    }
134    }