Debian Codegraph @

src/dr/app/beauti/sitemodelspanel/PartitionModelPanel.java

raw symbols SCIP
1 /*
2 * PartitionModelPanel.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.beauti.sitemodelspanel;
27
28 import dr.app.beauti.BeautiFrame;
29 import dr.evomodel.substmodel.aminoacid.AminoAcidModelType;
30 import dr.evomodel.substmodel.nucleotide.NucModelType;
31 import dr.app.beauti.components.continuous.ContinuousComponentOptions;
32 import dr.app.beauti.components.continuous.ContinuousSubstModelType;
33 import dr.app.beauti.components.discrete.DiscreteSubstModelType;
34 import dr.app.beauti.components.dollo.DolloComponentOptions;
35 import dr.app.beauti.options.PartitionSubstitutionModel;
36 import dr.app.beauti.types.BinaryModelType;
37 import dr.app.beauti.types.FrequencyPolicyType;
38 import dr.app.beauti.types.MicroSatModelType;
39 import dr.app.beauti.util.PanelUtils;
40 import dr.app.gui.components.RealNumberField;
41 import dr.app.gui.components.WholeNumberField;
42 import dr.app.util.OSType;
43 import dr.evolution.datatype.DataType;
44 import dr.evolution.datatype.Microsatellite;
45 import jam.panels.OptionsPanel;
46
47 import javax.swing.*;
48 import javax.swing.border.TitledBorder;
49 import java.awt.event.*;
50 import java.util.EnumSet;
51 import java.util.logging.Logger;
52
53 /**
54 * @author Alexei Drummond
55 * @author Andrew Rambaut
56 * @author Walter Xie
57 */
58 public class PartitionModelPanel extends OptionsPanel {
59
60 private static final boolean ENABLE_STOCHASTIC_DOLLO = true;
61
62 // Components
63 private static final long serialVersionUID = -1645661616353099424L;
64
65 private JComboBox nucSubstCombo = new JComboBox(EnumSet.range(
66 NucModelType.JC, NucModelType.TN93).toArray());
67 private JComboBox aaSubstCombo = new JComboBox(AminoAcidModelType.values());
68 private JComboBox binarySubstCombo = new JComboBox(
69 new BinaryModelType[] { BinaryModelType.BIN_SIMPLE, BinaryModelType.BIN_COVARION });
70 private JCheckBox useAmbiguitiesTreeLikelihoodCheck = new JCheckBox(
71 "Use ambiguities in the tree likelihood associated with this model");
72
73 private JComboBox frequencyCombo = new JComboBox(FrequencyPolicyType
74 .values());
75
76 private JComboBox heteroCombo = new JComboBox(new String[] { "None",
77 "Gamma", "Invariant Sites", "Gamma + Invariant Sites" });
78
79 private JComboBox gammaCatCombo = new JComboBox(new String[] { "4", "5",
80 "6", "7", "8", "9", "10" });
81 private JLabel gammaCatLabel;
82
83 private JComboBox codingCombo = new JComboBox(new String[] { "Off",
84 "2 partitions: positions (1 + 2), 3",
85 "3 partitions: positions 1, 2, 3" });
86
87 private JCheckBox substUnlinkCheck = new JCheckBox(
88 "Unlink substitution rate parameters across codon positions");
89 private JCheckBox heteroUnlinkCheck = new JCheckBox(
90 "Unlink rate heterogeneity model across codon positions");
91 private JCheckBox freqsUnlinkCheck = new JCheckBox(
92 "Unlink base frequencies across codon positions");
93
94 private JButton setYang96Button;
95 private JButton setSRD06Button;
96
97 private JCheckBox dolloCheck = new JCheckBox("Use stochastic Dollo model");
98 // private JComboBox dolloCombo = new JComboBox(new String[]{"Analytical",
99 // "Sample"});
100
101 private JComboBox discreteTraitSiteModelCombo = new JComboBox(
102 DiscreteSubstModelType.values());
103 private JCheckBox activateBSSVS = new JCheckBox(
104 // "Activate BSSVS"
105 "Infer social network with BSSVS");
106 private JButton setupGLMButton;
107 private GLMSettingsDialog glmSettingsDialog = null;
108
109 private JComboBox continuousTraitSiteModelCombo = new JComboBox(
110 ContinuousSubstModelType.values());
111
112 private JCheckBox latLongCheck = new JCheckBox(
113 "Bivariate trait represents latitude and longitude");
114
115 private JCheckBox useLambdaCheck = new JCheckBox(
116 "Estimate phylogenetic signal using tree transform");
117
118 private JCheckBox addJitterCheck = new JCheckBox(
119 "Add random jitter to tips");
120 private JLabel jitterWindowLabel = new JLabel("Jitter window size:");
121 private RealNumberField jitterWindowText = new RealNumberField(0, Double.POSITIVE_INFINITY);
122
123 private JTextArea citationText;
124
125 // =========== micro sat ===========
126 private JTextField microsatName = new JTextField();
127 private WholeNumberField microsatMax = new WholeNumberField(2,
128 Integer.MAX_VALUE);
129 private WholeNumberField microsatMin = new WholeNumberField(1,
130 Integer.MAX_VALUE);
131 private JComboBox rateProportionCombo = new JComboBox(
132 MicroSatModelType.RateProportionality.values());
133 private JComboBox mutationBiasCombo = new JComboBox(
134 MicroSatModelType.MutationalBias.values());
135 private JComboBox phaseCombo = new JComboBox(MicroSatModelType.Phase
136 .values());
137 JCheckBox shareMicroSatCheck = new JCheckBox(
138 "Share one microsatellite among all substitution model(s)");
139
140 protected final PartitionSubstitutionModel model;
141
142 final BeautiFrame frame;
143
144 public PartitionModelPanel(final BeautiFrame frame, final PartitionSubstitutionModel partitionModel) {
145
146 super(12, (OSType.isMac() ? 6 : 24));
147
148 this.frame = frame;
149
150 this.model = partitionModel;
151
152 initCodonPartitionComponents();
153
154 PanelUtils.setupComponent(nucSubstCombo);
155 nucSubstCombo.addItemListener(new ItemListener() {
156 public void itemStateChanged(ItemEvent ev) {
157 model.setNucSubstitutionModel((NucModelType) nucSubstCombo
158 .getSelectedItem());
159 if (model.getNucSubstitutionModel() == NucModelType.JC) {
160 frequencyCombo.getSelectedItem();
161
162 frequencyCombo.setSelectedItem(FrequencyPolicyType.ALLEQUAL);
163 }
164 frequencyCombo.setEnabled(model.getNucSubstitutionModel() != NucModelType.JC);
165 }
166 });
167 nucSubstCombo
168 .setToolTipText("<html>Select the type of nucleotide substitution model.</html>");
169
170 PanelUtils.setupComponent(aaSubstCombo);
171 aaSubstCombo.addItemListener(new ItemListener() {
172 public void itemStateChanged(ItemEvent ev) {
173 AminoAcidModelType type = (AminoAcidModelType) aaSubstCombo.getSelectedItem();
174 model.setAaSubstitutionModel(type);
175 citationText.setText(type.getCitation().toString());
176 }
177 });
178 aaSubstCombo
179 .setToolTipText("<html>Select the type of amino acid substitution model.</html>");
180
181 PanelUtils.setupComponent(binarySubstCombo);
182 binarySubstCombo.addItemListener(new ItemListener() {
183 public void itemStateChanged(ItemEvent ev) {
184 model
185 .setBinarySubstitutionModel((BinaryModelType) binarySubstCombo
186 .getSelectedItem());
187 useAmbiguitiesTreeLikelihoodCheck.setSelected(binarySubstCombo
188 .getSelectedItem() == BinaryModelType.BIN_COVARION);
189 useAmbiguitiesTreeLikelihoodCheck.setEnabled(binarySubstCombo
190 .getSelectedItem() != BinaryModelType.BIN_COVARION);
191 }
192 });
193 binarySubstCombo
194 .setToolTipText("<html>Select the type of binary substitution model.</html>");
195
196 PanelUtils.setupComponent(useAmbiguitiesTreeLikelihoodCheck);
197 useAmbiguitiesTreeLikelihoodCheck.addItemListener(new ItemListener() {
198 public void itemStateChanged(ItemEvent ev) {
199 model
200 .setUseAmbiguitiesTreeLikelihood(useAmbiguitiesTreeLikelihoodCheck
201 .isSelected());
202 }
203 });
204 useAmbiguitiesTreeLikelihoodCheck
205 .setToolTipText("<html>Detemine useAmbiguities in &lt treeLikelihood &gt .</html>");
206
207 PanelUtils.setupComponent(frequencyCombo);
208 frequencyCombo.addItemListener(new ItemListener() {
209 public void itemStateChanged(ItemEvent ev) {
210 model.setFrequencyPolicy((FrequencyPolicyType) frequencyCombo
211 .getSelectedItem());
212 }
213 });
214 frequencyCombo
215 .setToolTipText("<html>Select the policy for determining the base frequencies.</html>");
216
217 PanelUtils.setupComponent(heteroCombo);
218 heteroCombo
219 .setToolTipText("<html>Select the type of site-specific rate<br>heterogeneity model.</html>");
220 heteroCombo.addItemListener(new ItemListener() {
221 public void itemStateChanged(ItemEvent ev) {
222
223 boolean gammaHetero = heteroCombo.getSelectedIndex() == 1
224 || heteroCombo.getSelectedIndex() == 3;
225
226 model.setGammaHetero(gammaHetero);
227 model.setInvarHetero(heteroCombo.getSelectedIndex() == 2
228 || heteroCombo.getSelectedIndex() == 3);
229
230 if (gammaHetero) {
231 gammaCatLabel.setEnabled(true);
232 gammaCatCombo.setEnabled(true);
233 } else {
234 gammaCatLabel.setEnabled(false);
235 gammaCatCombo.setEnabled(false);
236 }
237
238 if (codingCombo.getSelectedIndex() != 0) {
239 heteroUnlinkCheck
240 .setEnabled(heteroCombo.getSelectedIndex() != 0);
241 heteroUnlinkCheck.setSelected(heteroCombo
242 .getSelectedIndex() != 0);
243 }
244 }
245 });
246
247 PanelUtils.setupComponent(gammaCatCombo);
248 gammaCatCombo
249 .setToolTipText("<html>Select the number of categories to use for<br>the discrete gamma rate heterogeneity model.</html>");
250 gammaCatCombo.addItemListener(new ItemListener() {
251 public void itemStateChanged(ItemEvent ev) {
252
253 model.setGammaCategories(gammaCatCombo.getSelectedIndex() + 4);
254 }
255 });
256
257 setYang96Button = new JButton("Use Yang96 model");
258 setYang96Button.addActionListener(new ActionListener() {
259 public void actionPerformed(ActionEvent ev) {
260 setYang96Model();
261 }
262 });
263 PanelUtils.setupComponent(setYang96Button);
264 setYang96Button
265 .setToolTipText("<html>Sets a 3 codon-position model with independent GTR and Gamma as described in<br>"
266 + "Yang (1996) <i>J Mol Evol</i> <b>42</b>: 587-596. This model is named 3' in this paper.</html>");
267
268 setSRD06Button = new JButton("Use SRD06 model");
269 setSRD06Button.addActionListener(new ActionListener() {
270 public void actionPerformed(ActionEvent ev) {
271 setSRD06Model();
272 }
273 });
274 PanelUtils.setupComponent(setSRD06Button);
275 setSRD06Button
276 .setToolTipText("<html>Sets the SRD06 model as described in<br>"
277 + "Shapiro, Rambaut & Drummond (2006) <i>MBE</i> <b>23</b>: 7-9.</html>");
278
279 citationText = new JTextArea(1, 40);
280 citationText.setLineWrap(true);
281 citationText.setWrapStyleWord(true);
282 citationText.setEditable(false);
283 citationText.setFont(this.getFont());
284 citationText.setOpaque(false);
285 AminoAcidModelType type = (AminoAcidModelType) aaSubstCombo.getSelectedItem();
286 citationText.setText(type.getCitation().toString());
287
288 dolloCheck.addActionListener(new ActionListener() {
289 public void actionPerformed(ActionEvent actionEvent) {
290 if (dolloCheck.isSelected()) {
291 binarySubstCombo.setSelectedIndex(0);
292 binarySubstCombo.setEnabled(false);
293 useAmbiguitiesTreeLikelihoodCheck.setSelected(true);
294 useAmbiguitiesTreeLikelihoodCheck.setEnabled(false);
295 frequencyCombo.setEnabled(false);
296 frequencyCombo.setSelectedItem(FrequencyPolicyType.EMPIRICAL);
297 heteroCombo.setSelectedIndex(0);
298 heteroCombo.setEnabled(false);
299 model.setBinarySubstitutionModel(BinaryModelType.BIN_DOLLO);
300 model.setDolloModel(true);
301 DolloComponentOptions comp = (DolloComponentOptions)
302 model.getOptions().getComponentOptions(DolloComponentOptions.class);
303 comp.createParameters(model.getOptions());
304 comp.setActive(true);
305
306 } else {
307 binarySubstCombo.setEnabled(true);
308 useAmbiguitiesTreeLikelihoodCheck.setEnabled(true);
309 frequencyCombo.setEnabled(true);
310 heteroCombo.setEnabled(true);
311 model.setBinarySubstitutionModel((BinaryModelType) binarySubstCombo.getSelectedItem());
312 model.setDolloModel(false);
313 }
314 }
315 });
316
317 PanelUtils.setupComponent(dolloCheck);
318 // dolloCheck.addChangeListener(new ChangeListener() {
319 // public void stateChanged(ChangeEvent e) {
320 // model.setDolloModel(true);
321 // }
322 // });
323 dolloCheck.setEnabled(true);
324 dolloCheck
325 .setToolTipText("<html>Activates a Stochastic Dollo model as described in<br>"
326 + "Alekseyenko, Lee & Suchard (2008) <i>Syst Biol</i> <b>57</b>: 772-784.</html>");
327
328 PanelUtils.setupComponent(discreteTraitSiteModelCombo);
329 discreteTraitSiteModelCombo.addItemListener(new ItemListener() {
330 public void itemStateChanged(ItemEvent ev) {
331 model
332 .setDiscreteSubstType((DiscreteSubstModelType) discreteTraitSiteModelCombo
333 .getSelectedItem());
334 activateBSSVS.setEnabled(model.getDiscreteSubstType() != DiscreteSubstModelType.GLM_SUBST);
335 setupGLMButton.setEnabled(model.getDiscreteSubstType() == DiscreteSubstModelType.GLM_SUBST);
336 }
337 });
338
339 PanelUtils.setupComponent(continuousTraitSiteModelCombo);
340 continuousTraitSiteModelCombo
341 .setToolTipText("<html>Select the model of continuous random walk, either homogenous<br>" +
342 "or relaxed random walk (RRW) with a choice of distributions.</html>");
343 continuousTraitSiteModelCombo.addItemListener(new ItemListener() {
344 public void itemStateChanged(ItemEvent ev) {
345 model
346 .setContinuousSubstModelType((ContinuousSubstModelType) continuousTraitSiteModelCombo
347 .getSelectedItem());
348 }
349 });
350
351 PanelUtils.setupComponent(latLongCheck);
352 latLongCheck
353 .setToolTipText("<html>Specify whether this is a geographical trait representing <br>"
354 + "latitude and longitude. Provides appropriate statistics to log file.</html>");
355
356 latLongCheck.addItemListener(new ItemListener() {
357 public void itemStateChanged(ItemEvent ev) {
358 model.setIsLatitudeLongitude(latLongCheck.isSelected());
359 }
360 });
361 latLongCheck.setEnabled(false);
362
363 PanelUtils.setupComponent(addJitterCheck);
364 addJitterCheck
365 .setToolTipText("<html>Specify if the tip values should have some added random<br>" +
366 "noise. This can be useful if some tips have precisely<br>" +
367 "the same location.</html>");
368
369 jitterWindowText.setValue(model.getJitterWindow());
370 jitterWindowText.setColumns(10);
371
372 addJitterCheck.addItemListener(new ItemListener() {
373 public void itemStateChanged(ItemEvent ev) {
374 jitterWindowLabel.setEnabled(addJitterCheck.isSelected());
375 jitterWindowText.setEnabled(addJitterCheck.isSelected());
376 model.setJitterWindow(addJitterCheck.isSelected() ? jitterWindowText.getValue() : 0.0);
377 }
378 });
379 jitterWindowText.addKeyListener(new java.awt.event.KeyListener() {
380 public void keyTyped(KeyEvent e) {
381 }
382
383 public void keyPressed(KeyEvent e) {
384 }
385
386 public void keyReleased(KeyEvent e) {
387 model.setJitterWindow(addJitterCheck.isSelected() ? jitterWindowText.getValue() : 0.0);
388 }
389 });
390
391 PanelUtils.setupComponent(useLambdaCheck);
392 useLambdaCheck.addItemListener(new ItemListener() {
393 public void itemStateChanged(ItemEvent ev) {
394 ContinuousComponentOptions component = (ContinuousComponentOptions) model.getOptions()
395 .getComponentOptions(ContinuousComponentOptions.class);
396 component.setUseLambda(model, useLambdaCheck.isSelected());
397 }
398 });
399 useLambdaCheck
400 .setToolTipText("<html>Estimate degree of phylogenetic correlation in continuous traits using <br>"
401 + "a tree transform. Inspired by Pagel (1999), described in Lemey et al (2013) <i>in prep</i></html>");
402
403 PanelUtils.setupComponent(activateBSSVS);
404 activateBSSVS.addItemListener(new ItemListener() {
405 public void itemStateChanged(ItemEvent ev) {
406 model.setActivateBSSVS(activateBSSVS.isSelected());
407 }
408 });
409 activateBSSVS
410 .setToolTipText("<html>Activates Bayesian stochastic search variable selection on the rates as described in<br>"
411 + "Lemey, Rambaut, Drummond & Suchard (2009) <i>PLoS Computational Biology</i> <b>5</b>: e1000520</html>");
412 activateBSSVS.setEnabled(model.getDiscreteSubstType() != DiscreteSubstModelType.GLM_SUBST);
413
414 setupGLMButton = new JButton("Setup GLM");
415 setupGLMButton.addActionListener(new ActionListener() {
416 public void actionPerformed(ActionEvent ev) {
417 setupGLM();
418 }
419 });
420 PanelUtils.setupComponent(setupGLMButton);
421 setupGLMButton
422 .setToolTipText("<html>Set-up design of phylogenetic GLM.</html>");
423 setupGLMButton.setEnabled(model.getDiscreteSubstType() == DiscreteSubstModelType.GLM_SUBST);
424
425 // ============ micro-sat ================
426 microsatName.setColumns(30);
427 microsatName.addKeyListener(new java.awt.event.KeyListener() {
428 public void keyTyped(KeyEvent e) {
429 }
430
431 public void keyPressed(KeyEvent e) {
432 }
433
434 public void keyReleased(KeyEvent e) {
435 model.getMicrosatellite().setName(microsatName.getText());
436 }
437 });
438 microsatMax.setColumns(10);
439 microsatMax.addKeyListener(new java.awt.event.KeyListener() {
440 public void keyTyped(KeyEvent e) {
441 }
442
443 public void keyPressed(KeyEvent e) {
444 }
445
446 public void keyReleased(KeyEvent e) {
447 model.getMicrosatellite().setMax(
448 Integer.parseInt(microsatMax.getText()));
449 }
450 });
451 microsatMin.setColumns(10);
452 microsatMin.addKeyListener(new java.awt.event.KeyListener() {
453 public void keyTyped(KeyEvent e) {
454 }
455
456 public void keyPressed(KeyEvent e) {
457 }
458
459 public void keyReleased(KeyEvent e) {
460 model.getMicrosatellite().setMin(
461 Integer.parseInt(microsatMin.getText()));
462 }
463 });
464
465 PanelUtils.setupComponent(shareMicroSatCheck);
466 shareMicroSatCheck.addActionListener(new ActionListener() {
467 public void actionPerformed(ActionEvent e) {
468 model.getOptions().shareMicroSat = shareMicroSatCheck
469 .isSelected();
470 if (shareMicroSatCheck.isSelected()) {
471 model.getOptions().shareMicroSat();
472 } else {
473 model.getOptions().unshareMicroSat();
474 }
475 setOptions();
476 }
477 });
478
479 PanelUtils.setupComponent(rateProportionCombo);
480 rateProportionCombo.addItemListener(new ItemListener() {
481 public void itemStateChanged(ItemEvent ev) {
482 model
483 .setRatePorportion((MicroSatModelType.RateProportionality) rateProportionCombo
484 .getSelectedItem());
485 }
486 });
487 // rateProportionCombo.setToolTipText("<html>Select the type of microsatellite substitution model.</html>");
488 PanelUtils.setupComponent(mutationBiasCombo);
489 mutationBiasCombo.addItemListener(new ItemListener() {
490 public void itemStateChanged(ItemEvent ev) {
491 model
492 .setMutationBias((MicroSatModelType.MutationalBias) mutationBiasCombo
493 .getSelectedItem());
494 }
495 });
496 PanelUtils.setupComponent(phaseCombo);
497 phaseCombo.addItemListener(new ItemListener() {
498 public void itemStateChanged(ItemEvent ev) {
499 model.setPhase((MicroSatModelType.Phase) phaseCombo
500 .getSelectedItem());
501 }
502 });
503
504 setupPanel();
505 setOpaque(false);
506 }
507
508 /**
509 * Sets the components up according to the partition model - but does not
510 * layout the top level options panel.
511 */
512 public void setOptions() {
513
514 if (SiteModelsPanel.DEBUG) {
515 String modelName = (model == null) ? "null" : model.getName();
516 Logger.getLogger("dr.app.beauti").info(
517 "ModelsPanel.setModelOptions(" + modelName + ")");
518 }
519
520 if (model == null) {
521 return;
522 }
523
524 int dataType = model.getDataType().getType();
525 switch (dataType) {
526 case DataType.NUCLEOTIDES:
527 nucSubstCombo.setSelectedItem(model.getNucSubstitutionModel());
528 frequencyCombo.setSelectedItem(model.getFrequencyPolicy());
529
530 break;
531
532 case DataType.AMINO_ACIDS:
533 aaSubstCombo.setSelectedItem(model.getAaSubstitutionModel());
534
535 break;
536
537 case DataType.TWO_STATES:
538 case DataType.COVARION:
539 binarySubstCombo
540 .setSelectedItem(model.getBinarySubstitutionModel());
541 useAmbiguitiesTreeLikelihoodCheck.setSelected(model
542 .isUseAmbiguitiesTreeLikelihood());
543
544 break;
545
546 case DataType.GENERAL:
547 discreteTraitSiteModelCombo.setSelectedItem(model
548 .getDiscreteSubstType());
549 activateBSSVS.setSelected(model.getDiscreteSubstType() != DiscreteSubstModelType.GLM_SUBST ?
550 model.isActivateBSSVS() : false);
551 break;
552
553 case DataType.CONTINUOUS:
554 continuousTraitSiteModelCombo.setSelectedItem(model
555 .getContinuousSubstModelType());
556
557 ContinuousComponentOptions component = (ContinuousComponentOptions) model.getOptions()
558 .getComponentOptions(ContinuousComponentOptions.class);
559
560 latLongCheck.setSelected(model.isLatitudeLongitude());
561 latLongCheck.setEnabled(model.getContinuousTraitCount() == 2);
562 useLambdaCheck.setSelected(component.useLambda(model));
563 break;
564 case DataType.MICRO_SAT:
565 microsatName.setText(model.getMicrosatellite().getName());
566 microsatMax.setText(Integer.toString(model.getMicrosatellite()
567 .getMax()));
568 microsatMin.setText(Integer.toString(model.getMicrosatellite()
569 .getMin()));
570 shareMicroSatCheck.setSelected(model.getOptions().shareMicroSat);
571 rateProportionCombo.setSelectedItem(model.getRatePorportion());
572 mutationBiasCombo.setSelectedItem(model.getMutationBias());
573 phaseCombo.setSelectedItem(model.getPhase());
574 shareMicroSatCheck.setEnabled(model.getOptions()
575 .getPartitionSubstitutionModels(Microsatellite.INSTANCE)
576 .size() > 1);
577 break;
578
579 default:
580 throw new IllegalArgumentException("Unknown data type");
581 }
582
583 if (model.isGammaHetero() && !model.isInvarHetero()) {
584 heteroCombo.setSelectedIndex(1);
585 } else if (!model.isGammaHetero() && model.isInvarHetero()) {
586 heteroCombo.setSelectedIndex(2);
587 } else if (model.isGammaHetero() && model.isInvarHetero()) {
588 heteroCombo.setSelectedIndex(3);
589 } else {
590 heteroCombo.setSelectedIndex(0);
591 }
592
593 gammaCatCombo.setSelectedIndex(model.getGammaCategories() - 4);
594
595 if (model.getCodonHeteroPattern() == null) {
596 codingCombo.setSelectedIndex(0);
597 } else if (model.getCodonHeteroPattern().equals("112")) {
598 codingCombo.setSelectedIndex(1);
599 } else {
600 codingCombo.setSelectedIndex(2);
601 }
602
603 substUnlinkCheck.setSelected(model.isUnlinkedSubstitutionModel());
604 heteroUnlinkCheck.setSelected(model.isUnlinkedHeterogeneityModel());
605 freqsUnlinkCheck.setSelected(model.isUnlinkedFrequencyModel());
606
607 dolloCheck.setSelected(model.isDolloModel());
608 }
609
610 /**
611 * Configure this panel for the Yang 96 codon
612 * position model
613 */
614 private void setYang96Model() {
615 nucSubstCombo.setSelectedIndex(2);
616 heteroCombo.setSelectedIndex(1);
617 codingCombo.setSelectedIndex(2);
618 substUnlinkCheck.setSelected(true);
619 heteroUnlinkCheck.setSelected(true);
620 freqsUnlinkCheck.setSelected(true);
621 }
622
623 /**
624 * Configure this panel for the Shapiro, Rambaut and Drummond 2006 codon
625 * position model
626 */
627 private void setSRD06Model() {
628 nucSubstCombo.setSelectedIndex(1);
629 heteroCombo.setSelectedIndex(1);
630 codingCombo.setSelectedIndex(1);
631 substUnlinkCheck.setSelected(true);
632 heteroUnlinkCheck.setSelected(true);
633 freqsUnlinkCheck.setSelected(false);
634 }
635
636 private void setupGLM() {
637 if (glmSettingsDialog == null) {
638 glmSettingsDialog = new GLMSettingsDialog(frame);
639 }
640
641 glmSettingsDialog.setTrait(model.getTraitData());
642
643 int result = glmSettingsDialog.showDialog();
644
645 if (result == JOptionPane.OK_OPTION) {
646 // Only do this if OK button is pressed (not cancel):
647
648 frame.setAllOptions();
649 }
650 }
651
652 /**
653 * Lays out the appropriate components in the panel for this partition
654 * model.
655 */
656 private void setupPanel() {
657
658 switch (model.getDataType().getType()) {
659 case DataType.NUCLEOTIDES:
660 addComponentWithLabel("Substitution Model:", nucSubstCombo);
661 addComponentWithLabel("Base frequencies:", frequencyCombo);
662 addComponentWithLabel("Site Heterogeneity Model:", heteroCombo);
663 heteroCombo.setSelectedIndex(0);
664 gammaCatLabel = addComponentWithLabel(
665 "Number of Gamma Categories:", gammaCatCombo);
666 gammaCatCombo.setEnabled(false);
667
668 addSeparator();
669
670 addComponentWithLabel("Partition into codon positions:",
671 codingCombo);
672
673 JPanel panel2 = new JPanel();
674 panel2.setOpaque(false);
675 panel2.setLayout(new BoxLayout(panel2, BoxLayout.PAGE_AXIS));
676 panel2.setBorder(new TitledBorder(null, "Link/Unlink parameters:", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.ABOVE_TOP));
677 panel2.add(substUnlinkCheck);
678 panel2.add(heteroUnlinkCheck);
679 panel2.add(freqsUnlinkCheck);
680
681 addComponent(panel2);
682
683 addComponent(setYang96Button);
684 addComponent(setSRD06Button);
685
686 break;
687
688 case DataType.AMINO_ACIDS:
689 addComponentWithLabel("Substitution Model:", aaSubstCombo);
690 addComponentWithLabel("Citation:", citationText);
691
692 addComponentWithLabel("Site Heterogeneity Model:", heteroCombo);
693 heteroCombo.setSelectedIndex(0);
694 gammaCatLabel = addComponentWithLabel(
695 "Number of Gamma Categories:", gammaCatCombo);
696 gammaCatCombo.setEnabled(false);
697
698 break;
699
700 case DataType.TWO_STATES:
701 case DataType.COVARION:
702 addComponentWithLabel("Substitution Model:", binarySubstCombo);
703 addComponentWithLabel("Base frequencies:", frequencyCombo);
704 addComponentWithLabel("Site Heterogeneity Model:", heteroCombo);
705 heteroCombo.setSelectedIndex(0);
706 gammaCatLabel = addComponentWithLabel(
707 "Number of Gamma Categories:", gammaCatCombo);
708 gammaCatCombo.setEnabled(false);
709
710 addSeparator();
711
712 addComponentWithLabel("", useAmbiguitiesTreeLikelihoodCheck);
713
714 // Easy XML specification is currently only available for binary models
715 if (ENABLE_STOCHASTIC_DOLLO) {
716 addSeparator();
717 addComponent(dolloCheck);
718 }
719
720 break;
721
722 case DataType.GENERAL:
723 addComponentWithLabel("Discrete Trait Substitution Model:",
724 discreteTraitSiteModelCombo);
725 addComponent(activateBSSVS);
726 addComponent(setupGLMButton);
727 break;
728
729 case DataType.CONTINUOUS:
730 addComponentWithLabel("Continuous Trait Model:",
731 continuousTraitSiteModelCombo);
732 addComponent(latLongCheck);
733 addSeparator();
734 addComponent(addJitterCheck);
735 OptionsPanel panel = new OptionsPanel();
736 panel.addComponents(jitterWindowLabel, jitterWindowText);
737 addComponent(panel);
738 jitterWindowLabel.setEnabled(false);
739 jitterWindowText.setEnabled(false);
740
741 addSeparator();
742 addComponent(useLambdaCheck);
743 break;
744
745 case DataType.MICRO_SAT:
746 addComponentWithLabel("Microsatellite Name:", microsatName);
747 addComponentWithLabel("Max of Length:", microsatMax);
748 addComponentWithLabel("Min of Length:", microsatMin);
749 addComponent(shareMicroSatCheck);
750
751 addSeparator();
752
753 addComponentWithLabel("Rate Proportionality:", rateProportionCombo);
754 addComponentWithLabel("Mutational Bias:", mutationBiasCombo);
755 addComponentWithLabel("Phase:", phaseCombo);
756 break;
757
758 default:
759 throw new IllegalArgumentException("Unknown data type");
760
761 }
762
763 setOptions();
764 }
765
766 /**
767 * Initializes and binds the components related to modeling codon positions.
768 */
769 private void initCodonPartitionComponents() {
770
771 PanelUtils.setupComponent(substUnlinkCheck);
772
773 substUnlinkCheck.addItemListener(new ItemListener() {
774 public void itemStateChanged(ItemEvent ev) {
775 model.setUnlinkedSubstitutionModel(substUnlinkCheck
776 .isSelected());
777 }
778 });
779 substUnlinkCheck.setEnabled(false);
780 substUnlinkCheck.setToolTipText(""
781 + "<html>Gives each codon position partition different<br>"
782 + "substitution model parameters.</html>");
783
784 PanelUtils.setupComponent(heteroUnlinkCheck);
785 heteroUnlinkCheck.addItemListener(new ItemListener() {
786 public void itemStateChanged(ItemEvent ev) {
787 model.setUnlinkedHeterogeneityModel(heteroUnlinkCheck
788 .isSelected());
789 }
790 });
791 heteroUnlinkCheck.setEnabled(heteroCombo.getSelectedIndex() != 0);
792 heteroUnlinkCheck
793 .setToolTipText("<html>Gives each codon position partition different<br>rate heterogeneity model parameters.</html>");
794
795 PanelUtils.setupComponent(freqsUnlinkCheck);
796 freqsUnlinkCheck.addItemListener(new ItemListener() {
797 public void itemStateChanged(ItemEvent ev) {
798 model.setUnlinkedFrequencyModel(freqsUnlinkCheck.isSelected());
799 }
800 });
801 freqsUnlinkCheck.setEnabled(false);
802 freqsUnlinkCheck
803 .setToolTipText("<html>Gives each codon position partition different<br>nucleotide frequency parameters.</html>");
804
805 PanelUtils.setupComponent(codingCombo);
806 codingCombo
807 .setToolTipText("<html>Select how to partition the codon positions.</html>");
808 codingCombo.addItemListener(new ItemListener() {
809 public void itemStateChanged(ItemEvent ev) {
810
811 switch (codingCombo.getSelectedIndex()) {
812 case 0:
813 model.setCodonHeteroPattern(null);
814 break;
815 case 1:
816 model.setCodonHeteroPattern("112");
817 break;
818 default:
819 model.setCodonHeteroPattern("123");
820 break;
821
822 }
823
824 if (codingCombo.getSelectedIndex() != 0) {
825 // codon position partitioning
826 substUnlinkCheck.setEnabled(true);
827 heteroUnlinkCheck
828 .setEnabled(heteroCombo.getSelectedIndex() != 3);
829 freqsUnlinkCheck.setEnabled(true);
830 substUnlinkCheck.setSelected(true);
831 heteroUnlinkCheck.setSelected(heteroCombo
832 .getSelectedIndex() != 0);
833 freqsUnlinkCheck.setSelected(true);
834
835 } else {
836 substUnlinkCheck.setEnabled(false);
837 substUnlinkCheck.setSelected(false);
838 heteroUnlinkCheck.setEnabled(false);
839 heteroUnlinkCheck.setSelected(false);
840 freqsUnlinkCheck.setEnabled(false);
841 freqsUnlinkCheck.setSelected(false);
842 }
843 }
844 });
845 }
846 }