Search in sources :

Example 1 with TreeTraitProvider

use of dr.evolution.tree.TreeTraitProvider in project beast-mcmc by beast-dev.

the class Utils method annotatedTreeModelToString.

// END: partitionDataListToString
// TODO: doesn't work
public static String annotatedTreeModelToString(TreeModel treeModel, LinkedHashMap<NodeRef, int[]> sequencesMap, DataType dataType) {
    StringBuffer buffer = new StringBuffer();
    NumberFormat format = NumberFormat.getNumberInstance(Locale.ENGLISH);
    boolean useTipLabels = true;
    AncestralSequenceTrait ancestralSequence = new AncestralSequenceTrait(sequencesMap, dataType);
    TreeTraitProvider[] treeTraitProviders = new TreeTraitProvider[] { ancestralSequence };
    // 
    TreeUtils.newick(// 
    treeModel, // 
    treeModel.getRoot(), // 
    useTipLabels, // 
    TreeUtils.BranchLengthType.LENGTHS_AS_TIME, // 
    format, // 
    null, // 
    treeTraitProviders, null, buffer);
    return buffer.toString();
}
Also used : AncestralSequenceTrait(dr.app.bss.test.AncestralSequenceTrait) TreeTraitProvider(dr.evolution.tree.TreeTraitProvider) NumberFormat(java.text.NumberFormat)

Example 2 with TreeTraitProvider

use of dr.evolution.tree.TreeTraitProvider in project beast-mcmc by beast-dev.

the class ContinuousDataLikelihoodDelegate method addNewFullConditionalDensityTrait.

public void addNewFullConditionalDensityTrait(String traitName) {
    ProcessSimulationDelegate gradientDelegate = new NewTipFullConditionalDistributionDelegate(traitName, getCallbackLikelihood().getTree(), getDiffusionModel(), getDataModel(), getRootPrior(), getRateTransformation(), this);
    TreeTraitProvider traitProvider = new ProcessSimulation(getCallbackLikelihood(), gradientDelegate);
    getCallbackLikelihood().addTraits(traitProvider.getTreeTraits());
}
Also used : TreeTraitProvider(dr.evolution.tree.TreeTraitProvider)

Example 3 with TreeTraitProvider

use of dr.evolution.tree.TreeTraitProvider in project beast-mcmc by beast-dev.

the class ContinuousDataLikelihoodDelegate method addWrappedFullConditionalDensityTrait.

public void addWrappedFullConditionalDensityTrait(String traitName) {
    ProcessSimulationDelegate gradientDelegate = new WrappedTipFullConditionalDistributionDelegate(traitName, getCallbackLikelihood().getTree(), getDiffusionModel(), getDataModel(), getRootPrior(), getRateTransformation(), this);
    TreeTraitProvider traitProvider = new ProcessSimulation(getCallbackLikelihood(), gradientDelegate);
    getCallbackLikelihood().addTraits(traitProvider.getTreeTraits());
}
Also used : TreeTraitProvider(dr.evolution.tree.TreeTraitProvider)

Example 4 with TreeTraitProvider

use of dr.evolution.tree.TreeTraitProvider in project beast-mcmc by beast-dev.

the class DiscreteTraitBranchRateModelParser method parseXMLObject.

