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