Search in sources :

Example 1 with TreePriorType

use of dr.app.beauti.types.TreePriorType in project beast-mcmc by beast-dev.

the class STARBEASTGenerator method writeSpeciesTreePrior.

private void writeSpeciesTreePrior(XMLWriter writer) {
    Parameter para;
    TreePriorType nodeHeightPrior = options.getPartitionTreePriors().get(0).getNodeHeightPrior();
    if (nodeHeightPrior == TreePriorType.SPECIES_BIRTH_DEATH) {
        writer.writeComment("Species tree prior: Birth Death Model");
        writer.writeOpenTag(BirthDeathModelParser.BIRTH_DEATH_MODEL, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, BirthDeathModelParser.BIRTH_DEATH), new Attribute.Default<String>(XMLUnits.UNITS, XMLUnits.SUBSTITUTIONS) });
        writer.writeOpenTag(BirthDeathModelParser.BIRTHDIFF_RATE);
        para = options.starBEASTOptions.getParameter(TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.MEAN_GROWTH_RATE_PARAM_NAME);
        //            writer.writeTag(ParameterParser.PARAMETER, new Attribute[]{
        //                    new Attribute.Default<String>(XMLParser.ID, TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.MEAN_GROWTH_RATE_PARAM_NAME),
        //                    new Attribute.Default<String>(ParameterParser.VALUE, Double.toString(para.initial)),
        //                    new Attribute.Default<String>(ParameterParser.LOWER, Double.toString(para.lower)),
        //                    new Attribute.Default<String>(ParameterParser.UPPER, Double.toString(para.upper))}, true);
        writeParameter(TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.MEAN_GROWTH_RATE_PARAM_NAME, para, writer);
        writer.writeCloseTag(BirthDeathModelParser.BIRTHDIFF_RATE);
        writer.writeOpenTag(BirthDeathModelParser.RELATIVE_DEATH_RATE);
        para = options.starBEASTOptions.getParameter(TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.RELATIVE_DEATH_RATE_PARAM_NAME);
        //            writer.writeTag(ParameterParser.PARAMETER, new Attribute[]{
        //                    new Attribute.Default<String>(XMLParser.ID, TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.RELATIVE_DEATH_RATE_PARAM_NAME),
        //                    new Attribute.Default<String>(ParameterParser.VALUE, Double.toString(para.initial)),
        //                    new Attribute.Default<String>(ParameterParser.LOWER, Double.toString(para.lower)),
        //                    new Attribute.Default<String>(ParameterParser.UPPER, Double.toString(para.upper))}, true);
        writeParameter(TraitData.TRAIT_SPECIES + "." + BirthDeathModelParser.RELATIVE_DEATH_RATE_PARAM_NAME, para, writer);
        writer.writeCloseTag(BirthDeathModelParser.RELATIVE_DEATH_RATE);
        writer.writeCloseTag(BirthDeathModelParser.BIRTH_DEATH_MODEL);
    } else if (nodeHeightPrior == TreePriorType.SPECIES_YULE || nodeHeightPrior == TreePriorType.SPECIES_YULE_CALIBRATION) {
        writer.writeComment("Species tree prior: Yule Model");
        writer.writeOpenTag(YuleModelParser.YULE_MODEL, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, YuleModelParser.YULE), new Attribute.Default<String>(XMLUnits.UNITS, XMLUnits.SUBSTITUTIONS) });
        writer.writeOpenTag(YuleModelParser.BIRTH_RATE);
        para = options.starBEASTOptions.getParameter(TraitData.TRAIT_SPECIES + "." + YuleModelParser.YULE + "." + YuleModelParser.BIRTH_RATE);
        //            writer.writeTag(ParameterParser.PARAMETER, new Attribute[]{
        //                    new Attribute.Default<String>(XMLParser.ID, TraitData.TRAIT_SPECIES + "." + YuleModelParser.YULE + "." + YuleModelParser.BIRTH_RATE),
        //                    new Attribute.Default<String>(ParameterParser.VALUE, Double.toString(para.initial)),
        //                    new Attribute.Default<String>(ParameterParser.LOWER, Double.toString(para.lower)),
        //                    new Attribute.Default<String>(ParameterParser.UPPER, Double.toString(para.upper))}, true);
        writeParameter(TraitData.TRAIT_SPECIES + "." + YuleModelParser.YULE + "." + YuleModelParser.BIRTH_RATE, para, writer);
        writer.writeCloseTag(YuleModelParser.BIRTH_RATE);
        writer.writeCloseTag(YuleModelParser.YULE_MODEL);
    } else if (nodeHeightPrior == TreePriorType.SPECIES_YULE_CALIBRATION) {
    } else {
        throw new IllegalArgumentException("Get wrong species tree prior using *BEAST : " + nodeHeightPrior.toString());
    }
}
Also used : Attribute(dr.util.Attribute) Parameter(dr.app.beauti.options.Parameter) TreePriorType(dr.app.beauti.types.TreePriorType)

