1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ext.jmol; |
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.DataProvider; |
34 |
|
import org.testng.annotations.Test; |
35 |
|
|
36 |
|
import jalview.datamodel.Alignment; |
37 |
|
import jalview.datamodel.AlignmentI; |
38 |
|
import jalview.datamodel.ColumnSelection; |
39 |
|
import jalview.datamodel.Sequence; |
40 |
|
import jalview.datamodel.SequenceI; |
41 |
|
import jalview.gui.AlignFrame; |
42 |
|
import jalview.gui.SequenceRenderer; |
43 |
|
import jalview.schemes.JalviewColourScheme; |
44 |
|
import jalview.structure.AtomSpecModel; |
45 |
|
import jalview.structure.StructureCommandI; |
46 |
|
import jalview.structure.StructureCommandsI.AtomSpecType; |
47 |
|
import jalview.structure.StructureMapping; |
48 |
|
import jalview.structure.StructureSelectionManager; |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (141) |
Complexity: 19 |
Complexity Density: 0.16 |
|
50 |
|
public class JmolCommandsTest |
51 |
|
{ |
52 |
|
private JmolCommands testee; |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
1 |
@BeforeClass(alwaysRun = true)... |
55 |
|
public void setUp() |
56 |
|
{ |
57 |
1 |
testee = new JmolCommands(); |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (36) |
Complexity: 2 |
Complexity Density: 0.06 |
1PASS
|
|
60 |
1 |
@Test(groups = { "Functional" })... |
61 |
|
public void testGetColourBySequenceCommands_hiddenColumns() |
62 |
|
{ |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
1 |
SequenceI seq1 = new Sequence("seq1", "MHRSQSSSGG"); |
68 |
1 |
SequenceI seq2 = new Sequence("seq2", "MVRSNGGSSS"); |
69 |
1 |
AlignmentI al = new Alignment(new SequenceI[] { seq1, seq2 }); |
70 |
1 |
AlignFrame af = new AlignFrame(al, 800, 500); |
71 |
1 |
af.changeColour_actionPerformed(JalviewColourScheme.Strand.toString()); |
72 |
1 |
ColumnSelection cs = new ColumnSelection(); |
73 |
1 |
cs.addElement(2); |
74 |
1 |
cs.addElement(3); |
75 |
1 |
cs.addElement(4); |
76 |
1 |
af.getViewport().setColumnSelection(cs); |
77 |
1 |
af.hideSelColumns_actionPerformed(null); |
78 |
1 |
SequenceRenderer sr = new SequenceRenderer(af.getViewport()); |
79 |
1 |
SequenceI[][] seqs = new SequenceI[][] { { seq1 }, { seq2 } }; |
80 |
1 |
String[] files = new String[] { "seq1.pdb", "seq2.pdb" }; |
81 |
1 |
StructureSelectionManager ssm = new StructureSelectionManager(); |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
1 |
HashMap<Integer, int[]> map = new HashMap<>(); |
87 |
11 |
for (int pos = 1; pos <= seq1.getLength(); pos++) |
88 |
|
{ |
89 |
10 |
map.put(pos, new int[] { 20 + pos, 5 * (20 + pos) }); |
90 |
|
} |
91 |
1 |
StructureMapping sm1 = new StructureMapping(seq1, "seq1.pdb", "pdb1", |
92 |
|
"A", map, null); |
93 |
1 |
ssm.addStructureMapping(sm1); |
94 |
1 |
StructureMapping sm2 = new StructureMapping(seq2, "seq2.pdb", "pdb2", |
95 |
|
"B", map, null); |
96 |
1 |
ssm.addStructureMapping(sm2); |
97 |
|
|
98 |
1 |
String[] commands = testee.colourBySequence(ssm, files, seqs, sr, |
99 |
|
af.alignPanel); |
100 |
1 |
assertEquals(commands.length, 2); |
101 |
|
|
102 |
1 |
String chainACommand = commands[0]; |
103 |
|
|
104 |
1 |
assertTrue( |
105 |
|
chainACommand.contains("select 21:A/1.1;color[130,130,125]")); |
106 |
|
|
107 |
|
|
108 |
1 |
assertTrue(chainACommand.contains(";select 22:A/1.1;color[96,96,159]")); |
109 |
|
|
110 |
1 |
assertTrue(chainACommand |
111 |
|
.contains(";select 23-25:A/1.1;color[128,128,128]")); |
112 |
|
|
113 |
1 |
assertTrue( |
114 |
|
chainACommand.contains(";select 26-30:A/1.1;color[73,73,182]")); |
115 |
|
|
116 |
1 |
String chainBCommand = commands[1]; |
117 |
|
|
118 |
1 |
assertTrue( |
119 |
|
chainBCommand.contains("select 21:B/2.1;color[130,130,125]")); |
120 |
|
|
121 |
1 |
assertTrue(chainBCommand.contains(";select 22:B/2.1;color[255,255,0]")); |
122 |
|
|
123 |
1 |
assertTrue(chainBCommand |
124 |
|
.contains(";select 23-25:B/2.1;color[128,128,128]")); |
125 |
|
|
126 |
1 |
assertTrue( |
127 |
|
chainBCommand.contains(";select 26-30:B/2.1;color[73,73,182]")); |
128 |
|
} |
129 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
130 |
1 |
@Test(groups = "Functional")... |
131 |
|
public void testGetAtomSpec() |
132 |
|
{ |
133 |
1 |
AtomSpecModel model = new AtomSpecModel(); |
134 |
1 |
assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), ""); |
135 |
1 |
model.addRange("1", 2, 4, "A"); |
136 |
1 |
assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), |
137 |
|
"2-4:A/1.1"); |
138 |
1 |
model.addRange("1", 8, 8, "A"); |
139 |
1 |
assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), |
140 |
|
"2-4:A/1.1|8:A/1.1"); |
141 |
1 |
model.addRange("1", 5, 7, "B"); |
142 |
1 |
assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), |
143 |
|
"2-4:A/1.1|8:A/1.1|5-7:B/1.1"); |
144 |
1 |
model.addRange("1", 3, 5, "A"); |
145 |
1 |
assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), |
146 |
|
"2-5:A/1.1|8:A/1.1|5-7:B/1.1"); |
147 |
1 |
model.addRange("2", 1, 4, "B"); |
148 |
1 |
assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), |
149 |
|
"2-5:A/1.1|8:A/1.1|5-7:B/1.1|1-4:B/2.1"); |
150 |
1 |
model.addRange("2", 5, 9, "C"); |
151 |
1 |
assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), |
152 |
|
"2-5:A/1.1|8:A/1.1|5-7:B/1.1|1-4:B/2.1|5-9:C/2.1"); |
153 |
1 |
model.addRange("1", 8, 10, "B"); |
154 |
1 |
assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), |
155 |
|
"2-5:A/1.1|8:A/1.1|5-10:B/1.1|1-4:B/2.1|5-9:C/2.1"); |
156 |
1 |
model.addRange("1", 8, 9, "B"); |
157 |
1 |
assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), |
158 |
|
"2-5:A/1.1|8:A/1.1|5-10:B/1.1|1-4:B/2.1|5-9:C/2.1"); |
159 |
1 |
model.addRange("2", 3, 10, "C"); |
160 |
1 |
assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), |
161 |
|
"2-5:A/1.1|8:A/1.1|5-10:B/1.1|1-4:B/2.1|3-10:C/2.1"); |
162 |
1 |
model.addRange("5", 25, 35, " "); |
163 |
1 |
assertEquals(testee.getAtomSpec(model, AtomSpecType.RESIDUE_ONLY), |
164 |
|
"2-5:A/1.1|8:A/1.1|5-10:B/1.1|1-4:B/2.1|3-10:C/2.1|25-35:/5.1"); |
165 |
|
|
166 |
|
} |
167 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
168 |
1 |
@Test(groups = { "Functional" })... |
169 |
|
public void testColourBySequence() |
170 |
|
{ |
171 |
1 |
Map<Object, AtomSpecModel> map = new LinkedHashMap<>(); |
172 |
1 |
JmolCommands.addAtomSpecRange(map, Color.blue, "1", 2, 5, "A"); |
173 |
1 |
JmolCommands.addAtomSpecRange(map, Color.blue, "1", 7, 7, "B"); |
174 |
1 |
JmolCommands.addAtomSpecRange(map, Color.blue, "1", 9, 23, "A"); |
175 |
1 |
JmolCommands.addAtomSpecRange(map, Color.blue, "2", 1, 1, "A"); |
176 |
1 |
JmolCommands.addAtomSpecRange(map, Color.blue, "2", 4, 7, "B"); |
177 |
1 |
JmolCommands.addAtomSpecRange(map, Color.yellow, "2", 8, 8, "A"); |
178 |
1 |
JmolCommands.addAtomSpecRange(map, Color.yellow, "2", 3, 5, "A"); |
179 |
1 |
JmolCommands.addAtomSpecRange(map, Color.red, "1", 3, 5, "A"); |
180 |
1 |
JmolCommands.addAtomSpecRange(map, Color.red, "1", 6, 9, "A"); |
181 |
|
|
182 |
|
|
183 |
|
|
184 |
1 |
List<StructureCommandI> commands = testee.colourBySequence(map); |
185 |
1 |
assertEquals(commands.size(), 1); |
186 |
1 |
String expected1 = "select 2-5:A/1.1|9-23:A/1.1|7:B/1.1|1:A/2.1|4-7:B/2.1;color[0,0,255]"; |
187 |
1 |
String expected2 = "select 3-5:A/2.1|8:A/2.1;color[255,255,0]"; |
188 |
1 |
String expected3 = "select 3-9:A/1.1;color[255,0,0]"; |
189 |
1 |
assertEquals(commands.get(0).getCommand(), |
190 |
|
expected1 + ";" + expected2 + ";" + expected3); |
191 |
|
} |
192 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
193 |
1 |
@Test(groups = { "Functional" })... |
194 |
|
public void testSuperposeStructures() |
195 |
|
{ |
196 |
1 |
AtomSpecModel ref = new AtomSpecModel(); |
197 |
1 |
ref.addRange("1", 12, 14, "A"); |
198 |
1 |
ref.addRange("1", 18, 18, "B"); |
199 |
1 |
ref.addRange("1", 22, 23, "B"); |
200 |
1 |
AtomSpecModel toAlign = new AtomSpecModel(); |
201 |
1 |
toAlign.addRange("2", 15, 17, "B"); |
202 |
1 |
toAlign.addRange("2", 20, 21, "B"); |
203 |
1 |
toAlign.addRange("2", 22, 22, "C"); |
204 |
1 |
List<StructureCommandI> command = testee.superposeStructures(ref, |
205 |
|
toAlign, AtomSpecType.ALPHA); |
206 |
|
|
207 |
1 |
assertEquals(command.size(), 1); |
208 |
1 |
String refSpec = "12-14:A/1.1|18:B/1.1|22-23:B/1.1"; |
209 |
1 |
String toAlignSpec = "15-17:B/2.1|20-21:B/2.1|22:C/2.1"; |
210 |
1 |
String expected = String.format( |
211 |
|
"compare {2.1} {1.1} SUBSET {(*.CA | *.P) and conformation=1} ATOMS {%s}{%s} ROTATE TRANSLATE ;select %s|%s;cartoons", |
212 |
|
toAlignSpec, refSpec, toAlignSpec, refSpec); |
213 |
1 |
assertEquals(command.get(0).getCommand(), expected); |
214 |
|
} |
215 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
216 |
1 |
@Test(groups = "Functional")... |
217 |
|
public void testGetModelStartNo() |
218 |
|
{ |
219 |
1 |
assertEquals(testee.getModelStartNo(), 1); |
220 |
|
} |
221 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
222 |
1 |
@Test(groups = "Functional")... |
223 |
|
public void testColourByChain() |
224 |
|
{ |
225 |
1 |
StructureCommandI cmd = testee.colourByChain(); |
226 |
1 |
assertEquals(cmd.getCommand(), "select *;color chain"); |
227 |
|
} |
228 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
229 |
1 |
@Test(groups = "Functional")... |
230 |
|
public void testColourByCharge() |
231 |
|
{ |
232 |
1 |
List<StructureCommandI> cmds = testee.colourByCharge(); |
233 |
1 |
assertEquals(cmds.size(), 1); |
234 |
1 |
assertEquals(cmds.get(0).getCommand(), |
235 |
|
"select *;color white;select ASP,GLU;color red;" |
236 |
|
+ "select LYS,ARG;color blue;select CYS;color yellow"); |
237 |
|
} |
238 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
239 |
1 |
@Test(groups = "Functional")... |
240 |
|
public void testSetBackgroundColour() |
241 |
|
{ |
242 |
1 |
StructureCommandI cmd = testee.setBackgroundColour(Color.PINK); |
243 |
1 |
assertEquals(cmd.getCommand(), "background [255,175,175]"); |
244 |
|
} |
245 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
246 |
1 |
@Test(groups = "Functional")... |
247 |
|
public void testFocusView() |
248 |
|
{ |
249 |
1 |
StructureCommandI cmd = testee.focusView(); |
250 |
1 |
assertEquals(cmd.getCommand(), "zoom 0"); |
251 |
|
} |
252 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
253 |
1 |
@Test(groups = "Functional")... |
254 |
|
public void testSaveSession() |
255 |
|
{ |
256 |
1 |
StructureCommandI cmd = testee.saveSession("/some/filepath"); |
257 |
1 |
assertEquals(cmd.getCommand(), "write STATE \"/some/filepath\""); |
258 |
1 |
cmd = testee.saveSession("\\some\\filepath"); |
259 |
1 |
assertEquals(cmd.getCommand(), "write STATE \"\\\\some\\\\filepath\""); |
260 |
|
} |
261 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
262 |
1 |
@Test(groups = "Functional")... |
263 |
|
public void testShowBackbone() |
264 |
|
{ |
265 |
1 |
List<StructureCommandI> cmds = testee.showBackbone(); |
266 |
1 |
assertEquals(cmds.size(), 1); |
267 |
1 |
assertEquals(cmds.get(0).getCommand(), |
268 |
|
"select *; cartoons off; backbone"); |
269 |
|
} |
270 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
271 |
1 |
@Test(groups = "Functional")... |
272 |
|
public void testLoadFile() |
273 |
|
{ |
274 |
1 |
StructureCommandI cmd = testee.loadFile("/some/filepath"); |
275 |
1 |
assertEquals(cmd.getCommand(), "load FILES \"/some/filepath\""); |
276 |
|
|
277 |
|
|
278 |
1 |
cmd = testee.loadFile("\\some\\filepath"); |
279 |
1 |
assertEquals(cmd.getCommand(), "load FILES \"\\\\some\\\\filepath\""); |
280 |
|
|
281 |
|
|
282 |
1 |
cmd = testee.loadFile("\\\\some\\filepath"); |
283 |
1 |
assertEquals(cmd.getCommand(), |
284 |
|
"load FILES \"file:\\\\\\\\some\\\\filepath\""); |
285 |
|
|
286 |
|
|
287 |
1 |
cmd = testee.loadFile("//some/filepath"); |
288 |
1 |
assertEquals(cmd.getCommand(), "load FILES \"file://some/filepath\""); |
289 |
|
|
290 |
|
} |
291 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
292 |
4 |
@Test(... |
293 |
|
groups = "Functional", |
294 |
|
dataProvider = "testFilePathEquivalence", |
295 |
|
singleThreaded = true) |
296 |
|
public void testFilePathEquivalence(String jalviewpath, String jmolpath) |
297 |
|
{ |
298 |
4 |
assertEquals(JmolCommands.escapeQuotedFilename(jalviewpath), jmolpath, |
299 |
|
"for " + jalviewpath); |
300 |
|
|
301 |
4 |
assertTrue(JmolCommands.filePathMatch(jmolpath.replace("\\\\", "\\"), |
302 |
|
jalviewpath)); |
303 |
|
} |
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
@return |
311 |
|
|
312 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
313 |
1 |
@DataProvider(name = "testFilePathEquivalence")... |
314 |
|
public Object[][] fileEquivalences() |
315 |
|
{ |
316 |
1 |
return new String[][] { |
317 |
|
new String[] |
318 |
|
{ "/some/filepath", "/some/filepath" }, |
319 |
|
new String[] |
320 |
|
{ "\\some\\filepath", "\\\\some\\\\filepath" }, |
321 |
|
new String[] |
322 |
|
{ "\\\\some\\filepath", "file:\\\\\\\\some\\\\filepath" }, |
323 |
|
new String[] |
324 |
|
{ "//some/filepath", "file://some/filepath" } }; |
325 |
|
} |
326 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
327 |
7 |
@Test(... |
328 |
|
groups = "Functional", |
329 |
|
dataProvider = "testForwardBackslashFilePathEquivalence") |
330 |
|
public void filePathMatchTest(String jmolPath, String jalviewPath) |
331 |
|
{ |
332 |
7 |
assertTrue(JmolCommands.filePathMatch(jmolPath, jalviewPath)); |
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
@return |
341 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
342 |
1 |
@DataProvider(name = "testForwardBackslashFilePathEquivalence")... |
343 |
|
public Object[][] forwardBackslashFilePathEquivalence() |
344 |
|
{ |
345 |
1 |
return new String[][] { |
346 |
|
new String[] |
347 |
|
{ "file:\\\\some\\filepath", "\\\\some\\filepath" }, |
348 |
|
new String[] |
349 |
|
{ "file://some/filepath", "\\\\some\\filepath" }, |
350 |
|
new String[] |
351 |
|
{ "file:////some//filepath", "\\\\some\\filepath" }, |
352 |
|
new String[] |
353 |
|
{ "file:\\\\\\\\estorage.dundee.ac.uk\\\\cluster-gjb_lab\\\\jprocter\\\\public_html\\\\1QIP.cif", |
354 |
|
"//estorage.dundee.ac.uk/cluster-gjb_lab/jprocter/public_html/1QIP.cif" }, |
355 |
|
new String[] |
356 |
|
{ "file:\\\\\\\\estorage.dundee.ac.uk\\\\cluster-gjb_lab\\\\jprocter\\\\public_html\\\\1QIP.cif", |
357 |
|
"\\\\estorage.dundee.ac.uk\\cluster-gjb_lab\\jprocter\\public_html\\1QIP.cif" }, |
358 |
|
new String[] |
359 |
|
{ "file://estorage.dundee.ac.uk/cluster-gjb_lab/jprocter/public_html/1QIP.cif", |
360 |
|
"\\\\estorage.dundee.ac.uk\\cluster-gjb_lab\\jprocter\\public_html\\1QIP.cif" }, |
361 |
|
new String[] |
362 |
|
{ "file:////estorage.dundee.ac.uk//cluster-gjb_lab//jprocter//public_html//1QIP.cif", |
363 |
|
"\\\\estorage.dundee.ac.uk\\cluster-gjb_lab\\jprocter\\public_html\\1QIP.cif" } }; |
364 |
|
} |
365 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
366 |
1 |
@Test(groups = "Functional")... |
367 |
|
public void testOpenSession() |
368 |
|
{ |
369 |
1 |
StructureCommandI cmd = testee.openSession("/some/filepath"); |
370 |
1 |
assertEquals(cmd.getCommand(), "load FILES \"/some/filepath\""); |
371 |
|
|
372 |
|
|
373 |
1 |
cmd = testee.openSession("\\some\\filepath"); |
374 |
1 |
assertEquals(cmd.getCommand(), "load FILES \"\\\\some\\\\filepath\""); |
375 |
|
} |
376 |
|
} |