use of beast.evolution.substitutionmodel.GTR in project beast2 by CompEvol.
the class GTRTest method testGTR.
public void testGTR() throws Exception {
for (Instance test : all) {
RealParameter f = new RealParameter(test.getPi());
Frequencies freqs = new Frequencies();
freqs.initByName("frequencies", f, "estimate", false);
GTR gtr = new GTR();
Double[] rates = test.getRates();
gtr.initByName("rateAC", new RealParameter(rates[0] + ""), "rateAG", new RealParameter(rates[1] + ""), "rateAT", new RealParameter(rates[2] + ""), "rateCG", new RealParameter(rates[3] + ""), "rateCT", new RealParameter(rates[4] + ""), "rateGT", new RealParameter(rates[5] + ""), "frequencies", freqs);
double distance = test.getDistance();
double[] mat = new double[4 * 4];
gtr.getTransitionProbabilities(null, distance, 0, 1, mat);
final double[] result = test.getExpectedResult();
for (int k = 0; k < mat.length; ++k) {
assertEquals(mat[k], result[k], 1e-10);
System.out.println(k + " : " + (mat[k] - result[k]));
}
}
}
use of beast.evolution.substitutionmodel.GTR 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);
}
Aggregations