Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.ext.rbvi.chimera

File ChimeraXCommandsTest.java

 

Code metrics

0
142
23
1
364
280
23
0.16
6.17
23
1

Classes

Class Line # Actions
ChimeraXCommandsTest 39 142 23
1.0100%
 

Contributing tests

This file is covered by 22 tests. .

Source view

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.Assert.assertEquals;
24    import static org.testng.Assert.assertTrue;
25   
26    import java.awt.Color;
27    import java.util.HashMap;
28    import java.util.LinkedHashMap;
29    import java.util.List;
30    import java.util.Map;
31   
32    import org.testng.annotations.BeforeClass;
33    import org.testng.annotations.Test;
34   
35    import jalview.structure.AtomSpecModel;
36    import jalview.structure.StructureCommand;
37    import jalview.structure.StructureCommandI;
38   
 
39    public class ChimeraXCommandsTest
40    {
41    private ChimeraXCommands testee;
42   
 
43  1 toggle @BeforeClass(alwaysRun = true)
44    public void setUp()
45    {
46  1 testee = new ChimeraXCommands();
47    }
48   
 
49  1 toggle @Test(groups = { "Functional" })
50    public void testColourByCharge()
51    {
52  1 List<StructureCommandI> cmd = testee.colourByCharge();
53  1 assertEquals(cmd.size(), 1);
54  1 assertEquals(cmd.get(0).getCommand(),
55    "color white;color :ASP,GLU red;color :LYS,ARG blue;color :CYS yellow");
56    }
57   
 
58  1 toggle @Test(groups = { "Functional" })
59    public void testColourByChain()
60    {
61  1 StructureCommandI cmd = testee.colourByChain();
62  1 assertEquals(cmd.getCommand(), "rainbow chain");
63    }
64   
 
65  1 toggle @Test(groups = { "Functional" })
66    public void testFocusView()
67    {
68  1 StructureCommandI cmd = testee.focusView();
69  1 assertEquals(cmd.getCommand(), "view");
70    }
71   
 
72  1 toggle @Test(groups = { "Functional" })
73    public void testSetBackgroundColour()
74    {
75  1 StructureCommandI cmd = testee.setBackgroundColour(Color.PINK);
76  1 assertEquals(cmd.getCommand(), "set bgColor #ffafaf");
77    }
78   
 
79  1 toggle @Test(groups = { "Functional" })
80    public void testOpenSession()
81    {
82  1 StructureCommandI cmd = testee.openSession("/some/filepath");
83  1 assertEquals(cmd.getCommand(), "open /some/filepath format session");
84    }
85   
 
86  1 toggle @Test(groups = { "Functional" })
87    public void testColourBySequence()
88    {
89  1 Map<Object, AtomSpecModel> map = new LinkedHashMap<>();
90  1 ChimeraCommands.addAtomSpecRange(map, Color.blue, "1", 2, 5, "A");
91  1 ChimeraCommands.addAtomSpecRange(map, Color.blue, "1", 7, 7, "B");
92  1 ChimeraCommands.addAtomSpecRange(map, Color.blue, "1", 9, 23, "A");
93  1 ChimeraCommands.addAtomSpecRange(map, Color.blue, "2", 1, 1, "A");
94  1 ChimeraCommands.addAtomSpecRange(map, Color.blue, "2", 4, 7, "B");
95  1 ChimeraCommands.addAtomSpecRange(map, Color.yellow, "2", 8, 8, "A");
96  1 ChimeraCommands.addAtomSpecRange(map, Color.yellow, "2", 3, 5, "A");
97  1 ChimeraCommands.addAtomSpecRange(map, Color.red, "1", 3, 5, "A");
98  1 ChimeraCommands.addAtomSpecRange(map, Color.red, "1", 6, 9, "A");
99   
100    /*
101    * Colours should appear in the Chimera command in the order in which
102    * they were added; within colour, by model, by chain, ranges in start order
103    */
104  1 List<StructureCommandI> commands = testee.colourBySequence(map);
105  1 assertEquals(commands.size(), 1);
106  1 assertEquals(commands.get(0).getCommand(),
107    "color #1/A:2-5,9-23/B:7|#2/A:1/B:4-7 #0000ff;color #2/A:3-5,8 #ffff00;color #1/A:3-9 #ff0000");
108    }
109   
 
110  1 toggle @Test(groups = { "Functional" })
111    public void testSetAttributes()
112    {
113    /*
114    * make a map of { featureType, {featureValue, {residue range specification } } }
115    */
116  1 Map<String, Map<Object, AtomSpecModel>> featuresMap = new LinkedHashMap<>();
117  1 Map<Object, AtomSpecModel> featureValues = new HashMap<>();
118   
119    /*
120    * start with just one feature/value...
121    */
122  1 featuresMap.put("chain", featureValues);
123  1 ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 8, 20, "A");
124   
125  1 List<StructureCommandI> commands = testee.setAttributes(featuresMap);
126  1 assertEquals(commands.size(), 1);
127   
128    /*
129    * feature name gets a jv_ namespace prefix
130    * feature value is quoted in case it contains spaces
131    */
132  1 assertEquals(commands.get(0).getCommand(),
133    "setattr #0/A:8-20 res jv_chain 'X' create true");
134   
135    // add same feature value, overlapping range
136  1 ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 3, 9, "A");
137    // same feature value, contiguous range
138  1 ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 21, 25, "A");
139  1 commands = testee.setAttributes(featuresMap);
140  1 assertEquals(commands.size(), 1);
141  1 assertEquals(commands.get(0).getCommand(),
142    "setattr #0/A:3-25 res jv_chain 'X' create true");
143   
144    // same feature value and model, different chain
145  1 ChimeraCommands.addAtomSpecRange(featureValues, "X", "0", 21, 25, "B");
146    // same feature value and chain, different model
147  1 ChimeraCommands.addAtomSpecRange(featureValues, "X", "1", 26, 30, "A");
148  1 commands = testee.setAttributes(featuresMap);
149  1 assertEquals(commands.size(), 1);
150  1 String expected1 = "setattr #0/A:3-25/B:21-25|#1/A:26-30 res jv_chain 'X' create true";
151  1 assertEquals(commands.get(0).getCommand(), expected1);
152   
153    // same feature, different value
154  1 ChimeraCommands.addAtomSpecRange(featureValues, "Y", "0", 40, 50, "A");
155  1 commands = testee.setAttributes(featuresMap);
156  1 assertEquals(2, commands.size());
157    // commands are ordered by feature type but not by value
158    // so test for the expected command in either order
159  1 String cmd1 = commands.get(0).getCommand();
160  1 String cmd2 = commands.get(1).getCommand();
161  1 assertTrue(cmd1.equals(expected1) || cmd2.equals(expected1));
162  1 String expected2 = "setattr #0/A:40-50 res jv_chain 'Y' create true";
163  1 assertTrue(cmd1.equals(expected2) || cmd2.equals(expected2));
164   
165  1 featuresMap.clear();
166  1 featureValues.clear();
167  1 featuresMap.put("side-chain binding!", featureValues);
168  1 ChimeraCommands.addAtomSpecRange(featureValues,
169    "<html>metal <a href=\"http:a.b.c/x\"> 'ion!", "0", 7, 15, "A");
170    // feature names are sanitised to change non-alphanumeric to underscore
171    // feature values are sanitised to encode single quote characters
172  1 commands = testee.setAttributes(featuresMap);
173  1 assertEquals(commands.size(), 1);
174  1 String expected3 = "setattr #0/A:7-15 res jv_side_chain_binding_ '<html>metal <a href=\"http:a.b.c/x\"> &#39;ion!' create true";
175  1 assertTrue(commands.get(0).getCommand().equals(expected3));
176    }
177   
 