Example 2 with TreePriorType

use of dr.app.beauti.types.TreePriorType in project beast-mcmc by beast-dev.

the class TreePriorGenerator method writeNodeHeightPriorModelRef.

void writeNodeHeightPriorModelRef(PartitionTreePrior prior, XMLWriter writer) {
    TreePriorType treePrior = prior.getNodeHeightPrior();
    String priorPrefix = prior.getPrefix();
    switch(treePrior) {
        case CONSTANT:
            writer.writeIDref(ConstantPopulationModelParser.CONSTANT_POPULATION_MODEL, priorPrefix + "constant");
            break;
        case EXPONENTIAL:
            writer.writeIDref(ExponentialGrowthModelParser.EXPONENTIAL_GROWTH_MODEL, priorPrefix + "exponential");
            break;
        case LOGISTIC:
            writer.writeIDref(LogisticGrowthModelParser.LOGISTIC_GROWTH_MODEL, priorPrefix + "logistic");
            break;
        case EXPANSION:
            writer.writeIDref(ExpansionModelParser.EXPANSION_MODEL, priorPrefix + "expansion");
            break;
        case SKYLINE:
            writer.writeIDref(BayesianSkylineLikelihoodParser.SKYLINE_LIKELIHOOD, priorPrefix + "skyline");
            break;
        case GMRF_SKYRIDE:
            writer.writeIDref(GMRFSkyrideLikelihoodParser.SKYLINE_LIKELIHOOD, priorPrefix + "skyride");
            break;
        case SKYGRID:
            writer.writeIDref(GMRFSkyrideLikelihoodParser.SKYGRID_LIKELIHOOD, priorPrefix + "skygrid");
            break;
        case YULE:
        case YULE_CALIBRATION:
            writer.writeIDref(YuleModelParser.YULE_MODEL, priorPrefix + YuleModelParser.YULE);
            break;
        case BIRTH_DEATH:
        case BIRTH_DEATH_INCOMPLETE_SAMPLING:
            writer.writeIDref(BirthDeathModelParser.BIRTH_DEATH_MODEL, priorPrefix + BirthDeathModelParser.BIRTH_DEATH);
            break;
        case BIRTH_DEATH_SERIAL_SAMPLING:
            writer.writeIDref(BirthDeathSerialSamplingModelParser.BIRTH_DEATH_SERIAL_MODEL, priorPrefix + BirthDeathSerialSamplingModelParser.BDSS);
            break;
        case BIRTH_DEATH_BASIC_REPRODUCTIVE_NUMBER:
            writer.writeIDref(BirthDeathEpidemiologyModelParser.BIRTH_DEATH_EPIDEMIOLOGY, priorPrefix + BirthDeathEpidemiologyModelParser.BIRTH_DEATH_EPIDEMIOLOGY);
            break;
        default:
            throw new IllegalArgumentException("No tree prior has been specified so cannot refer to it");
    }
}
Also used : TreePriorType(dr.app.beauti.types.TreePriorType)

Example 3 with TreePriorType

use of dr.app.beauti.types.TreePriorType in project beast-mcmc by beast-dev.

the class TreePriorGenerator method writePriorLikelihood.

/**
 * Write the prior on node heights (coalescent or speciational models)
 *
 * @param model  PartitionTreeModel
 * @param writer the writer
 */
