Debian Codegraph @

src/dr/app/beauti/clockmodelspanel/PartitionClockModelPanel.java

raw symbols SCIP
1 /*
2 * PartitionClockModelPanel.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.clockmodelspanel;
27
28 import dr.app.beauti.options.PartitionClockModel;
29 import dr.app.beauti.types.ClockDistributionType;
30 import dr.app.beauti.types.ClockType;
31 import dr.app.beauti.util.PanelUtils;
32 import dr.app.util.OSType;
33 import jam.panels.OptionsPanel;
34
35 import javax.swing.*;
36 import java.awt.event.ItemEvent;
37 import java.awt.event.ItemListener;
38 import java.util.EnumSet;
39
40 /**
41 * @author Andrew Rambaut
42 */
43 public class PartitionClockModelPanel extends OptionsPanel {
44
45 // Components
46 private static final long serialVersionUID = -1645661616353099424L;
47
48 private JComboBox clockTypeCombo = new JComboBox(EnumSet.range(
49 ClockType.STRICT_CLOCK, ClockType.FIXED_LOCAL_CLOCK).toArray());
50 private JComboBox clockDistributionCombo = new JComboBox (new ClockDistributionType[] {
51 ClockDistributionType.LOGNORMAL,
52 ClockDistributionType.GAMMA,
53 // ClockDistributionType.CAUCHY,
54 ClockDistributionType.EXPONENTIAL,
55 //ClockDistributionType.MODEL_AVERAGING
56 });
57 private JCheckBox continuousQuantileCheck = new JCheckBox("Use continuous quantile parameterization.");
58
59 private JLabel modelAveragingInfo = new JLabel(
60 "<html>Using the Bayesian Model Averaging (BMA) approach on the<br>" +
61 "available relaxed clock models as described by Li & Drummond (2012)<br>" +
62 " Mol. Biol. Evol. 29:751-761.</html>");
63
64 protected final PartitionClockModel model;
65
66 public PartitionClockModelPanel(final PartitionClockModel partitionModel) {
67
68 super(12, (OSType.isMac() ? 6 : 24));
69
70 this.model = partitionModel;
71
72 PanelUtils.setupComponent(clockTypeCombo);
73 clockTypeCombo.addItemListener(new ItemListener() {
74 public void itemStateChanged(ItemEvent ev) {
75 model.setClockType((ClockType) clockTypeCombo.getSelectedItem());
76 setupPanel();
77 }
78 });
79 clockTypeCombo.setToolTipText("<html>Select the type of molecular clock model.</html>");
80
81 clockTypeCombo.setSelectedItem(model.getClockType());
82
83 PanelUtils.setupComponent(clockDistributionCombo);
84 clockDistributionCombo.addItemListener(new ItemListener() {
85 public void itemStateChanged(ItemEvent ev) {
86 model.setClockDistributionType((ClockDistributionType) clockDistributionCombo.getSelectedItem());
87 if (clockDistributionCombo.getSelectedItem() == ClockDistributionType.MODEL_AVERAGING) {
88 model.setPerformModelAveraging(true);
89 continuousQuantileCheck.setSelected(true);
90 continuousQuantileCheck.setEnabled(false);
91 addComponent(modelAveragingInfo);
92 } else {
93 model.setPerformModelAveraging(false);
94 continuousQuantileCheck.setEnabled(true);
95 remove(modelAveragingInfo);
96 }
97 model.setContinuousQuantile(continuousQuantileCheck.isSelected());
98 }
99 });
100 clockDistributionCombo.setToolTipText("<html>Select the distribution that describes the variation in rate.</html>");
101
102 clockDistributionCombo.setSelectedItem(model.getClockDistributionType());
103
104 PanelUtils.setupComponent(continuousQuantileCheck);
105 continuousQuantileCheck.setToolTipText("<html>" +
106 "Select this option to use the continuous quantile form of the relaxed<br>" +
107 "clock model described by Li & Drummond (2012) MBE 29:751-61 instead of<br>" +
108 "the discretized categorical form.<html>");
109 continuousQuantileCheck.setSelected(model.isContinuousQuantile());
110 continuousQuantileCheck.addItemListener(
111 new ItemListener() {
112 public void itemStateChanged(ItemEvent ev) {
113 model.setContinuousQuantile(continuousQuantileCheck.isSelected());
114 }
115 });
116
117 setupPanel();
118 setOpaque(false);
119
120 }
121
122
123 /**
124 * Lays out the appropriate components in the panel for this partition model.
125 */
126 public void setupPanel() {
127 removeAll();
128 addComponentWithLabel("Clock Type:", clockTypeCombo);
129
130 switch (model.getClockType()) {
131 case STRICT_CLOCK:
132 break;
133
134 case UNCORRELATED:
135 addComponent(new JLabel(
136 "<html>" +
137 "Using the uncorrelated relaxed clock model of Drummond, Ho, Phillips & <br>" +
138 "Rambaut (2006) PLoS Biology 4, e88.<html>"));
139 addComponentWithLabel("Relaxed Distribution:", clockDistributionCombo);
140 addComponent(continuousQuantileCheck);
141 break;
142
143 case AUTOCORRELATED:
144 addComponentWithLabel("Relaxed Distribution:", clockDistributionCombo);
145 break;
146
147 case RANDOM_LOCAL_CLOCK:
148 case FIXED_LOCAL_CLOCK:
149 break;
150
151 default:
152 throw new IllegalArgumentException("Unknown clock model type");
153
154 }
155
156 }
157
158 /**
159 * Sets the components up according to the partition model - but does not
160 * layout the top level options panel.
161 */
162 public void setOptions() {
163
164 if (model == null) {
165 return;
166 }
167 clockTypeCombo.setSelectedItem(model.getClockType());
168 clockDistributionCombo.setSelectedItem(model.getClockDistributionType());
169
170 setupPanel();
171 setOpaque(false);
172
173 }
174
175 }