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.awt.BorderLayout; |
24 |
|
import java.awt.Color; |
25 |
|
import java.awt.Dimension; |
26 |
|
import java.awt.FlowLayout; |
27 |
|
import java.awt.Font; |
28 |
|
import java.awt.Graphics; |
29 |
|
import java.awt.GridLayout; |
30 |
|
import java.awt.event.ActionEvent; |
31 |
|
import java.awt.event.ActionListener; |
32 |
|
import java.awt.event.KeyAdapter; |
33 |
|
import java.awt.event.KeyEvent; |
34 |
|
import java.beans.PropertyChangeEvent; |
35 |
|
import java.beans.PropertyChangeListener; |
36 |
|
import java.io.File; |
37 |
|
import java.io.FileOutputStream; |
38 |
|
import java.util.ArrayList; |
39 |
|
import java.util.HashMap; |
40 |
|
import java.util.List; |
41 |
|
import java.util.Locale; |
42 |
|
import java.util.Map; |
43 |
|
|
44 |
|
import javax.swing.ButtonGroup; |
45 |
|
import javax.swing.JLabel; |
46 |
|
import javax.swing.JMenuItem; |
47 |
|
import javax.swing.JPanel; |
48 |
|
import javax.swing.JRadioButtonMenuItem; |
49 |
|
import javax.swing.JScrollPane; |
50 |
|
import javax.swing.SwingConstants; |
51 |
|
import javax.swing.event.InternalFrameAdapter; |
52 |
|
import javax.swing.event.InternalFrameEvent; |
53 |
|
|
54 |
|
import org.jibble.epsgraphics.EpsGraphics2D; |
55 |
|
|
56 |
|
import jalview.analysis.AlignmentSorter; |
57 |
|
import jalview.analysis.AlignmentUtils; |
58 |
|
import jalview.analysis.AverageDistanceTree; |
59 |
|
import jalview.analysis.NJTree; |
60 |
|
import jalview.analysis.TreeBuilder; |
61 |
|
import jalview.analysis.TreeModel; |
62 |
|
import jalview.analysis.scoremodels.ScoreModels; |
63 |
|
import jalview.api.analysis.ScoreModelI; |
64 |
|
import jalview.api.analysis.SimilarityParamsI; |
65 |
|
import jalview.bin.Cache; |
66 |
|
import jalview.bin.Console; |
67 |
|
import jalview.commands.CommandI; |
68 |
|
import jalview.commands.OrderCommand; |
69 |
|
import jalview.datamodel.Alignment; |
70 |
|
import jalview.datamodel.AlignmentAnnotation; |
71 |
|
import jalview.datamodel.AlignmentI; |
72 |
|
import jalview.datamodel.AlignmentView; |
73 |
|
import jalview.datamodel.BinaryNode; |
74 |
|
import jalview.datamodel.DBRefEntry; |
75 |
|
import jalview.datamodel.HiddenColumns; |
76 |
|
import jalview.datamodel.NodeTransformI; |
77 |
|
import jalview.datamodel.SequenceFeature; |
78 |
|
import jalview.datamodel.SequenceI; |
79 |
|
import jalview.datamodel.SequenceNode; |
80 |
|
import jalview.gui.ImageExporter.ImageWriterI; |
81 |
|
import jalview.io.JalviewFileChooser; |
82 |
|
import jalview.io.JalviewFileView; |
83 |
|
import jalview.io.NewickFile; |
84 |
|
import jalview.io.exceptions.ImageOutputException; |
85 |
|
import jalview.jbgui.GTreePanel; |
86 |
|
import jalview.util.ImageMaker.TYPE; |
87 |
|
import jalview.util.MessageManager; |
88 |
|
import jalview.viewmodel.AlignmentViewport; |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
@author |
94 |
|
@version |
95 |
|
|
|
|
| 31.8% |
Uncovered Elements: 234 (343) |
Complexity: 93 |
Complexity Density: 0.4 |
|
96 |
|
public class TreePanel extends GTreePanel |
97 |
|
{ |
98 |
|
String treeType; |
99 |
|
|
100 |
|
String scoreModelName; |
101 |
|
|
102 |
|
String treeTitle; |
103 |
|
|
104 |
|
SimilarityParamsI similarityParams; |
105 |
|
|
106 |
|
private TreeCanvas treeCanvas; |
107 |
|
|
108 |
|
TreeModel tree; |
109 |
|
|
110 |
|
private AlignViewport av; |
111 |
|
|
112 |
|
|
113 |
|
private JLabel subtitleLabel; |
114 |
|
|
115 |
|
private Map<String, Color> secondaryStructureProviderColorMap; |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
@param |
121 |
|
@param |
122 |
|
@param |
123 |
|
@param |
124 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
125 |
0 |
public TreePanel(AlignmentPanel ap, String type, String modelName,... |
126 |
|
SimilarityParamsI options) |
127 |
|
{ |
128 |
0 |
super(); |
129 |
0 |
this.setFrameIcon(null); |
130 |
0 |
this.similarityParams = options; |
131 |
0 |
initTreePanel(ap, type, modelName, null, null, null); |
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
|
136 |
|
} |
137 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
138 |
14 |
public TreePanel(AlignmentPanel alignPanel, NewickFile newtree,... |
139 |
|
String theTitle, AlignmentView inputData) |
140 |
|
{ |
141 |
14 |
this(alignPanel, newtree, theTitle, inputData, null, null); |
142 |
|
} |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
boolean forAnnotation = false; |
148 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
149 |
14 |
public TreePanel(AlignmentPanel alignPanel, NewickFile newtree,... |
150 |
|
String theTitle, AlignmentView inputData, |
151 |
|
AlignmentAnnotation[] leafAnnotations, String subTitle) |
152 |
|
{ |
153 |
14 |
super(); |
154 |
14 |
this.forAnnotation = leafAnnotations != null |
155 |
|
&& leafAnnotations.length > 0; |
156 |
14 |
this.setFrameIcon(null); |
157 |
14 |
this.treeTitle = theTitle; |
158 |
14 |
initTreePanel(alignPanel, null, null, newtree, inputData, null); |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
@param |
165 |
|
@param |
166 |
|
@param |
167 |
|
@param |
168 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
169 |
0 |
public TreePanel(AlignmentPanel alignPanel, NewickFile fin,... |
170 |
|
AlignmentAnnotation aa, String title) |
171 |
|
{ |
172 |
0 |
super(); |
173 |
0 |
columnWise = true; |
174 |
0 |
assocAnnotation = aa; |
175 |
0 |
this.setFrameIcon(null); |
176 |
0 |
this.treeTitle = title; |
177 |
0 |
initTreePanel(alignPanel, null, null, fin, null, null); |
178 |
|
} |
179 |
|
|
180 |
|
boolean columnWise = false; |
181 |
|
|
182 |
|
AlignmentAnnotation assocAnnotation = null; |
183 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
174 |
public boolean isColumnWise()... |
185 |
|
{ |
186 |
174 |
return columnWise; |
187 |
|
} |
188 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
189 |
14 |
public AlignmentAnnotation getAssocAnnotation()... |
190 |
|
{ |
191 |
14 |
return assocAnnotation; |
192 |
|
} |
193 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
194 |
0 |
public AlignmentI getAlignment()... |
195 |
|
{ |
196 |
0 |
return getTreeCanvas().getViewport().getAlignment(); |
197 |
|
} |
198 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
199 |
0 |
public AlignmentViewport getViewPort()... |
200 |
|
{ |
201 |
|
|
202 |
0 |
return getTreeCanvas().getViewport(); |
203 |
|
} |
204 |
|
|
205 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
206 |
0 |
public Map<String, Color> getSecondaryStructureProviderColorMap()... |
207 |
|
{ |
208 |
0 |
return secondaryStructureProviderColorMap; |
209 |
|
} |
210 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
211 |
0 |
private void addSubtitlePanel(String subTitle)... |
212 |
|
{ |
213 |
0 |
subtitleLabel = new JLabel(subTitle, SwingConstants.LEFT); |
214 |
|
|
215 |
0 |
JPanel panel = new JPanel(new BorderLayout()); |
216 |
0 |
panel.add(subtitleLabel, BorderLayout.NORTH); |
217 |
0 |
panel.add(scrollPane, BorderLayout.CENTER); |
218 |
|
|
219 |
0 |
this.add(panel); |
220 |
|
} |
221 |
|
|
|
|
| 63.3% |
Uncovered Elements: 11 (30) |
Complexity: 5 |
Complexity Density: 0.21 |
|
222 |
14 |
void initTreePanel(AlignmentPanel ap, String type, String modelName,... |
223 |
|
NewickFile newTree, AlignmentView inputData, |
224 |
|
AlignmentAnnotation[] leafAnnotations) |
225 |
|
{ |
226 |
|
|
227 |
14 |
av = ap.av; |
228 |
14 |
this.treeType = type; |
229 |
14 |
this.scoreModelName = modelName; |
230 |
|
|
231 |
14 |
treeCanvas = new TreeCanvas(this, ap, scrollPane); |
232 |
14 |
scrollPane.setViewportView(treeCanvas); |
233 |
|
|
234 |
14 |
if (similarityParams != null |
235 |
|
&& similarityParams.getSecondaryStructureSource() != null) |
236 |
|
{ |
237 |
|
|
238 |
|
|
239 |
0 |
showSecondaryStructureProviderMenu.setVisible(true); |
240 |
0 |
addSubtitlePanel(" Secondary Structure Provider : " |
241 |
|
+ similarityParams.getSecondaryStructureSource()); |
242 |
|
|
243 |
|
} |
244 |
|
else { |
245 |
|
|
246 |
|
|
247 |
14 |
showSecondaryStructureProviderMenu.setVisible(false); |
248 |
|
} |
249 |
14 |
if (leafAnnotations != null) |
250 |
|
{ |
251 |
0 |
forAnnotation = true; |
252 |
|
} |
253 |
14 |
if (columnWise) |
254 |
|
{ |
255 |
0 |
bootstrapMenu.setVisible(false); |
256 |
0 |
placeholdersMenu.setState(false); |
257 |
0 |
placeholdersMenu.setVisible(false); |
258 |
0 |
fitToWindow.setState(false); |
259 |
0 |
sortAssocViews.setVisible(false); |
260 |
|
} |
261 |
|
|
262 |
14 |
addKeyListener(new KeyAdapter() |
263 |
|
{ |
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
264 |
0 |
@Override... |
265 |
|
public void keyPressed(KeyEvent e) |
266 |
|
{ |
267 |
0 |
switch (e.getKeyCode()) |
268 |
|
{ |
269 |
0 |
case 27: |
270 |
0 |
treeCanvas.clearSelectedLeaves(); |
271 |
0 |
e.consume(); |
272 |
0 |
break; |
273 |
|
|
274 |
|
} |
275 |
|
|
276 |
|
} |
277 |
|
}); |
278 |
14 |
PaintRefresher.Register(this, ap.av.getSequenceSetId()); |
279 |
|
|
280 |
14 |
buildAssociatedViewMenu(); |
281 |
|
|
282 |
14 |
final PropertyChangeListener listener = addAlignmentListener(); |
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
14 |
addInternalFrameListener(new InternalFrameAdapter() |
289 |
|
{ |
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
290 |
12 |
@Override... |
291 |
|
public void internalFrameClosed(InternalFrameEvent evt) |
292 |
|
{ |
293 |
12 |
if (av != null) |
294 |
|
{ |
295 |
12 |
av.removePropertyChangeListener(listener); |
296 |
|
} |
297 |
12 |
releaseReferences(); |
298 |
|
} |
299 |
|
}); |
300 |
|
|
301 |
14 |
TreeLoader tl = new TreeLoader(newTree, inputData, leafAnnotations); |
302 |
14 |
tl.start(); |
303 |
|
|
304 |
|
} |
305 |
|
|
306 |
|
|
307 |
|
|
308 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
309 |
12 |
public void releaseReferences()... |
310 |
|
{ |
311 |
12 |
this.tree = null; |
312 |
12 |
this.treeCanvas.tree = null; |
313 |
12 |
this.treeCanvas.nodeHash = null; |
314 |
12 |
this.treeCanvas.nameHash = null; |
315 |
|
} |
316 |
|
|
317 |
|
|
318 |
|
@return |
319 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
320 |
14 |
protected PropertyChangeListener addAlignmentListener()... |
321 |
|
{ |
322 |
14 |
final PropertyChangeListener listener = new PropertyChangeListener() |
323 |
|
{ |
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
324 |
0 |
@Override... |
325 |
|
public void propertyChange(PropertyChangeEvent evt) |
326 |
|
{ |
327 |
0 |
if (evt.getPropertyName().equals("alignment")) |
328 |
|
{ |
329 |
0 |
if (tree == null) |
330 |
|
{ |
331 |
0 |
jalview.bin.Console.outPrintln("tree is null"); |
332 |
|
|
333 |
|
|
334 |
|
|
335 |
0 |
return; |
336 |
|
} |
337 |
0 |
if (evt.getNewValue() == null) |
338 |
|
{ |
339 |
0 |
jalview.bin.Console.outPrintln( |
340 |
|
"new alignment sequences vector value is null"); |
341 |
|
} |
342 |
|
|
343 |
0 |
tree.updatePlaceHolders((List<SequenceI>) evt.getNewValue()); |
344 |
0 |
treeCanvas.nameHash.clear(); |
345 |
|
|
346 |
0 |
repaint(); |
347 |
|
} |
348 |
|
} |
349 |
|
}; |
350 |
14 |
av.addPropertyChangeListener(listener); |
351 |
14 |
return listener; |
352 |
|
} |
353 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
354 |
0 |
@Override... |
355 |
|
public void viewMenu_menuSelected() |
356 |
|
{ |
357 |
0 |
buildAssociatedViewMenu(); |
358 |
|
} |
359 |
|
|
|
|
| 96.6% |
Uncovered Elements: 1 (29) |
Complexity: 5 |
Complexity Density: 0.22 |
|
360 |
14 |
void buildAssociatedViewMenu()... |
361 |
|
{ |
362 |
14 |
AlignmentPanel[] aps = PaintRefresher |
363 |
|
.getAssociatedPanels(av.getSequenceSetId()); |
364 |
14 |
if (aps.length == 1 && getTreeCanvas().getAssociatedPanel() == aps[0]) |
365 |
|
{ |
366 |
7 |
associateLeavesMenu.setVisible(false); |
367 |
7 |
return; |
368 |
|
} |
369 |
|
|
370 |
7 |
associateLeavesMenu.setVisible(true); |
371 |
|
|
372 |
7 |
if ((viewMenu |
373 |
|
.getItem(viewMenu.getItemCount() - 2) instanceof JMenuItem)) |
374 |
|
{ |
375 |
7 |
viewMenu.insertSeparator(viewMenu.getItemCount() - 1); |
376 |
|
} |
377 |
|
|
378 |
7 |
associateLeavesMenu.removeAll(); |
379 |
|
|
380 |
7 |
JRadioButtonMenuItem item; |
381 |
7 |
ButtonGroup buttonGroup = new ButtonGroup(); |
382 |
7 |
int i, iSize = aps.length; |
383 |
7 |
final TreePanel thisTreePanel = this; |
384 |
27 |
for (i = 0; i < iSize; i++) |
385 |
|
{ |
386 |
20 |
final AlignmentPanel ap = aps[i]; |
387 |
20 |
item = new JRadioButtonMenuItem(ap.av.getViewName(), |
388 |
|
ap == treeCanvas.getAssociatedPanel()); |
389 |
20 |
buttonGroup.add(item); |
390 |
20 |
item.addActionListener(new ActionListener() |
391 |
|
{ |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
392 |
0 |
@Override... |
393 |
|
public void actionPerformed(ActionEvent evt) |
394 |
|
{ |
395 |
0 |
treeCanvas.applyToAllViews = false; |
396 |
0 |
treeCanvas.setAssociatedPanel(ap); |
397 |
0 |
treeCanvas.setViewport(ap.av); |
398 |
0 |
PaintRefresher.Register(thisTreePanel, ap.av.getSequenceSetId()); |
399 |
|
} |
400 |
|
}); |
401 |
|
|
402 |
20 |
associateLeavesMenu.add(item); |
403 |
|
} |
404 |
|
|
405 |
7 |
final JRadioButtonMenuItem itemf = new JRadioButtonMenuItem( |
406 |
|
MessageManager.getString("label.all_views")); |
407 |
7 |
buttonGroup.add(itemf); |
408 |
7 |
itemf.setSelected(treeCanvas.applyToAllViews); |
409 |
7 |
itemf.addActionListener(new ActionListener() |
410 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
411 |
0 |
@Override... |
412 |
|
public void actionPerformed(ActionEvent evt) |
413 |
|
{ |
414 |
0 |
treeCanvas.applyToAllViews = itemf.isSelected(); |
415 |
|
} |
416 |
|
}); |
417 |
7 |
associateLeavesMenu.add(itemf); |
418 |
|
|
419 |
|
} |
420 |
|
|
|
|
| 64.1% |
Uncovered Elements: 14 (39) |
Complexity: 9 |
Complexity Density: 0.36 |
|
421 |
|
class TreeLoader extends Thread |
422 |
|
{ |
423 |
|
private NewickFile newtree; |
424 |
|
|
425 |
|
private AlignmentView odata = null; |
426 |
|
|
427 |
|
private AlignmentAnnotation[] leafAnnotations; |
428 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
429 |
14 |
public TreeLoader(NewickFile newickFile, AlignmentView inputData,... |
430 |
|
AlignmentAnnotation[] leafAnnotations) |
431 |
|
{ |
432 |
14 |
this.newtree = newickFile; |
433 |
14 |
this.odata = inputData; |
434 |
14 |
this.leafAnnotations = leafAnnotations; |
435 |
|
|
436 |
14 |
if (newickFile != null) |
437 |
|
{ |
438 |
|
|
439 |
|
|
440 |
14 |
showBootstrap(newickFile.HasBootstrap()); |
441 |
14 |
showDistances(newickFile.HasDistances()); |
442 |
|
} |
443 |
|
} |
444 |
|
|
|
|
| 55.2% |
Uncovered Elements: 13 (29) |
Complexity: 7 |
Complexity Density: 0.37 |
|
445 |
14 |
@Override... |
446 |
|
public void run() |
447 |
|
{ |
448 |
|
|
449 |
14 |
if (newtree != null) |
450 |
|
{ |
451 |
14 |
tree = new TreeModel(av.getAlignment().getSequencesArray(), odata, |
452 |
|
newtree, leafAnnotations); |
453 |
14 |
if (tree.getOriginalData() == null) |
454 |
|
{ |
455 |
14 |
originalSeqData.setVisible(false); |
456 |
|
} |
457 |
|
} |
458 |
|
else |
459 |
|
{ |
460 |
0 |
ScoreModelI sm = ScoreModels.getInstance().getScoreModel( |
461 |
|
scoreModelName, treeCanvas.getAssociatedPanel()); |
462 |
0 |
TreeBuilder njtree = treeType.equals(TreeBuilder.NEIGHBOUR_JOINING) |
463 |
|
? new NJTree(av, sm, similarityParams) |
464 |
|
: new AverageDistanceTree(av, sm, similarityParams); |
465 |
0 |
List<String> labels = njtree.getLabels(); |
466 |
0 |
if(labels != null && labels.size()>0) { |
467 |
0 |
secondaryStructureProviderColorMap = new HashMap<String, Color>(); |
468 |
0 |
AlignmentUtils.assignSecondaryStructureProviderColor(secondaryStructureProviderColorMap, labels); |
469 |
|
} |
470 |
0 |
tree = new TreeModel(njtree); |
471 |
|
|
472 |
|
} |
473 |
14 |
showDistances(!columnWise); |
474 |
14 |
tree.reCount(tree.getTopNode()); |
475 |
14 |
tree.findHeight(tree.getTopNode()); |
476 |
14 |
treeCanvas.setTree(tree); |
477 |
14 |
treeCanvas.repaint(); |
478 |
14 |
av.setCurrentTree(tree); |
479 |
14 |
if (av.getSortByTree()) |
480 |
|
{ |
481 |
1 |
sortByTree_actionPerformed(); |
482 |
|
} |
483 |
|
} |
484 |
|
} |
485 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
486 |
40 |
public void showDistances(boolean b)... |
487 |
|
{ |
488 |
40 |
treeCanvas.setShowDistances(b); |
489 |
40 |
distanceMenu.setSelected(b); |
490 |
|
} |
491 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
492 |
26 |
public void showBootstrap(boolean b)... |
493 |
|
{ |
494 |
26 |
treeCanvas.setShowBootstrap(b); |
495 |
26 |
bootstrapMenu.setSelected(b); |
496 |
|
} |
497 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
498 |
12 |
public void showPlaceholders(boolean b)... |
499 |
|
{ |
500 |
12 |
placeholdersMenu.setState(b); |
501 |
12 |
treeCanvas.setMarkPlaceholders(b); |
502 |
|
} |
503 |
|
|
504 |
|
|
505 |
|
|
506 |
|
|
507 |
|
@return |
508 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
509 |
22 |
public TreeModel getTree()... |
510 |
|
{ |
511 |
22 |
return tree; |
512 |
|
} |
513 |
|
|
514 |
|
|
515 |
|
|
516 |
|
|
517 |
|
@param |
518 |
|
|
519 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
520 |
0 |
@Override... |
521 |
|
public void textbox_actionPerformed(ActionEvent e) |
522 |
|
{ |
523 |
0 |
CutAndPasteTransfer cap = new CutAndPasteTransfer(); |
524 |
|
|
525 |
0 |
String newTitle = getPanelTitle(); |
526 |
|
|
527 |
0 |
NewickFile fout = new NewickFile(tree.getTopNode()); |
528 |
0 |
try |
529 |
|
{ |
530 |
0 |
cap.setText(fout.print(tree.hasBootstrap(), tree.hasDistances(), |
531 |
|
tree.hasRootDistance())); |
532 |
0 |
Desktop.addInternalFrame(cap, newTitle, 500, 100); |
533 |
|
} catch (OutOfMemoryError oom) |
534 |
|
{ |
535 |
0 |
new OOMWarning("generating newick tree file", oom); |
536 |
0 |
cap.dispose(); |
537 |
|
} |
538 |
|
|
539 |
|
} |
540 |
|
|
541 |
|
|
542 |
|
|
543 |
|
|
544 |
|
@param |
545 |
|
|
546 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 3 |
Complexity Density: 0.2 |
|
547 |
0 |
@Override... |
548 |
|
public void saveAsNewick_actionPerformed(ActionEvent e) |
549 |
|
{ |
550 |
|
|
551 |
0 |
JalviewFileChooser chooser = new JalviewFileChooser( |
552 |
|
Cache.getProperty("LAST_DIRECTORY")); |
553 |
0 |
chooser.setFileView(new JalviewFileView()); |
554 |
0 |
chooser.setDialogTitle( |
555 |
|
MessageManager.getString("label.save_tree_as_newick")); |
556 |
0 |
chooser.setToolTipText(MessageManager.getString("action.save")); |
557 |
|
|
558 |
0 |
int value = chooser.showSaveDialog(null); |
559 |
|
|
560 |
0 |
if (value == JalviewFileChooser.APPROVE_OPTION) |
561 |
|
{ |
562 |
0 |
String choice = chooser.getSelectedFile().getPath(); |
563 |
0 |
Cache.setProperty("LAST_DIRECTORY", |
564 |
|
chooser.getSelectedFile().getParent()); |
565 |
|
|
566 |
0 |
try |
567 |
|
{ |
568 |
0 |
jalview.io.NewickFile fout = new jalview.io.NewickFile( |
569 |
|
tree.getTopNode()); |
570 |
0 |
String output = fout.print(tree.hasBootstrap(), tree.hasDistances(), |
571 |
|
tree.hasRootDistance()); |
572 |
0 |
java.io.PrintWriter out = new java.io.PrintWriter( |
573 |
|
new java.io.FileWriter(choice)); |
574 |
0 |
out.println(output); |
575 |
0 |
out.close(); |
576 |
|
} catch (Exception ex) |
577 |
|
{ |
578 |
0 |
ex.printStackTrace(); |
579 |
|
} |
580 |
|
} |
581 |
|
} |
582 |
|
|
583 |
|
|
584 |
|
|
585 |
|
|
586 |
|
@param |
587 |
|
|
588 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
589 |
0 |
@Override... |
590 |
|
public void printMenu_actionPerformed(ActionEvent e) |
591 |
|
{ |
592 |
|
|
593 |
0 |
treeCanvas.startPrinting(); |
594 |
|
} |
595 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 8 |
Complexity Density: 0.5 |
|
596 |
0 |
@Override... |
597 |
|
public void originalSeqData_actionPerformed(ActionEvent e) |
598 |
|
{ |
599 |
0 |
AlignmentView originalData = tree.getOriginalData(); |
600 |
0 |
if (originalData == null) |
601 |
|
{ |
602 |
0 |
Console.info( |
603 |
|
"Unexpected call to originalSeqData_actionPerformed - should have hidden this menu action."); |
604 |
0 |
return; |
605 |
|
} |
606 |
|
|
607 |
|
|
608 |
|
|
609 |
|
|
610 |
|
|
611 |
|
|
612 |
0 |
char gc = '-'; |
613 |
0 |
try |
614 |
|
{ |
615 |
|
|
616 |
|
|
617 |
0 |
gc = av.getGapCharacter(); |
618 |
|
|
619 |
|
} catch (Exception ex) |
620 |
|
{ |
621 |
|
} |
622 |
|
|
623 |
0 |
Object[] alAndColsel = originalData.getAlignmentAndHiddenColumns(gc); |
624 |
|
|
625 |
0 |
if (alAndColsel != null && alAndColsel[0] != null) |
626 |
|
{ |
627 |
|
|
628 |
|
|
629 |
0 |
AlignmentI al = new Alignment((SequenceI[]) alAndColsel[0]); |
630 |
0 |
AlignmentI dataset = (av != null && av.getAlignment() != null) |
631 |
|
? av.getAlignment().getDataset() |
632 |
|
: null; |
633 |
0 |
if (dataset != null) |
634 |
|
{ |
635 |
0 |
al.setDataset(dataset); |
636 |
|
} |
637 |
|
|
638 |
0 |
if (true) |
639 |
|
{ |
640 |
|
|
641 |
0 |
AlignFrame af = new AlignFrame(al, (HiddenColumns) alAndColsel[1], |
642 |
|
AlignFrame.DEFAULT_WIDTH, AlignFrame.DEFAULT_HEIGHT); |
643 |
|
|
644 |
|
|
645 |
|
|
646 |
|
|
647 |
|
|
648 |
|
|
649 |
|
|
650 |
|
|
651 |
0 |
Desktop.addInternalFrame(af, MessageManager.formatMessage( |
652 |
|
"label.original_data_for_params", new Object[] |
653 |
|
{ this.title }), AlignFrame.DEFAULT_WIDTH, |
654 |
|
AlignFrame.DEFAULT_HEIGHT); |
655 |
|
} |
656 |
|
} |
657 |
|
} |
658 |
|
|
659 |
|
|
660 |
|
|
661 |
|
|
662 |
|
@param |
663 |
|
|
664 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
665 |
12 |
@Override... |
666 |
|
public void fitToWindow_actionPerformed(ActionEvent e) |
667 |
|
{ |
668 |
12 |
treeCanvas.fitToWindow = fitToWindow.isSelected(); |
669 |
12 |
repaint(); |
670 |
|
} |
671 |
|
|
672 |
|
|
673 |
|
|
674 |
|
|
675 |
|
@param |
676 |
|
|
|
|
| 30% |
Uncovered Elements: 7 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
677 |
1 |
@Override... |
678 |
|
public void sortByTree_actionPerformed() |
679 |
|
{ |
680 |
|
|
681 |
1 |
if (treeCanvas.applyToAllViews) |
682 |
|
{ |
683 |
0 |
final ArrayList<CommandI> commands = new ArrayList<>(); |
684 |
0 |
for (AlignmentPanel ap : PaintRefresher |
685 |
|
.getAssociatedPanels(av.getSequenceSetId())) |
686 |
|
{ |
687 |
0 |
commands.add(sortAlignmentIn(ap.av.getAlignPanel())); |
688 |
|
} |
689 |
0 |
av.getAlignPanel().alignFrame.addHistoryItem(new CommandI() |
690 |
|
{ |
691 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
692 |
0 |
@Override... |
693 |
|
public void undoCommand(AlignmentI[] views) |
694 |
|
{ |
695 |
0 |
for (CommandI tsort : commands) |
696 |
|
{ |
697 |
0 |
tsort.undoCommand(views); |
698 |
|
} |
699 |
|
} |
700 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
701 |
0 |
@Override... |
702 |
|
public int getSize() |
703 |
|
{ |
704 |
0 |
return commands.size(); |
705 |
|
} |
706 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
707 |
0 |
@Override... |
708 |
|
public String getDescription() |
709 |
|
{ |
710 |
0 |
return "Tree Sort (many views)"; |
711 |
|
} |
712 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
713 |
0 |
@Override... |
714 |
|
public void doCommand(AlignmentI[] views) |
715 |
|
{ |
716 |
|
|
717 |
0 |
for (CommandI tsort : commands) |
718 |
|
{ |
719 |
0 |
tsort.doCommand(views); |
720 |
|
} |
721 |
|
} |
722 |
|
}); |
723 |
0 |
for (AlignmentPanel ap : PaintRefresher |
724 |
|
.getAssociatedPanels(av.getSequenceSetId())) |
725 |
|
{ |
726 |
|
|
727 |
0 |
ap.alignFrame.updateEditMenuBar(); |
728 |
|
} |
729 |
|
} |
730 |
|
else |
731 |
|
{ |
732 |
1 |
treeCanvas.getAssociatedPanel().alignFrame.addHistoryItem( |
733 |
|
sortAlignmentIn(treeCanvas.getAssociatedPanel())); |
734 |
|
} |
735 |
|
|
736 |
|
} |
737 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
738 |
1 |
public CommandI sortAlignmentIn(AlignmentPanel ap)... |
739 |
|
{ |
740 |
|
|
741 |
1 |
AlignmentViewport viewport = ap.av; |
742 |
1 |
SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray(); |
743 |
1 |
AlignmentSorter.sortByTree(viewport.getAlignment(), tree); |
744 |
1 |
CommandI undo; |
745 |
1 |
undo = new OrderCommand("Tree Sort", oldOrder, viewport.getAlignment()); |
746 |
|
|
747 |
1 |
ap.paintAlignment(true, false); |
748 |
1 |
return undo; |
749 |
|
} |
750 |
|
|
751 |
|
|
752 |
|
|
753 |
|
|
754 |
|
@param |
755 |
|
|
756 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
757 |
0 |
@Override... |
758 |
|
public void font_actionPerformed(ActionEvent e) |
759 |
|
{ |
760 |
0 |
if (treeCanvas == null) |
761 |
|
{ |
762 |
0 |
return; |
763 |
|
} |
764 |
|
|
765 |
0 |
new FontChooser(this); |
766 |
|
} |
767 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
768 |
12 |
public Font getTreeFont()... |
769 |
|
{ |
770 |
12 |
return treeCanvas.font; |
771 |
|
} |
772 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
773 |
12 |
public void setTreeFont(Font f)... |
774 |
|
{ |
775 |
12 |
if (treeCanvas != null) |
776 |
|
{ |
777 |
12 |
treeCanvas.setFont(f); |
778 |
|
} |
779 |
|
} |
780 |
|
|
781 |
|
|
782 |
|
|
783 |
|
|
784 |
|
@param |
785 |
|
|
786 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
787 |
0 |
@Override... |
788 |
|
public void distanceMenu_actionPerformed(ActionEvent e) |
789 |
|
{ |
790 |
0 |
treeCanvas.setShowDistances(distanceMenu.isSelected()); |
791 |
|
} |
792 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
793 |
0 |
@Override... |
794 |
|
public void hideStructureProviders_actionPerformed(ActionEvent e) |
795 |
|
{ |
796 |
0 |
treeCanvas.hideStructureProviders(hideStructureProviders.isSelected()); |
797 |
|
} |
798 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
799 |
0 |
@Override... |
800 |
|
public void showStructureProviderColouredLines_actionPerformed(ActionEvent e) |
801 |
|
{ |
802 |
0 |
treeCanvas.setShowStructureProviderColouredLines(showStructureProviderColouredLines.isSelected()); |
803 |
|
} |
804 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
805 |
0 |
@Override... |
806 |
|
public void showStructureProviderLabels_actionPerformed(ActionEvent e) |
807 |
|
{ |
808 |
0 |
treeCanvas.setShowStructureProviderLabels(showStructureProviderLabels.isSelected()); |
809 |
|
} |
810 |
|
|
811 |
|
|
812 |
|
|
813 |
|
|
814 |
|
@param |
815 |
|
|
816 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
817 |
0 |
@Override... |
818 |
|
public void bootstrapMenu_actionPerformed(ActionEvent e) |
819 |
|
{ |
820 |
0 |
treeCanvas.setShowBootstrap(bootstrapMenu.isSelected()); |
821 |
|
} |
822 |
|
|
823 |
|
|
824 |
|
|
825 |
|
|
826 |
|
@param |
827 |
|
|
828 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
829 |
0 |
@Override... |
830 |
|
public void placeholdersMenu_actionPerformed(ActionEvent e) |
831 |
|
{ |
832 |
0 |
treeCanvas.setMarkPlaceholders(placeholdersMenu.isSelected()); |
833 |
|
} |
834 |
|
|
835 |
|
|
836 |
|
|
837 |
|
|
838 |
|
|
839 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
840 |
0 |
@Override... |
841 |
|
public void writeTreeImage(TYPE imageFormat) |
842 |
|
{ |
843 |
0 |
int width = treeCanvas.getWidth(); |
844 |
0 |
int height = treeCanvas.getHeight(); |
845 |
0 |
ImageWriterI writer = new ImageWriterI() |
846 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
847 |
0 |
@Override... |
848 |
|
public void exportImage(Graphics g) throws Exception |
849 |
|
{ |
850 |
0 |
treeCanvas.draw(g, width, height); |
851 |
|
} |
852 |
|
}; |
853 |
0 |
String tree = MessageManager.getString("label.tree"); |
854 |
0 |
ImageExporter exporter = new ImageExporter(writer, null, imageFormat, |
855 |
|
tree); |
856 |
0 |
try |
857 |
|
{ |
858 |
0 |
exporter.doExport(null, this, width, height, |
859 |
|
tree.toLowerCase(Locale.ROOT)); |
860 |
|
} catch (ImageOutputException ioex) |
861 |
|
{ |
862 |
0 |
Console.error( |
863 |
|
"Unexpected error whilst writing " + imageFormat.toString(), |
864 |
|
ioex); |
865 |
|
} |
866 |
|
} |
867 |
|
|
868 |
|
|
869 |
|
|
870 |
|
|
871 |
|
|
872 |
|
|
873 |
|
|
874 |
|
@param |
875 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
876 |
0 |
public void changeNames(final String labelClass)... |
877 |
|
{ |
878 |
0 |
tree.applyToNodes(new NodeTransformI() |
879 |
|
{ |
880 |
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 11 |
Complexity Density: 0.61 |
|
881 |
0 |
@Override... |
882 |
|
public void transform(BinaryNode node) |
883 |
|
{ |
884 |
0 |
if (node instanceof SequenceNode |
885 |
|
&& !((SequenceNode) node).isPlaceholder() |
886 |
|
&& !((SequenceNode) node).isDummy()) |
887 |
|
{ |
888 |
0 |
String newname = null; |
889 |
0 |
SequenceI sq = (SequenceI) ((BinaryNode) node).element(); |
890 |
0 |
if (sq != null) |
891 |
|
{ |
892 |
|
|
893 |
0 |
List<DBRefEntry> refs = jalview.util.DBRefUtils |
894 |
|
.selectRefs(sq.getDBRefs(), new String[] |
895 |
|
{ labelClass.toUpperCase(Locale.ROOT) }); |
896 |
0 |
if (refs != null) |
897 |
|
{ |
898 |
0 |
for (int i = 0, ni = refs.size(); i < ni; i++) |
899 |
|
{ |
900 |
0 |
if (newname == null) |
901 |
|
{ |
902 |
0 |
newname = new String(refs.get(i).getAccessionId()); |
903 |
|
} |
904 |
|
else |
905 |
|
{ |
906 |
0 |
newname += "; " + refs.get(i).getAccessionId(); |
907 |
|
} |
908 |
|
} |
909 |
|
} |
910 |
0 |
if (newname == null) |
911 |
|
{ |
912 |
0 |
List<SequenceFeature> features = sq.getFeatures() |
913 |
|
.getPositionalFeatures(labelClass); |
914 |
0 |
for (SequenceFeature feature : features) |
915 |
|
{ |
916 |
0 |
if (newname == null) |
917 |
|
{ |
918 |
0 |
newname = feature.getDescription(); |
919 |
|
} |
920 |
|
else |
921 |
|
{ |
922 |
0 |
newname = newname + "; " + feature.getDescription(); |
923 |
|
} |
924 |
|
} |
925 |
|
} |
926 |
|
} |
927 |
0 |
if (newname != null) |
928 |
|
{ |
929 |
|
|
930 |
|
|
931 |
0 |
((BinaryNode) node).setName(newname); |
932 |
|
} |
933 |
|
} |
934 |
|
} |
935 |
|
}); |
936 |
|
} |
937 |
|
|
938 |
|
|
939 |
|
|
940 |
|
|
941 |
|
|
942 |
|
|
943 |
|
|
944 |
|
|
945 |
|
@return |
946 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
947 |
0 |
public String getPanelTitle()... |
948 |
|
{ |
949 |
0 |
if (treeTitle != null) |
950 |
|
{ |
951 |
0 |
return treeTitle; |
952 |
|
} |
953 |
|
|
954 |
|
|
955 |
|
|
956 |
|
|
957 |
0 |
String treecalcnm = MessageManager.getString( |
958 |
|
"label.tree_calc_" + treeType.toLowerCase(Locale.ROOT)); |
959 |
|
|
960 |
|
|
961 |
|
|
962 |
|
|
963 |
0 |
String smn = scoreModelName; |
964 |
|
|
965 |
|
|
966 |
|
|
967 |
|
|
968 |
0 |
final String ttl = MessageManager.formatMessage("label.calc_title", |
969 |
|
treecalcnm, smn); |
970 |
0 |
return ttl; |
971 |
|
} |
972 |
|
|
973 |
|
|
974 |
|
|
975 |
|
|
976 |
|
@param |
977 |
|
@param |
978 |
|
|
979 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 2 |
Complexity Density: 0.18 |
|
980 |
0 |
protected void writeEpsFile(File outFile, boolean textOption)... |
981 |
|
{ |
982 |
0 |
try |
983 |
|
{ |
984 |
0 |
int width = treeCanvas.getWidth(); |
985 |
0 |
int height = treeCanvas.getHeight(); |
986 |
|
|
987 |
0 |
FileOutputStream out = new FileOutputStream(outFile); |
988 |
0 |
EpsGraphics2D pg = new EpsGraphics2D("Tree", out, 0, 0, width, |
989 |
|
height); |
990 |
0 |
pg.setAccurateTextMode(!textOption); |
991 |
0 |
treeCanvas.draw(pg, width, height); |
992 |
|
|
993 |
0 |
pg.flush(); |
994 |
0 |
pg.close(); |
995 |
|
} catch (Exception ex) |
996 |
|
{ |
997 |
0 |
jalview.bin.Console.errPrintln("Error writing tree as EPS"); |
998 |
0 |
ex.printStackTrace(); |
999 |
|
} |
1000 |
|
} |
1001 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1002 |
0 |
public AlignViewport getViewport()... |
1003 |
|
{ |
1004 |
0 |
return av; |
1005 |
|
} |
1006 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1007 |
0 |
public void setViewport(AlignViewport av)... |
1008 |
|
{ |
1009 |
0 |
this.av = av; |
1010 |
|
} |
1011 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
1012 |
43 |
public TreeCanvas getTreeCanvas()... |
1013 |
|
{ |
1014 |
43 |
return treeCanvas; |
1015 |
|
} |
1016 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
1017 |
0 |
public static TreePanel newTreeForAnnotations(AlignmentPanel alignPanel,... |
1018 |
|
NewickFile nf, String treeTitle2, AlignmentView input) |
1019 |
|
{ |
1020 |
|
|
1021 |
0 |
TreePanel tp = new TreePanel(alignPanel, nf, treeTitle2, input, null, |
1022 |
|
"Annotation Tree"); |
1023 |
0 |
return tp; |
1024 |
|
} |
1025 |
|
} |