use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class RandomBranchAssignmentModelParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Logger.getLogger("dr.evomodel").info("\nUsing random assignment branch model.");
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
XMLObject cxo = xo.getChild(MODELS);
List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>();
for (int i = 0; i < cxo.getChildCount(); i++) {
SubstitutionModel substModel = (SubstitutionModel) cxo.getChild(i);
substitutionModels.add(substModel);
}
return new RandomBranchAssignmentModel(treeModel, substitutionModels);
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class RandomBranchModelParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Logger.getLogger("dr.evomodel").info("\nUsing random assignment branch model.");
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
GY94CodonModel baseSubstitutionModel = (GY94CodonModel) xo.getElementFirstChild(BASE_MODEL);
long seed = -1;
boolean hasSeed = false;
if (xo.hasAttribute(SEED)) {
seed = xo.getLongIntegerAttribute(SEED);
hasSeed = true;
}
double rate = 1;
if (xo.hasAttribute(RATE)) {
rate = xo.getDoubleAttribute(RATE);
}
return new RandomBranchModel(treeModel, baseSubstitutionModel, rate, hasSeed, seed);
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class BranchCategoriesParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
Parameter allocationParameter = (Parameter) xo.getElementFirstChild(ALLOCATION);
CountableBranchCategoryProvider cladeModel;
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
if (!xo.getAttribute(RANDOMIZE, true)) {
CountableBranchCategoryProvider.CladeBranchCategoryModel cm = new CountableBranchCategoryProvider.CladeBranchCategoryModel(treeModel, allocationParameter);
for (int i = 0; i < xo.getChildCount(); ++i) {
if (xo.getChild(i) instanceof XMLObject) {
XMLObject xoc = (XMLObject) xo.getChild(i);
if (xoc.getName().equals(LocalClockModelParser.CLADE)) {
TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
boolean includeStem = xoc.getAttribute(LocalClockModelParser.INCLUDE_STEM, false);
boolean excludeClade = xoc.getAttribute(LocalClockModelParser.EXCLUDE_CLADE, false);
// XML index-start = 1 not 0
int rateCategory = xoc.getIntegerAttribute(CATEGORY) - 1;
try {
cm.setClade(taxonList, rateCategory, includeStem, excludeClade, false);
} catch (TreeUtils.MissingTaxonException e) {
throw new XMLParseException("Unable to find taxon for clade in countable mixture model: " + e.getMessage());
}
} else if (xoc.getName().equals(LocalClockModelParser.TRUNK)) {
TaxonList taxonList = (TaxonList) xoc.getChild(TaxonList.class);
boolean includeStem = xoc.getAttribute(LocalClockModelParser.INCLUDE_STEM, false);
boolean excludeClade = xoc.getAttribute(LocalClockModelParser.EXCLUDE_CLADE, false);
// XML index-start = 1 not 0
int rateCategory = xoc.getIntegerAttribute(CATEGORY) - 1;
try {
cm.setClade(taxonList, rateCategory, includeStem, excludeClade, true);
} catch (TreeUtils.MissingTaxonException e) {
throw new XMLParseException("Unable to find taxon for trunk in countable mixture model: " + e.getMessage());
}
}
}
}
cladeModel = cm;
} else {
CountableBranchCategoryProvider.IndependentBranchCategoryModel cm = new CountableBranchCategoryProvider.IndependentBranchCategoryModel(treeModel, allocationParameter);
cm.randomize();
cladeModel = cm;
}
return cladeModel;
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class TKF91LikelihoodParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
Alignment alignment = (Alignment) xo.getChild(Alignment.class);
GammaSiteModel siteModel = (GammaSiteModel) xo.getChild(GammaSiteModel.class);
TKF91Model tkfModel = (TKF91Model) xo.getChild(TKF91Model.class);
return new TKF91Likelihood(tree, alignment, siteModel, tkfModel);
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class MicrosatelliteSamplerTreeLikelihood method traverse.
private void traverse() {
TreeModel tree = treeMicrosatSamplerModel.getTreeModel();
int updateNum = updatedNodeList.size();
for (int i = 0; i < updateNum; i++) {
NodeRef node = tree.getNode(updatedNodeList.get(i));
int nodeState = treeMicrosatSamplerModel.getNodeValue(node);
if (!tree.isRoot(node)) {
NodeRef parent = tree.getParent(node);
int parentState = treeMicrosatSamplerModel.getNodeValue(parent);
double branchLength = tree.getBranchLength(node) * branchRateModel.getBranchRate(tree, node);
double nodePr = microsatelliteModel.getLogOneTransitionProbabilityEntry(branchLength, parentState, nodeState);
treeMicrosatSamplerModel.setLogBranchLikelihood(node, nodePr);
} else {
double logEqFreq = Math.log(microsatelliteModel.getStationaryDistribution()[nodeState]);
treeMicrosatSamplerModel.setLogBranchLikelihood(node, logEqFreq);
}
}
}
Aggregations