1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.appletgui; |
22 |
|
|
23 |
|
import jalview.analysis.AverageDistanceTree; |
24 |
|
import jalview.analysis.NJTree; |
25 |
|
import jalview.analysis.TreeBuilder; |
26 |
|
import jalview.analysis.TreeModel; |
27 |
|
import jalview.analysis.scoremodels.ScoreModels; |
28 |
|
import jalview.analysis.scoremodels.SimilarityParams; |
29 |
|
import jalview.api.analysis.ScoreModelI; |
30 |
|
import jalview.datamodel.Alignment; |
31 |
|
import jalview.datamodel.HiddenColumns; |
32 |
|
import jalview.datamodel.SequenceI; |
33 |
|
import jalview.io.NewickFile; |
34 |
|
import jalview.util.MessageManager; |
35 |
|
|
36 |
|
import java.awt.BorderLayout; |
37 |
|
import java.awt.CheckboxMenuItem; |
38 |
|
import java.awt.Color; |
39 |
|
import java.awt.Menu; |
40 |
|
import java.awt.MenuBar; |
41 |
|
import java.awt.MenuItem; |
42 |
|
import java.awt.ScrollPane; |
43 |
|
import java.awt.event.ActionEvent; |
44 |
|
import java.awt.event.ActionListener; |
45 |
|
import java.awt.event.ItemEvent; |
46 |
|
import java.awt.event.ItemListener; |
47 |
|
|
|
|
| 0% |
Uncovered Elements: 124 (124) |
Complexity: 27 |
Complexity Density: 0.3 |
|
48 |
|
public class TreePanel extends EmbmenuFrame |
49 |
|
implements ActionListener, ItemListener, AutoCloseable |
50 |
|
{ |
51 |
|
SequenceI[] seq; |
52 |
|
|
53 |
|
String type; |
54 |
|
|
55 |
|
String pwtype; |
56 |
|
|
57 |
|
int start; |
58 |
|
|
59 |
|
int end; |
60 |
|
|
61 |
|
TreeCanvas treeCanvas; |
62 |
|
|
63 |
|
TreeModel tree; |
64 |
|
|
65 |
|
AlignmentPanel ap; |
66 |
|
|
67 |
|
AlignViewport av; |
68 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
69 |
0 |
public TreeModel getTree()... |
70 |
|
{ |
71 |
0 |
return tree; |
72 |
|
} |
73 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
74 |
0 |
@Override... |
75 |
|
public void close() |
76 |
|
{ |
77 |
0 |
ap = null; |
78 |
0 |
av = null; |
79 |
0 |
super.close(); |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
85 |
0 |
public TreePanel(AlignmentPanel alignPanel, String type, String pwtype)... |
86 |
|
{ |
87 |
0 |
try |
88 |
|
{ |
89 |
0 |
jbInit(); |
90 |
0 |
this.setMenuBar(jMenuBar1); |
91 |
|
} catch (Exception ex) |
92 |
|
{ |
93 |
0 |
ex.printStackTrace(); |
94 |
|
} |
95 |
|
|
96 |
0 |
initTreePanel(alignPanel, type, pwtype, null); |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
103 |
0 |
public TreePanel(AlignmentPanel ap, String type, String pwtype,... |
104 |
|
NewickFile newtree) |
105 |
|
{ |
106 |
0 |
try |
107 |
|
{ |
108 |
0 |
jbInit(); |
109 |
0 |
this.setMenuBar(jMenuBar1); |
110 |
|
} catch (Exception e) |
111 |
|
{ |
112 |
0 |
e.printStackTrace(); |
113 |
|
} |
114 |
|
|
115 |
0 |
initTreePanel(ap, type, pwtype, newtree); |
116 |
|
} |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
118 |
0 |
void initTreePanel(AlignmentPanel ap, String type, String pwtype,... |
119 |
|
NewickFile newTree) |
120 |
|
{ |
121 |
|
|
122 |
0 |
this.ap = ap; |
123 |
0 |
this.av = ap.av; |
124 |
0 |
this.type = type; |
125 |
0 |
this.pwtype = pwtype; |
126 |
|
|
127 |
0 |
treeCanvas = new TreeCanvas(ap, scrollPane); |
128 |
0 |
TreeLoader tl = new TreeLoader(newTree); |
129 |
0 |
tl.start(); |
130 |
0 |
embedMenuIfNeeded(treeCanvas); |
131 |
0 |
scrollPane.add(treeCanvas, BorderLayout.CENTER); |
132 |
|
} |
133 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 5 |
Complexity Density: 0.5 |
|
134 |
0 |
void showOriginalData()... |
135 |
|
{ |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
0 |
if (tree.getOriginalData() != null) |
143 |
|
{ |
144 |
0 |
char gc = '-'; |
145 |
0 |
try |
146 |
|
{ |
147 |
|
|
148 |
|
|
149 |
0 |
gc = av.getGapCharacter(); |
150 |
|
} catch (Exception ex) |
151 |
|
{ |
152 |
|
} |
153 |
|
|
154 |
0 |
Object[] alAndColsel = tree.getOriginalData() |
155 |
|
.getAlignmentAndHiddenColumns(gc); |
156 |
|
|
157 |
0 |
if (alAndColsel != null && alAndColsel[0] != null) |
158 |
|
{ |
159 |
0 |
Alignment al = new Alignment((SequenceI[]) alAndColsel[0]); |
160 |
0 |
AlignFrame af = new AlignFrame(al, av.applet, |
161 |
|
"Original Data for Tree", false); |
162 |
|
|
163 |
0 |
af.viewport.getAlignment() |
164 |
|
.setHiddenColumns((HiddenColumns) alAndColsel[1]); |
165 |
|
} |
166 |
|
} |
167 |
|
else |
168 |
|
{ |
169 |
0 |
jalview.bin.Console.outPrintln("Original Tree Data not available"); |
170 |
|
} |
171 |
|
} |
172 |
|
|
|
|
| 0% |
Uncovered Elements: 28 (28) |
Complexity: 5 |
Complexity Density: 0.25 |
|
173 |
|
class TreeLoader extends Thread |
174 |
|
{ |
175 |
|
NewickFile newtree; |
176 |
|
|
177 |
|
jalview.datamodel.AlignmentView odata = null; |
178 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
179 |
0 |
public TreeLoader(NewickFile newtree)... |
180 |
|
{ |
181 |
0 |
this.newtree = newtree; |
182 |
|
} |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 4 |
Complexity Density: 0.21 |
|
184 |
0 |
@Override... |
185 |
|
public void run() |
186 |
|
{ |
187 |
0 |
if (newtree != null) |
188 |
|
{ |
189 |
0 |
tree = new TreeModel(av.getAlignment().getSequencesArray(), odata, |
190 |
|
newtree); |
191 |
|
} |
192 |
|
else |
193 |
|
{ |
194 |
0 |
ScoreModelI sm1 = ScoreModels.getInstance().getScoreModel(pwtype, |
195 |
|
treeCanvas.ap); |
196 |
0 |
ScoreModelI sm = sm1; |
197 |
0 |
TreeBuilder njtree = type.equals(TreeBuilder.NEIGHBOUR_JOINING) |
198 |
|
? new NJTree(av, sm, SimilarityParams.Jalview) |
199 |
|
: new AverageDistanceTree(av, sm, SimilarityParams.Jalview); |
200 |
0 |
tree = new TreeModel(njtree); |
201 |
|
} |
202 |
|
|
203 |
0 |
tree.reCount(tree.getTopNode()); |
204 |
0 |
tree.findHeight(tree.getTopNode()); |
205 |
0 |
treeCanvas.setTree(tree); |
206 |
0 |
if (newtree != null) |
207 |
|
{ |
208 |
|
|
209 |
|
|
210 |
0 |
boolean showDist = newtree.HasDistances() |
211 |
|
&& av.applet.getDefaultParameter("showTreeDistances", |
212 |
|
newtree.HasDistances()); |
213 |
0 |
boolean showBoots = newtree.HasBootstrap() |
214 |
|
&& av.applet.getDefaultParameter("showTreeBootstraps", |
215 |
|
newtree.HasBootstrap()); |
216 |
0 |
distanceMenu.setState(showDist); |
217 |
0 |
bootstrapMenu.setState(showBoots); |
218 |
0 |
treeCanvas.setShowBootstrap(showBoots); |
219 |
0 |
treeCanvas.setShowDistances(showDist); |
220 |
0 |
treeCanvas.setMarkPlaceholders(av.applet |
221 |
|
.getDefaultParameter("showUnlinkedTreeNodes", false)); |
222 |
|
} |
223 |
|
|
224 |
0 |
treeCanvas.repaint(); |
225 |
|
|
226 |
0 |
av.setCurrentTree(tree); |
227 |
|
|
228 |
|
} |
229 |
|
} |
230 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
231 |
0 |
@Override... |
232 |
|
public void actionPerformed(ActionEvent evt) |
233 |
|
{ |
234 |
0 |
if (evt.getSource() == newickOutput) |
235 |
|
{ |
236 |
0 |
newickOutput_actionPerformed(); |
237 |
|
} |
238 |
0 |
else if (evt.getSource() == fontSize) |
239 |
|
{ |
240 |
0 |
fontSize_actionPerformed(); |
241 |
|
} |
242 |
0 |
else if (evt.getSource() == inputData) |
243 |
|
{ |
244 |
0 |
showOriginalData(); |
245 |
|
} |
246 |
|
} |
247 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 5 |
Complexity Density: 0.56 |
|
248 |
0 |
@Override... |
249 |
|
public void itemStateChanged(ItemEvent evt) |
250 |
|
{ |
251 |
0 |
if (evt.getSource() == fitToWindow) |
252 |
|
{ |
253 |
0 |
treeCanvas.fitToWindow = fitToWindow.getState(); |
254 |
|
} |
255 |
|
|
256 |
0 |
else if (evt.getSource() == distanceMenu) |
257 |
|
{ |
258 |
0 |
treeCanvas.setShowDistances(distanceMenu.getState()); |
259 |
|
} |
260 |
|
|
261 |
0 |
else if (evt.getSource() == bootstrapMenu) |
262 |
|
{ |
263 |
0 |
treeCanvas.setShowBootstrap(bootstrapMenu.getState()); |
264 |
|
} |
265 |
|
|
266 |
0 |
else if (evt.getSource() == placeholdersMenu) |
267 |
|
{ |
268 |
0 |
treeCanvas.setMarkPlaceholders(placeholdersMenu.getState()); |
269 |
|
} |
270 |
|
|
271 |
0 |
treeCanvas.repaint(); |
272 |
|
} |
273 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
274 |
0 |
public void newickOutput_actionPerformed()... |
275 |
|
{ |
276 |
0 |
jalview.io.NewickFile fout = new jalview.io.NewickFile( |
277 |
|
tree.getTopNode()); |
278 |
0 |
String output = fout.print(false, true); |
279 |
0 |
CutAndPasteTransfer cap = new CutAndPasteTransfer(false, null); |
280 |
0 |
cap.setText(output); |
281 |
0 |
java.awt.Frame frame = new java.awt.Frame(); |
282 |
0 |
frame.add(cap); |
283 |
0 |
jalview.bin.JalviewLite.addFrame(frame, type + " " + pwtype, 500, 100); |
284 |
|
} |
285 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
286 |
0 |
public java.awt.Font getTreeFont()... |
287 |
|
{ |
288 |
0 |
return treeCanvas.font; |
289 |
|
} |
290 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
291 |
0 |
public void setTreeFont(java.awt.Font font)... |
292 |
|
{ |
293 |
0 |
treeCanvas.font = font; |
294 |
0 |
treeCanvas.repaint(); |
295 |
|
} |
296 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
297 |
0 |
protected void fontSize_actionPerformed()... |
298 |
|
{ |
299 |
0 |
if (treeCanvas == null) |
300 |
|
{ |
301 |
0 |
return; |
302 |
|
} |
303 |
|
|
304 |
0 |
new FontChooser(this); |
305 |
|
} |
306 |
|
|
307 |
|
BorderLayout borderLayout1 = new BorderLayout(); |
308 |
|
|
309 |
|
protected ScrollPane scrollPane = new ScrollPane(); |
310 |
|
|
311 |
|
MenuBar jMenuBar1 = new MenuBar(); |
312 |
|
|
313 |
|
Menu jMenu2 = new Menu(); |
314 |
|
|
315 |
|
protected MenuItem fontSize = new MenuItem(); |
316 |
|
|
317 |
|
protected CheckboxMenuItem bootstrapMenu = new CheckboxMenuItem(); |
318 |
|
|
319 |
|
protected CheckboxMenuItem distanceMenu = new CheckboxMenuItem(); |
320 |
|
|
321 |
|
protected CheckboxMenuItem placeholdersMenu = new CheckboxMenuItem(); |
322 |
|
|
323 |
|
protected CheckboxMenuItem fitToWindow = new CheckboxMenuItem(); |
324 |
|
|
325 |
|
Menu fileMenu = new Menu(); |
326 |
|
|
327 |
|
MenuItem newickOutput = new MenuItem(); |
328 |
|
|
329 |
|
MenuItem inputData = new MenuItem(); |
330 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 1 |
Complexity Density: 0.03 |
|
331 |
0 |
private void jbInit() throws Exception... |
332 |
|
{ |
333 |
0 |
setLayout(borderLayout1); |
334 |
0 |
this.setBackground(Color.white); |
335 |
0 |
this.setFont(new java.awt.Font("Verdana", 0, 12)); |
336 |
0 |
jMenu2.setLabel(MessageManager.getString("action.view")); |
337 |
0 |
fontSize.setLabel(MessageManager.getString("action.font")); |
338 |
0 |
fontSize.addActionListener(this); |
339 |
0 |
bootstrapMenu.setLabel( |
340 |
|
MessageManager.getString("label.show_bootstrap_values")); |
341 |
0 |
bootstrapMenu.addItemListener(this); |
342 |
0 |
distanceMenu.setLabel(MessageManager.getString("label.show_distances")); |
343 |
0 |
distanceMenu.addItemListener(this); |
344 |
0 |
placeholdersMenu.setLabel( |
345 |
|
MessageManager.getString("label.mark_unassociated_leaves")); |
346 |
0 |
placeholdersMenu.addItemListener(this); |
347 |
0 |
fitToWindow.setState(true); |
348 |
0 |
fitToWindow.setLabel(MessageManager.getString("label.fit_to_window")); |
349 |
0 |
fitToWindow.addItemListener(this); |
350 |
0 |
fileMenu.setLabel(MessageManager.getString("action.file")); |
351 |
0 |
newickOutput.setLabel(MessageManager.getString("label.newick_format")); |
352 |
0 |
newickOutput.addActionListener(this); |
353 |
0 |
inputData.setLabel(MessageManager.getString("label.input_data")); |
354 |
|
|
355 |
0 |
add(scrollPane, BorderLayout.CENTER); |
356 |
0 |
jMenuBar1.add(fileMenu); |
357 |
0 |
jMenuBar1.add(jMenu2); |
358 |
0 |
jMenu2.add(fitToWindow); |
359 |
0 |
jMenu2.add(fontSize); |
360 |
0 |
jMenu2.add(distanceMenu); |
361 |
0 |
jMenu2.add(bootstrapMenu); |
362 |
0 |
jMenu2.add(placeholdersMenu); |
363 |
0 |
fileMenu.add(newickOutput); |
364 |
0 |
fileMenu.add(inputData); |
365 |
0 |
inputData.addActionListener(this); |
366 |
|
} |
367 |
|
|
368 |
|
} |