2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.ext.rbvi.chimera;
23 import static org.testng.AssertJUnit.assertEquals;
24 import static org.testng.AssertJUnit.assertTrue;
26 import jalview.gui.JvOptionPane;
28 import java.awt.Color;
29 import java.util.Arrays;
30 import java.util.LinkedHashMap;
31 import java.util.List;
33 import java.util.SortedMap;
35 import org.testng.annotations.BeforeClass;
36 import org.testng.annotations.Test;
38 public class ChimeraCommandsTest
41 @BeforeClass(alwaysRun = true)
42 public void setUpJvOptionPane()
44 JvOptionPane.setInteractiveMode(false);
45 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
48 @Test(groups = { "Functional" })
49 public void testAddColourRange()
51 Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<Color, SortedMap<Integer, Map<String, List<int[]>>>>();
52 ChimeraCommands.addColourRange(map, Color.pink, 1, 2, 4, "A");
53 ChimeraCommands.addColourRange(map, Color.pink, 1, 8, 8, "A");
54 ChimeraCommands.addColourRange(map, Color.pink, 1, 5, 7, "B");
55 ChimeraCommands.addColourRange(map, Color.red, 1, 3, 5, "A");
56 ChimeraCommands.addColourRange(map, Color.red, 0, 1, 4, "B");
57 ChimeraCommands.addColourRange(map, Color.orange, 0, 5, 9, "C");
59 // three colours mapped
60 assertEquals(3, map.keySet().size());
62 // Red has two models, Pink and Orange one each
63 assertEquals(2, map.get(Color.red).keySet().size());
64 assertEquals(1, map.get(Color.orange).keySet().size());
65 assertEquals(1, map.get(Color.pink).keySet().size());
67 // pink model 1 has two chains, red.0 / red.1 / orange.0 one each
68 assertEquals(2, map.get(Color.pink).get(1).keySet().size());
69 assertEquals(1, map.get(Color.red).get(0).keySet().size());
70 assertEquals(1, map.get(Color.red).get(1).keySet().size());
71 assertEquals(1, map.get(Color.orange).get(0).keySet().size());
74 List<int[]> posList = map.get(Color.pink).get(1).get("A");
75 assertEquals(2, posList.size());
76 assertTrue(Arrays.equals(new int[] { 2, 4 }, posList.get(0)));
77 assertTrue(Arrays.equals(new int[] { 8, 8 }, posList.get(1)));
79 posList = map.get(Color.pink).get(1).get("B");
80 assertEquals(1, posList.size());
81 assertTrue(Arrays.equals(new int[] { 5, 7 }, posList.get(0)));
83 posList = map.get(Color.red).get(0).get("B");
84 assertEquals(1, posList.size());
85 assertTrue(Arrays.equals(new int[] { 1, 4 }, posList.get(0)));
87 posList = map.get(Color.red).get(1).get("A");
88 assertEquals(1, posList.size());
89 assertTrue(Arrays.equals(new int[] { 3, 5 }, posList.get(0)));
91 posList = map.get(Color.orange).get(0).get("C");
92 assertEquals(1, posList.size());
93 assertTrue(Arrays.equals(new int[] { 5, 9 }, posList.get(0)));
96 @Test(groups = { "Functional" })
97 public void testBuildColourCommands()
100 Map<Color, SortedMap<Integer, Map<String, List<int[]>>>> map = new LinkedHashMap<Color, SortedMap<Integer, Map<String, List<int[]>>>>();
101 ChimeraCommands.addColourRange(map, Color.blue, 0, 2, 5, "A");
102 ChimeraCommands.addColourRange(map, Color.blue, 0, 7, 7, "B");
103 ChimeraCommands.addColourRange(map, Color.blue, 0, 9, 23, "A");
104 ChimeraCommands.addColourRange(map, Color.blue, 1, 1, 1, "A");
105 ChimeraCommands.addColourRange(map, Color.blue, 1, 4, 7, "B");
106 ChimeraCommands.addColourRange(map, Color.yellow, 1, 8, 8, "A");
107 ChimeraCommands.addColourRange(map, Color.yellow, 1, 3, 5, "A");
108 ChimeraCommands.addColourRange(map, Color.red, 0, 3, 5, "A");
110 // Colours should appear in the Chimera command in the order in which
111 // they were added; within colour, by model, by chain, and positions as
113 String command = ChimeraCommands.buildColourCommands(map).get(0);
115 "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",