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