178  1 toggle @Test(groups = { "Functional" })
179    public void testSuperposeStructures()
180    {
181  1 AtomSpecModel ref = new AtomSpecModel();
182  1 ref.addRange("1", 12, 14, "A");
183  1 ref.addRange("1", 18, 18, "B");
184  1 ref.addRange("1", 22, 23, "B");
185  1 AtomSpecModel toAlign = new AtomSpecModel();
186  1 toAlign.addRange("2", 15, 17, "B");
187  1 toAlign.addRange("2", 20, 21, "B");
188  1 toAlign.addRange("2", 22, 22, "C");
189  1 List<StructureCommandI> command = testee.superposeStructures(ref,
190    toAlign);
191  1 assertEquals(command.size(), 1);
192  1 String cmd = command.get(0).getCommand();
193  1 String refSpec = "#1/A:12-14/B:18,22-23";
194  1 String toAlignSpec = "#2/B:15-17,20-21/C:22";
195   
196    /*
197    * superposition arguments include AlphaCarbon restriction,
198    * ribbon command does not
199    */
200  1 String expected = String.format(
201    "align %s@CA toAtoms %s@CA; ribbon %s|%s; view", toAlignSpec,
202    refSpec, toAlignSpec, refSpec);
203  1 assertEquals(cmd, expected);
204    }
205   
 
