Search in sources :

Example 21 with Taxa

use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.

the class TMRCAStatisticsGenerator method writeTaxonSets.

/**
 * Generate additional taxon sets
 *
 * @param writer    the writer
 * @param taxonSets a list of taxa to write
 */
public void writeTaxonSets(XMLWriter writer, List<Taxa> taxonSets) {
    writer.writeText("");
    for (Taxa taxa : taxonSets) {
        writer.writeOpenTag(TaxaParser.TAXA, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, taxa.getId()) });
        for (int j = 0; j < taxa.getTaxonCount(); j++) {
            writer.writeIDref(TaxonParser.TAXON, taxa.getTaxon(j).getId());
        }
        writer.writeCloseTag(TaxaParser.TAXA);
    }
}
Also used : Taxa(dr.evolution.util.Taxa) Attribute(dr.util.Attribute)

Example 22 with Taxa

use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.

the class TMRCAStatisticsGenerator method writeTMRCAStatistics.

/**
 * Generate tmrca statistics
 *
 * @param writer       the writer
 */
public void writeTMRCAStatistics(XMLWriter writer) {
    List<Taxa> taxonSets;
    Map<Taxa, Boolean> taxonSetsMono;
    taxonSets = options.taxonSets;
    taxonSetsMono = options.taxonSetsMono;
    writer.writeComment("Taxon Sets");
    writer.writeText("");
    for (Taxa taxa : taxonSets) {
        PartitionTreeModel treeModel = options.taxonSetsTreeModel.get(taxa);
        String id = "tmrca(" + treeModel.getPrefix() + taxa.getId() + ")";
        writeTMRCAStatistic(writer, id, taxa, treeModel, false, options.taxonSetsIncludeStem.get(taxa));
        if (treeModel.hasTipCalibrations()) {
            id = "age(" + treeModel.getPrefix() + taxa.getId() + ")";
            writeTMRCAStatistic(writer, id, taxa, treeModel, true, options.taxonSetsIncludeStem.get(taxa));
        }
        if (taxonSetsMono.get(taxa)) {
            // && treeModel.getPartitionTreePrior().getNodeHeightPrior() != TreePriorType.YULE
            // && options.getKeysFromValue(options.taxonSetsTreeModel, treeModel).size() > 1) {
            writer.writeOpenTag(MonophylyStatisticParser.MONOPHYLY_STATISTIC, new Attribute[] { new Attribute.Default<String>(XMLParser.ID, "monophyly(" + taxa.getId() + ")") });
            writer.writeOpenTag(MonophylyStatisticParser.MRCA);
            writer.writeIDref(TaxaParser.TAXA, taxa.getId());
            writer.writeCloseTag(MonophylyStatisticParser.MRCA);
            writer.writeIDref(DefaultTreeModel.TREE_MODEL, treeModel.getPrefix() + DefaultTreeModel.TREE_MODEL);
            writer.writeCloseTag(MonophylyStatisticParser.MONOPHYLY_STATISTIC);
        }
    }
}
Also used : Taxa(dr.evolution.util.Taxa) Attribute(dr.util.Attribute) PartitionTreeModel(dr.app.beauti.options.PartitionTreeModel)

Example 23 with Taxa

use of dr.evolution.util.Taxa 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 24 with Taxa

use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.

the class PartitionClockModel method selectParameters.

