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();
}
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());
}
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());
}
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);
}
}
}
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);
}
Aggregations