void writePriorLikelihood(PartitionTreeModel model, XMLWriter writer) {
    // tree model prefix
    String prefix = model.getPrefix();
    PartitionTreePrior prior = model.getPartitionTreePrior();
    TreePriorType treePrior = prior.getNodeHeightPrior();
    switch(treePrior) {
        case YULE:
        case BIRTH_DEATH:
        case BIRTH_DEATH_INCOMPLETE_SAMPLING:
        case BIRTH_DEATH_SERIAL_SAMPLING:
        case BIRTH_DEATH_BASIC_REPRODUCTIVE_NUMBER:
        case YULE_CALIBRATION:
            // generate a speciational process
            writer.writeComment("Generate a speciation likelihood for Yule or Birth Death");
            writer.writeOpenTag(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, prefix + "speciation") });
            // write pop size socket
            writer.writeOpenTag(SpeciationLikelihoodParser.MODEL);
            writeNodeHeightPriorModelRef(prior, writer);
            writer.writeCloseTag(SpeciationLikelihoodParser.MODEL);
            writer.writeOpenTag(SpeciationLikelihoodParser.TREE);
            writer.writeIDref(DefaultTreeModel.TREE_MODEL, prefix + DefaultTreeModel.TREE_MODEL);
            writer.writeCloseTag(SpeciationLikelihoodParser.TREE);
            if (treePrior == TreePriorType.YULE_CALIBRATION) {
                if (options.treeModelOptions.isNodeCalibrated(model) == 0) {
                    writer.writeOpenTag(SpeciationLikelihoodParser.CALIBRATION, new Attribute[] { new Attribute.Default<String>(SpeciationLikelihoodParser.CORRECTION, prior.getCalibCorrectionType().toString()) });
                    writer.writeOpenTag(SpeciationLikelihoodParser.POINT);
                    String taxaId;
                    if (options.hasIdenticalTaxa()) {
                        taxaId = TaxaParser.TAXA;
                    } else {
                        taxaId = options.getDataPartitions(model).get(0).getPrefix() + TaxaParser.TAXA;
                    }
                    writer.writeIDref(TaxaParser.TAXA, taxaId);
                    writeDistribution(model.getParameter("treeModel.rootHeight"), true, writer);
                    writer.writeCloseTag(SpeciationLikelihoodParser.POINT);
                    writer.writeCloseTag(SpeciationLikelihoodParser.CALIBRATION);
                } else if (options.treeModelOptions.isNodeCalibrated(model) == 1) {
                    // should be only 1 calibrated internal node with monophyletic for each tree at moment
                    Taxa t = (Taxa) options.getKeysFromValue(options.taxonSetsTreeModel, model).get(0);
                    Parameter nodeCalib = options.getStatistic(t);
                    writer.writeOpenTag(SpeciationLikelihoodParser.CALIBRATION, new Attribute[] { new Attribute.Default<String>(SpeciationLikelihoodParser.CORRECTION, prior.getCalibCorrectionType().toString()) });
                    writer.writeOpenTag(SpeciationLikelihoodParser.POINT);
                    writer.writeIDref(TaxaParser.TAXA, t.getId());
                    writeDistribution(nodeCalib, true, writer);
                    writer.writeCloseTag(SpeciationLikelihoodParser.POINT);
                    writer.writeCloseTag(SpeciationLikelihoodParser.CALIBRATION);
                    if (!options.treeModelOptions.isNodeCalibrated(nodeCalib)) {
                        throw new IllegalArgumentException("Calibrated Yule model requires a calibration to be specified for node, " + nodeCalib.getName() + ".");
                    }
                }
            }
            writer.writeCloseTag(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD);
            break;
        case SKYLINE:
            // generate a Bayesian skyline plot
            writer.writeComment("Generate a generalizedSkyLineLikelihood for Bayesian Skyline");
            writer.writeOpenTag(BayesianSkylineLikelihoodParser.SKYLINE_LIKELIHOOD, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, prefix + "skyline"), new Attribute.Default<String>("linear", prior.getSkylineModel() == TreePriorParameterizationType.LINEAR_SKYLINE ? "true" : "false") });
            // write pop size socket
            writer.writeOpenTag(BayesianSkylineLikelihoodParser.POPULATION_SIZES);
            if (prior.getSkylineModel() == TreePriorParameterizationType.LINEAR_SKYLINE) {
                writeParameter(prior.getParameter("skyline.popSize"), prior.getSkylineGroupCount() + 1, writer);
            } else {
                writeParameter(prior.getParameter("skyline.popSize"), prior.getSkylineGroupCount(), writer);
            }
            writer.writeCloseTag(BayesianSkylineLikelihoodParser.POPULATION_SIZES);
            // write group size socket
            writer.writeOpenTag(BayesianSkylineLikelihoodParser.GROUP_SIZES);
            writeParameter(prior.getParameter("skyline.groupSize"), prior.getSkylineGroupCount(), writer);
            writer.writeCloseTag(BayesianSkylineLikelihoodParser.GROUP_SIZES);
            writer.writeOpenTag(CoalescentLikelihoodParser.POPULATION_TREE);
            writer.writeIDref(DefaultTreeModel.TREE_MODEL, prefix + DefaultTreeModel.TREE_MODEL);
            writer.writeCloseTag(CoalescentLikelihoodParser.POPULATION_TREE);
            writer.writeCloseTag(BayesianSkylineLikelihoodParser.SKYLINE_LIKELIHOOD);
            writer.writeText("");
            writeExponentialMarkovLikelihood(prior, writer);
            break;
        case EXTENDED_SKYLINE:
            // different format
            break;
        case GMRF_SKYRIDE:
            writer.writeComment("Generate a gmrfSkyrideLikelihood for GMRF Bayesian Skyride process");
            writer.writeOpenTag(GMRFSkyrideLikelihoodParser.SKYLINE_LIKELIHOOD, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, prefix + "skyride"), new Attribute.Default<String>(GMRFSkyrideLikelihoodParser.TIME_AWARE_SMOOTHING, prior.getSkyrideSmoothing() == TreePriorParameterizationType.TIME_AWARE_SKYRIDE ? "true" : "false"), new Attribute.Default<String>(GMRFSkyrideLikelihoodParser.RANDOMIZE_TREE, // TODO For GMRF, tree model/tree prior combination not implemented by BEAST yet. The validation is in BeastGenerator.checkOptions()
            options.getPartitionTreeModels(prior).get(0).getStartingTreeType() == StartingTreeType.UPGMA ? "true" : "false") });
            int skyrideIntervalCount = options.taxonList.getTaxonCount() - 1;
            writer.writeOpenTag(GMRFSkyrideLikelihoodParser.POPULATION_PARAMETER);
            writer.writeComment("skyride.logPopSize is in log units unlike other popSize");
            writeParameter(prior.getParameter("skyride.logPopSize"), skyrideIntervalCount, writer);
            writer.writeCloseTag(GMRFSkyrideLikelihoodParser.POPULATION_PARAMETER);
            writer.writeOpenTag(GMRFSkyrideLikelihoodParser.GROUP_SIZES);
            writeParameter(prior.getParameter("skyride.groupSize"), skyrideIntervalCount, writer);
            writer.writeCloseTag(GMRFSkyrideLikelihoodParser.GROUP_SIZES);
            writer.writeOpenTag(GMRFSkyrideLikelihoodParser.PRECISION_PARAMETER);
            writeParameter(prior.getParameter("skyride.precision"), 1, writer);
            writer.writeCloseTag(GMRFSkyrideLikelihoodParser.PRECISION_PARAMETER);
            writer.writeOpenTag(GMRFSkyrideLikelihoodParser.POPULATION_TREE);
            writer.writeIDref(DefaultTreeModel.TREE_MODEL, prefix + DefaultTreeModel.TREE_MODEL);
            writer.writeCloseTag(GMRFSkyrideLikelihoodParser.POPULATION_TREE);
            writer.writeCloseTag(GMRFSkyrideLikelihoodParser.SKYLINE_LIKELIHOOD);
            break;
        case SKYGRID:
            break;
        default:
            // generate a coalescent process
            writer.writeComment("Generate a coalescent likelihood");
            writer.writeOpenTag(CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, prefix + COALESCENT) });
            writer.writeOpenTag(CoalescentLikelihoodParser.MODEL);
            writeNodeHeightPriorModelRef(prior, writer);
            writer.writeCloseTag(CoalescentLikelihoodParser.MODEL);
            writer.writeOpenTag(CoalescentLikelihoodParser.POPULATION_TREE);
            writer.writeIDref(DefaultTreeModel.TREE_MODEL, prefix + DefaultTreeModel.TREE_MODEL);
            writer.writeCloseTag(CoalescentLikelihoodParser.POPULATION_TREE);
            writer.writeCloseTag(CoalescentLikelihoodParser.COALESCENT_LIKELIHOOD);
    }
}
Also used : Taxa(dr.evolution.util.Taxa) Attribute(dr.util.Attribute) TreePriorType(dr.app.beauti.types.TreePriorType)

