use of beast.evolution.substitutionmodel.Frequencies in project beast2 by CompEvol.
the class TreeLikelihoodTest method testHKY85GILikelihood.
@Test
public void testHKY85GILikelihood() throws Exception {
// Set up HKY85+G+I model: estimated freqs, kappa = 39.464538, 4 gamma categories, shape = 0.587649, prop invariant = 0.486548
Alignment data = BEASTTestCase.getAlignment();
Tree tree = BEASTTestCase.getTree(data);
Frequencies freqs = new Frequencies();
freqs.initByName("data", data);
HKY hky = new HKY();
hky.initByName("kappa", "39.464538", "frequencies", freqs);
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 4, "shape", "0.587649", "proportionInvariant", "0.486548", "substModel", hky);
TreeLikelihood likelihood = newTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
double logP = 0;
logP = likelihood.calculateLogP();
assertEquals(logP, -1789.639227747059, BEASTTestCase.PRECISION);
likelihood.initByName("useAmbiguities", true, "data", data, "tree", tree, "siteModel", siteModel);
logP = likelihood.calculateLogP();
assertEquals(logP, -1789.639227747059, BEASTTestCase.PRECISION);
}
use of beast.evolution.substitutionmodel.Frequencies in project beast2 by CompEvol.
the class TreeLikelihoodTest method testMarginalisationOfLikelihoodBinary.
@Test
public void testMarginalisationOfLikelihoodBinary() throws Exception {
// test summation over all patterns adds to 1 for binary data
Sequence German_ST = new Sequence("German_ST", " 10110010");
Sequence Dutch_List = new Sequence("Dutch_List", " 11010100");
Sequence English_ST = new Sequence("English_ST", " 11101000");
Alignment data = new Alignment();
data.initByName("sequence", German_ST, "sequence", Dutch_List, "sequence", English_ST, "dataType", "binary");
Tree tree = BEASTTestCase.getTree(data, "(English_ST:0.22743347188019544,(German_ST:0.10557648379843088,Dutch_List:0.10557648379843088):0.12185698808176457):0.0;");
RealParameter frequencies = new RealParameter("0.683 0.317");
Frequencies freqs = new Frequencies();
freqs.initByName("frequencies", frequencies);
GeneralSubstitutionModel covarion = new GeneralSubstitutionModel();
covarion.initByName("frequencies", freqs, "rates", new RealParameter("1.0 1.0"));
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", covarion);
TreeLikelihood likelihood = newTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
likelihood.initByName("useAmbiguities", false, "data", data, "tree", tree, "siteModel", siteModel);
likelihood.calculateLogP();
double[] logPs = likelihood.getPatternLogLikelihoods();
double P = 0;
for (double d : logPs) {
P += Math.exp(d);
}
assertEquals(P, 1.0, BEASTTestCase.PRECISION);
}
use of beast.evolution.substitutionmodel.Frequencies in project beast2 by CompEvol.
the class TreeLikelihoodTest method testSDolloLikelihood.
@Test
public void testSDolloLikelihood() throws Exception {
UserDataType dataType = new UserDataType();
dataType.initByName("states", 2, "codeMap", "0=1, 1=0, ?=0 1, -=0 1");
Alignment data = new Alignment();
Sequence German_ST = new Sequence("German_ST", BEASTTestCase.German_ST.dataInput.get());
Sequence Dutch_List = new Sequence("Dutch_List", BEASTTestCase.Dutch_List.dataInput.get());
;
Sequence English_ST = new Sequence("English_ST", BEASTTestCase.English_ST.dataInput.get());
;
Sequence French = new Sequence("French", BEASTTestCase.French.dataInput.get());
;
Sequence Italian = new Sequence("Italian", BEASTTestCase.Italian.dataInput.get());
;
Sequence Spanish = new Sequence("Spanish", BEASTTestCase.Spanish.dataInput.get());
;
data.initByName("sequence", German_ST, "sequence", Dutch_List, "sequence", English_ST, "sequence", French, "sequence", Italian, "sequence", Spanish, "userDataType", dataType);
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 frequencies = new RealParameter("1 0");
Frequencies freqs = new Frequencies();
freqs.initByName("frequencies", frequencies);
RealParameter deathprob = new RealParameter("1.7");
MutationDeathModel SDollo = new MutationDeathModel();
SDollo.initByName("deathprob", deathprob, "frequencies", freqs);
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", SDollo);
TreeLikelihood likelihood = newTreeLikelihood();
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
double logP = 0;
likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel, "useAmbiguities", true);
logP = likelihood.calculateLogP();
// beast1 xml gives -3551.6436
assertEquals(logP, -3551.6436270344648, BEASTTestCase.PRECISION);
}
use of beast.evolution.substitutionmodel.Frequencies 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.substitutionmodel.Frequencies in project beast2 by CompEvol.
the class BinaryCovarionModelTest method doWithEqualHFreqs.
private void doWithEqualHFreqs(String mode) {
Frequencies dummyFreqs = new Frequencies();
dummyFreqs.initByName("frequencies", "0.25 0.25 0.25 0.25", "estimate", false);
BinaryCovarion substModel;
RealParameter hfrequencies = new RealParameter(new Double[] { 0.5, 0.5 });
double d = Randomizer.nextDouble();
RealParameter vfrequencies = new RealParameter(new Double[] { d, 1.0 - d });
substModel = new BinaryCovarion();
substModel.initByName("frequencies", dummyFreqs, "hfrequencies", hfrequencies, /* [f0, f1] */
"vfrequencies", vfrequencies, /* [p0, p1] */
"alpha", "0.01", "switchRate", "0.1", "mode", mode);
double[] matrix = new double[16];
substModel.getTransitionProbabilities(null, 100, 0, 1.0, matrix);
double EPSILON = 1e-10;
assertEquals(vfrequencies.getValue(0) * hfrequencies.getValue(0), matrix[0], EPSILON);
assertEquals(vfrequencies.getValue(1) * hfrequencies.getValue(0), matrix[1], EPSILON);
assertEquals(vfrequencies.getValue(0) * hfrequencies.getValue(1), matrix[2], EPSILON);
assertEquals(vfrequencies.getValue(1) * hfrequencies.getValue(1), matrix[3], EPSILON);
}
Aggregations