1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.ext.rbvi.chimera; |
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.Locale; |
28 |
|
import java.util.Map; |
29 |
|
|
30 |
|
import jalview.structure.AtomSpecModel; |
31 |
|
import jalview.structure.StructureCommand; |
32 |
|
import jalview.structure.StructureCommandI; |
33 |
|
import jalview.structure.StructureCommandsBase; |
34 |
|
import jalview.util.ColorUtils; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
@author |
40 |
|
|
41 |
|
|
|
|
| 83.3% |
Uncovered Elements: 21 (126) |
Complexity: 33 |
Complexity Density: 0.38 |
|
42 |
|
public class ChimeraCommands extends StructureCommandsBase |
43 |
|
{ |
44 |
|
|
45 |
|
private static final StructureCommand FOCUS_VIEW = new StructureCommand( |
46 |
|
"focus"); |
47 |
|
|
48 |
|
|
49 |
|
private static final StructureCommand LIST_RESIDUE_ATTRIBUTES = new StructureCommand( |
50 |
|
"list resattr"); |
51 |
|
|
52 |
|
|
53 |
|
private static final StructureCommand CLOSE_CHIMERA = new StructureCommand( |
54 |
|
"stop really"); |
55 |
|
|
56 |
|
|
57 |
|
private static final StructureCommand STOP_NOTIFY_SELECTION = new StructureCommand( |
58 |
|
"listen stop selection"); |
59 |
|
|
60 |
|
private static final StructureCommand STOP_NOTIFY_MODELS = new StructureCommand( |
61 |
|
"listen stop models"); |
62 |
|
|
63 |
|
|
64 |
|
private static final StructureCommand GET_SELECTION = new StructureCommand( |
65 |
|
"list selection level residue"); |
66 |
|
|
67 |
|
private static final StructureCommand SHOW_BACKBONE = new StructureCommand( |
68 |
|
"~display all;~ribbon;chain @CA|P"); |
69 |
|
|
70 |
|
private static final StructureCommandI COLOUR_BY_CHARGE = new StructureCommand( |
71 |
|
"color white;color red ::ASP,GLU;color blue ::LYS,ARG;color yellow ::CYS"); |
72 |
|
|
73 |
|
|
74 |
|
private static final StructureCommandI COLOUR_BY_CHAIN = new StructureCommand( |
75 |
|
"rainbow chain"); |
76 |
|
|
77 |
|
|
78 |
|
private static final String NO_ALTLOCS = "&~@.B-Z&~@.2-9"; |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
80 |
4 |
@Override... |
81 |
|
public StructureCommandI colourResidues(String atomSpec, Color colour) |
82 |
|
{ |
83 |
|
|
84 |
4 |
String colourCode = getColourString(colour); |
85 |
4 |
return new StructureCommand("color " + colourCode + " " + atomSpec); |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
@param |
92 |
|
@return |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
94 |
8 |
protected String getColourString(Color colour)... |
95 |
|
{ |
96 |
8 |
return ColorUtils.toTkCode(colour); |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
@param |
112 |
|
@return |
113 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
|
114 |
10 |
@Override... |
115 |
|
public List<StructureCommandI> setAttributes( |
116 |
|
Map<String, Map<Object, AtomSpecModel>> featureMap) |
117 |
|
{ |
118 |
10 |
List<StructureCommandI> commands = new ArrayList<>(); |
119 |
10 |
for (String featureType : featureMap.keySet()) |
120 |
|
{ |
121 |
10 |
String attributeName = makeAttributeName(featureType); |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
129 |
10 |
Map<Object, AtomSpecModel> values = featureMap.get(featureType); |
130 |
10 |
for (Object value : values.keySet()) |
131 |
|
{ |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
|
137 |
12 |
AtomSpecModel atomSpecModel = values.get(value); |
138 |
12 |
String featureValue = value.toString(); |
139 |
12 |
featureValue = featureValue.replaceAll("\\'", "'"); |
140 |
12 |
StructureCommandI cmd = setAttribute(attributeName, featureValue, |
141 |
|
atomSpecModel); |
142 |
12 |
commands.add(cmd); |
143 |
|
} |
144 |
|
} |
145 |
|
|
146 |
10 |
return commands; |
147 |
|
} |
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
@param |
158 |
|
@param |
159 |
|
@param |
160 |
|
@return |
161 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
162 |
7 |
protected StructureCommandI setAttribute(String attributeName,... |
163 |
|
String attributeValue, AtomSpecModel atomSpecModel) |
164 |
|
{ |
165 |
7 |
StringBuilder sb = new StringBuilder(128); |
166 |
7 |
sb.append("setattr res ").append(attributeName).append(" '") |
167 |
|
.append(attributeValue).append("' "); |
168 |
7 |
sb.append(getAtomSpec(atomSpecModel, AtomSpecType.RESIDUE_ONLY)); |
169 |
7 |
return new StructureCommand(sb.toString()); |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
@param |
178 |
|
@return |
179 |
|
@see |
180 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
181 |
16 |
@Override... |
182 |
|
protected String makeAttributeName(String featureType) |
183 |
|
{ |
184 |
16 |
String attName = super.makeAttributeName(featureType); |
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
16 |
if (attName.toUpperCase(Locale.ROOT).endsWith("COLOR")) |
191 |
|
{ |
192 |
1 |
attName += "_"; |
193 |
|
} |
194 |
|
|
195 |
16 |
return attName; |
196 |
|
} |
197 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
198 |
2 |
@Override... |
199 |
|
public StructureCommandI colourByChain() |
200 |
|
{ |
201 |
2 |
return COLOUR_BY_CHAIN; |
202 |
|
} |
203 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
204 |
1 |
@Override... |
205 |
|
public List<StructureCommandI> colourByCharge() |
206 |
|
{ |
207 |
1 |
return Arrays.asList(COLOUR_BY_CHARGE); |
208 |
|
} |
209 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
210 |
1 |
@Override... |
211 |
|
public String getResidueSpec(String residue) |
212 |
|
{ |
213 |
1 |
return "::" + residue; |
214 |
|
} |
215 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
216 |
2 |
@Override... |
217 |
|
public StructureCommandI setBackgroundColour(Color col) |
218 |
|
{ |
219 |
|
|
220 |
2 |
return new StructureCommand("set bgColor " + ColorUtils.toTkCode(col)); |
221 |
|
} |
222 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
223 |
1 |
@Override... |
224 |
|
public StructureCommandI focusView() |
225 |
|
{ |
226 |
1 |
return FOCUS_VIEW; |
227 |
|
} |
228 |
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.25 |
|
229 |
0 |
@Override... |
230 |
|
public List<StructureCommandI> showChains(List<String> toShow) |
231 |
|
{ |
232 |
|
|
233 |
|
|
234 |
|
|
235 |
|
|
236 |
|
|
237 |
0 |
StringBuilder cmd = new StringBuilder(64); |
238 |
0 |
boolean first = true; |
239 |
0 |
for (String chain : toShow) |
240 |
|
{ |
241 |
0 |
String[] tokens = chain.split(":"); |
242 |
0 |
if (tokens.length == 2) |
243 |
|
{ |
244 |
0 |
String showChainCmd = tokens[0] + ":." + tokens[1]; |
245 |
0 |
if (!first) |
246 |
|
{ |
247 |
0 |
cmd.append(","); |
248 |
|
} |
249 |
0 |
cmd.append(showChainCmd); |
250 |
0 |
first = false; |
251 |
|
} |
252 |
|
} |
253 |
|
|
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
0 |
final String command = "~display #*; ~ribbon #*; ribbon :" |
260 |
|
+ cmd.toString(); |
261 |
0 |
return Arrays.asList(new StructureCommand(command)); |
262 |
|
} |
263 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
264 |
1 |
@Override... |
265 |
|
public List<StructureCommandI> superposeStructures(AtomSpecModel ref, |
266 |
|
AtomSpecModel spec, AtomSpecType backbone) |
267 |
|
{ |
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
@see |
275 |
|
|
276 |
1 |
StringBuilder cmd = new StringBuilder(); |
277 |
1 |
String atomSpecAlphaOnly = getAtomSpec(spec, backbone); |
278 |
1 |
String refSpecAlphaOnly = getAtomSpec(ref, backbone); |
279 |
1 |
cmd.append("match ").append(atomSpecAlphaOnly).append(" ") |
280 |
|
.append(refSpecAlphaOnly); |
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
1 |
String atomSpec = getAtomSpec(spec, AtomSpecType.RESIDUE_ONLY); |
286 |
1 |
String refSpec = getAtomSpec(ref, AtomSpecType.RESIDUE_ONLY); |
287 |
1 |
cmd.append("; ribbon "); |
288 |
1 |
cmd.append(atomSpec).append("|").append(refSpec).append("; focus"); |
289 |
|
|
290 |
1 |
return Arrays.asList(new StructureCommand(cmd.toString())); |
291 |
|
} |
292 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
293 |
1 |
@Override... |
294 |
|
public StructureCommandI openCommandFile(String path) |
295 |
|
{ |
296 |
|
|
297 |
1 |
return new StructureCommand("open cmd:" + path); |
298 |
|
} |
299 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
300 |
1 |
@Override... |
301 |
|
public StructureCommandI saveSession(String filepath) |
302 |
|
{ |
303 |
|
|
304 |
1 |
return new StructureCommand("save " + filepath); |
305 |
|
} |
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
|
|
325 |
|
|
326 |
|
@param |
327 |
|
@param |
328 |
|
@return |
329 |
|
@see |
330 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
331 |
41 |
@Override... |
332 |
|
public String getAtomSpec(AtomSpecModel atomSpec, AtomSpecType specType) |
333 |
|
{ |
334 |
41 |
StringBuilder sb = new StringBuilder(128); |
335 |
41 |
boolean firstModel = true; |
336 |
41 |
for (String model : atomSpec.getModels()) |
337 |
|
{ |
338 |
60 |
if (!firstModel) |
339 |
|
{ |
340 |
21 |
sb.append("|"); |
341 |
|
} |
342 |
60 |
firstModel = false; |
343 |
60 |
appendModel(sb, model, atomSpec, specType); |
344 |
|
} |
345 |
41 |
return sb.toString(); |
346 |
|
} |
347 |
|
|
348 |
|
|
349 |
|
|
350 |
|
|
351 |
|
@param |
352 |
|
@param |
353 |
|
@param |
354 |
|
@param |
355 |
|
|
|
|
| 88.9% |
Uncovered Elements: 2 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
356 |
60 |
protected void appendModel(StringBuilder sb, String model,... |
357 |
|
AtomSpecModel atomSpec, AtomSpecType specType) |
358 |
|
{ |
359 |
60 |
sb.append("#").append(model).append(":"); |
360 |
|
|
361 |
60 |
boolean firstPositionForModel = true; |
362 |
|
|
363 |
60 |
for (String chain : atomSpec.getChains(model)) |
364 |
|
{ |
365 |
94 |
chain = " ".equals(chain) ? chain : chain.trim(); |
366 |
|
|
367 |
94 |
List<int[]> rangeList = atomSpec.getRanges(model, chain); |
368 |
94 |
for (int[] range : rangeList) |
369 |
|
{ |
370 |
119 |
appendRange(sb, range[0], range[1], chain, firstPositionForModel, |
371 |
|
false); |
372 |
119 |
firstPositionForModel = false; |
373 |
|
} |
374 |
|
} |
375 |
60 |
if (specType == AtomSpecType.ALPHA) |
376 |
|
{ |
377 |
|
|
378 |
|
|
379 |
|
|
380 |
|
|
381 |
19 |
sb.append("@CA").append(NO_ALTLOCS); |
382 |
|
} |
383 |
60 |
if (specType == AtomSpecType.PHOSPHATE) |
384 |
|
{ |
385 |
0 |
sb.append("@P").append(NO_ALTLOCS); |
386 |
|
} |
387 |
|
} |
388 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
389 |
1 |
@Override... |
390 |
|
public List<StructureCommandI> showBackbone() |
391 |
|
{ |
392 |
1 |
return Arrays.asList(SHOW_BACKBONE); |
393 |
|
} |
394 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
395 |
1 |
@Override... |
396 |
|
public StructureCommandI loadFile(String file) |
397 |
|
{ |
398 |
1 |
return new StructureCommand("open " + file); |
399 |
|
} |
400 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
401 |
1 |
@Override... |
402 |
|
public StructureCommandI openSession(String filepath) |
403 |
|
{ |
404 |
|
|
405 |
|
|
406 |
1 |
return new StructureCommand("open chimera:" + filepath); |
407 |
|
} |
408 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
409 |
1 |
@Override... |
410 |
|
public StructureCommandI closeViewer() |
411 |
|
{ |
412 |
1 |
return CLOSE_CHIMERA; |
413 |
|
} |
414 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
415 |
1 |
@Override... |
416 |
|
public List<StructureCommandI> startNotifications(String uri) |
417 |
|
{ |
418 |
|
|
419 |
1 |
List<StructureCommandI> cmds = new ArrayList<>(); |
420 |
1 |
cmds.add(new StructureCommand("listen start models url " + uri)); |
421 |
1 |
cmds.add(new StructureCommand( |
422 |
|
"listen start select prefix SelectionChanged url " + uri)); |
423 |
1 |
return cmds; |
424 |
|
} |
425 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
426 |
1 |
@Override... |
427 |
|
public List<StructureCommandI> stopNotifications() |
428 |
|
{ |
429 |
1 |
List<StructureCommandI> cmds = new ArrayList<>(); |
430 |
1 |
cmds.add(STOP_NOTIFY_MODELS); |
431 |
1 |
cmds.add(STOP_NOTIFY_SELECTION); |
432 |
1 |
return cmds; |
433 |
|
} |
434 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
435 |
1 |
@Override... |
436 |
|
public StructureCommandI getSelectedResidues() |
437 |
|
{ |
438 |
1 |
return GET_SELECTION; |
439 |
|
} |
440 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
441 |
1 |
@Override... |
442 |
|
public StructureCommandI listResidueAttributes() |
443 |
|
{ |
444 |
1 |
return LIST_RESIDUE_ATTRIBUTES; |
445 |
|
} |
446 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
447 |
1 |
@Override... |
448 |
|
public StructureCommandI getResidueAttributes(String attName) |
449 |
|
{ |
450 |
|
|
451 |
|
|
452 |
|
|
453 |
|
|
454 |
1 |
return new StructureCommand("list residues attr '" + attName + "'"); |
455 |
|
} |
456 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
457 |
0 |
@Override... |
458 |
|
public List<StructureCommandI> centerViewOn(List<AtomSpecModel> residues) |
459 |
|
{ |
460 |
|
|
461 |
0 |
return null; |
462 |
|
} |
463 |
|
|
464 |
|
} |