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 jalview.api.AlignViewportI; |
24 |
|
import jalview.api.AlignmentViewPanel; |
25 |
|
import jalview.api.FeatureRenderer; |
26 |
|
import jalview.api.SequenceRenderer; |
27 |
|
import jalview.datamodel.AlignmentI; |
28 |
|
import jalview.datamodel.HiddenColumns; |
29 |
|
import jalview.datamodel.SequenceFeature; |
30 |
|
import jalview.datamodel.SequenceI; |
31 |
|
import jalview.renderer.seqfeatures.FeatureColourFinder; |
32 |
|
import jalview.structure.StructureMapping; |
33 |
|
import jalview.structure.StructureMappingcommandSet; |
34 |
|
import jalview.structure.StructureSelectionManager; |
35 |
|
import jalview.util.ColorUtils; |
36 |
|
import jalview.util.Comparison; |
37 |
|
|
38 |
|
import java.awt.Color; |
39 |
|
import java.util.ArrayList; |
40 |
|
import java.util.HashMap; |
41 |
|
import java.util.LinkedHashMap; |
42 |
|
import java.util.List; |
43 |
|
import java.util.Map; |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@author |
49 |
|
|
50 |
|
|
|
|
| 51.1% |
Uncovered Elements: 110 (225) |
Complexity: 52 |
Complexity Density: 0.35 |
|
51 |
|
public class ChimeraCommands |
52 |
|
{ |
53 |
|
|
54 |
|
public static final String NAMESPACE_PREFIX = "jv_"; |
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
@param |
60 |
|
@param |
61 |
|
@param |
62 |
|
@param |
63 |
|
@param |
64 |
|
@param |
65 |
|
@return |
66 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
67 |
1 |
public static StructureMappingcommandSet[] getColourBySequenceCommand(... |
68 |
|
StructureSelectionManager ssm, String[] files, |
69 |
|
SequenceI[][] sequence, SequenceRenderer sr, |
70 |
|
AlignmentViewPanel viewPanel) |
71 |
|
{ |
72 |
1 |
Map<Object, AtomSpecModel> colourMap = buildColoursMap(ssm, files, |
73 |
|
sequence, sr, viewPanel); |
74 |
|
|
75 |
1 |
List<String> colourCommands = buildColourCommands(colourMap); |
76 |
|
|
77 |
1 |
StructureMappingcommandSet cs = new StructureMappingcommandSet( |
78 |
|
ChimeraCommands.class, null, |
79 |
|
colourCommands.toArray(new String[colourCommands.size()])); |
80 |
|
|
81 |
1 |
return new StructureMappingcommandSet[] { cs }; |
82 |
|
} |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
@param |
97 |
|
@return |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 2 |
Complexity Density: 0.14 |
|
99 |
2 |
protected static List<String> buildColourCommands(... |
100 |
|
Map<Object, AtomSpecModel> colourMap) |
101 |
|
{ |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
|
107 |
2 |
List<String> commands = new ArrayList<String>(); |
108 |
2 |
StringBuilder sb = new StringBuilder(256); |
109 |
2 |
boolean firstColour = true; |
110 |
2 |
for (Object key : colourMap.keySet()) |
111 |
|
{ |
112 |
8 |
Color colour = (Color) key; |
113 |
8 |
String colourCode = ColorUtils.toTkCode(colour); |
114 |
8 |
if (!firstColour) |
115 |
|
{ |
116 |
6 |
sb.append("; "); |
117 |
|
} |
118 |
8 |
sb.append("color ").append(colourCode).append(" "); |
119 |
8 |
firstColour = false; |
120 |
8 |
final AtomSpecModel colourData = colourMap.get(colour); |
121 |
8 |
sb.append(colourData.getAtomSpec()); |
122 |
|
} |
123 |
2 |
commands.add(sb.toString()); |
124 |
2 |
return commands; |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
@param |
132 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 5 |
Complexity Density: 0.24 |
|
133 |
0 |
protected static String getAtomSpec(... |
134 |
|
Map<Integer, Map<String, List<int[]>>> modelAndChainRanges) |
135 |
|
{ |
136 |
0 |
StringBuilder sb = new StringBuilder(128); |
137 |
0 |
boolean firstModelForColour = true; |
138 |
0 |
for (Integer model : modelAndChainRanges.keySet()) |
139 |
|
{ |
140 |
0 |
boolean firstPositionForModel = true; |
141 |
0 |
if (!firstModelForColour) |
142 |
|
{ |
143 |
0 |
sb.append("|"); |
144 |
|
} |
145 |
0 |
firstModelForColour = false; |
146 |
0 |
sb.append("#").append(model).append(":"); |
147 |
|
|
148 |
0 |
final Map<String, List<int[]>> modelData = modelAndChainRanges |
149 |
|
.get(model); |
150 |
0 |
for (String chain : modelData.keySet()) |
151 |
|
{ |
152 |
0 |
boolean hasChain = !"".equals(chain.trim()); |
153 |
0 |
for (int[] range : modelData.get(chain)) |
154 |
|
{ |
155 |
0 |
if (!firstPositionForModel) |
156 |
|
{ |
157 |
0 |
sb.append(","); |
158 |
|
} |
159 |
0 |
if (range[0] == range[1]) |
160 |
|
{ |
161 |
0 |
sb.append(range[0]); |
162 |
|
} |
163 |
|
else |
164 |
|
{ |
165 |
0 |
sb.append(range[0]).append("-").append(range[1]); |
166 |
|
} |
167 |
0 |
if (hasChain) |
168 |
|
{ |
169 |
0 |
sb.append(".").append(chain); |
170 |
|
} |
171 |
0 |
firstPositionForModel = false; |
172 |
|
} |
173 |
|
} |
174 |
|
} |
175 |
0 |
return sb.toString(); |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
|
|
|
|
| 86.2% |
Uncovered Elements: 9 (65) |
Complexity: 18 |
Complexity Density: 0.44 |
|
189 |
1 |
protected static Map<Object, AtomSpecModel> buildColoursMap(... |
190 |
|
StructureSelectionManager ssm, String[] files, |
191 |
|
SequenceI[][] sequence, SequenceRenderer sr, |
192 |
|
AlignmentViewPanel viewPanel) |
193 |
|
{ |
194 |
1 |
FeatureRenderer fr = viewPanel.getFeatureRenderer(); |
195 |
1 |
FeatureColourFinder finder = new FeatureColourFinder(fr); |
196 |
1 |
AlignViewportI viewport = viewPanel.getAlignViewport(); |
197 |
1 |
HiddenColumns cs = viewport.getAlignment().getHiddenColumns(); |
198 |
1 |
AlignmentI al = viewport.getAlignment(); |
199 |
1 |
Map<Object, AtomSpecModel> colourMap = new LinkedHashMap<Object, AtomSpecModel>(); |
200 |
1 |
Color lastColour = null; |
201 |
|
|
202 |
3 |
for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) |
203 |
|
{ |
204 |
2 |
StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]); |
205 |
|
|
206 |
2 |
if (mapping == null || mapping.length < 1) |
207 |
|
{ |
208 |
0 |
continue; |
209 |
|
} |
210 |
|
|
211 |
2 |
int startPos = -1, lastPos = -1; |
212 |
2 |
String lastChain = ""; |
213 |
4 |
for (int s = 0; s < sequence[pdbfnum].length; s++) |
214 |
|
{ |
215 |
4 |
for (int sp, m = 0; m < mapping.length; m++) |
216 |
|
{ |
217 |
2 |
final SequenceI seq = sequence[pdbfnum][s]; |
218 |
? |
if (mapping[m].getSequence() == seq |
219 |
|
&& (sp = al.findIndex(seq)) > -1) |
220 |
|
{ |
221 |
2 |
SequenceI asp = al.getSequenceAt(sp); |
222 |
22 |
for (int r = 0; r < asp.getLength(); r++) |
223 |
|
{ |
224 |
|
|
225 |
20 |
if (Comparison.isGap(asp.getCharAt(r))) |
226 |
|
{ |
227 |
0 |
continue; |
228 |
|
} |
229 |
20 |
int pos = mapping[m].getPDBResNum(asp.findPosition(r)); |
230 |
|
|
231 |
20 |
if (pos < 1 || pos == lastPos) |
232 |
|
{ |
233 |
0 |
continue; |
234 |
|
} |
235 |
|
|
236 |
20 |
Color colour = sr.getResidueColour(seq, r, finder); |
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
20 |
if (!cs.isVisible(r)) |
242 |
|
{ |
243 |
6 |
colour = Color.GRAY; |
244 |
|
} |
245 |
|
|
246 |
20 |
final String chain = mapping[m].getChain(); |
247 |
|
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
|
|
252 |
|
|
253 |
20 |
final boolean newColour = !colour.equals(lastColour); |
254 |
20 |
final boolean nonContig = lastPos + 1 != pos; |
255 |
20 |
final boolean newChain = !chain.equals(lastChain); |
256 |
20 |
if (newColour || nonContig || newChain) |
257 |
|
{ |
258 |
8 |
if (startPos != -1) |
259 |
|
{ |
260 |
6 |
addColourRange(colourMap, lastColour, pdbfnum, startPos, |
261 |
|
lastPos, lastChain); |
262 |
|
} |
263 |
8 |
startPos = pos; |
264 |
|
} |
265 |
20 |
lastColour = colour; |
266 |
20 |
lastPos = pos; |
267 |
20 |
lastChain = chain; |
268 |
|
} |
269 |
|
|
270 |
2 |
if (lastColour != null) |
271 |
|
{ |
272 |
2 |
addColourRange(colourMap, lastColour, pdbfnum, startPos, |
273 |
|
lastPos, lastChain); |
274 |
|
} |
275 |
|
|
276 |
|
} |
277 |
|
} |
278 |
|
} |
279 |
|
} |
280 |
1 |
return colourMap; |
281 |
|
} |
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
@param |
287 |
|
@param |
288 |
|
@param |
289 |
|
@param |
290 |
|
@param |
291 |
|
@param |
292 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
293 |
24 |
protected static void addColourRange(Map<Object, AtomSpecModel> map,... |
294 |
|
Object key, int model, int startPos, int endPos, String chain) |
295 |
|
{ |
296 |
|
|
297 |
|
|
298 |
|
|
299 |
24 |
AtomSpecModel atomSpec = map.get(key); |
300 |
24 |
if (atomSpec == null) |
301 |
|
{ |
302 |
11 |
atomSpec = new AtomSpecModel(); |
303 |
11 |
map.put(key, atomSpec); |
304 |
|
} |
305 |
|
|
306 |
24 |
atomSpec.addRange(model, startPos, endPos, chain); |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
@param |
315 |
|
@param |
316 |
|
@param |
317 |
|
@param |
318 |
|
@return |
319 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
320 |
0 |
public static StructureMappingcommandSet getSetAttributeCommandsForFeatures(... |
321 |
|
StructureSelectionManager ssm, String[] files, SequenceI[][] seqs, |
322 |
|
AlignmentViewPanel viewPanel) |
323 |
|
{ |
324 |
0 |
Map<String, Map<Object, AtomSpecModel>> featureMap = buildFeaturesMap( |
325 |
|
ssm, files, seqs, viewPanel); |
326 |
|
|
327 |
0 |
List<String> commands = buildSetAttributeCommands(featureMap); |
328 |
|
|
329 |
0 |
StructureMappingcommandSet cs = new StructureMappingcommandSet( |
330 |
|
ChimeraCommands.class, null, |
331 |
|
commands.toArray(new String[commands.size()])); |
332 |
|
|
333 |
0 |
return cs; |
334 |
|
} |
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
|
|
341 |
|
|
342 |
|
@param |
343 |
|
@param |
344 |
|
@param |
345 |
|
@param |
346 |
|
@return |
347 |
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 10 |
Complexity Density: 0.5 |
|
348 |
0 |
protected static Map<String, Map<Object, AtomSpecModel>> buildFeaturesMap(... |
349 |
|
StructureSelectionManager ssm, String[] files, SequenceI[][] seqs, |
350 |
|
AlignmentViewPanel viewPanel) |
351 |
|
{ |
352 |
0 |
Map<String, Map<Object, AtomSpecModel>> theMap = new LinkedHashMap<String, Map<Object, AtomSpecModel>>(); |
353 |
|
|
354 |
0 |
FeatureRenderer fr = viewPanel.getFeatureRenderer(); |
355 |
0 |
if (fr == null) |
356 |
|
{ |
357 |
0 |
return theMap; |
358 |
|
} |
359 |
|
|
360 |
0 |
List<String> visibleFeatures = fr.getDisplayedFeatureTypes(); |
361 |
0 |
if (visibleFeatures.isEmpty()) |
362 |
|
{ |
363 |
0 |
return theMap; |
364 |
|
} |
365 |
|
|
366 |
0 |
AlignmentI alignment = viewPanel.getAlignment(); |
367 |
0 |
for (int pdbfnum = 0; pdbfnum < files.length; pdbfnum++) |
368 |
|
{ |
369 |
0 |
StructureMapping[] mapping = ssm.getMapping(files[pdbfnum]); |
370 |
|
|
371 |
0 |
if (mapping == null || mapping.length < 1) |
372 |
|
{ |
373 |
0 |
continue; |
374 |
|
} |
375 |
|
|
376 |
0 |
for (int seqNo = 0; seqNo < seqs[pdbfnum].length; seqNo++) |
377 |
|
{ |
378 |
0 |
for (int m = 0; m < mapping.length; m++) |
379 |
|
{ |
380 |
0 |
final SequenceI seq = seqs[pdbfnum][seqNo]; |
381 |
0 |
int sp = alignment.findIndex(seq); |
382 |
0 |
if (mapping[m].getSequence() == seq && sp > -1) |
383 |
|
{ |
384 |
|
|
385 |
|
|
386 |
|
|
387 |
|
|
388 |
0 |
SequenceI asp = alignment.getSequenceAt(sp); |
389 |
|
|
390 |
0 |
scanSequenceFeatures(visibleFeatures, mapping[m], asp, theMap, |
391 |
|
pdbfnum); |
392 |
|
} |
393 |
|
} |
394 |
|
} |
395 |
|
} |
396 |
0 |
return theMap; |
397 |
|
} |
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
|
402 |
|
|
403 |
|
|
404 |
|
@param |
405 |
|
@param |
406 |
|
@param |
407 |
|
@param |
408 |
|
@param |
409 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 8 |
Complexity Density: 0.4 |
|
410 |
0 |
protected static void scanSequenceFeatures(List<String> visibleFeatures,... |
411 |
|
StructureMapping mapping, SequenceI seq, |
412 |
|
Map<String, Map<Object, AtomSpecModel>> theMap, int modelNumber) |
413 |
|
{ |
414 |
0 |
List<SequenceFeature> sfs = seq.getFeatures().getPositionalFeatures( |
415 |
|
visibleFeatures.toArray(new String[visibleFeatures.size()])); |
416 |
0 |
for (SequenceFeature sf : sfs) |
417 |
|
{ |
418 |
0 |
String type = sf.getType(); |
419 |
|
|
420 |
|
|
421 |
|
|
422 |
|
|
423 |
|
|
424 |
0 |
boolean isFromViewer = JalviewChimeraBinding.CHIMERA_FEATURE_GROUP |
425 |
|
.equals(sf.getFeatureGroup()); |
426 |
0 |
if (isFromViewer) |
427 |
|
{ |
428 |
0 |
continue; |
429 |
|
} |
430 |
0 |
List<int[]> mappedRanges = mapping.getPDBResNumRanges(sf.getBegin(), |
431 |
|
sf.getEnd()); |
432 |
|
|
433 |
0 |
if (!mappedRanges.isEmpty()) |
434 |
|
{ |
435 |
0 |
String value = sf.getDescription(); |
436 |
0 |
if (value == null || value.length() == 0) |
437 |
|
{ |
438 |
0 |
value = type; |
439 |
|
} |
440 |
0 |
float score = sf.getScore(); |
441 |
0 |
if (score != 0f && !Float.isNaN(score)) |
442 |
|
{ |
443 |
0 |
value = Float.toString(score); |
444 |
|
} |
445 |
0 |
Map<Object, AtomSpecModel> featureValues = theMap.get(type); |
446 |
0 |
if (featureValues == null) |
447 |
|
{ |
448 |
0 |
featureValues = new HashMap<Object, AtomSpecModel>(); |
449 |
0 |
theMap.put(type, featureValues); |
450 |
|
} |
451 |
0 |
for (int[] range : mappedRanges) |
452 |
|
{ |
453 |
0 |
addColourRange(featureValues, value, modelNumber, range[0], |
454 |
|
range[1], mapping.getChain()); |
455 |
|
} |
456 |
|
} |
457 |
|
} |
458 |
|
} |
459 |
|
|
460 |
|
|
461 |
|
|
462 |
|
|
463 |
|
|
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
|
|
469 |
|
|
470 |
|
|
471 |
|
|
472 |
|
@param |
473 |
|
@return |
474 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
475 |
5 |
protected static List<String> buildSetAttributeCommands(... |
476 |
|
Map<String, Map<Object, AtomSpecModel>> featureMap) |
477 |
|
{ |
478 |
5 |
List<String> commands = new ArrayList<String>(); |
479 |
5 |
for (String featureType : featureMap.keySet()) |
480 |
|
{ |
481 |
5 |
String attributeName = makeAttributeName(featureType); |
482 |
|
|
483 |
|
|
484 |
|
|
485 |
|
|
486 |
|
|
487 |
|
|
488 |
|
|
489 |
5 |
Map<Object, AtomSpecModel> values = featureMap.get(featureType); |
490 |
5 |
for (Object value : values.keySet()) |
491 |
|
{ |
492 |
|
|
493 |
|
|
494 |
|
|
495 |
|
|
496 |
|
|
497 |
6 |
StringBuilder sb = new StringBuilder(128); |
498 |
6 |
String featureValue = value.toString(); |
499 |
6 |
featureValue = featureValue.replaceAll("\\'", "'"); |
500 |
6 |
sb.append("setattr r ").append(attributeName).append(" '") |
501 |
|
.append(featureValue).append("' "); |
502 |
6 |
sb.append(values.get(value).getAtomSpec()); |
503 |
6 |
commands.add(sb.toString()); |
504 |
|
} |
505 |
|
} |
506 |
|
|
507 |
5 |
return commands; |
508 |
|
} |
509 |
|
|
510 |
|
|
511 |
|
|
512 |
|
|
513 |
|
|
514 |
|
|
515 |
|
@param |
516 |
|
@return |
517 |
|
|
518 |
|
|
519 |
|
|
520 |
|
|
521 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
522 |
11 |
protected static String makeAttributeName(String featureType)... |
523 |
|
{ |
524 |
11 |
StringBuilder sb = new StringBuilder(); |
525 |
11 |
if (featureType != null) |
526 |
|
{ |
527 |
10 |
for (char c : featureType.toCharArray()) |
528 |
|
{ |
529 |
93 |
sb.append(Character.isLetterOrDigit(c) ? c : '_'); |
530 |
|
} |
531 |
|
} |
532 |
11 |
String attName = NAMESPACE_PREFIX + sb.toString(); |
533 |
|
|
534 |
|
|
535 |
|
|
536 |
|
|
537 |
|
|
538 |
11 |
if (attName.toUpperCase().endsWith("COLOR")) |
539 |
|
{ |
540 |
1 |
attName += "_"; |
541 |
|
} |
542 |
|
|
543 |
11 |
return attName; |
544 |
|
} |
545 |
|
|
546 |
|
} |