Example 4 with TreePriorType

use of dr.app.beauti.types.TreePriorType in project beast-mcmc by beast-dev.

the class PartitionTreePriorPanel method setTreePriorChoices.

public void setTreePriorChoices(boolean isMultiLocus, boolean isTipCalibrated) {
    TreePriorType type = (TreePriorType) treePriorCombo.getSelectedItem();
    treePriorCombo.removeAllItems();
    for (TreePriorType treePriorType : EnumSet.range(TreePriorType.CONSTANT, TreePriorType.BIRTH_DEATH_SERIAL_SAMPLING)) {
        treePriorCombo.addItem(treePriorType);
    }
    // would be much better to disable these rather than removing them
    if (isMultiLocus) {
        treePriorCombo.removeItem(TreePriorType.SKYLINE);
    }
    if (isTipCalibrated) {
        // remove models that require contemporaneous tips...
        treePriorCombo.removeItem(TreePriorType.YULE);
        treePriorCombo.removeItem(TreePriorType.YULE_CALIBRATION);
        treePriorCombo.removeItem(TreePriorType.BIRTH_DEATH);
        treePriorCombo.removeItem(TreePriorType.BIRTH_DEATH_INCOMPLETE_SAMPLING);
    }
    // this makes sure treePriorCombo selects correct prior
    treePriorCombo.setSelectedItem(type);
    if (treePriorCombo.getSelectedItem() == null) {
        treePriorCombo.setSelectedIndex(0);
    }
}
Also used : TreePriorType(dr.app.beauti.types.TreePriorType)