// From PartitionClockModelTreeModelLink
// public List<Parameter> selectParameters(List<Parameter> params) {
// setAvgRootAndRate();
// getParameter("branchRates.categories");
// getParameter("treeModel.rootRate");
// getParameter("treeModel.nodeRates");
// getParameter("treeModel.allRates");
// 
// if (options.hasData()) {
// // if not fixed then do mutation rate move and up/down move
// boolean fixed = !model.isEstimatedRate();
// 
// Parameter rateParam;
// 
// switch (model.getClockType()) {
// case AUTOCORRELATED:
// rateParam = getParameter("treeModel.rootRate");
// rateParam.isFixed = fixed;
// if (!fixed) params.add(rateParam);
// 
// params.add(getParameter("branchRates.var"));
// break;
// }
// }
// return params;
// }
@Override
public List<Parameter> selectParameters(List<Parameter> params) {
    // setAvgRootAndRate();
    double rate = 1.0;
    if (options.hasData()) {
        switch(clockType) {
            case STRICT_CLOCK:
                params.add(getClockRateParameter());
                break;
            case RANDOM_LOCAL_CLOCK:
                params.add(getClockRateParameter());
                getParameter(ClockType.LOCAL_CLOCK + ".changes");
                params.add(getParameter("rateChanges"));
                params.add(getParameter(ClockType.LOCAL_CLOCK + ".relativeRates"));
                break;
            case FIXED_LOCAL_CLOCK:
                params.add(getClockRateParameter());
                for (Taxa taxonSet : options.taxonSets) {
                    if (options.taxonSetsMono.get(taxonSet)) {
                        String parameterName = taxonSet.getId() + ".rate";
                        if (!hasParameter(parameterName)) {
                            new Parameter.Builder(parameterName, "substitution rate").prior(PriorType.CTMC_RATE_REFERENCE_PRIOR).initial(rate).isCMTCRate(true).isNonNegative(true).partitionOptions(this).taxonSet(taxonSet).build(parameters);
                            createScaleOperator(parameterName, demoTuning, rateWeights);
                        }
                        params.add(getParameter(taxonSet.getId() + ".rate"));
                    }
                }
                break;
            case UNCORRELATED:
                // in getClockRateParameter.
                switch(clockDistributionType) {
                    case LOGNORMAL:
                        params.add(getClockRateParameter());
                        params.add(getParameter(ClockType.UCLD_STDEV));
                        break;
                    case GAMMA:
                        params.add(getClockRateParameter());
                        params.add(getParameter(ClockType.UCGD_SHAPE));
                        break;
                    case CAUCHY:
                        throw new UnsupportedOperationException("Uncorrelated Cauchy clock not implemented yet");
                    // break;
                    case EXPONENTIAL:
                        params.add(getClockRateParameter());
                        break;
                    case MODEL_AVERAGING:
                        params.add(getClockRateParameter(ClockType.UNCORRELATED, ClockDistributionType.LOGNORMAL));
                        params.add(getParameter(ClockType.UCLD_STDEV));
                        params.add(getClockRateParameter(ClockType.UNCORRELATED, ClockDistributionType.GAMMA));
                        params.add(getParameter(ClockType.UCGD_SHAPE));
                        params.add(getClockRateParameter(ClockType.UNCORRELATED, ClockDistributionType.EXPONENTIAL));
                        params.add(getParameter("branchRates.quantiles"));
                        params.add(getParameter("branchRates.distributionIndex"));
                        break;
                }
                break;
            case AUTOCORRELATED:
                throw new UnsupportedOperationException("Autocorrelated clock not implemented yet");
            default:
                throw new IllegalArgumentException("Unknown clock model");
        }
    // Parameter rateParam = getClockRateParameter();
    // params.add(rateParam);
    }
    return params;
}
Also used : Taxa(dr.evolution.util.Taxa)

Example 25 with Taxa

use of dr.evolution.util.Taxa in project beast-mcmc by beast-dev.

the class TaxonSetPanel method setupTaxonSetsComboBox.

protected void setupTaxonSetsComboBox(JComboBox comboBox, List<Taxon> availableTaxa) {
    comboBox.removeAllItems();
    comboBox.addItem(TAXON.toLowerCase() + "...");
    for (Taxa taxa : options.taxonSets) {
        // AR - as these comboboxes are just intended to be handy ways of selecting taxa, I have removed
        // these requirements (it was just confusing why they weren't in the lists.
        // if (taxa != currentTaxonSet) {
        // if (isCompatible(taxa, availableTaxa)) {
        // have to add String, otherwise it will throw Exception to cast "taxa..." into Taxa
        comboBox.addItem(taxa.getId());
    // }
    // }
    }
}
Also used : Taxa(dr.evolution.util.Taxa)

Aggregations

Taxa (dr.evolution.util.Taxa)75 Taxon (dr.evolution.util.Taxon)34 ArrayList (java.util.ArrayList)23 Tree (dr.evolution.tree.Tree)19 TaxonList (dr.evolution.util.TaxonList)15 Attribute (dr.util.Attribute)13 DefaultTreeModel (dr.evomodel.tree.DefaultTreeModel)10 TreeModel (dr.evomodel.tree.TreeModel)10 Patterns (dr.evolution.alignment.Patterns)9 Microsatellite (dr.evolution.datatype.Microsatellite)9 IOException (java.io.IOException)8 NewickImporter (dr.evolution.io.NewickImporter)7 Parameter (dr.inference.model.Parameter)6 Date (dr.evolution.util.Date)5 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)5 SimpleAlignment (dr.evolution.alignment.SimpleAlignment)4 ImportException (dr.evolution.io.Importer.ImportException)4 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)4 CoalescentSimulator (dr.evomodel.coalescent.CoalescentSimulator)4 PartitionTreeModel (dr.app.beauti.options.PartitionTreeModel)3