Search in sources :

Example 1 with GeneralSubstitutionModel

use of beast.evolution.substitutionmodel.GeneralSubstitutionModel in project beast2 by CompEvol.

the class TreeLikelihoodTest method testMarginalisationOfLikelihoodNucleotide.

@Test
public void testMarginalisationOfLikelihoodNucleotide() throws Exception {
    // test summation over all patterns adds to 1 for nucleotide data
    Sequence German_ST = new Sequence("German_ST", "           AAAAAAAAAAAAAAAA CCCCCCCCCCCCCCCC GGGGGGGGGGGGGGGG TTTTTTTTTTTTTTTT");
    Sequence Dutch_List = new Sequence("Dutch_List", "          AAAACCCCGGGGTTTT AAAACCCCGGGGTTTT AAAACCCCGGGGTTTT AAAACCCCGGGGTTTT");
    Sequence English_ST = new Sequence("English_ST", "          ACGTACGTACGTACGT ACGTACGTACGTACGT ACGTACGTACGTACGT ACGTACGTACGTACGT");
    Alignment data = new Alignment();
    data.initByName("sequence", German_ST, "sequence", Dutch_List, "sequence", English_ST, "dataType", "nucleotide");
    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.2 0.3 0.4 0.1");
    Frequencies freqs = new Frequencies();
    freqs.initByName("frequencies", frequencies);
    GeneralSubstitutionModel gsm = new GeneralSubstitutionModel();
    gsm.initByName("rates", "1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0", "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);
    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);
}
Also used : Alignment(beast.evolution.alignment.Alignment) BeagleTreeLikelihood(beast.evolution.likelihood.BeagleTreeLikelihood) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) Tree(beast.evolution.tree.Tree) RealParameter(beast.core.parameter.RealParameter) GeneralSubstitutionModel(beast.evolution.substitutionmodel.GeneralSubstitutionModel) SiteModel(beast.evolution.sitemodel.SiteModel) Sequence(beast.evolution.alignment.Sequence) Frequencies(beast.evolution.substitutionmodel.Frequencies) UncertainAlignmentTest(test.beast.evolution.alignment.UncertainAlignmentTest) Test(org.junit.Test)

Example 2 with GeneralSubstitutionModel

use of beast.evolution.substitutionmodel.GeneralSubstitutionModel in project beast2 by CompEvol.

the class TreeLikelihoodTest method testGTRILikelihood.

@Test
public void testGTRILikelihood() throws Exception {
    // Set up GTR model: prop invariant = 0.5
    Alignment data = BEASTTestCase.getAlignment();
    Tree tree = BEASTTestCase.getTree(data);
    Frequencies freqs = new Frequencies();
    freqs.initByName("data", data);
    GeneralSubstitutionModel gsm = new GeneralSubstitutionModel();
    gsm.initByName("rates", "1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0", "frequencies", freqs);
    SiteModel siteModel = new SiteModel();
    siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "proportionInvariant", "0.5", "substModel", gsm);
    // siteModel.init("1.0", 1, null, "0.5", gsm);
    TreeLikelihood likelihood = newTreeLikelihood();
    likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
    double logP = 0;
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1948.8417455357564, BEASTTestCase.PRECISION);
    likelihood.initByName("useAmbiguities", false, "data", data, "tree", tree, "siteModel", siteModel);
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1948.8417455357564, BEASTTestCase.PRECISION);
}
Also used : Alignment(beast.evolution.alignment.Alignment) BeagleTreeLikelihood(beast.evolution.likelihood.BeagleTreeLikelihood) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) Tree(beast.evolution.tree.Tree) GeneralSubstitutionModel(beast.evolution.substitutionmodel.GeneralSubstitutionModel) SiteModel(beast.evolution.sitemodel.SiteModel) Frequencies(beast.evolution.substitutionmodel.Frequencies) UncertainAlignmentTest(test.beast.evolution.alignment.UncertainAlignmentTest) Test(org.junit.Test)

Example 3 with GeneralSubstitutionModel

use of beast.evolution.substitutionmodel.GeneralSubstitutionModel in project beast2 by CompEvol.

the class TreeLikelihoodTest method testGTRGILikelihood.

