29c7d1603aad120405de34cdc9d0e16d5e1414f7
[jalview.git] / test / jalview / ext / rbvi / chimera / ChimeraCommandsTest.java
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.ext.rbvi.chimera;
22
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
25
26 import java.awt.Color;
27 import java.util.Arrays;
28 import java.util.LinkedHashMap;
29 import java.util.List;
30 import java.util.Map;
31
32 import org.testng.annotations.Test;
33
34 public class ChimeraCommandsTest
35 {
36   @Test(groups = { "Functional" })
37   public void testAddColourRange()
38   {
39     Map<Color, Map<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<Color, Map<Integer, Map<String, List<int[]>>>>();
40     ChimeraCommands.addColourRange(map, Color.pink, 1, 2, 4, "A");
41     ChimeraCommands.addColourRange(map, Color.pink, 1, 8, 8, "A");
42     ChimeraCommands.addColourRange(map, Color.pink, 1, 5, 7, "B");
43     ChimeraCommands.addColourRange(map, Color.red, 1, 3, 5, "A");
44     ChimeraCommands.addColourRange(map, Color.red, 0, 1, 4, "B");
45     ChimeraCommands.addColourRange(map, Color.orange, 0, 5, 9, "C");
46
47     // three colours mapped
48     assertEquals(3, map.keySet().size());
49
50     // Red has two models, Pink and Orange one each
51     assertEquals(2, map.get(Color.red).keySet().size());
52     assertEquals(1, map.get(Color.orange).keySet().size());
53     assertEquals(1, map.get(Color.pink).keySet().size());
54
55     // pink model 1 has two chains, red.0 / red.1 / orange.0 one each
56     assertEquals(2, map.get(Color.pink).get(1).keySet().size());
57     assertEquals(1, map.get(Color.red).get(0).keySet().size());
58     assertEquals(1, map.get(Color.red).get(1).keySet().size());
59     assertEquals(1, map.get(Color.orange).get(0).keySet().size());
60
61     // inspect positions
62     List<int[]> posList = map.get(Color.pink).get(1).get("A");
63     assertEquals(2, posList.size());
64     assertTrue(Arrays.equals(new int[] { 2, 4 }, posList.get(0)));
65     assertTrue(Arrays.equals(new int[] { 8, 8 }, posList.get(1)));
66
67     posList = map.get(Color.pink).get(1).get("B");
68     assertEquals(1, posList.size());
69     assertTrue(Arrays.equals(new int[] { 5, 7 }, posList.get(0)));
70
71     posList = map.get(Color.red).get(0).get("B");
72     assertEquals(1, posList.size());
73     assertTrue(Arrays.equals(new int[] { 1, 4 }, posList.get(0)));
74
75     posList = map.get(Color.red).get(1).get("A");
76     assertEquals(1, posList.size());
77     assertTrue(Arrays.equals(new int[] { 3, 5 }, posList.get(0)));
78
79     posList = map.get(Color.orange).get(0).get("C");
80     assertEquals(1, posList.size());
81     assertTrue(Arrays.equals(new int[] { 5, 9 }, posList.get(0)));
82   }
83
84   @Test(groups = { "Functional" })
85   public void testBuildColourCommands()
86   {
87
88     Map<Color, Map<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<Color, Map<Integer, Map<String, List<int[]>>>>();
89     ChimeraCommands.addColourRange(map, Color.blue, 0, 2, 5, "A");
90     ChimeraCommands.addColourRange(map, Color.blue, 0, 7, 7, "B");
91     ChimeraCommands.addColourRange(map, Color.blue, 0, 9, 23, "A");
92     ChimeraCommands.addColourRange(map, Color.blue, 1, 1, 1, "A");
93     ChimeraCommands.addColourRange(map, Color.blue, 1, 4, 7, "B");
94     ChimeraCommands.addColourRange(map, Color.yellow, 1, 8, 8, "A");
95     ChimeraCommands.addColourRange(map, Color.yellow, 1, 3, 5, "A");
96     ChimeraCommands.addColourRange(map, Color.red, 0, 3, 5, "A");
97
98     // Colours should appear in the Chimera command in the order in which
99     // they were added; within colour, by model, by chain, and positions as
100     // added
101     String command = ChimeraCommands.buildColourCommands(map).get(0);
102     assertEquals(
103             "color #0000ff #0:2-5.A,9-23.A,7.B|#1:1.A,4-7.B; color #ffff00 #1:8.A,3-5.A; color #ff0000 #0:3-5.A",
104             command);
105   }
106 }