public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
    PatternList patternList = (PatternList) xo.getChild(PatternList.class);
    TreeTraitProvider traitProvider = (TreeTraitProvider) xo.getChild(TreeTraitProvider.class);
    DataType dataType = DataTypeUtils.getDataType(xo);
    Parameter rateParameter = null;
    Parameter relativeRatesParameter = null;
    Parameter indicatorsParameter = null;
    if (xo.getChild(RATE) != null) {
        rateParameter = (Parameter) xo.getElementFirstChild(RATE);
    }
    if (xo.getChild(RATES) != null) {
        rateParameter = (Parameter) xo.getElementFirstChild(RATES);
    }
    if (xo.getChild(RELATIVE_RATES) != null) {
        relativeRatesParameter = (Parameter) xo.getElementFirstChild(RELATIVE_RATES);
    }
    if (xo.getChild(INDICATORS) != null) {
        indicatorsParameter = (Parameter) xo.getElementFirstChild(INDICATORS);
    }
    int traitIndex = xo.getAttribute(TRAIT_INDEX, 1) - 1;
    String traitName = "states";
    Logger.getLogger("dr.evomodel").info("Using discrete trait branch rate model.\n" + "\tIf you use this model, please cite:\n" + "\t\tDrummond and Suchard (in preparation)");
    if (traitProvider == null) {
        // Use the version that reconstructs the trait using parsimony:
        return new DiscreteTraitBranchRateModel(treeModel, patternList, traitIndex, rateParameter);
    } else {
        if (traitName != null) {
            TreeTrait trait = traitProvider.getTreeTrait(traitName);
            if (trait == null) {
                throw new XMLParseException("A trait called, " + traitName + ", was not available from the TreeTraitProvider supplied to " + getParserName() + ", with ID " + xo.getId());
            }
            if (relativeRatesParameter != null) {
                return new DiscreteTraitBranchRateModel(traitProvider, dataType, treeModel, trait, traitIndex, rateParameter, relativeRatesParameter, indicatorsParameter);
            } else {
                return new DiscreteTraitBranchRateModel(traitProvider, dataType, treeModel, trait, traitIndex, rateParameter);
            }
        } else {
            TreeTrait[] traits = new TreeTrait[dataType.getStateCount()];
            for (int i = 0; i < dataType.getStateCount(); i++) {
                traits[i] = traitProvider.getTreeTrait(dataType.getCode(i));
                if (traits[i] == null) {
                    throw new XMLParseException("A trait called, " + dataType.getCode(i) + ", was not available from the TreeTraitProvider supplied to " + getParserName() + ", with ID " + xo.getId());
                }
            }
            return new DiscreteTraitBranchRateModel(traitProvider, traits, treeModel, rateParameter);
        }
    }
}
Also used : TreeModel(dr.evomodel.tree.TreeModel) TreeTraitProvider(dr.evolution.tree.TreeTraitProvider) PatternList(dr.evolution.alignment.PatternList) DataType(dr.evolution.datatype.DataType) Parameter(dr.inference.model.Parameter) DiscreteTraitBranchRateModel(dr.evomodel.branchratemodel.DiscreteTraitBranchRateModel) TreeTrait(dr.evolution.tree.TreeTrait)

Example 5 with TreeTraitProvider

use of dr.evolution.tree.TreeTraitProvider in project beast-mcmc by beast-dev.

the class TransformedTreeTraitParser method parseXMLObject.

@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
    TreeTraitProvider treeTraits = (TreeTraitProvider) xo.getChild(TreeTraitProvider.class);
    Transform transform = (Transform) xo.getChild(Transform.class);
    return new TransformedTreeTraitProvider(treeTraits, transform);
}
Also used : TransformedTreeTraitProvider(dr.evolution.tree.TransformedTreeTraitProvider) TreeTraitProvider(dr.evolution.tree.TreeTraitProvider) Transform(dr.util.Transform) TransformedTreeTraitProvider(dr.evolution.tree.TransformedTreeTraitProvider)

Aggregations

TreeTraitProvider (dr.evolution.tree.TreeTraitProvider)13 Tree (dr.evolution.tree.Tree)3 TreeTrait (dr.evolution.tree.TreeTrait)3 DataType (dr.evolution.datatype.DataType)2 ProcessSimulation (dr.evomodel.treedatalikelihood.ProcessSimulation)2 TreeDataLikelihood (dr.evomodel.treedatalikelihood.TreeDataLikelihood)2 NumberFormat (java.text.NumberFormat)2 AncestralSequenceTrait (dr.app.bss.test.AncestralSequenceTrait)1 PatternList (dr.evolution.alignment.PatternList)1 ImportException (dr.evolution.io.Importer.ImportException)1 NewickImporter (dr.evolution.io.NewickImporter)1 NodeRef (dr.evolution.tree.NodeRef)1 TransformedTreeTraitProvider (dr.evolution.tree.TransformedTreeTraitProvider)1 TreeUtils (dr.evolution.tree.TreeUtils)1 TaxonList (dr.evolution.util.TaxonList)1 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)1 DefaultBranchRateModel (dr.evomodel.branchratemodel.DefaultBranchRateModel)1 DiscreteTraitBranchRateModel (dr.evomodel.branchratemodel.DiscreteTraitBranchRateModel)1 MultivariateDiffusionModel (dr.evomodel.continuous.MultivariateDiffusionModel)1 MultivariateElasticModel (dr.evomodel.continuous.MultivariateElasticModel)1