13bf47b98722e2917b1bebdc63c39eed9b7f574d
[jalview.git] / test / jalview / schemes / HmmerGlobalBackgroundTest.java
1 package jalview.schemes;
2
3 import static org.testng.Assert.assertEquals;
4
5 import jalview.datamodel.Alignment;
6 import jalview.datamodel.AlignmentI;
7 import jalview.datamodel.SequenceI;
8 import jalview.io.DataSourceType;
9 import jalview.io.HMMFile;
10
11 import java.awt.Color;
12 import java.io.IOException;
13 import java.net.MalformedURLException;
14
15 import org.testng.annotations.Test;
16
17 public class HmmerGlobalBackgroundTest {
18
19   @Test(groups = "Functional")
20   public void testFindColour() throws MalformedURLException, IOException
21   {
22     HMMFile file = new HMMFile("test/jalview/io/test_PKinase_hmm.txt",
23             DataSourceType.FILE);
24
25     SequenceI hmmSeq = file.getSeqsAsArray()[0];
26     AlignmentI al = new Alignment(new SequenceI[] { hmmSeq });
27     al.setHmmConsensus(hmmSeq);
28     ColourSchemeI scheme = new HmmerGlobalBackground(al);
29
30     /*
31      * 'A' in column 1, node 2, match emission 2.77204
32      * e-2.77204 = 0.0625 
33      * background frequency is 0.0826
34      * ratio is 0.757, log is negative, colour is Orange
35      */
36     Color actual = scheme.findColour('A', 1, null, null, 0);
37     assertEquals(actual, Color.ORANGE);
38
39     // gap is white
40     actual = scheme.findColour('-', 2, null, null, 0);
41     assertEquals(actual, Color.WHITE);
42     actual = scheme.findColour(' ', 2, null, null, 0);
43     assertEquals(actual, Color.WHITE);
44     actual = scheme.findColour('.', 2, null, null, 0);
45     assertEquals(actual, Color.WHITE);
46
47     /*
48      * 'Y' in column 4, node 5, match emission 4.41426
49      * e-4.41426 = 0.0121 
50      * background frequency is 0.0292
51      * ratio is 0.414, log is negative, colour is Orange
52      */
53     actual = scheme.findColour('Y', 4, null, null, 0);
54     assertEquals(actual, Color.ORANGE);
55
56     /*
57      * 'M' in column 109, no matching node, colour is reddish
58      */
59     actual = scheme.findColour('M', 109, null, null, 0);
60     assertEquals(actual, new Color(230, 0, 0));
61
62     /*
63      * 'I' in column 6, node 7, match emission 1.33015
64      * e-1.33015 = 0.2644
65      * background frequency is 0.0593
66      * ratio is 4.459, log is 1.495
67      * colour is graduated 1.495/4.52 or 84/255 of the way from
68      * white(255, 255, 255) to blue(0, 0, 255)
69      */
70     actual = scheme.findColour('I', 6, null, null, 0);
71     assertEquals(actual, new Color(171, 171, 255));
72
73     /*
74      * 'V' in column 14, node 15, match emission 0.44769
75      * e-0.44769 = 0.6391
76      * background frequency is 0.0686
77      * ratio is 9.316, log is 2.232
78      * colour is graduated 2.232/4.52 or 126/255 of the way from
79      * white(255, 255, 255) to blue(0, 0, 255)
80      */
81     actual = scheme.findColour('V', 14, null, null, 0);
82     assertEquals(actual, new Color(129, 129, 255));
83
84     /*
85      * invalid symbol is White
86      */
87     actual = scheme.findColour('X', 2, null, null, 0);
88     assertEquals(actual, Color.WHITE);
89   }
90
91 }