| 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.treespanel; |
| 27 |
|
| 28 |
import dr.app.beauti.options.PartitionTreeModel; |
| 29 |
import dr.app.beauti.options.PartitionTreePrior; |
| 30 |
import dr.app.beauti.types.PopulationSizeModelType; |
| 31 |
import dr.app.beauti.types.TreePriorParameterizationType; |
| 32 |
import dr.app.beauti.types.TreePriorType; |
| 33 |
import dr.app.beauti.util.PanelUtils; |
| 34 |
import dr.app.gui.components.RealNumberField; |
| 35 |
import dr.app.gui.components.WholeNumberField; |
| 36 |
import dr.app.util.OSType; |
| 37 |
import dr.evomodel.coalescent.VariableDemographicModel; |
| 38 |
import dr.evomodelxml.speciation.BirthDeathModelParser; |
| 39 |
import dr.evomodelxml.speciation.BirthDeathSerialSamplingModelParser; |
| 40 |
import jam.panels.OptionsPanel; |
| 41 |
|
| 42 |
import javax.swing.*; |
| 43 |
import java.awt.event.ItemEvent; |
| 44 |
import java.awt.event.ItemListener; |
| 45 |
import java.util.EnumSet; |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
public class PartitionTreePriorPanel extends OptionsPanel { |
| 54 |
|
| 55 |
private static final long serialVersionUID = 5016996360264782252L; |
| 56 |
|
| 57 |
private JComboBox treePriorCombo = new JComboBox(); |
| 58 |
|
| 59 |
private JComboBox parameterizationCombo = new JComboBox(EnumSet.range(TreePriorParameterizationType.GROWTH_RATE, |
| 60 |
TreePriorParameterizationType.DOUBLING_TIME).toArray()); |
| 61 |
|
| 62 |
private JComboBox bayesianSkylineCombo = new JComboBox(EnumSet.range(TreePriorParameterizationType.CONSTANT_SKYLINE, |
| 63 |
TreePriorParameterizationType.LINEAR_SKYLINE).toArray()); |
| 64 |
private WholeNumberField groupCountField = new WholeNumberField(2, Integer.MAX_VALUE); |
| 65 |
|
| 66 |
private JComboBox extendedBayesianSkylineCombo = new JComboBox( |
| 67 |
new VariableDemographicModel.Type[]{VariableDemographicModel.Type.LINEAR, VariableDemographicModel.Type.STEPWISE}); |
| 68 |
|
| 69 |
private JComboBox gmrfBayesianSkyrideCombo = new JComboBox(EnumSet.range(TreePriorParameterizationType.UNIFORM_SKYRIDE, |
| 70 |
TreePriorParameterizationType.TIME_AWARE_SKYRIDE).toArray()); |
| 71 |
|
| 72 |
private WholeNumberField skyGridPointsField = new WholeNumberField(2, Integer.MAX_VALUE); |
| 73 |
private RealNumberField skyGridInterval = new RealNumberField(0.0, Double.MAX_VALUE); |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
private JComboBox populationSizeCombo = new JComboBox(PopulationSizeModelType.values()); |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
PartitionTreePrior partitionTreePrior; |
| 88 |
private final TreesPanel treesPanel; |
| 89 |
|
| 90 |
private boolean settingOptions = false; |
| 91 |
|
| 92 |
|
| 93 |
public PartitionTreePriorPanel(PartitionTreePrior parTreePrior, final TreesPanel parent) { |
| 94 |
super(12, (OSType.isMac() ? 6 : 24)); |
| 95 |
|
| 96 |
this.partitionTreePrior = parTreePrior; |
| 97 |
this.treesPanel = parent; |
| 98 |
|
| 99 |
setTreePriorChoices(false, false); |
| 100 |
PanelUtils.setupComponent(treePriorCombo); |
| 101 |
treePriorCombo.setMaximumRowCount(10); |
| 102 |
treePriorCombo.addItemListener(new ItemListener() { |
| 103 |
public void itemStateChanged(ItemEvent ev) { |
| 104 |
|
| 105 |
if (treePriorCombo.getSelectedItem() != null) { |
| 106 |
setupPanel(); |
| 107 |
|
| 108 |
partitionTreePrior.setNodeHeightPrior((TreePriorType) treePriorCombo.getSelectedItem()); |
| 109 |
parent.fireTreePriorsChanged(); |
| 110 |
} |
| 111 |
} |
| 112 |
}); |
| 113 |
|
| 114 |
PanelUtils.setupComponent(parameterizationCombo); |
| 115 |
parameterizationCombo.setToolTipText("<html>" + |
| 116 |
"Select the parameterization of growth rate to use for<br>" + |
| 117 |
"the parametric coalescent model. This does not affect<br>" + |
| 118 |
"nature of the model but may assist with mixing.<html>"); |
| 119 |
parameterizationCombo.addItemListener(new ItemListener() { |
| 120 |
public void itemStateChanged(ItemEvent ev) { |
| 121 |
partitionTreePrior.setParameterization((TreePriorParameterizationType) parameterizationCombo.getSelectedItem()); |
| 122 |
parent.fireTreePriorsChanged(); |
| 123 |
} |
| 124 |
}); |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
PanelUtils.setupComponent(groupCountField); |
| 134 |
groupCountField.setToolTipText("<html>" + |
| 135 |
"Set the number of groups to be used in the Skyline model<br>" + |
| 136 |
"It will affect the resolution of the reconstruction. This<br>" + |
| 137 |
"should be set at fewer than the number of nodes in the<br>" + |
| 138 |
"tree.<html>"); |
| 139 |
groupCountField.addKeyListener(new java.awt.event.KeyAdapter() { |
| 140 |
public void keyTyped(java.awt.event.KeyEvent ev) { |
| 141 |
|
| 142 |
|
| 143 |
} |
| 144 |
}); |
| 145 |
|
| 146 |
PanelUtils.setupComponent(skyGridInterval); |
| 147 |
skyGridInterval.setToolTipText("<html>" + |
| 148 |
"This sets the time interval over which the change-points<br>" + |
| 149 |
"of the Skygrid are placed. It is measured relative to the<br>" + |
| 150 |
"most recent tip and should be commensurate with the predicted<br>" + |
| 151 |
"age of the tree.<html>"); |
| 152 |
skyGridInterval.addKeyListener(new java.awt.event.KeyAdapter() { |
| 153 |
public void keyTyped(java.awt.event.KeyEvent ev) { |
| 154 |
} |
| 155 |
}); |
| 156 |
|
| 157 |
PanelUtils.setupComponent(bayesianSkylineCombo); |
| 158 |
bayesianSkylineCombo.addItemListener(new ItemListener() { |
| 159 |
public void itemStateChanged(ItemEvent ev) { |
| 160 |
partitionTreePrior.setSkylineModel((TreePriorParameterizationType) bayesianSkylineCombo.getSelectedItem()); |
| 161 |
parent.fireTreePriorsChanged(); |
| 162 |
} |
| 163 |
}); |
| 164 |
|
| 165 |
PanelUtils.setupComponent(extendedBayesianSkylineCombo); |
| 166 |
extendedBayesianSkylineCombo.addItemListener(new ItemListener() { |
| 167 |
public void itemStateChanged(ItemEvent ev) { |
| 168 |
partitionTreePrior.setExtendedSkylineModel(((VariableDemographicModel.Type) |
| 169 |
extendedBayesianSkylineCombo.getSelectedItem())); |
| 170 |
parent.fireTreePriorsChanged(); |
| 171 |
} |
| 172 |
}); |
| 173 |
|
| 174 |
PanelUtils.setupComponent(gmrfBayesianSkyrideCombo); |
| 175 |
gmrfBayesianSkyrideCombo.addItemListener(new ItemListener() { |
| 176 |
public void itemStateChanged(ItemEvent ev) { |
| 177 |
partitionTreePrior.setSkyrideSmoothing((TreePriorParameterizationType) gmrfBayesianSkyrideCombo.getSelectedItem()); |
| 178 |
parent.fireTreePriorsChanged(); |
| 179 |
} |
| 180 |
}); |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
PanelUtils.setupComponent(skyGridPointsField); |
| 190 |
skyGridPointsField.setToolTipText("<html>" + |
| 191 |
"This sets number of population size parameters for<br>" + |
| 192 |
"the Skygrid. This determines the number of transition-points<br>" + |
| 193 |
"at which the population size changes. The last one spans to<br>" + |
| 194 |
"infinite time.<html>"); |
| 195 |
skyGridPointsField.addKeyListener(new java.awt.event.KeyAdapter() { |
| 196 |
public void keyTyped(java.awt.event.KeyEvent ev) { |
| 197 |
} |
| 198 |
}); |
| 199 |
|
| 200 |
PanelUtils.setupComponent(populationSizeCombo); |
| 201 |
populationSizeCombo.addItemListener(new ItemListener() { |
| 202 |
public void itemStateChanged(ItemEvent ev) { |
| 203 |
partitionTreePrior.setPopulationSizeModel((PopulationSizeModelType) populationSizeCombo.getSelectedItem()); |
| 204 |
parent.fireTreePriorsChanged(); |
| 205 |
} |
| 206 |
} |
| 207 |
); |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
setOptions(); |
| 220 |
setupPanel(); |
| 221 |
} |
| 222 |
|
| 223 |
private void setupPanel() { |
| 224 |
|
| 225 |
removeAll(); |
| 226 |
|
| 227 |
JTextArea citationText = new JTextArea(1, 40); |
| 228 |
citationText.setLineWrap(true); |
| 229 |
citationText.setWrapStyleWord(true); |
| 230 |
citationText.setEditable(false); |
| 231 |
citationText.setFont(this.getFont()); |
| 232 |
citationText.setOpaque(false); |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
String calYule = "Heled J, Drummond AJ (2011), Syst Biol, doi: 10.1093/sysbio/syr087 [Calibrated Yule]"; |
| 238 |
String citation; |
| 239 |
|
| 240 |
String citationCoalescent = "Kingman JFC (1982) Stoch Proc Appl 13, 235-248 [Constant Coalescent]."; |
| 241 |
|
| 242 |
addComponentWithLabel("Tree Prior:", treePriorCombo); |
| 243 |
|
| 244 |
if (!treesPanel.linkTreePriorCheck.isEnabled()) { |
| 245 |
treesPanel.updateLinkTreePriorEnablility(); |
| 246 |
} |
| 247 |
|
| 248 |
switch ((TreePriorType) treePriorCombo.getSelectedItem()) { |
| 249 |
case CONSTANT: |
| 250 |
citation = citationCoalescent; |
| 251 |
break; |
| 252 |
|
| 253 |
case EXPONENTIAL: |
| 254 |
case LOGISTIC: |
| 255 |
case EXPANSION: |
| 256 |
addComponentWithLabel("Parameterization for growth:", parameterizationCombo); |
| 257 |
partitionTreePrior.setParameterization((TreePriorParameterizationType) parameterizationCombo.getSelectedItem()); |
| 258 |
|
| 259 |
citation = |
| 260 |
"Griffiths RC, Tavare S (1994) Phil Trans R Soc Lond B Biol Sci 344, 403-410 [Parametric Coalescent]."; |
| 261 |
|
| 262 |
break; |
| 263 |
|
| 264 |
case SKYLINE: |
| 265 |
groupCountField.setColumns(6); |
| 266 |
addComponentWithLabel("Number of groups:", groupCountField); |
| 267 |
addComponentWithLabel("Skyline Model:", bayesianSkylineCombo); |
| 268 |
|
| 269 |
citation = |
| 270 |
"Drummond AJ, Rambaut A, Shapiro B, Pybus OG (2005) Mol Biol Evol 22, 1185-1192 [Skyline Coalescent]."; |
| 271 |
break; |
| 272 |
|
| 273 |
case EXTENDED_SKYLINE: |
| 274 |
addComponentWithLabel("Model Type:", extendedBayesianSkylineCombo); |
| 275 |
treesPanel.linkTreePriorCheck.setSelected(true); |
| 276 |
treesPanel.linkTreePriorCheck.setEnabled(false); |
| 277 |
treesPanel.updateShareSameTreePriorChanged(); |
| 278 |
|
| 279 |
citation = |
| 280 |
"Heled J, Drummond AJ (2008) BMC Evol Biol 8, 289 [Extended Skyline Coalescent]."; |
| 281 |
break; |
| 282 |
|
| 283 |
case GMRF_SKYRIDE: |
| 284 |
addComponentWithLabel("Smoothing:", gmrfBayesianSkyrideCombo); |
| 285 |
treesPanel.linkTreePriorCheck.setSelected(true); |
| 286 |
treesPanel.linkTreePriorCheck.setEnabled(false); |
| 287 |
|
| 288 |
addLabel("<html>For the Skyride, tree model/tree prior combination not implemented by BEAST. " |
| 289 |
+ "The Skyride is only available for a single tree<br>model partition in this release. " |
| 290 |
+ "Please try the Skygrid or link all tree models." + "</html>"); |
| 291 |
|
| 292 |
citation = |
| 293 |
"Minin VN, Bloomquist EW, Suchard MA (2008) Mol Biol Evol 25, 1459-1471 [Skyride Coalescent]."; |
| 294 |
break; |
| 295 |
|
| 296 |
case SKYGRID: |
| 297 |
skyGridPointsField.setColumns(6); |
| 298 |
addComponentWithLabel("Number of parameters:", skyGridPointsField); |
| 299 |
skyGridInterval.setColumns(6); |
| 300 |
addComponentWithLabel("Time at last transition point:", skyGridInterval); |
| 301 |
treesPanel.linkTreePriorCheck.setSelected(true); |
| 302 |
treesPanel.linkTreePriorCheck.setEnabled(false); |
| 303 |
treesPanel.updateShareSameTreePriorChanged(); |
| 304 |
|
| 305 |
citation = |
| 306 |
"Gill MS, Lemey P, Faria NR, Rambaut A, Shapiro B, Suchard MA (2013) Mol Biol Evol 30, 713-724 [SkyGrid Coalescent]."; |
| 307 |
break; |
| 308 |
|
| 309 |
case YULE: |
| 310 |
citation = "Gernhard T (2008) J Theor Biol 253, 769-778 [Yule Process]." + |
| 311 |
"\nYule GU (1925) Phil Trans R Soc Lond B Biol Sci 213, 21-87 [Yule Process]."; |
| 312 |
break; |
| 313 |
|
| 314 |
case YULE_CALIBRATION: |
| 315 |
|
| 316 |
citation = calYule; |
| 317 |
break; |
| 318 |
|
| 319 |
case BIRTH_DEATH: |
| 320 |
citation = BirthDeathModelParser.getCitation(); |
| 321 |
break; |
| 322 |
|
| 323 |
case BIRTH_DEATH_INCOMPLETE_SAMPLING: |
| 324 |
citation = BirthDeathModelParser.getCitationRHO(); |
| 325 |
break; |
| 326 |
|
| 327 |
case BIRTH_DEATH_SERIAL_SAMPLING: |
| 328 |
citation = BirthDeathSerialSamplingModelParser.getCitationPsiOrg(); |
| 329 |
break; |
| 330 |
|
| 331 |
case BIRTH_DEATH_BASIC_REPRODUCTIVE_NUMBER: |
| 332 |
citation = BirthDeathSerialSamplingModelParser.getCitationRT(); |
| 333 |
break; |
| 334 |
|
| 335 |
default: |
| 336 |
throw new RuntimeException("No such tree prior has been specified so cannot refer to it"); |
| 337 |
} |
| 338 |
|
| 339 |
if (treesPanel.options.maximumTipHeight > 0) |
| 340 |
citation = citation |
| 341 |
|
| 342 |
|
| 343 |
+ "\n" + |
| 344 |
"Drummond AJ, Nicholls GK, Rodrigo AG, Solomon W (2002) Genetics 161, 1307-1320 [Serially Sampled Data]."; |
| 345 |
|
| 346 |
addComponentWithLabel("Citation:", citationText); |
| 347 |
citationText.setText(citation); |
| 348 |
|
| 349 |
for (PartitionTreeModel model : treesPanel.treeModelPanels.keySet()) { |
| 350 |
if (model != null) { |
| 351 |
treesPanel.treeModelPanels.get(model).setOptions(); |
| 352 |
treesPanel.treeModelPanels.get(model).setupPanel(); |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
validate(); |
| 357 |
repaint(); |
| 358 |
} |
| 359 |
|
| 360 |
public void setOptions() { |
| 361 |
|
| 362 |
if (settingOptions) { |
| 363 |
|
| 364 |
return; |
| 365 |
} |
| 366 |
|
| 367 |
if (partitionTreePrior == null) { |
| 368 |
return; |
| 369 |
} |
| 370 |
|
| 371 |
settingOptions = true; |
| 372 |
|
| 373 |
treePriorCombo.setSelectedItem(partitionTreePrior.getNodeHeightPrior()); |
| 374 |
|
| 375 |
groupCountField.setValue(partitionTreePrior.getSkylineGroupCount()); |
| 376 |
|
| 377 |
|
| 378 |
parameterizationCombo.setSelectedItem(partitionTreePrior.getParameterization()); |
| 379 |
bayesianSkylineCombo.setSelectedItem(partitionTreePrior.getSkylineModel()); |
| 380 |
|
| 381 |
extendedBayesianSkylineCombo.setSelectedItem(partitionTreePrior.getExtendedSkylineModel()); |
| 382 |
|
| 383 |
gmrfBayesianSkyrideCombo.setSelectedItem(partitionTreePrior.getSkyrideSmoothing()); |
| 384 |
|
| 385 |
|
| 386 |
skyGridPointsField.setValue(partitionTreePrior.getSkyGridCount()); |
| 387 |
|
| 388 |
double initialCutOff = partitionTreePrior.getOptions().getPartitionTreeModels().get(0).getInitialRootHeight(); |
| 389 |
final double arbitraryScalar = 1.0; |
| 390 |
initialCutOff = roundToSignificantFigures(arbitraryScalar * initialCutOff, 2); |
| 391 |
|
| 392 |
skyGridInterval.setAllowEmpty(true); |
| 393 |
|
| 394 |
if (Double.isNaN(partitionTreePrior.getSkyGridInterval())) { |
| 395 |
if (initialCutOff > 0.0) { |
| 396 |
skyGridInterval.setValue(initialCutOff); |
| 397 |
} else { |
| 398 |
skyGridInterval.setText((Double)null); |
| 399 |
} |
| 400 |
} else { |
| 401 |
skyGridInterval.setValue(partitionTreePrior.getSkyGridInterval()); |
| 402 |
} |
| 403 |
|
| 404 |
populationSizeCombo.setSelectedItem(partitionTreePrior.getPopulationSizeModel()); |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
setupPanel(); |
| 409 |
|
| 410 |
settingOptions = false; |
| 411 |
|
| 412 |
validate(); |
| 413 |
repaint(); |
| 414 |
} |
| 415 |
|
| 416 |
private static double roundToSignificantFigures(double num, int n) { |
| 417 |
if (num == 0) { |
| 418 |
return 0; |
| 419 |
} |
| 420 |
|
| 421 |
final double d = Math.ceil(Math.log10(num < 0 ? -num : num)); |
| 422 |
final int power = n - (int) d; |
| 423 |
|
| 424 |
final double magnitude = Math.pow(10, power); |
| 425 |
final long shifted = Math.round(num * magnitude); |
| 426 |
return shifted / magnitude; |
| 427 |
} |
| 428 |
|
| 429 |
public void getOptions() { |
| 430 |
if (settingOptions) return; |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
if (partitionTreePrior.getNodeHeightPrior() == TreePriorType.SKYLINE) { |
| 435 |
Integer groupCount = groupCountField.getValue(); |
| 436 |
if (groupCount != null) { |
| 437 |
partitionTreePrior.setSkylineGroupCount(groupCount); |
| 438 |
} else { |
| 439 |
partitionTreePrior.setSkylineGroupCount(5); |
| 440 |
} |
| 441 |
} else if (partitionTreePrior.getNodeHeightPrior() == TreePriorType.SKYGRID) { |
| 442 |
Double interval = skyGridInterval.getValue(); |
| 443 |
if (interval != null) { |
| 444 |
partitionTreePrior.setSkyGridInterval(interval); |
| 445 |
} else { |
| 446 |
partitionTreePrior.setSkyGridInterval(Double.NaN); |
| 447 |
} |
| 448 |
partitionTreePrior.setSkyGridCount(skyGridPointsField.getValue()); |
| 449 |
} else if (partitionTreePrior.getNodeHeightPrior() == TreePriorType.BIRTH_DEATH) { |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
} |
| 457 |
|
| 458 |
} |
| 459 |
|
| 460 |
public void setTreePriorChoices(boolean isMultiLocus, boolean isTipCalibrated) { |
| 461 |
TreePriorType type = (TreePriorType) treePriorCombo.getSelectedItem(); |
| 462 |
treePriorCombo.removeAllItems(); |
| 463 |
|
| 464 |
|
| 465 |
for (TreePriorType treePriorType : EnumSet.range(TreePriorType.CONSTANT, TreePriorType.BIRTH_DEATH_SERIAL_SAMPLING)) { |
| 466 |
treePriorCombo.addItem(treePriorType); |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
if (isMultiLocus) { |
| 475 |
treePriorCombo.removeItem(TreePriorType.SKYLINE); |
| 476 |
} |
| 477 |
|
| 478 |
if (isTipCalibrated) { |
| 479 |
|
| 480 |
treePriorCombo.removeItem(TreePriorType.YULE); |
| 481 |
treePriorCombo.removeItem(TreePriorType.YULE_CALIBRATION); |
| 482 |
treePriorCombo.removeItem(TreePriorType.BIRTH_DEATH); |
| 483 |
treePriorCombo.removeItem(TreePriorType.BIRTH_DEATH_INCOMPLETE_SAMPLING); |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
treePriorCombo.setSelectedItem(type); |
| 488 |
if (treePriorCombo.getSelectedItem() == null) { |
| 489 |
treePriorCombo.setSelectedIndex(0); |
| 490 |
} |
| 491 |
} |
| 492 |
} |