use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class CodonPartitionedRobustCountingParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
AncestralStateBeagleTreeLikelihood[] partition = new AncestralStateBeagleTreeLikelihood[3];
String[] labels = new String[] { FIRST, SECOND, THIRD };
int patternCount = -1;
BranchRateModel testBranchRateModel = null;
for (int i = 0; i < 3; i++) {
partition[i] = (AncestralStateBeagleTreeLikelihood) xo.getChild(labels[i]).getChild(AncestralStateBeagleTreeLikelihood.class);
if (i == 0) {
patternCount = partition[i].getPatternCount();
} else {
if (partition[i].getPatternCount() != patternCount) {
throw new XMLParseException("Codon-partitioned robust counting requires all partitions to have the same length." + " Make sure that partitions include all unique sites and do not strip gaps.");
}
}
// Ensure that siteRateModel has one category
if (partition[i].getSiteRateModel().getCategoryCount() > 1) {
throw new XMLParseException("Robust counting currently only implemented for single category models");
}
// Ensure that branchRateModel is the same across all partitions
if (testBranchRateModel == null) {
testBranchRateModel = partition[i].getBranchRateModel();
} else if (testBranchRateModel != partition[i].getBranchRateModel()) {
throw new XMLParseException("Robust counting currently requires the same branch rate model for all partitions");
}
}
TreeModel tree = (TreeModel) xo.getChild(TreeModel.class);
Codons codons = Codons.UNIVERSAL;
if (xo.hasAttribute(GeneticCode.GENETIC_CODE)) {
String codeStr = xo.getStringAttribute(GeneticCode.GENETIC_CODE);
codons = Codons.findByName(codeStr);
}
String labelingString = (String) xo.getAttribute(LABELING);
CodonLabeling codonLabeling = CodonLabeling.parseFromString(labelingString);
if (codonLabeling == null) {
throw new XMLParseException("Unrecognized codon labeling '" + labelingString + "'");
}
String branchFormatString = xo.getAttribute(BRANCH_FORMAT, StratifiedTraitOutputFormat.SUM_OVER_SITES.getText());
StratifiedTraitOutputFormat branchFormat = StratifiedTraitOutputFormat.parseFromString(branchFormatString);
if (branchFormat == null) {
throw new XMLParseException("Unrecognized branch output format '" + branchFormat + "'");
}
String logFormatString = xo.getAttribute(LOG_FORMAT, StratifiedTraitOutputFormat.SUM_OVER_SITES.getText());
StratifiedTraitOutputFormat logFormat = StratifiedTraitOutputFormat.parseFromString(logFormatString);
if (logFormat == null) {
throw new XMLParseException("Unrecognized log output format '" + branchFormat + "'");
}
boolean useUniformization = xo.getAttribute(USE_UNIFORMIZATION, false);
boolean includeExternalBranches = xo.getAttribute(INCLUDE_EXTERNAL, true);
boolean includeInternalBranches = xo.getAttribute(INCLUDE_INTERNAL, true);
boolean doUnconditionedPerBranch = xo.getAttribute(DO_UNCONDITIONED_PER_BRANCH, false);
boolean averageRates = xo.getAttribute(AVERAGE_RATES, true);
boolean saveCompleteHistory = xo.getAttribute(SAVE_HISTORY, false);
boolean useNewNeutralModel = xo.getAttribute(USE_NEW_NEUTRAL_MODEL, false);
String prefix = xo.hasAttribute(PREFIX) ? xo.getStringAttribute(PREFIX) : null;
return new CodonPartitionedRobustCounting(xo.getId(), tree, partition, codons, codonLabeling, useUniformization, includeExternalBranches, includeInternalBranches, doUnconditionedPerBranch, saveCompleteHistory, averageRates, useNewNeutralModel, branchFormat, logFormat, prefix);
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class TreeUniformParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
final double weight = xo.getDoubleAttribute(MCMCOperator.WEIGHT);
final int n = xo.getAttribute(COUNT, 2);
if (!(n == 2 || n == 3)) {
throw new XMLParseException("Sorry, only moves of 2 or 3 nodes implemented.");
}
return new TreeUniform(n, treeModel, weight);
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class CTMCScalePriorParser method parseXMLObject.
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
Parameter ctmcScale = (Parameter) xo.getElementFirstChild(SCALEPARAMETER);
boolean reciprocal = xo.getAttribute(RECIPROCAL, false);
boolean trial = xo.getAttribute(TRIAL, false);
SubstitutionModel substitutionModel = (SubstitutionModel) xo.getChild(SubstitutionModel.class);
Logger.getLogger("dr.evolution").info("Creating CTMC Scale Reference Prior model.");
return new CTMCScalePrior(MODEL_NAME, ctmcScale, treeModel, reciprocal, substitutionModel, trial);
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class MsatFullLikelihoodTest method setUp.
public void setUp() throws Exception {
super.setUp();
//taxa
ArrayList<Taxon> taxonList1 = new ArrayList<Taxon>();
Collections.addAll(taxonList1, new Taxon("taxon1"), new Taxon("taxon2"), new Taxon("taxon3"));
Taxa taxa1 = new Taxa(taxonList1);
//msat datatype
Microsatellite msat = new Microsatellite(1, 3);
Patterns msatPatterns = new Patterns(msat, taxa1);
//pattern in the correct code form.
msatPatterns.addPattern(new int[] { 0, 1, 2 });
//create tree
NewickImporter importer = new NewickImporter("(taxon1:7.5,(taxon2:5.3,taxon3:5.3):2.2);");
Tree tree = importer.importTree(null);
//treeModel
TreeModel treeModel = new TreeModel(tree);
//msatsubstModel
AsymmetricQuadraticModel aqm1 = new AsymmetricQuadraticModel(msat, null);
//siteModel
GammaSiteModel siteModel = new GammaSiteModel(aqm1);
//treeLikelihood
treeLikelihood1 = new TreeLikelihood(msatPatterns, treeModel, siteModel, null, null, false, false, true, false, false);
setUpExample2();
setUpExample3();
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class MsatFullLikelihoodTest method setUpExample2.
private void setUpExample2() throws Exception {
//taxa
ArrayList<Taxon> taxonList2 = new ArrayList<Taxon>();
Collections.addAll(taxonList2, new Taxon("taxon1"), new Taxon("taxon2"), new Taxon("taxon3"), new Taxon("taxon4"), new Taxon("taxon5"));
Taxa taxa2 = new Taxa(taxonList2);
//msat datatype
Microsatellite msat = new Microsatellite(1, 3);
Patterns msatPatterns = new Patterns(msat, taxa2);
//pattern in the correct code form.
msatPatterns.addPattern(new int[] { 0, 1, 2, 1, 2 });
//create tree
NewickImporter importer = new NewickImporter("(((taxon1:1.5,taxon2:1.5):1.5,(taxon3:2.1,taxon4:2.1):0.9):0.7,taxon5:3.7);");
Tree tree = importer.importTree(null);
//treeModel
TreeModel treeModel = new TreeModel(tree);
//msatsubstModel
AsymmetricQuadraticModel aqm2 = new AsymmetricQuadraticModel(msat, null);
//siteModel
GammaSiteModel siteModel = new GammaSiteModel(aqm2);
//treeLikelihood
treeLikelihood2 = new TreeLikelihood(msatPatterns, treeModel, siteModel, null, null, false, false, true, false, false);
}
Aggregations