| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 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 |
|
| 42 |
|
| 43 |
public class PartitionClockModelPanel extends OptionsPanel { |
| 44 |
|
| 45 |
|
| 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 |
|
| 54 |
ClockDistributionType.EXPONENTIAL, |
| 55 |
|
| 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 |
|
| 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 |
|
| 160 |
|
| 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 |
} |