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.Assert.assertEquals;
24 import static org.testng.Assert.assertTrue;
26 import jalview.gui.JvOptionPane;
28 import java.awt.Color;
29 import java.util.HashMap;
30 import java.util.LinkedHashMap;
31 import java.util.List;
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.Test;
37 public class ChimeraCommandsTest
40 @BeforeClass(alwaysRun = true)
41 public void setUpJvOptionPane()
43 JvOptionPane.setInteractiveMode(false);
44 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
47 @Test(groups = { "Functional" })
48 public void testBuildColourCommands()
51 Map<Object, AtomSpecModel> map = new LinkedHashMap<Object, AtomSpecModel>();
52 ChimeraCommands.addRange(map, Color.blue, 0, 2, 5, "A");
53 ChimeraCommands.addRange(map, Color.blue, 0, 7, 7, "B");
54 ChimeraCommands.addRange(map, Color.blue, 0, 9, 23, "A");
55 ChimeraCommands.addRange(map, Color.blue, 1, 1, 1, "A");
56 ChimeraCommands.addRange(map, Color.blue, 1, 4, 7, "B");
57 ChimeraCommands.addRange(map, Color.yellow, 1, 8, 8, "A");
58 ChimeraCommands.addRange(map, Color.yellow, 1, 3, 5, "A");
59 ChimeraCommands.addRange(map, Color.red, 0, 3, 5, "A");
60 ChimeraCommands.addRange(map, Color.red, 0, 6, 9, "A");
62 // Colours should appear in the Chimera command in the order in which
63 // they were added; within colour, by model, by chain, ranges in start order
64 String command = ChimeraCommands.buildColourCommands(map).get(0);
67 "color #0000ff #0:2-5.A,9-23.A,7.B|#1:1.A,4-7.B; color #ffff00 #1:3-5.A,8.A; color #ff0000 #0:3-9.A");
70 @Test(groups = { "Functional" })
71 public void testBuildSetAttributeCommands()
74 * make a map of { featureType, {featureValue, {residue range specification } } }
76 Map<String, Map<Object, AtomSpecModel>> featuresMap = new LinkedHashMap<String, Map<Object, AtomSpecModel>>();
77 Map<Object, AtomSpecModel> featureValues = new HashMap<Object, AtomSpecModel>();
80 * start with just one feature/value...
82 featuresMap.put("chain", featureValues);
83 ChimeraCommands.addRange(featureValues, "X", 0, 8, 20, "A");
85 List<String> commands = ChimeraCommands
86 .buildSetAttributeCommands(featuresMap);
87 assertEquals(1, commands.size());
90 * feature name gets a jv_ namespace prefix
91 * feature value is quoted in case it contains spaces
93 assertEquals(commands.get(0), "setattr r jv_chain \"X\" #0:8-20.A");
95 // add same feature value, overlapping range
96 ChimeraCommands.addRange(featureValues, "X", 0, 3, 9, "A");
97 // same feature value, contiguous range
98 ChimeraCommands.addRange(featureValues, "X", 0, 21, 25, "A");
99 commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
100 assertEquals(1, commands.size());
101 assertEquals(commands.get(0), "setattr r jv_chain \"X\" #0:3-25.A");
103 // same feature value and model, different chain
104 ChimeraCommands.addRange(featureValues, "X", 0, 21, 25, "B");
105 // same feature value and chain, different model
106 ChimeraCommands.addRange(featureValues, "X", 1, 26, 30, "A");
107 commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
108 assertEquals(1, commands.size());
109 assertEquals(commands.get(0),
110 "setattr r jv_chain \"X\" #0:3-25.A,21-25.B|#1:26-30.A");
112 // same feature, different value
113 ChimeraCommands.addRange(featureValues, "Y", 0, 40, 50, "A");
114 commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
115 assertEquals(2, commands.size());
116 // commands are ordered by feature type but not by value
117 // so use contains to test for the expected command:
119 .contains("setattr r jv_chain \"X\" #0:3-25.A,21-25.B|#1:26-30.A"));
120 assertTrue(commands.contains("setattr r jv_chain \"Y\" #0:40-50.A"));
123 featureValues.clear();
124 featuresMap.put("side-chain binding!", featureValues);
125 ChimeraCommands.addRange(featureValues, "metal ion!", 0, 7, 15, "A");
126 // feature names are sanitised to change space or hyphen to underscore
127 commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
129 .contains("setattr r jv_side_chain_binding_ \"metal ion!\" #0:7-15.A"));
133 * Tests for the method that prefixes and sanitises a feature name so it can
134 * be used as a valid, namespaced attribute name in Chimera
136 @Test(groups = { "Functional" })
137 public void testMakeAttributeName()
139 assertEquals(ChimeraCommands.makeAttributeName(null), "jv_");
140 assertEquals(ChimeraCommands.makeAttributeName(""), "jv_");
141 assertEquals(ChimeraCommands.makeAttributeName("helix"), "jv_helix");
142 assertEquals(ChimeraCommands.makeAttributeName("Hello World 24"),
143 "jv_Hello_World_24");
145 ChimeraCommands.makeAttributeName("!this is-a_very*{odd(name"),
146 "jv__this_is_a_very__odd_name");
147 // name ending in color gets underscore appended
148 assertEquals(ChimeraCommands.makeAttributeName("helixColor"),