use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class MsatSamplingTreeLikelihoodTest method setUp.
public void setUp() throws Exception {
super.setUp();
//taxa
ArrayList<Taxon> taxonList3 = new ArrayList<Taxon>();
Collections.addAll(taxonList3, new Taxon("Taxon1"), new Taxon("Taxon2"), new Taxon("Taxon3"), new Taxon("Taxon4"), new Taxon("Taxon5"), new Taxon("Taxon6"), new Taxon("Taxon7"));
Taxa taxa3 = new Taxa(taxonList3);
//msat datatype
Microsatellite msat = new Microsatellite(1, 6);
Patterns msatPatterns = new Patterns(msat, taxa3);
//pattern in the correct code form.
msatPatterns.addPattern(new int[] { 0, 1, 3, 2, 4, 5, 1 });
//create tree
NewickImporter importer = new NewickImporter("(((Taxon1:0.3,Taxon2:0.3):0.6,Taxon3:0.9):0.9,((Taxon4:0.5,Taxon5:0.5):0.3,(Taxon6:0.7,Taxon7:0.7):0.1):1.0);");
Tree tree = importer.importTree(null);
//treeModel
TreeModel treeModel = new TreeModel(tree);
//msatsubstModel
AsymmetricQuadraticModel eu1 = new AsymmetricQuadraticModel(msat, null);
//create msatSamplerTreeModel
Parameter internalVal = new Parameter.Default(new double[] { 2, 3, 4, 2, 1, 5 });
int[] externalValues = msatPatterns.getPattern(0);
HashMap<String, Integer> taxaMap = new HashMap<String, Integer>(externalValues.length);
boolean internalValuesProvided = true;
for (int i = 0; i < externalValues.length; i++) {
taxaMap.put(msatPatterns.getTaxonId(i), i);
}
MicrosatelliteSamplerTreeModel msatTreeModel = new MicrosatelliteSamplerTreeModel("JUnitTestEx", treeModel, internalVal, msatPatterns, externalValues, taxaMap, internalValuesProvided);
//create msatSamplerTreeLikelihood
BranchRateModel branchRateModel = new StrictClockBranchRates(new Parameter.Default(1.0));
eu1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, eu1, branchRateModel);
//eu2
TwoPhaseModel eu2 = new TwoPhaseModel(msat, null, eu1, new Parameter.Default(0.0), new Parameter.Default(0.4), null, false);
eu2Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, eu2, branchRateModel);
//ec1
LinearBiasModel ec1 = new LinearBiasModel(msat, null, eu1, new Parameter.Default(0.48), new Parameter.Default(0.0), false, false, false);
ec1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, ec1, branchRateModel);
//ec2
TwoPhaseModel ec2 = new TwoPhaseModel(msat, null, ec1, new Parameter.Default(0.0), new Parameter.Default(0.4), null, false);
ec2Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, ec2, branchRateModel);
//el1
LinearBiasModel el1 = new LinearBiasModel(msat, null, eu1, new Parameter.Default(0.2), new Parameter.Default(-0.018), true, false, false);
el1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, el1, branchRateModel);
AsymmetricQuadraticModel pu1 = new AsymmetricQuadraticModel(msat, null, new Parameter.Default(1.0), new Parameter.Default(0.015), new Parameter.Default(0.0), new Parameter.Default(1.0), new Parameter.Default(0.015), new Parameter.Default(0.0), false);
pu1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, pu1, branchRateModel);
//ec2
TwoPhaseModel pu2 = new TwoPhaseModel(msat, null, pu1, new Parameter.Default(0.0), new Parameter.Default(0.4), null, false);
pu2Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, pu2, branchRateModel);
//ec1
LinearBiasModel pc1 = new LinearBiasModel(msat, null, pu1, new Parameter.Default(0.48), new Parameter.Default(0.0), false, false, false);
pc1Likelihood = new MicrosatelliteSamplerTreeLikelihood(msatTreeModel, pc1, branchRateModel);
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class CompleteHistorySimulatorTest method setUp.
public void setUp() throws Exception {
super.setUp();
MathUtils.setSeed(666);
NewickImporter importer = new NewickImporter("(1:2.0,(2:1.0,3:1.0):1.0);");
tree = importer.importTree(null);
treeModel = new TreeModel("treeModel", tree);
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class NormalizedSequenceLikelihoodTest method createSillyTreeModel.
protected TreeModel createSillyTreeModel(int numTaxa) {
SimpleNode[] nodes = new SimpleNode[2 * numTaxa - 1];
for (int n = 0; n < 2 * numTaxa - 1; n++) {
nodes[n] = new SimpleNode();
}
nodes[0].setTaxon(taxa[0]);
nodes[1].setTaxon(taxa[1]);
nodes[2].setHeight(1);
nodes[2].addChild(nodes[0]);
nodes[2].addChild(nodes[1]);
SimpleNode root = nodes[2];
if (numTaxa == 3) {
nodes[3].setTaxon(taxa[2]);
nodes[4].setHeight(2);
nodes[4].addChild(nodes[2]);
nodes[4].addChild(nodes[3]);
root = nodes[4];
}
Tree tree = new SimpleTree(root);
tree.setUnits(Units.Type.YEARS);
//treeModel
return new TreeModel(tree);
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class Coevolve method runModel2.
private void runModel2(PatternList patternList, PrintWriter pw, Tree tree, SubstitutionModel substModel, final Parameter betaParameter) {
final Parameter muParameter = new Parameter.Default(1.0);
muParameter.setId("mu");
SiteModel siteModel = new GammaSiteModel(substModel, muParameter, null, 1, null);
TreeModel treeModel = new TreeModel(tree);
final TreeLikelihood treeLikelihood = new TreeLikelihood(patternList, treeModel, siteModel, null, null, false, false, true, false, false);
treeLikelihood.setId("likelihood");
MultivariateFunction function = new MultivariateFunction() {
public double evaluate(double[] argument) {
betaParameter.setParameterValue(0, argument[0]);
betaParameter.setParameterValue(1, argument[1]);
muParameter.setParameterValue(0, argument[2]);
double lnL = -treeLikelihood.getLogLikelihood();
// System.err.println("" + argument[0] + "\t" + argument[1] + "\t" + argument[2] + "\t" + lnL);
return lnL;
}
public int getNumArguments() {
return 3;
}
public double getLowerBound(int n) {
return 0.0;
}
public double getUpperBound(int n) {
return 100.0;
}
};
MultivariateMinimum optimizer = new ConjugateGradientSearch();
double lnL = optimizer.findMinimum(function, new double[] { 1.0, 1.0, 1.0 }, 6, 6);
pw.write(betaParameter.getParameterValue(0) + "\t");
pw.write(betaParameter.getParameterValue(1) + "\t");
pw.write(muParameter.getParameterValue(0) + "\t");
pw.write(lnL + "\n");
pw.flush();
System.out.println("" + betaParameter.getParameterValue(0) + "\t" + betaParameter.getParameterValue(1) + "\t" + muParameter.getParameterValue(0) + "\t" + lnL);
}
use of dr.evomodel.tree.TreeModel in project beast-mcmc by beast-dev.
the class LineageSpecificBranchModelParser method parseXMLObject.
@Override
public Object parseXMLObject(XMLObject xo) throws XMLParseException {
TreeModel treeModel = (TreeModel) xo.getChild(TreeModel.class);
FrequencyModel rootFrequencyModel = (FrequencyModel) xo.getChild(FrequencyModel.class);
List<SubstitutionModel> substitutionModels = new ArrayList<SubstitutionModel>();
XMLObject cxo = xo.getChild(MODELS);
for (int i = 0; i < cxo.getChildCount(); i++) {
SubstitutionModel substModel = (SubstitutionModel) cxo.getChild(i);
substitutionModels.add(substModel);
}
//END: models loop
// TODO: check if categories numbering starts from zero
Parameter categories = (Parameter) xo.getElementFirstChild(CATEGORIES);
return new //provider,
LineageSpecificBranchModel(//provider,
treeModel, //provider,
rootFrequencyModel, //provider,
substitutionModels, categories);
}
Aggregations