use of beast.evolution.tree.Tree in project beast2 by CompEvol.
the class TreeLikelihoodTest method testJC69Likelihood.
@Test
public void testJC69Likelihood() throws Exception {
// Set up JC69 model: uniform freqs, kappa = 1, 0 gamma categories
Alignment data = BEASTTestCase.getAlignment();
Tree tree = BEASTTestCase.getTree(data);
JukesCantor JC = new JukesCantor();
JC.initAndValidate();
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", JC);
TreeLikelihood likelihood = newTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
double logP = 0;
logP = likelihood.calculateLogP();
assertEquals(logP, -1992.2056440317247, BEASTTestCase.PRECISION);
likelihood.initByName("useAmbiguities", true, "data", data, "tree", tree, "siteModel", siteModel);
logP = likelihood.calculateLogP();
assertEquals(logP, -1992.2056440317247, BEASTTestCase.PRECISION);
}
use of beast.evolution.tree.Tree in project beast2 by CompEvol.
the class TreeLikelihoodTest method testGTRLikelihood.
@Test
public void testGTRLikelihood() throws Exception {
// Set up GTR model: no gamma categories, no proportion invariant
Alignment data = BEASTTestCase.getAlignment();
Tree tree = BEASTTestCase.getTree(data);
Frequencies freqs = new Frequencies();
freqs.initByName("data", data);
GTR gsm = new GTR();
gsm.initByName("frequencies", freqs);
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", gsm);
TreeLikelihood likelihood = newTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
double logP = 0;
logP = likelihood.calculateLogP();
assertEquals(logP, -1969.145839307625, BEASTTestCase.PRECISION);
likelihood.initByName("useAmbiguities", false, "data", data, "tree", tree, "siteModel", siteModel);
logP = likelihood.calculateLogP();
assertEquals(logP, -1969.145839307625, BEASTTestCase.PRECISION);
}
use of beast.evolution.tree.Tree in project beast2 by CompEvol.
the class TreeLikelihoodTest method testBinaryCovarionLikelihood.
@Test
public void testBinaryCovarionLikelihood() throws Exception {
Alignment data = BEASTTestCase.getCovarionAlignment();
Tree tree = BEASTTestCase.getTree(data, "((English_ST:0.22743347188019544,(German_ST:0.10557648379843088,Dutch_List:0.10557648379843088):0.12185698808176457):1.5793160946109988,(Spanish:0.11078392189606047,(Italian:0.10119772534558173,French:0.10119772534558173):0.009586196550478737):1.6959656445951337)");
RealParameter alpha = new RealParameter("0.284");
RealParameter switchRate = new RealParameter("0.829");
RealParameter frequencies = new RealParameter("0.683 0.317");
RealParameter hfrequencies = new RealParameter("0.5 0.5");
BinaryCovarion covarion = new BinaryCovarion();
covarion.initByName("alpha", alpha, "switchRate", switchRate, "vfrequencies", frequencies, "hfrequencies", hfrequencies);
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", covarion);
TreeLikelihood likelihood = newTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
double logP = 0;
likelihood.initByName("useAmbiguities", true, "data", data, "tree", tree, "siteModel", siteModel);
logP = likelihood.calculateLogP();
// beast1 xml gives -1730.5363
assertEquals(logP, -1730.53631739, BEASTTestCase.PRECISION);
}
use of beast.evolution.tree.Tree in project beast2 by CompEvol.
the class TreeAnnotatorTest method testTreeScoreAndCladeSystemSA.
@Test
public void testTreeScoreAndCladeSystemSA() throws Exception {
for (Tree tree : treesSA) {
cladeSystemSA.add(tree, false);
}
Assert.assertEquals(cladesSA.length, cladeSystemSA.getCladeMap().size());
cladeSystemSA.calculateCladeCredibilities(treesSA.length);
int i = 0;
for (Map.Entry<BitSet, CladeSystem.Clade> entry : cladeSystemSA.getCladeMap().entrySet()) {
// System.out.println(entry.getKey() + " = " + entry.getValue().getCount());
int index = -1;
// find the clade in the clades array
for (int j = 0; j < cladesSA.length; j++) {
if (cladesSA[j].equals(entry.getKey().toString())) {
index = j;
break;
}
}
// if the clade is not found then index = -1
Assert.assertFalse(i == -1);
Assert.assertEquals(cladesCountSA[index], entry.getValue().getCount());
i++;
}
int maxScoreIndex = -1;
int maxScoreLogIndex = -1;
double maxScore = Double.NEGATIVE_INFINITY;
double maxScoreLog = Double.NEGATIVE_INFINITY;
i = 0;
for (Tree tree : treesSA) {
double score = treeAnnotatorSA.scoreTree(tree, cladeSystemSA, true);
double scoreLog = treeAnnotatorSA.scoreTree(tree, cladeSystemSA, false);
// Assert.assertEquals(logTreeScoresSA[i], scoreLog, 1e-6);
System.out.println(i + " => " + score + ", log " + scoreLog);
if (maxScore < score) {
maxScore = score;
maxScoreIndex = i;
}
if (maxScoreLog < scoreLog) {
maxScoreLog = scoreLog;
maxScoreLogIndex = i;
}
i++;
}
// System.out.println(maxScoreIndex + " => " + maxScore + ", log " + maxScoreLog);
Assert.assertEquals(1, maxScoreIndex);
Assert.assertEquals(1, maxScoreLogIndex);
}
use of beast.evolution.tree.Tree in project beast2 by CompEvol.
the class BayesianSkylineTest method testSkyline.
@Test
public void testSkyline() throws Exception {
// RealParameter popSize = new RealParameter("1.0", 0.0, 10.0, 2);
// IntegerParameter groupSize = new IntegerParameter("2", 1, 4, 2);
// popSize.setValue(1, 2.0);
Tree tree = new Tree("(((1:1,2:1):2.5,(3:1.5,4:1.5):2):2,5:5.5);");
TreeIntervals intervals = new TreeIntervals(tree);
BayesianSkyline skyline = new BayesianSkyline();
// skyline.init(popSize, groupSize, intervals);
skyline.initByName("popSizes", "1.0 2.0", "groupSizes", "2 2", "treeIntervals", intervals);
assertEquals(skyline.getPopSize(0.01), 1.0);
assertEquals(skyline.getPopSize(1.49), 1.0);
assertEquals(skyline.getPopSize(1.51), 2.0);
assertEquals(skyline.getPopSize(5.51), 2.0);
}
Aggregations