Merge branch 'Jalview-JS/develop' into merge_js_develop
[jalview.git] / test / jalview / schemes / HmmerLocalBackgroundTest.java
1 package jalview.schemes;
2
3 import static org.testng.Assert.assertEquals;
4
5 import jalview.datamodel.Alignment;
6 import jalview.datamodel.AnnotatedCollectionI;
7 import jalview.datamodel.Sequence;
8 import jalview.datamodel.SequenceI;
9 import jalview.io.DataSourceType;
10 import jalview.io.HMMFile;
11
12 import java.awt.Color;
13 import java.io.IOException;
14 import java.net.MalformedURLException;
15
16 import org.testng.annotations.Test;
17
18 public class HmmerLocalBackgroundTest {
19
20   @Test(groups = "Functional")
21   public void testFindColour() throws MalformedURLException, IOException
22   {
23     HMMFile file = new HMMFile("test/jalview/io/test_PKinase_hmm.txt",
24             DataSourceType.FILE);
25
26     /*
27      * alignment with 20 residues and background frequencies:
28      * A/a, S 3/20 = 0.15
29      * M, K 4/20 = 0.2
30      * V 2/20 = 0.1
31      * Q, R, L 1/20 = 0.05
32      * log(totalCount) = log(20) = 2.996
33      */
34     SequenceI seq1 = new Sequence("seq1", "AAMMMKKKVV");
35     SequenceI seq2 = new Sequence("seq2", "aAM-QKRSSSL");
36     SequenceI hmmSeq = file.getSeqsAsArray()[0];
37     AnnotatedCollectionI ac = new Alignment(
38             new SequenceI[]
39             { hmmSeq, seq1, seq2 });
40     ColourSchemeI scheme = new HmmerLocalBackground(ac);
41
42     /*
43      * 'A' in column 1, node 2, match emission 2.77204
44      * e-2.77204 = 0.0625 
45      * background frequency is 0.15
46      * ratio is < 1, log is negative, colour is Orange
47      */
48     Color actual = scheme.findColour('A', 1, null, null, 0);
49     assertEquals(actual, Color.ORANGE);
50
51     // gap is white
52     actual = scheme.findColour('-', 2, null, null, 0);
53     assertEquals(actual, Color.WHITE);
54     actual = scheme.findColour(' ', 2, null, null, 0);
55     assertEquals(actual, Color.WHITE);
56     actual = scheme.findColour('.', 2, null, null, 0);
57     assertEquals(actual, Color.WHITE);
58
59     /*
60      * 'L' in column 3, node 4, match emission 1.98342
61      * e-1.98342 = 0.1376 
62      * background frequency is 0.05
63      * ratio is 2.752, log is 1.012
64      * colour is graduated 1.012/2.996 or 86/255 of the way from
65      * white(255, 255, 255) to blue(0, 0, 255)
66      */
67     actual = scheme.findColour('L', 3, null, null, 0);
68     assertEquals(actual, new Color(169, 169, 255));
69
70     /*
71      * invalid symbol is White
72      */
73     actual = scheme.findColour('X', 2, null, null, 0);
74     assertEquals(actual, Color.WHITE);
75   }
76
77 }