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 java.awt.Color; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.Arrays; |
26 |
|
import java.util.List; |
27 |
|
import java.util.Map; |
28 |
|
|
29 |
|
import jalview.api.AlignViewportI; |
30 |
|
import jalview.api.AlignmentViewPanel; |
31 |
|
import jalview.api.FeatureRenderer; |
32 |
|
import jalview.api.SequenceRenderer; |
33 |
|
import jalview.datamodel.AlignmentI; |
34 |
|
import jalview.datamodel.HiddenColumns; |
35 |
|
import jalview.datamodel.SequenceI; |
36 |
|
import jalview.renderer.seqfeatures.FeatureColourFinder; |
37 |
|
import jalview.structure.AtomSpecModel; |
38 |
|
import jalview.structure.StructureCommand; |
39 |
|
import jalview.structure.StructureCommandI; |
40 |
|
import jalview.structure.StructureCommandsBase; |
41 |
|
import jalview.structure.StructureMapping; |
42 |
|
import jalview.structure.StructureSelectionManager; |
43 |
|
import jalview.util.Comparison; |
44 |
|
import jalview.util.Platform; |
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
@author |
50 |
|
|
51 |
|
|
|
|
| 73.4% |
Uncovered Elements: 49 (184) |
Complexity: 49 |
Complexity Density: 0.42 |
|
52 |
|
public class JmolCommands extends StructureCommandsBase |
53 |
|
{ |
54 |
|
private static final StructureCommand SHOW_BACKBONE = new StructureCommand( |
55 |
|
"select *; cartoons off; backbone"); |
56 |
|
|
57 |
|
private static final StructureCommand FOCUS_VIEW = new StructureCommand("zoom 0"); |
58 |
|
|
59 |
|
private static final StructureCommand COLOUR_ALL_WHITE = new StructureCommand( |
60 |
|
"select *;color white;"); |
61 |
|
|
62 |
|
private static final StructureCommandI COLOUR_BY_CHARGE = new StructureCommand( |
63 |
|
"select *;color white;select ASP,GLU;color red;" |
64 |
|
+ "select LYS,ARG;color blue;select CYS;color yellow"); |
65 |
|
|
66 |
|
private static final StructureCommandI COLOUR_BY_CHAIN = new StructureCommand( |
67 |
|
"select *;color chain"); |
68 |
|
|
69 |
|
private static final String PIPE = "|"; |
70 |
|
|
71 |
|
private static final String HYPHEN = "-"; |
72 |
|
|
73 |
|
private static final String COLON = ":"; |
74 |
|
|
75 |
|
private static final String SLASH = "/"; |
76 |
|
|
77 |
|
|
78 |
|
@inheritDoc |
79 |
|
|
80 |
|
@return |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
1 |
@Override... |
83 |
|
public int getModelStartNo() |
84 |
|
{ |
85 |
1 |
return 1; |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
@param |
93 |
|
@return |
94 |
|
|
|
|
| 66.7% |
Uncovered Elements: 1 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
95 |
32 |
protected String getColourString(Color c)... |
96 |
|
{ |
97 |
32 |
return c == null ? null |
98 |
|
: String.format("[%d,%d,%d]", c.getRed(), c.getGreen(), |
99 |
|
c.getBlue()); |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
1 |
@Override... |
103 |
|
public StructureCommandI colourByChain() |
104 |
|
{ |
105 |
1 |
return COLOUR_BY_CHAIN; |
106 |
|
} |
107 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
108 |
1 |
@Override... |
109 |
|
public List<StructureCommandI> colourByCharge() |
110 |
|
{ |
111 |
1 |
return Arrays.asList(COLOUR_BY_CHARGE); |
112 |
|
} |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
114 |
0 |
@Override... |
115 |
|
public List<StructureCommandI> colourByResidues(Map<String, Color> colours) |
116 |
|
{ |
117 |
0 |
List<StructureCommandI> cmds = super.colourByResidues(colours); |
118 |
0 |
cmds.add(0, COLOUR_ALL_WHITE); |
119 |
0 |
return cmds; |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
1 |
@Override... |
123 |
|
public StructureCommandI setBackgroundColour(Color col) |
124 |
|
{ |
125 |
1 |
return new StructureCommand("background " + getColourString(col)); |
126 |
|
} |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
128 |
1 |
@Override... |
129 |
|
public StructureCommandI focusView() |
130 |
|
{ |
131 |
1 |
return FOCUS_VIEW; |
132 |
|
} |
133 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
134 |
0 |
@Override... |
135 |
|
public List<StructureCommandI> showChains(List<String> toShow) |
136 |
|
{ |
137 |
0 |
StringBuilder atomSpec = new StringBuilder(128); |
138 |
0 |
boolean first = true; |
139 |
0 |
for (String chain : toShow) |
140 |
|
{ |
141 |
0 |
String[] tokens = chain.split(":"); |
142 |
0 |
if (tokens.length == 2) |
143 |
|
{ |
144 |
0 |
if (!first) |
145 |
|
{ |
146 |
0 |
atomSpec.append(" or "); |
147 |
|
} |
148 |
0 |
first = false; |
149 |
0 |
atomSpec.append(":").append(tokens[1]).append(" /").append(tokens[0]); |
150 |
|
} |
151 |
|
} |
152 |
|
|
153 |
0 |
String spec = atomSpec.toString(); |
154 |
0 |
String command = "select *;restrict " + spec + ";cartoon;center " |
155 |
|
+ spec; |
156 |
0 |
return Arrays.asList(new StructureCommand(command)); |
157 |
|
} |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
@see |
178 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
179 |
1 |
@Override... |
180 |
|
public List<StructureCommandI> superposeStructures(AtomSpecModel refAtoms, |
181 |
|
AtomSpecModel atomSpec) |
182 |
|
{ |
183 |
1 |
StringBuilder sb = new StringBuilder(64); |
184 |
1 |
String refModel = refAtoms.getModels().iterator().next(); |
185 |
1 |
String model2 = atomSpec.getModels().iterator().next(); |
186 |
1 |
sb.append(String.format("compare {%s.1} {%s.1}", model2, refModel)); |
187 |
1 |
sb.append(" SUBSET {(*.CA | *.P) and conformation=1} ATOMS {"); |
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
1 |
sb.append(getAtomSpec(atomSpec, true)).append("}{"); |
194 |
1 |
sb.append(getAtomSpec(refAtoms, true)).append("}"); |
195 |
1 |
sb.append(" ROTATE TRANSLATE "); |
196 |
1 |
sb.append(getCommandSeparator()); |
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
201 |
1 |
sb.append("select ").append(getAtomSpec(atomSpec, false)).append("|"); |
202 |
1 |
sb.append(getAtomSpec(refAtoms, false)).append(getCommandSeparator()) |
203 |
|
.append("cartoons"); |
204 |
|
|
205 |
1 |
return Arrays.asList(new StructureCommand(sb.toString())); |
206 |
|
} |
207 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
208 |
0 |
@Override... |
209 |
|
public StructureCommandI openCommandFile(String path) |
210 |
|
{ |
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
0 |
return new StructureCommand("script " + path); |
216 |
|
} |
217 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
218 |
3 |
@Override... |
219 |
|
public StructureCommandI saveSession(String filepath) |
220 |
|
{ |
221 |
|
|
222 |
|
|
223 |
|
|
224 |
3 |
return new StructureCommand("write STATE \"" + filepath + "\""); |
225 |
|
} |
226 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
227 |
11 |
@Override... |
228 |
|
protected StructureCommandI colourResidues(String atomSpec, Color colour) |
229 |
|
{ |
230 |
11 |
StringBuilder sb = new StringBuilder(atomSpec.length()+20); |
231 |
11 |
sb.append("select ").append(atomSpec).append(getCommandSeparator()) |
232 |
|
.append("color").append(getColourString(colour)); |
233 |
11 |
return new StructureCommand(sb.toString()); |
234 |
|
} |
235 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
236 |
0 |
@Override... |
237 |
|
protected String getResidueSpec(String residue) |
238 |
|
{ |
239 |
0 |
return residue; |
240 |
|
} |
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (18) |
Complexity: 3 |
Complexity Density: 0.21 |
|
252 |
26 |
@Override... |
253 |
|
public String getAtomSpec(AtomSpecModel model, boolean alphaOnly) |
254 |
|
{ |
255 |
26 |
StringBuilder sb = new StringBuilder(128); |
256 |
|
|
257 |
26 |
boolean first = true; |
258 |
26 |
for (String modelNo : model.getModels()) |
259 |
|
{ |
260 |
35 |
for (String chain : model.getChains(modelNo)) |
261 |
|
{ |
262 |
54 |
for (int[] range : model.getRanges(modelNo, chain)) |
263 |
|
{ |
264 |
69 |
if (!first) |
265 |
|
{ |
266 |
44 |
sb.append(PIPE); |
267 |
|
} |
268 |
69 |
first = false; |
269 |
69 |
if (range[0] == range[1]) |
270 |
|
{ |
271 |
16 |
sb.append(range[0]); |
272 |
|
} |
273 |
|
else |
274 |
|
{ |
275 |
53 |
sb.append(range[0]).append(HYPHEN).append(range[1]); |
276 |
|
} |
277 |
69 |
sb.append(COLON).append(chain.trim()).append(SLASH); |
278 |
69 |
sb.append(String.valueOf(modelNo)).append(".1"); |
279 |
|
} |
280 |
|
} |
281 |
|
} |
282 |
|
|
283 |
26 |
return sb.toString(); |
284 |
|
} |
285 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
286 |
2 |
@Override... |
287 |
|
public List<StructureCommandI> showBackbone() |
288 |
|
{ |
289 |
2 |
return Arrays.asList(SHOW_BACKBONE); |
290 |
|
} |
291 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
292 |
4 |
@Override... |
293 |
|
public StructureCommandI loadFile(String file) |
294 |
|
{ |
295 |
|
|
296 |
4 |
return new StructureCommand("load FILES \"" + |
297 |
|
Platform.escapeBackslashes(file) + "\""); |
298 |
|
} |
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
@param |
305 |
|
@param |
306 |
|
@param |
307 |
|
@param |
308 |
|
@param |
309 |
|
@return |
310 |
|
|
|
|
| 75.3% |
Uncovered Elements: 19 (77) |
Complexity: 21 |
Complexity Density: 0.45 |
|
311 |
1 |
@Deprecated... |
312 |
|
public String[] colourBySequence(StructureSelectionManager ssm, |
313 |
|
String[] files, SequenceI[][] sequence, SequenceRenderer sr, |
314 |
|
AlignmentViewPanel viewPanel) |
315 |
|
{ |
316 |
|
|
317 |
|
|
318 |
1 |
FeatureRenderer fr = viewPanel.getFeatureRenderer(); |
319 |
1 |
FeatureColourFinder finder = new FeatureColourFinder(fr); |
320 |
1 |
AlignViewportI viewport = viewPanel.getAlignViewport(); |
321 |
1 |
HiddenColumns cs = viewport.getAlignment().getHiddenColumns(); |
322 |
1 |
AlignmentI al = viewport.getAlignment(); |
323 |
1 |
List<String> cset = new ArrayList<>(); |
324 |
|
|
325 |
3 |
for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) |
326 |
|
{ |
327 |
2 |
StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]); |
328 |
2 |
StringBuilder command = new StringBuilder(128); |
329 |
2 |
List<String> str = new ArrayList<>(); |
330 |
|
|
331 |
2 |
if (mapping == null || mapping.length < 1) |
332 |
|
{ |
333 |
0 |
continue; |
334 |
|
} |
335 |
|
|
336 |
4 |
for (int s = 0; s < sequence[pdbfnum].length; s++) |
337 |
|
{ |
338 |
4 |
for (int sp, m = 0; m < mapping.length; m++) |
339 |
|
{ |
340 |
? |
if (mapping[m].getSequence() == sequence[pdbfnum][s] |
341 |
|
&& (sp = al.findIndex(sequence[pdbfnum][s])) > -1) |
342 |
|
{ |
343 |
2 |
int lastPos = StructureMapping.UNASSIGNED_VALUE; |
344 |
2 |
SequenceI asp = al.getSequenceAt(sp); |
345 |
22 |
for (int r = 0; r < asp.getLength(); r++) |
346 |
|
{ |
347 |
|
|
348 |
20 |
if (Comparison.isGap(asp.getCharAt(r))) |
349 |
|
{ |
350 |
0 |
continue; |
351 |
|
} |
352 |
20 |
int pos = mapping[m].getPDBResNum(asp.findPosition(r)); |
353 |
|
|
354 |
20 |
if (pos == lastPos) |
355 |
|
{ |
356 |
0 |
continue; |
357 |
|
} |
358 |
20 |
if (pos == StructureMapping.UNASSIGNED_VALUE) |
359 |
|
{ |
360 |
|
|
361 |
0 |
if (command.length() > 0 |
362 |
|
&& command.charAt(command.length() - 1) != ';') |
363 |
|
{ |
364 |
0 |
command.append(";"); |
365 |
|
} |
366 |
|
|
367 |
0 |
lastPos = StructureMapping.UNASSIGNED_VALUE; |
368 |
0 |
continue; |
369 |
|
} |
370 |
|
|
371 |
20 |
lastPos = pos; |
372 |
|
|
373 |
20 |
Color col = sr.getResidueColour(sequence[pdbfnum][s], r, |
374 |
|
finder); |
375 |
|
|
376 |
|
|
377 |
|
|
378 |
|
|
379 |
20 |
if (!cs.isVisible(r)) |
380 |
|
{ |
381 |
6 |
col = Color.GRAY; |
382 |
|
} |
383 |
|
|
384 |
20 |
String newSelcom = (mapping[m].getChain() != " " |
385 |
|
? ":" + mapping[m].getChain() |
386 |
|
: "") + "/" + (pdbfnum + 1) + ".1" + ";color" |
387 |
|
+ getColourString(col); |
388 |
20 |
if (command.length() > newSelcom.length() && command |
389 |
|
.substring(command.length() - newSelcom.length()) |
390 |
|
.equals(newSelcom)) |
391 |
|
{ |
392 |
12 |
command = JmolCommands.condenseCommand(command, pos); |
393 |
12 |
continue; |
394 |
|
} |
395 |
|
|
396 |
|
|
397 |
|
|
398 |
8 |
if (command.length() > 0 |
399 |
|
&& command.charAt(command.length() - 1) != ';') |
400 |
|
{ |
401 |
6 |
command.append(";"); |
402 |
|
} |
403 |
|
|
404 |
8 |
if (command.length() > 51200) |
405 |
|
{ |
406 |
|
|
407 |
0 |
str.add(command.toString()); |
408 |
0 |
command.setLength(0); |
409 |
|
} |
410 |
8 |
command.append("select " + pos); |
411 |
8 |
command.append(newSelcom); |
412 |
|
} |
413 |
|
|
414 |
|
} |
415 |
|
} |
416 |
|
} |
417 |
|
{ |
418 |
|
|
419 |
2 |
str.add(command.toString()); |
420 |
2 |
command.setLength(0); |
421 |
|
} |
422 |
2 |
cset.addAll(str); |
423 |
|
|
424 |
|
} |
425 |
1 |
return cset.toArray(new String[cset.size()]); |
426 |
|
} |
427 |
|
|
428 |
|
|
429 |
|
|
430 |
|
|
431 |
|
@param |
432 |
|
@param |
433 |
|
@return |
434 |
|
|
|
|
| 80% |
Uncovered Elements: 4 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
435 |
12 |
@Deprecated... |
436 |
|
private static StringBuilder condenseCommand( |
437 |
|
StringBuilder command, |
438 |
|
int pos) |
439 |
|
{ |
440 |
|
|
441 |
|
|
442 |
12 |
int p = command.length(), q = p; |
443 |
12 |
do |
444 |
|
{ |
445 |
74 |
p -= 6; |
446 |
74 |
if (p < 1) |
447 |
|
{ |
448 |
0 |
p = 0; |
449 |
|
} |
450 |
74 |
; |
451 |
? |
} while ((q = command.indexOf("select", p)) == -1 && p > 0); |
452 |
|
|
453 |
12 |
StringBuilder sb = new StringBuilder(command.substring(0, q + 7)); |
454 |
|
|
455 |
12 |
command = command.delete(0, q + 7); |
456 |
|
|
457 |
12 |
String start; |
458 |
|
|
459 |
12 |
if (command.indexOf("-") > -1) |
460 |
|
{ |
461 |
8 |
start = command.substring(0, command.indexOf("-")); |
462 |
|
} |
463 |
|
else |
464 |
|
{ |
465 |
4 |
start = command.substring(0, command.indexOf(":")); |
466 |
|
} |
467 |
|
|
468 |
12 |
sb.append(start + "-" + pos + command.substring(command.indexOf(":"))); |
469 |
|
|
470 |
12 |
return sb; |
471 |
|
} |
472 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
473 |
2 |
@Override... |
474 |
|
public StructureCommandI openSession(String filepath) |
475 |
|
{ |
476 |
2 |
return loadFile(filepath); |
477 |
|
} |
478 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
479 |
1 |
@Override... |
480 |
|
public StructureCommandI closeViewer() |
481 |
|
{ |
482 |
1 |
return null; |
483 |
|
} |
484 |
|
} |