206  1 toggle @Test(groups = "Functional")
207    public void testGetAtomSpec()
208    {
209  1 AtomSpecModel model = new AtomSpecModel();
210  1 assertEquals(testee.getAtomSpec(model, false), "");
211  1 model.addRange("1", 2, 4, "A");
212  1 assertEquals(testee.getAtomSpec(model, false), "#1/A:2-4");
213  1 model.addRange("1", 8, 8, "A");
214  1 assertEquals(testee.getAtomSpec(model, false), "#1/A:2-4,8");
215  1 model.addRange("1", 5, 7, "B");
216  1 assertEquals(testee.getAtomSpec(model, false), "#1/A:2-4,8/B:5-7");
217  1 model.addRange("1", 3, 5, "A");
218  1 assertEquals(testee.getAtomSpec(model, false), "#1/A:2-5,8/B:5-7");
219  1 model.addRange("0", 1, 4, "B");
220  1 assertEquals(testee.getAtomSpec(model, false),
221    "#0/B:1-4|#1/A:2-5,8/B:5-7");
222  1 model.addRange("0", 5, 9, "C");
223  1 assertEquals(testee.getAtomSpec(model, false),
224    "#0/B:1-4/C:5-9|#1/A:2-5,8/B:5-7");
225  1 model.addRange("1", 8, 10, "B");
226  1 assertEquals(testee.getAtomSpec(model, false),
227    "#0/B:1-4/C:5-9|#1/A:2-5,8/B:5-10");
228  1 model.addRange("1", 8, 9, "B");
229  1 assertEquals(testee.getAtomSpec(model, false),
230    "#0/B:1-4/C:5-9|#1/A:2-5,8/B:5-10");
231  1 model.addRange("0", 3, 10, "C"); // subsumes 5-9
232  1 assertEquals(testee.getAtomSpec(model, false),
233    "#0/B:1-4/C:3-10|#1/A:2-5,8/B:5-10");
234  1 model.addRange("5", 25, 35, " ");
235  1 assertEquals(testee.getAtomSpec(model, false),
236    "#0/B:1-4/C:3-10|#1/A:2-5,8/B:5-10|#5/:25-35");
237    }
238   
 
239  1 toggle @Test(groups = "Functional")
240    public void testGetAtomSpec_alphaOnly()
241    {
242  1 AtomSpecModel model = new AtomSpecModel();
243  1 assertEquals(testee.getAtomSpec(model, true), "");
244  1 model.addRange("1", 2, 4, "A");
245  1 assertEquals(testee.getAtomSpec(model, true), "#1/A:2-4@CA");
246  1 model.addRange("1", 8, 8, "A");
247  1 assertEquals(testee.getAtomSpec(model, true), "#1/A:2-4,8@CA");
248  1 model.addRange("1", 5, 7, "B");
249  1 assertEquals(testee.getAtomSpec(model, true), "#1/A:2-4,8/B:5-7@CA");
250  1 model.addRange("1", 3, 5, "A");
251  1 assertEquals(testee.getAtomSpec(model, true), "#1/A:2-5,8/B:5-7@CA");
252  1 model.addRange("0", 1, 4, "B");
253  1 assertEquals(testee.getAtomSpec(model, true),
254    "#0/B:1-4@CA|#1/A:2-5,8/B:5-7@CA");
255  1 model.addRange("0", 5, 9, "C");
256  1 assertEquals(testee.getAtomSpec(model, true),
257    "#0/B:1-4/C:5-9@CA|#1/A:2-5,8/B:5-7@CA");
258  1 model.addRange("1", 8, 10, "B");
259  1 assertEquals(testee.getAtomSpec(model, true),
260    "#0/B:1-4/C:5-9@CA|#1/A:2-5,8/B:5-10@CA");
261  1 model.addRange("1", 8, 9, "B");
262  1 assertEquals(testee.getAtomSpec(model, true),
263    "#0/B:1-4/C:5-9@CA|#1/A:2-5,8/B:5-10@CA");
264  1 model.addRange("0", 3, 10, "C"); // subsumes 5-9
265  1 assertEquals(testee.getAtomSpec(model, true),
266    "#0/B:1-4/C:3-10@CA|#1/A:2-5,8/B:5-10@CA");
267  1 model.addRange("5", 25, 35, " "); // empty chain code
268  1 assertEquals(testee.getAtomSpec(model, true),
269    "#0/B:1-4/C:3-10@CA|#1/A:2-5,8/B:5-10@CA|#5/:25-35@CA");
270    }
271   
 
