use of dr.evomodel.tree.DefaultTreeModel in project beast-mcmc by beast-dev.
the class FNPRTest method testDoOperation.
/**
* Test method for {@link SimpleMCMCOperator#doOperation()}.
* @throws ImportException
* @throws IOException
*/
public void testDoOperation() throws IOException, ImportException {
// if you pick A you can reattach it to 3 new branches
// if you pick B you can reattach it to 3 new branches
// if you pick {A,B} you can reattach it to 2 new branches
// if you pick C you can reattach it to 2 new branches
// if you pick {A,B,C} you can reattach it to 1 new branch
// if you pick D you can reattach it to 1 new branch
// total: 1/12 for every new tree
System.out.println("Test 1: Forward");
// String treeMatch = "(((A,C),D),(B,E));";
String treeMatch = "(((A,C),D),(E,B));";
int count = 0;
int reps = 100000;
HashMap<String, Boolean> trees = new HashMap<String, Boolean>();
for (int i = 0; i < reps; i++) {
DefaultTreeModel treeModel = new DefaultTreeModel("treeModel", tree5);
FNPR operator = new FNPR(treeModel, 1);
operator.doOperation();
String tree = TreeUtils.newickNoLengths(treeModel);
// System.out.println(tree);
if (!trees.containsKey(tree)) {
trees.put(tree, true);
}
if (tree.equals(treeMatch)) {
count += 1;
}
}
System.out.println("Number of trees found:\t" + trees.size());
Set<String> keys = trees.keySet();
for (String s : keys) {
System.out.println(s);
}
double p_1 = (double) count / (double) reps;
System.out.println("Number of proposals:\t" + count);
System.out.println("Number of tries:\t" + reps);
System.out.println("Number of ratio:\t" + p_1);
System.out.println("Number of expected ratio:\t" + 1.0 / 12.0);
assertExpectation(1.0 / 12.0, p_1, reps);
}
use of dr.evomodel.tree.DefaultTreeModel 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 DefaultTreeModel(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.DefaultTreeModel 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 DefaultTreeModel(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.DefaultTreeModel 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 DefaultTreeModel(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);
}
use of dr.evomodel.tree.DefaultTreeModel in project beast-mcmc by beast-dev.
the class TraceCorrelationAssert method createPrimateTreeModel.
// ************************** data ****************************
protected TreeModel createPrimateTreeModel() {
SimpleNode[] nodes = new SimpleNode[10];
for (int n = 0; n < 10; n++) {
nodes[n] = new SimpleNode();
}
// nodes[0].setHeight(0);
// human
nodes[0].setTaxon(taxa[0]);
// chimp
nodes[1].setTaxon(taxa[1]);
// bonobo
nodes[2].setTaxon(taxa[2]);
nodes[3].setHeight(0.010772);
nodes[3].addChild(nodes[1]);
nodes[3].addChild(nodes[2]);
nodes[4].setHeight(0.024003);
nodes[4].addChild(nodes[0]);
nodes[4].addChild(nodes[3]);
// gorilla
nodes[5].setTaxon(taxa[3]);
nodes[6].setHeight(0.036038);
nodes[6].addChild(nodes[4]);
nodes[6].addChild(nodes[5]);
// orangutan
nodes[7].setTaxon(taxa[4]);
nodes[8].setHeight(0.069125);
nodes[8].addChild(nodes[6]);
nodes[8].addChild(nodes[7]);
// siamang
nodes[9].setTaxon(taxa[5]);
SimpleNode root = new SimpleNode();
root.setHeight(0.099582);
root.addChild(nodes[8]);
root.addChild(nodes[9]);
Tree tree = new SimpleTree(root);
tree.setUnits(Units.Type.YEARS);
// treeModel
return new DefaultTreeModel(tree);
}
Aggregations