Example 5 with TreePriorType

use of dr.app.beauti.types.TreePriorType in project beast-mcmc by beast-dev.

the class STARBEASTGenerator method writeSpeciesTreeLikelihood.

private void writeSpeciesTreeLikelihood(XMLWriter writer) {
    TreePriorType nodeHeightPrior = options.getPartitionTreePriors().get(0).getNodeHeightPrior();
    if (nodeHeightPrior == TreePriorType.SPECIES_BIRTH_DEATH) {
        writer.writeComment("Species Tree Likelihood: Birth Death Model");
        writer.writeOpenTag(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, SPECIATION_LIKE) });
        writer.writeOpenTag(SpeciationLikelihoodParser.MODEL);
        writer.writeIDref(BirthDeathModelParser.BIRTH_DEATH_MODEL, BirthDeathModelParser.BIRTH_DEATH);
        writer.writeCloseTag(SpeciationLikelihoodParser.MODEL);
    } else if (nodeHeightPrior == TreePriorType.SPECIES_YULE || nodeHeightPrior == TreePriorType.SPECIES_YULE_CALIBRATION) {
        writer.writeComment("Species Tree Likelihood: Yule Model");
        writer.writeOpenTag(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, SPECIATION_LIKE) });
        writer.writeOpenTag(SpeciationLikelihoodParser.MODEL);
        writer.writeIDref(YuleModelParser.YULE_MODEL, YuleModelParser.YULE);
        writer.writeCloseTag(SpeciationLikelihoodParser.MODEL);
        if (nodeHeightPrior == TreePriorType.SPECIES_YULE_CALIBRATION) {
            // should be only 1 calibrated node with monophyletic for species tree at moment
            if (options.speciesSets.size() == 1 && options.speciesSetsMono.size() == 1) {
                Taxa t = options.speciesSets.get(0);
                Parameter nodeCalib = options.getStatistic(t);
                writer.writeOpenTag(SpeciationLikelihoodParser.CALIBRATION, new Attribute[] { new Attribute.Default<String>(SpeciationLikelihoodParser.CORRECTION, CalibrationPoints.CorrectionType.EXACT.toString()) });
                writer.writeOpenTag(SpeciationLikelihoodParser.POINT);
                writer.writeIDref(TaxaParser.TAXA, t.getId());
                writeDistribution(nodeCalib, true, writer);
                writer.writeCloseTag(SpeciationLikelihoodParser.POINT);
                writer.writeCloseTag(SpeciationLikelihoodParser.CALIBRATION);
                if (!options.treeModelOptions.isNodeCalibrated(nodeCalib)) {
                }
            } else {
                throw new IllegalArgumentException("Calibrated Yule model is only applied to 1 calibrated node with monophyletic for species tree at moment !");
            }
        }
    } else {
        throw new IllegalArgumentException("Get wrong species tree prior using *BEAST : " + nodeHeightPrior.toString());
    }
    // <sp> tree
    writer.writeOpenTag(SpeciesTreeModelParser.SPECIES_TREE);
    writer.writeIDref(SpeciesTreeModelParser.SPECIES_TREE, SP_TREE);
    writer.writeCloseTag(SpeciesTreeModelParser.SPECIES_TREE);
    writer.writeCloseTag(SpeciationLikelihoodParser.SPECIATION_LIKELIHOOD);
}
Also used : Taxa(dr.evolution.util.Taxa) Attribute(dr.util.Attribute) Parameter(dr.app.beauti.options.Parameter) TreePriorType(dr.app.beauti.types.TreePriorType)

Aggregations

TreePriorType (dr.app.beauti.types.TreePriorType)8 Attribute (dr.util.Attribute)4 Parameter (dr.app.beauti.options.Parameter)2 Taxa (dr.evolution.util.Taxa)2 PartitionTreeModel (dr.app.beauti.options.PartitionTreeModel)1 TreePriorParameterizationType (dr.app.beauti.types.TreePriorParameterizationType)1 Units (dr.evolution.util.Units)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 EmptyBorder (javax.swing.border.EmptyBorder)1