272  1 toggle @Test(groups = "Functional")
273    public void testGetModelStartNo()
274    {
275  1 assertEquals(testee.getModelStartNo(), 1);
276    }
277   
 
278  1 toggle @Test(groups = "Functional")
279    public void testGetResidueSpec()
280    {
281  1 assertEquals(testee.getResidueSpec("ALA"), ":ALA");
282    }
283   
 
284  1 toggle @Test(groups = "Functional")
285    public void testShowBackbone()
286    {
287  1 List<StructureCommandI> showBackbone = testee.showBackbone();
288  1 assertEquals(showBackbone.size(), 1);
289  1 assertEquals(showBackbone.get(0).getCommand(),
290    "~display all;~ribbon;show @CA|P atoms");
291    }
292   
 
293  1 toggle @Test(groups = "Functional")
294    public void testOpenCommandFile()
295    {
296  1 assertEquals(testee.openCommandFile("nowhere").getCommand(),
297    "open nowhere");
298    }
299   
 
300  1 toggle @Test(groups = "Functional")
301    public void testSaveSession()
302    {
303  1 assertEquals(testee.saveSession("somewhere").getCommand(),
304    "save somewhere format session");
305    }
306   
 
307  1 toggle @Test(groups = "Functional")
308    public void testGetColourCommand()
309    {
310  1 assertEquals(testee.colourResidues("something", Color.MAGENTA)
311    .getCommand(),
312    "color something #ff00ff");
313    }
314   
 
315  1 toggle @Test(groups = "Functional")
316    public void testSetAttribute()
317    {
318  1 AtomSpecModel model = new AtomSpecModel();
319  1 model.addRange("1", 89, 92, "A");
320  1 model.addRange("2", 12, 20, "B");
321  1 model.addRange("2", 8, 9, "B");
322  1 assertEquals(testee.setAttribute("jv_kd", "27.3", model)
323    .getCommand(),
324    "setattr #1/A:89-92|#2/B:8-9,12-20 res jv_kd '27.3' create true");
325    }
326   
 
327  1 toggle @Test(groups = "Functional")
328    public void testCloseViewer()
329    {
330  1 assertEquals(testee.closeViewer(), new StructureCommand("exit"));
331    }
332   
 
333  1 toggle @Test(groups = "Functional")
334    public void testGetSelectedResidues()
335    {
336  1 assertEquals(testee.getSelectedResidues(),
337    new StructureCommand("info selection level residue"));
338    }
339   
 
340  1 toggle @Test(groups = "Functional")
341    public void testStartNotifications()
342    {
343  1 List<StructureCommandI> cmds = testee.startNotifications("to here");
344  1 assertEquals(cmds.size(), 2);
345  1 assertEquals(cmds.get(0), new StructureCommand("info notify start models prefix ModelChanged jalview url to here"));
346  1 assertEquals(cmds.get(1), new StructureCommand("info notify start selection jalview prefix SelectionChanged url to here"));
347    }
348   
 
349  1 toggle @Test(groups = "Functional")
350    public void testStopNotifications()
351    {
352  1 List<StructureCommandI> cmds = testee.stopNotifications();
353  1 assertEquals(cmds.size(), 2);
354  1 assertEquals(cmds.get(0), new StructureCommand("info notify stop models jalview"));
355  1 assertEquals(cmds.get(1), new StructureCommand("info notify stop selection jalview"));
356    }
357   
 
358  1 toggle @Test(groups = "Functional")
359    public void testListResidueAttributes()
360    {
361  1 assertEquals(testee.listResidueAttributes(),
362    new StructureCommand("info resattr"));
363    }
364    }