1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.EnumSet; |
25 |
|
import java.util.HashMap; |
26 |
|
import java.util.LinkedHashMap; |
27 |
|
import java.util.List; |
28 |
|
import java.util.Locale; |
29 |
|
import java.util.Map; |
30 |
|
import java.util.Map.Entry; |
31 |
|
|
32 |
|
import jalview.api.structures.JalviewStructureDisplayI; |
33 |
|
import jalview.bin.Cache; |
34 |
|
import jalview.bin.Console; |
35 |
|
import jalview.datamodel.PDBEntry; |
36 |
|
import jalview.datamodel.SequenceI; |
37 |
|
import jalview.datamodel.StructureViewerModel; |
38 |
|
import jalview.structure.StructureSelectionManager; |
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
@author |
47 |
|
|
|
|
| 0% |
Uncovered Elements: 202 (202) |
Complexity: 57 |
Complexity Density: 0.46 |
|
48 |
|
public class StructureViewer |
49 |
|
{ |
50 |
|
private static final String UNKNOWN_VIEWER_TYPE = "Unknown structure viewer type "; |
51 |
|
|
52 |
|
StructureSelectionManager ssm; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
private boolean superposeAdded = true; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
private boolean async = true; |
63 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
0 |
public void setAsync(boolean b)... |
65 |
|
{ |
66 |
0 |
async = b; |
67 |
|
} |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.38 |
|
69 |
|
public enum ViewerType |
70 |
|
{ |
71 |
|
JMOL, CHIMERA, CHIMERAX, PYMOL; |
72 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
73 |
0 |
public static ViewerType getFromString(String viewerString)... |
74 |
|
{ |
75 |
0 |
ViewerType viewerType = null; |
76 |
0 |
if (!"none".equals(viewerString)) |
77 |
|
{ |
78 |
0 |
for (ViewerType v : EnumSet.allOf(ViewerType.class)) |
79 |
|
{ |
80 |
0 |
String name = v.name().toLowerCase(Locale.ROOT).replaceAll(" ", |
81 |
|
""); |
82 |
0 |
if (viewerString.equals(name)) |
83 |
|
{ |
84 |
0 |
viewerType = v; |
85 |
0 |
break; |
86 |
|
} |
87 |
|
} |
88 |
|
} |
89 |
0 |
return viewerType; |
90 |
|
} |
91 |
|
|
92 |
|
}; |
93 |
|
|
94 |
|
|
95 |
|
|
96 |
|
|
97 |
|
@param |
98 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
99 |
0 |
public StructureViewer(... |
100 |
|
StructureSelectionManager structureSelectionManager) |
101 |
|
{ |
102 |
0 |
ssm = structureSelectionManager; |
103 |
|
} |
104 |
|
|
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
109 |
0 |
public static StructureViewer reconfigure(... |
110 |
|
JalviewStructureDisplayI display) |
111 |
|
{ |
112 |
0 |
StructureViewer sv = new StructureViewer(display.getBinding().getSsm()); |
113 |
0 |
sv.sview = display; |
114 |
0 |
return sv; |
115 |
|
} |
116 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
117 |
0 |
@Override... |
118 |
|
public String toString() |
119 |
|
{ |
120 |
0 |
if (sview != null) |
121 |
|
{ |
122 |
0 |
return sview.toString(); |
123 |
|
} |
124 |
0 |
return "New View"; |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
|
129 |
|
@return |
130 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
131 |
0 |
public static ViewerType getViewerType()... |
132 |
|
{ |
133 |
0 |
String viewType = Cache.getDefault(Preferences.STRUCTURE_DISPLAY, |
134 |
|
ViewerType.JMOL.name()); |
135 |
0 |
return ViewerType.valueOf(viewType); |
136 |
|
} |
137 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
138 |
0 |
public void setViewerType(ViewerType type)... |
139 |
|
{ |
140 |
0 |
Cache.setProperty(Preferences.STRUCTURE_DISPLAY, type.name()); |
141 |
|
} |
142 |
|
|
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
@param |
147 |
|
@param |
148 |
|
@param |
149 |
|
@return |
150 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
151 |
0 |
public JalviewStructureDisplayI viewStructures(PDBEntry[] pdbs,... |
152 |
|
SequenceI[] seqs, AlignmentPanel ap) |
153 |
|
{ |
154 |
0 |
return viewStructures(pdbs, seqs, ap, null); |
155 |
|
} |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 41 (41) |
Complexity: 9 |
Complexity Density: 0.36 |
|
157 |
0 |
public JalviewStructureDisplayI viewStructures(PDBEntry[] pdbs,... |
158 |
|
SequenceI[] seqs, AlignmentPanel ap, ViewerType viewerType) |
159 |
|
{ |
160 |
0 |
JalviewStructureDisplayI viewer = onlyOnePdb(pdbs, seqs, ap); |
161 |
0 |
if (viewer != null) |
162 |
|
{ |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
0 |
return viewer; |
167 |
|
} |
168 |
|
|
169 |
0 |
if (viewerType == null) |
170 |
0 |
viewerType = getViewerType(); |
171 |
|
|
172 |
0 |
Map<PDBEntry, SequenceI[]> seqsForPdbs = getSequencesForPdbs(pdbs, |
173 |
|
seqs); |
174 |
0 |
PDBEntry[] pdbsForFile = seqsForPdbs.keySet() |
175 |
|
.toArray(new PDBEntry[seqsForPdbs.size()]); |
176 |
0 |
SequenceI[][] theSeqs = seqsForPdbs.values() |
177 |
|
.toArray(new SequenceI[seqsForPdbs.size()][]); |
178 |
0 |
if (sview != null) |
179 |
|
{ |
180 |
0 |
sview.setAlignAddedStructures(superposeAdded); |
181 |
|
|
182 |
0 |
Runnable viewRunnable = new Runnable() |
183 |
|
{ |
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
184 |
0 |
@Override... |
185 |
|
public void run() |
186 |
|
{ |
187 |
|
|
188 |
0 |
for (int pdbep = 0; pdbep < pdbsForFile.length; pdbep++) |
189 |
|
{ |
190 |
0 |
PDBEntry pdb = pdbsForFile[pdbep]; |
191 |
0 |
if (!sview.addAlreadyLoadedFile(theSeqs[pdbep], null, ap, |
192 |
|
pdb.getId())) |
193 |
|
{ |
194 |
0 |
sview.addToExistingViewer(pdb, theSeqs[pdbep], null, ap, |
195 |
|
pdb.getId()); |
196 |
|
} |
197 |
|
} |
198 |
|
|
199 |
0 |
sview.updateTitleAndMenus(); |
200 |
|
} |
201 |
|
}; |
202 |
0 |
if (async) |
203 |
|
{ |
204 |
0 |
new Thread(viewRunnable).start(); |
205 |
|
} |
206 |
|
else |
207 |
|
{ |
208 |
0 |
viewRunnable.run(); |
209 |
|
} |
210 |
0 |
return sview; |
211 |
|
} |
212 |
|
|
213 |
0 |
if (viewerType.equals(ViewerType.JMOL)) |
214 |
|
{ |
215 |
0 |
sview = new AppJmol(ap, superposeAdded, pdbsForFile, theSeqs); |
216 |
|
} |
217 |
0 |
else if (viewerType.equals(ViewerType.CHIMERA)) |
218 |
|
{ |
219 |
0 |
sview = new ChimeraViewFrame(pdbsForFile, superposeAdded, theSeqs, |
220 |
|
ap); |
221 |
|
} |
222 |
0 |
else if (viewerType.equals(ViewerType.CHIMERAX)) |
223 |
|
{ |
224 |
0 |
sview = new ChimeraXViewFrame(pdbsForFile, superposeAdded, theSeqs, |
225 |
|
ap); |
226 |
|
} |
227 |
0 |
else if (viewerType.equals(ViewerType.PYMOL)) |
228 |
|
{ |
229 |
0 |
sview = new PymolViewer(pdbsForFile, superposeAdded, theSeqs, ap); |
230 |
|
} |
231 |
|
else |
232 |
|
{ |
233 |
0 |
Console.error(UNKNOWN_VIEWER_TYPE + getViewerType().toString()); |
234 |
|
} |
235 |
0 |
return sview; |
236 |
|
} |
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
@param |
245 |
|
@param |
246 |
|
@return |
247 |
|
|
|
|
| 0% |
Uncovered Elements: 32 (32) |
Complexity: 9 |
Complexity Density: 0.41 |
|
248 |
0 |
Map<PDBEntry, SequenceI[]> getSequencesForPdbs(PDBEntry[] pdbs,... |
249 |
|
SequenceI[] seqs) |
250 |
|
{ |
251 |
0 |
if (pdbs == null || seqs == null || pdbs.length != seqs.length) |
252 |
|
{ |
253 |
0 |
return null; |
254 |
|
} |
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
0 |
Map<String, PDBEntry> pdbsSeen = new HashMap<>(); |
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
0 |
Map<PDBEntry, List<SequenceI>> pdbSeqs = new LinkedHashMap<>(); |
267 |
0 |
for (int i = 0; i < pdbs.length; i++) |
268 |
|
{ |
269 |
0 |
PDBEntry pdb = pdbs[i]; |
270 |
0 |
SequenceI seq = seqs[i]; |
271 |
0 |
String pdbFile = pdb.getFile(); |
272 |
0 |
if (pdbFile == null || pdbFile.length() == 0) |
273 |
|
{ |
274 |
0 |
pdbFile = pdb.getId(); |
275 |
|
} |
276 |
0 |
if (!pdbsSeen.containsKey(pdbFile)) |
277 |
|
{ |
278 |
0 |
pdbsSeen.put(pdbFile, pdb); |
279 |
0 |
pdbSeqs.put(pdb, new ArrayList<SequenceI>()); |
280 |
|
} |
281 |
|
else |
282 |
|
{ |
283 |
0 |
pdb = pdbsSeen.get(pdbFile); |
284 |
|
} |
285 |
0 |
List<SequenceI> seqsForPdb = pdbSeqs.get(pdb); |
286 |
0 |
if (!seqsForPdb.contains(seq)) |
287 |
|
{ |
288 |
0 |
seqsForPdb.add(seq); |
289 |
|
} |
290 |
|
} |
291 |
|
|
292 |
|
|
293 |
|
|
294 |
|
|
295 |
0 |
Map<PDBEntry, SequenceI[]> result = new LinkedHashMap<>(); |
296 |
0 |
for (Entry<PDBEntry, List<SequenceI>> entry : pdbSeqs.entrySet()) |
297 |
|
{ |
298 |
0 |
List<SequenceI> theSeqs = entry.getValue(); |
299 |
0 |
result.put(entry.getKey(), |
300 |
|
theSeqs.toArray(new SequenceI[theSeqs.size()])); |
301 |
|
} |
302 |
|
|
303 |
0 |
return result; |
304 |
|
} |
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
@param |
314 |
|
@param |
315 |
|
@param |
316 |
|
@return |
317 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 6 |
Complexity Density: 0.46 |
|
318 |
0 |
private JalviewStructureDisplayI onlyOnePdb(PDBEntry[] pdbs,... |
319 |
|
SequenceI[] seqsForPdbs, AlignmentPanel ap) |
320 |
|
{ |
321 |
0 |
List<SequenceI> seqs = new ArrayList<>(); |
322 |
0 |
if (pdbs == null || pdbs.length == 0) |
323 |
|
{ |
324 |
0 |
return null; |
325 |
|
} |
326 |
0 |
int i = 0; |
327 |
0 |
String firstFile = pdbs[0].getFile(); |
328 |
0 |
for (PDBEntry pdb : pdbs) |
329 |
|
{ |
330 |
0 |
String pdbFile = pdb.getFile(); |
331 |
0 |
if (pdbFile == null || !pdbFile.equals(firstFile)) |
332 |
|
{ |
333 |
0 |
return null; |
334 |
|
} |
335 |
0 |
SequenceI pdbseq = seqsForPdbs[i++]; |
336 |
0 |
if (pdbseq != null) |
337 |
|
{ |
338 |
0 |
seqs.add(pdbseq); |
339 |
|
} |
340 |
|
} |
341 |
0 |
return viewStructures(pdbs[0], seqs.toArray(new SequenceI[seqs.size()]), |
342 |
|
ap); |
343 |
|
} |
344 |
|
|
345 |
|
JalviewStructureDisplayI sview = null; |
346 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
347 |
0 |
public JalviewStructureDisplayI getJalviewStructureDisplay()... |
348 |
|
{ |
349 |
0 |
return sview; |
350 |
|
} |
351 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
352 |
0 |
public JalviewStructureDisplayI viewStructures(PDBEntry pdb,... |
353 |
|
SequenceI[] seqsForPdb, AlignmentPanel ap) |
354 |
|
{ |
355 |
0 |
return viewStructures(pdb, seqsForPdb, ap, null); |
356 |
|
} |
357 |
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 8 |
Complexity Density: 0.4 |
|
358 |
0 |
public JalviewStructureDisplayI viewStructures(PDBEntry pdb,... |
359 |
|
SequenceI[] seqsForPdb, AlignmentPanel ap, ViewerType viewerType) |
360 |
|
{ |
361 |
0 |
if (sview != null) |
362 |
|
{ |
363 |
0 |
sview.setAlignAddedStructures(superposeAdded); |
364 |
0 |
String pdbId = pdb.getId(); |
365 |
0 |
if (!sview.addAlreadyLoadedFile(seqsForPdb, null, ap, pdbId)) |
366 |
|
{ |
367 |
0 |
sview.addToExistingViewer(pdb, seqsForPdb, null, ap, pdbId); |
368 |
|
} |
369 |
0 |
sview.updateTitleAndMenus(); |
370 |
0 |
sview.raiseViewer(); |
371 |
0 |
return sview; |
372 |
|
} |
373 |
0 |
if (viewerType == null) |
374 |
0 |
viewerType = getViewerType(); |
375 |
0 |
if (viewerType.equals(ViewerType.JMOL)) |
376 |
|
{ |
377 |
0 |
sview = new AppJmol(pdb, seqsForPdb, null, ap); |
378 |
|
} |
379 |
0 |
else if (viewerType.equals(ViewerType.CHIMERA)) |
380 |
|
{ |
381 |
0 |
sview = new ChimeraViewFrame(pdb, seqsForPdb, null, ap); |
382 |
|
} |
383 |
0 |
else if (viewerType.equals(ViewerType.CHIMERAX)) |
384 |
|
{ |
385 |
0 |
sview = new ChimeraXViewFrame(pdb, seqsForPdb, null, ap); |
386 |
|
} |
387 |
0 |
else if (viewerType.equals(ViewerType.PYMOL)) |
388 |
|
{ |
389 |
0 |
sview = new PymolViewer(pdb, seqsForPdb, null, ap); |
390 |
|
} |
391 |
|
else |
392 |
|
{ |
393 |
0 |
Console.error(UNKNOWN_VIEWER_TYPE + getViewerType().toString()); |
394 |
|
} |
395 |
0 |
return sview; |
396 |
|
} |
397 |
|
|
398 |
|
|
399 |
|
|
400 |
|
|
401 |
|
@param |
402 |
|
@param |
403 |
|
@param |
404 |
|
@param |
405 |
|
@param |
406 |
|
@return |
407 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.29 |
|
408 |
0 |
public static JalviewStructureDisplayI createView(ViewerType type,... |
409 |
|
AlignmentPanel alignPanel, StructureViewerModel viewerData, |
410 |
|
String sessionFile, String vid) |
411 |
|
{ |
412 |
0 |
JalviewStructureDisplayI viewer = null; |
413 |
0 |
switch (type) |
414 |
|
{ |
415 |
0 |
case JMOL: |
416 |
0 |
viewer = new AppJmol(viewerData, alignPanel, sessionFile, vid); |
417 |
|
|
418 |
0 |
break; |
419 |
0 |
case CHIMERA: |
420 |
0 |
viewer = new ChimeraViewFrame(viewerData, alignPanel, sessionFile, |
421 |
|
vid); |
422 |
0 |
break; |
423 |
0 |
case CHIMERAX: |
424 |
0 |
viewer = new ChimeraXViewFrame(viewerData, alignPanel, sessionFile, |
425 |
|
vid); |
426 |
0 |
break; |
427 |
0 |
case PYMOL: |
428 |
0 |
viewer = new PymolViewer(viewerData, alignPanel, sessionFile, vid); |
429 |
0 |
break; |
430 |
0 |
default: |
431 |
0 |
Console.error(UNKNOWN_VIEWER_TYPE + type.toString()); |
432 |
|
} |
433 |
0 |
return viewer; |
434 |
|
} |
435 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
436 |
0 |
public boolean isBusy()... |
437 |
|
{ |
438 |
0 |
if (sview != null) |
439 |
|
{ |
440 |
0 |
if (!sview.hasMapping()) |
441 |
|
{ |
442 |
0 |
return true; |
443 |
|
} |
444 |
|
} |
445 |
0 |
return false; |
446 |
|
} |
447 |
|
|
448 |
|
|
449 |
|
|
450 |
|
@param |
451 |
|
@return |
452 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
453 |
0 |
public boolean hasPdbId(String pDBid)... |
454 |
|
{ |
455 |
0 |
if (sview == null) |
456 |
|
{ |
457 |
0 |
return false; |
458 |
|
} |
459 |
|
|
460 |
0 |
return sview.getBinding().hasPdbId(pDBid); |
461 |
|
} |
462 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
463 |
0 |
public boolean isVisible()... |
464 |
|
{ |
465 |
0 |
return sview != null && sview.isVisible(); |
466 |
|
} |
467 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
468 |
0 |
public void setSuperpose(boolean alignAddedStructures)... |
469 |
|
{ |
470 |
0 |
superposeAdded = alignAddedStructures; |
471 |
|
} |
472 |
|
|
473 |
|
} |