Search in sources :

Example 91 with Alignment

use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.

the class BEASTTestCase method getBinaryAlignment.

public static Alignment getBinaryAlignment() throws Exception {
    Alignment data = new Alignment();
    data.initByName("sequence", German_ST, "sequence", Dutch_List, "sequence", English_ST, "sequence", French, "sequence", Italian, "sequence", Spanish, "dataType", "binary");
    return data;
}
Also used : Alignment(beast.evolution.alignment.Alignment)

Example 92 with Alignment

use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.

the class UncertainAlignmentTest method getAlignment.

public static Alignment getAlignment() throws Exception {
    // The sequences now denote the most likely annotation
    Sequence seq1 = new Sequence("seq1", "ATT");
    Sequence seq2 = new Sequence("seq2", "ATC");
    Sequence seq3 = new Sequence("seq3", "GCC");
    Alignment data = new Alignment();
    data.initByName("sequence", seq1, "sequence", seq2, "sequence", seq3, "dataType", "nucleotide");
    return data;
}
Also used : Alignment(beast.evolution.alignment.Alignment) Sequence(beast.evolution.alignment.Sequence)

Example 93 with Alignment

use of beast.evolution.alignment.Alignment in project beast2 by CompEvol.

the class TreeLikelihoodTest method testJC69LikelihoodWithUncertainCharacters.

@Test
public void testJC69LikelihoodWithUncertainCharacters() throws Exception {
    Alignment data = UncertainAlignmentTest.getAlignment();
    Alignment data2 = UncertainAlignmentTest.getUncertainAlignment();
    double[] logL, logL_uncertain;
    System.out.println("\nTree A:");
    Tree tree = UncertainAlignmentTest.getTreeA(data2);
    logL = testJC69Likelihood(data, tree);
    logL_uncertain = testJC69Likelihood(data2, tree);
    double x1 = -11.853202336328778;
    double x2 = -12.069603116476458;
    assertEquals(logL[0], x1, BEASTTestCase.PRECISION);
    assertEquals(logL[1], x1, BEASTTestCase.PRECISION);
    assertEquals(logL_uncertain[0], x1, BEASTTestCase.PRECISION);
    assertEquals(logL_uncertain[1], x2, BEASTTestCase.PRECISION);
    System.out.println("\nTree B:");
    tree = UncertainAlignmentTest.getTreeB(data2);
    logL = testJC69Likelihood(data, tree);
    logL_uncertain = testJC69Likelihood(data2, tree);
    double x3 = -12.421114302827698;
    double x4 = -11.62105662310513;
    assertEquals(logL[0], x3, BEASTTestCase.PRECISION);
    assertEquals(logL[1], x3, BEASTTestCase.PRECISION);
    assertEquals(logL_uncertain[0], x3, BEASTTestCase.PRECISION);
    assertEquals(logL_uncertain[1], x4, BEASTTestCase.PRECISION);
    System.out.println("\nTesting alignment doubling:");
    Alignment data3 = UncertainAlignmentTest.getUncertainAlignmentDoubled();
    logL_uncertain = testJC69Likelihood(data3, tree);
    assertEquals(logL_uncertain[0], 2 * x3, BEASTTestCase.PRECISION);
    assertEquals(logL_uncertain[1], 2 * x4, BEASTTestCase.PRECISION);
}
Also used : Alignment(beast.evolution.alignment.Alignment) Tree(beast.evolution.tree.Tree) UncertainAlignmentTest(test.beast.evolution.alignment.UncertainAlignmentTest) Test(org.junit.Test)

Example 94 with Alignment

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

Example 95 with Alignment

use of beast.evolution.alignment.Alignment 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)102 Test (org.junit.Test)43 Sequence (beast.evolution.alignment.Sequence)31 FilteredAlignment (beast.evolution.alignment.FilteredAlignment)30 Tree (beast.evolution.tree.Tree)29 SiteModel (beast.evolution.sitemodel.SiteModel)27 TreeLikelihood (beast.evolution.likelihood.TreeLikelihood)22 BeagleTreeLikelihood (beast.evolution.likelihood.BeagleTreeLikelihood)20 ArrayList (java.util.ArrayList)17 UncertainAlignmentTest (test.beast.evolution.alignment.UncertainAlignmentTest)17 Frequencies (beast.evolution.substitutionmodel.Frequencies)13 RealParameter (beast.core.parameter.RealParameter)12 TaxonSet (beast.evolution.alignment.TaxonSet)11 BEASTInterface (beast.core.BEASTInterface)10 ClusterTree (beast.util.ClusterTree)9 Taxon (beast.evolution.alignment.Taxon)6 HKY (beast.evolution.substitutionmodel.HKY)6 Node (beast.evolution.tree.Node)6 TreeParser (beast.util.TreeParser)6 IOException (java.io.IOException)6