Search in sources :

Example 26 with Alignment

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

the class UncertainAlignmentTest method testUncertainAlignment.

@Test
public void testUncertainAlignment() throws Exception {
    Alignment data = getUncertainAlignment();
    DataType dataType = data.getDataType();
    System.out.println("Tip likelihoods:");
    int sites = data.getCounts().get(0).size();
    for (int taxon = 0; taxon < data.getTaxonCount(); taxon++) {
        for (int i = 0; i < sites; i++) {
            double[] probs = data.getTipLikelihoods(taxon, i);
            for (int j = 0; j < probs.length; j++) {
                System.out.print(probs[j] + " ");
            }
            System.out.print("; ");
        }
        System.out.println();
    }
    System.out.println("Most likely sequences:");
    for (List<Integer> seq : data.getCounts()) {
        System.out.println(dataType.state2string(seq));
    }
    Alignment data2 = getAlignment();
    for (int taxon = 0; taxon < data.getTaxonCount(); taxon++) {
        assertEquals(data.getCounts().get(taxon), data2.getCounts().get(taxon));
    }
}
Also used : Alignment(beast.evolution.alignment.Alignment) DataType(beast.evolution.datatype.DataType) Test(org.junit.Test)

Example 27 with Alignment

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

the class UncertainAlignmentTest method getUncertainAlignment.

public static Alignment getUncertainAlignment(boolean duplicate) throws Exception {
    String seq1Probs = new String("0.7,0.0,0.3,0.0; 0.0,0.3,0.0,0.7; 0.0,0.0,0.0,1.0;");
    String seq2Probs = new String("0.7,0.0,0.3,0.0; 0.0,0.3,0.0,0.7; 0.0,1.0,0.0,0.0;");
    String seq3Probs = new String("0.4,0.0,0.6,0.0; 0.0,0.6,0.0,0.4; 0.0,1.0,0.0,0.0;");
    if (duplicate) {
        seq1Probs += seq1Probs;
        seq2Probs += seq2Probs;
        seq3Probs += seq3Probs;
    }
    Sequence seq1 = new Sequence();
    seq1.initByName("taxon", "seq1", "value", seq1Probs, "uncertain", true);
    Sequence seq2 = new Sequence();
    seq2.initByName("taxon", "seq2", "value", seq2Probs, "uncertain", true);
    Sequence seq3 = new Sequence();
    seq3.initByName("taxon", "seq3", "value", seq3Probs, "uncertain", true);
    Alignment data = new Alignment();
    data.initByName("sequence", seq1, "sequence", seq2, "sequence", seq3, "dataType", "nucleotide");
    DataType dataType = data.getDataType();
    System.out.println("Most probable sequences:");
    for (List<Integer> seq : data.getCounts()) {
        System.out.println(dataType.state2string(seq));
    }
    return data;
}
Also used : Alignment(beast.evolution.alignment.Alignment) DataType(beast.evolution.datatype.DataType) Sequence(beast.evolution.alignment.Sequence)

Example 28 with Alignment

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

the class TreeLikelihoodTest method aminoacidModelTestI.

void aminoacidModelTestI(SubstitutionModel substModel, double expectedValue) throws Exception {
    Alignment data = BEASTTestCase.getAminoAcidAlignment();
    Tree tree = BEASTTestCase.getAminoAcidTree(data);
    SiteModel siteModel = new SiteModel();
    siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", substModel, "proportionInvariant", "0.2");
    TreeLikelihood likelihood = newTreeLikelihood();
    likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
    double logP = 0;
    logP = likelihood.calculateLogP();
    assertEquals(expectedValue, logP, BEASTTestCase.PRECISION);
}
Also used : Alignment(beast.evolution.alignment.Alignment) BeagleTreeLikelihood(beast.evolution.likelihood.BeagleTreeLikelihood) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) Tree(beast.evolution.tree.Tree) SiteModel(beast.evolution.sitemodel.SiteModel)

Example 29 with Alignment

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

the class TreeLikelihoodTest method testHKY85ILikelihood.

@Test
public void testHKY85ILikelihood() throws Exception {
    // Set up HKY85+I model: estimated freqs, kappa = 38.564672, 0 gamma categories, prop invariant = 0.701211
    Alignment data = BEASTTestCase.getAlignment();
    Tree tree = BEASTTestCase.getTree(data);
    Frequencies freqs = new Frequencies();
    freqs.initByName("data", data);
    HKY hky = new HKY();
    hky.initByName("kappa", "38.564672", "frequencies", freqs);
    SiteModel siteModel = new SiteModel();
    siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "shape", "0.137064", "proportionInvariant", "0.701211", "substModel", hky);
    TreeLikelihood likelihood = newTreeLikelihood();
    likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
    double logP = 0;
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1789.912401996943, BEASTTestCase.PRECISION);
    likelihood.initByName("useAmbiguities", true, "data", data, "tree", tree, "siteModel", siteModel);
    logP = likelihood.calculateLogP();
    assertEquals(logP, -1789.912401996943, 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 30 with Alignment

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

the class TreeLikelihoodTest method aminoacidModelTestIG.

void aminoacidModelTestIG(SubstitutionModel substModel, double expectedValue) throws Exception {
    Alignment data = BEASTTestCase.getAminoAcidAlignment();
    Tree tree = BEASTTestCase.getAminoAcidTree(data);
    SiteModel siteModel = new SiteModel();
    siteModel.initByName("mutationRate", "1.0", "gammaCategoryCount", 1, "substModel", substModel, "gammaCategoryCount", 4, "shape", "0.15", "proportionInvariant", "0.2");
    TreeLikelihood likelihood = newTreeLikelihood();
    likelihood.initByName("data", data, "tree", tree, "siteModel", siteModel);
    double logP = 0;
    logP = likelihood.calculateLogP();
    assertEquals(expectedValue, logP, BEASTTestCase.PRECISION);
}
Also used : Alignment(beast.evolution.alignment.Alignment) BeagleTreeLikelihood(beast.evolution.likelihood.BeagleTreeLikelihood) TreeLikelihood(beast.evolution.likelihood.TreeLikelihood) Tree(beast.evolution.tree.Tree) SiteModel(beast.evolution.sitemodel.SiteModel)

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