Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.schemes

File PIDColourSchemeTest.java

 

Code metrics

2
28
2
1
119
63
4
0.14
14
2
2

Classes

Class Line # Actions
PIDColourSchemeTest 15 28 4 4
0.87587.5%
 

Contributing tests

This file is covered by 2 tests. .

Source view

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