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 java.awt.Color;
27 import java.util.HashMap;
28 import java.util.LinkedHashMap;
29 import java.util.List;
32 import org.testng.annotations.Test;
34 public class ChimeraCommandsTest
36 @Test(groups = { "Functional" })
37 public void testBuildColourCommands()
40 Map<Object, AtomSpecModel> map = new LinkedHashMap<Object, AtomSpecModel>();
41 ChimeraCommands.addRange(map, Color.blue, 0, 2, 5, "A");
42 ChimeraCommands.addRange(map, Color.blue, 0, 7, 7, "B");
43 ChimeraCommands.addRange(map, Color.blue, 0, 9, 23, "A");
44 ChimeraCommands.addRange(map, Color.blue, 1, 1, 1, "A");
45 ChimeraCommands.addRange(map, Color.blue, 1, 4, 7, "B");
46 ChimeraCommands.addRange(map, Color.yellow, 1, 8, 8, "A");
47 ChimeraCommands.addRange(map, Color.yellow, 1, 3, 5, "A");
48 ChimeraCommands.addRange(map, Color.red, 0, 3, 5, "A");
49 ChimeraCommands.addRange(map, Color.red, 0, 6, 9, "A");
51 // Colours should appear in the Chimera command in the order in which
52 // they were added; within colour, by model, by chain, ranges in start order
53 String command = ChimeraCommands.buildColourCommands(map).get(0);
56 "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");
59 @Test(groups = { "Functional" })
60 public void testBuildSetAttributeCommands()
63 * make a map of { featureType, {featureValue, {residue range specification } } }
65 Map<String, Map<Object, AtomSpecModel>> featuresMap = new LinkedHashMap<String, Map<Object, AtomSpecModel>>();
66 Map<Object, AtomSpecModel> featureValues = new HashMap<Object, AtomSpecModel>();
69 * start with just one feature/value...
71 featuresMap.put("chain", featureValues);
72 ChimeraCommands.addRange(featureValues, "X", 0, 8, 20, "A");
74 List<String> commands = ChimeraCommands
75 .buildSetAttributeCommands(featuresMap);
76 assertEquals(1, commands.size());
79 * feature name gets a jv_ namespace prefix
80 * feature value is quoted in case it contains spaces
82 assertEquals(commands.get(0), "setattr r jv_chain \"X\" #0:8-20.A");
84 // add same feature value, overlapping range
85 ChimeraCommands.addRange(featureValues, "X", 0, 3, 9, "A");
86 // same feature value, contiguous range
87 ChimeraCommands.addRange(featureValues, "X", 0, 21, 25, "A");
88 commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
89 assertEquals(1, commands.size());
90 assertEquals(commands.get(0), "setattr r jv_chain \"X\" #0:3-25.A");
92 // same feature value and model, different chain
93 ChimeraCommands.addRange(featureValues, "X", 0, 21, 25, "B");
94 // same feature value and chain, different model
95 ChimeraCommands.addRange(featureValues, "X", 1, 26, 30, "A");
96 commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
97 assertEquals(1, commands.size());
98 assertEquals(commands.get(0),
99 "setattr r jv_chain \"X\" #0:3-25.A,21-25.B|#1:26-30.A");
101 // same feature, different value
102 ChimeraCommands.addRange(featureValues, "Y", 0, 40, 50, "A");
103 commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
104 assertEquals(2, commands.size());
105 // commands are ordered by feature type but not by value
106 // so use contains to test for the expected command:
108 .contains("setattr r jv_chain \"X\" #0:3-25.A,21-25.B|#1:26-30.A"));
109 assertTrue(commands.contains("setattr r jv_chain \"Y\" #0:40-50.A"));
112 featureValues.clear();
113 featuresMap.put("side-chain binding!", featureValues);
114 ChimeraCommands.addRange(featureValues, "metal ion!", 0, 7, 15, "A");
115 // feature names are sanitised to change space or hyphen to underscore
116 commands = ChimeraCommands.buildSetAttributeCommands(featuresMap);
118 .contains("setattr r jv_side_chain_binding_ \"metal ion!\" #0:7-15.A"));
122 * Tests for the method that prefixes and sanitises a feature name so it can
123 * be used as a valid, namespaced attribute name in Chimera
125 @Test(groups = { "Functional" })
126 public void testMakeAttributeName()
128 assertEquals(ChimeraCommands.makeAttributeName(null), "jv_");
129 assertEquals(ChimeraCommands.makeAttributeName(""), "jv_");
130 assertEquals(ChimeraCommands.makeAttributeName("helix"), "jv_helix");
131 assertEquals(ChimeraCommands.makeAttributeName("Hello World 24"),
132 "jv_Hello_World_24");
134 ChimeraCommands.makeAttributeName("!this is-a_very*{odd(name"),
135 "jv__this_is_a_very__odd_name");
136 // name ending in color gets underscore appended
137 assertEquals(ChimeraCommands.makeAttributeName("helixColor"),