@Test
public void testGTRGILikelihood() throws Exception {
    // Set up GTR model: 4 gamma categories, gamma shape = 0.5, prop invariant = 0.5
    Alignment data = BEASTTestCase.getAlignment();
    Tree tree = BEASTTestCase.getTree(data);
    Frequencies freqs = new Frequencies();
    freqs.initByName("data", data);
    GeneralSubstitutionModel gsm = new GeneralSubstitutionModel();
    gsm.initByName("rates", "1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0", "frequencies", freqs);
    SiteModel siteModel = new SiteModel();
    siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 4, "shape", "0.5", "proportionInvariant", "0.5", "substModel", gsm);
    TreeLikelihood likelihood = newTreeLikelihood();
    likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
    double logP = 0;
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1947.5829396144961, BEASTTestCase.PRECISION);
    likelihood.initByName("useAmbiguities", false, "data", data, "tree", tree, "siteModel", siteModel);
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1947.5829396144961, BEASTTestCase.PRECISION);
}
Also used : Alignment(beast.evolution.alignment.Alignment) BeagleTreeLikelihood(beast.evolution.likelihood.BeagleTreeLikelihood) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) Tree(beast.evolution.tree.Tree) GeneralSubstitutionModel(beast.evolution.substitutionmodel.GeneralSubstitutionModel) SiteModel(beast.evolution.sitemodel.SiteModel) Frequencies(beast.evolution.substitutionmodel.Frequencies) UncertainAlignmentTest(test.beast.evolution.alignment.UncertainAlignmentTest) Test(org.junit.Test)

Example 4 with GeneralSubstitutionModel

use of beast.evolution.substitutionmodel.GeneralSubstitutionModel in project beast2 by CompEvol.

the class TreeLikelihoodTest method testGTRGLikelihood.

@Test
public void testGTRGLikelihood() throws Exception {
    // Set up GTR model: 4 gamma categories, gamma shape = 0.5
    Alignment data = BEASTTestCase.getAlignment();
    Tree tree = BEASTTestCase.getTree(data);
    Frequencies freqs = new Frequencies();
    freqs.initByName("data", data);
    GeneralSubstitutionModel gsm = new GeneralSubstitutionModel();
    gsm.initByName("rates", "1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0", "frequencies", freqs);
    SiteModel siteModel = new SiteModel();
    siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 4, "shape", "0.5", "substModel", gsm);
    TreeLikelihood likelihood = newTreeLikelihood();
    likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
    double logP = 0;
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1949.0360143622, BEASTTestCase.PRECISION);
    likelihood.initByName("useAmbiguities", false, "data", data, "tree", tree, "siteModel", siteModel);
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1949.0360143622, BEASTTestCase.PRECISION);
}
Also used : Alignment(beast.evolution.alignment.Alignment) BeagleTreeLikelihood(beast.evolution.likelihood.BeagleTreeLikelihood) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) Tree(beast.evolution.tree.Tree) GeneralSubstitutionModel(beast.evolution.substitutionmodel.GeneralSubstitutionModel) SiteModel(beast.evolution.sitemodel.SiteModel) Frequencies(beast.evolution.substitutionmodel.Frequencies) UncertainAlignmentTest(test.beast.evolution.alignment.UncertainAlignmentTest) Test(org.junit.Test)

Example 5 with GeneralSubstitutionModel

use of beast.evolution.substitutionmodel.GeneralSubstitutionModel 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);
}
Also used : Alignment(beast.evolution.alignment.Alignment) BeagleTreeLikelihood(beast.evolution.likelihood.BeagleTreeLikelihood) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) Tree(beast.evolution.tree.Tree) RealParameter(beast.core.parameter.RealParameter) GeneralSubstitutionModel(beast.evolution.substitutionmodel.GeneralSubstitutionModel) SiteModel(beast.evolution.sitemodel.SiteModel) Sequence(beast.evolution.alignment.Sequence) Frequencies(beast.evolution.substitutionmodel.Frequencies) UncertainAlignmentTest(test.beast.evolution.alignment.UncertainAlignmentTest) Test(org.junit.Test)

Aggregations

Alignment (beast.evolution.alignment.Alignment)5 BeagleTreeLikelihood (beast.evolution.likelihood.BeagleTreeLikelihood)5 TreeLikelihood (beast.evolution.likelihood.TreeLikelihood)5 SiteModel (beast.evolution.sitemodel.SiteModel)5 Frequencies (beast.evolution.substitutionmodel.Frequencies)5 GeneralSubstitutionModel (beast.evolution.substitutionmodel.GeneralSubstitutionModel)5 Tree (beast.evolution.tree.Tree)5 Test (org.junit.Test)5 UncertainAlignmentTest (test.beast.evolution.alignment.UncertainAlignmentTest)5 RealParameter (beast.core.parameter.RealParameter)2 Sequence (beast.evolution.alignment.Sequence)2