Search in sources :

Example 11 with Alignment

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

the class FilteredAlignmentTest method testWeightedSites.

@Test
public void testWeightedSites() throws Exception {
    // add constant sites to ordinary alignment
    Alignment data = getAlignment();
    try {
        data.siteWeightsInput.setValue("11232,2,3,4", data);
        data.initAndValidate();
        throw new Exception("Should have failed by now");
    } catch (RuntimeException e) {
        System.err.println(e.getMessage());
    }
    // set up weighted alignment
    data = getAlignment();
    data.siteWeightsInput.setValue("11232, 2, 3, 4 ,1123,2,3,4,112,2,3,4,11,2,3,	4 ", data);
    data.initAndValidate();
    String weights = Arrays.toString(data.getWeights());
    System.err.println(weights + "\n0human\t" + alignmentToString(data, data.getTaxonIndex("0human")) + "\n1chimp\t" + alignmentToString(data, data.getTaxonIndex("1chimp")));
    assertEquals("[11232, 2, 3, 4, 1123, 2, 3, 4, 112, 2, 3, 4, 11, 2, 3, 4]", weights);
    data = getAlignment2();
    data.siteWeightsInput.setValue("11232, 2, 3, 4 ,1123,2,3,4,112,2,3,4,11,2,3,	4 ", data);
    data.initAndValidate();
    weights = Arrays.toString(data.getWeights());
    System.err.println(weights + "\n" + alignmentToString(data, 0) + "\n" + alignmentToString(data, 1));
    assertEquals("[11232, 2, 4, 3, 1123, 2, 3, 4, 11, 2, 3, 4, 112, 2, 3, 4]", weights);
    data = getAlignment3();
    data.siteWeightsInput.setValue("1, 10, 100, 1000, 10000, 100000", data);
    data.initAndValidate();
    weights = Arrays.toString(data.getWeights());
    System.err.println(weights + "\n" + alignmentToString(data, 0) + "\n" + alignmentToString(data, 1));
    assertEquals("[101000, 10000, 1, 110]", weights);
    // pass alignment to filtered alignment
    data = getAlignment();
    data.siteWeightsInput.setValue("11232, 2, 3, 4 ,1123,2,3,4,112,2,3,4,11,2,3,	4 ", data);
    data.initAndValidate();
    FilteredAlignment data2 = new FilteredAlignment();
    try {
        data2.initByName("data", data, "filter", "-");
        throw new Exception("Should have failed by now");
    } catch (RuntimeException e) {
        System.err.println(e.getMessage());
    }
// weights = Arrays.toString(data2.getWeights());
// System.err.println(weights);
// assertEquals("[11232, 2, 3, 4, 1123, 2, 3, 4, 112, 2, 3, 4, 11, 2, 3, 4]", weights);
// data2 = new FilteredAlignment();
// data2.initByName("data", data, "filter", "3-8");
// weights = Arrays.toString(data2.getWeights());
// System.err.println(weights);
// assertEquals("[4, 1123, 2, 3, 4, 112]", weights);
}
Also used : Alignment(beast.evolution.alignment.Alignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Test(org.junit.Test)

Example 12 with Alignment

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

the class WilsonBaldingTest method topologyDistribution.

/**
 * Test topology distribution.
 * @throws Exception
 */
@Test
public void topologyDistribution() throws Exception {
    // Fix seed: will hopefully ensure success of test unless something
    // goes terribly wrong.
    Randomizer.setSeed(42);
    // Assemble model:
    ConstantPopulation constantPop = new ConstantPopulation();
    constantPop.initByName("popSize", new RealParameter("10000.0"));
    List<Object> alignmentInitArgs = new ArrayList<Object>();
    for (int i = 0; i < 4; i++) {
        Sequence thisSeq = new Sequence();
        thisSeq.initByName("taxon", String.valueOf(i), "value", "?");
        alignmentInitArgs.add("sequence");
        alignmentInitArgs.add(thisSeq);
    }
    Alignment alignment = new Alignment();
    alignment.initByName(alignmentInitArgs.toArray());
    Tree tree = new RandomTree();
    tree.initByName("taxa", alignment, "populationModel", constantPop);
    TreeIntervals treeIntervals = new TreeIntervals();
    treeIntervals.initByName("tree", tree);
    Coalescent coalescentDistrib = new Coalescent();
    coalescentDistrib.initByName("treeIntervals", treeIntervals, "populationModel", constantPop);
    // Set up state:
    State state = new State();
    state.initByName("stateNode", tree);
    // Set up operator:
    WilsonBalding wilsonBalding = new WilsonBalding();
    wilsonBalding.initByName("weight", "1", "tree", tree);
    // Set up logger:
    TreeReport treeReport = new TreeReport();
    treeReport.initByName("logEvery", "100", "burnin", "200000", "credibleSetPercentage", "95.0", "log", tree, "silent", true);
    // Set up MCMC:
    MCMC mcmc = new MCMC();
    mcmc.initByName("chainLength", "2000000", "state", state, "distribution", coalescentDistrib, "operator", wilsonBalding, "logger", treeReport);
    // Run MCMC:
    mcmc.run();
    // Obtain analysis results:
    TreeTraceAnalysis analysis = treeReport.getAnalysis();
    Map<String, Integer> topologyCounts = analysis.getTopologyCounts();
    int totalTreesUsed = analysis.getNTrees();
    // Test topology distribution against ideal:
    double tol = 0.005;
    for (int i = 0; i < topologies.length; i++) {
        double thisProb = topologyCounts.get(topologies[i]) / (double) totalTreesUsed;
        boolean withinTol = (thisProb > probs[i] - tol && thisProb < probs[i] + tol);
        Assert.assertTrue(withinTol);
        System.err.format("Topology %s rel. freq. %.3f", topologies[i], thisProb);
        if (withinTol)
            System.err.println(" (Within tolerance " + tol + " of " + String.valueOf(probs[i]) + ")");
        else
            System.err.println(" (FAILURE: outside tolerance " + tol + " of " + String.valueOf(probs[i]) + ")");
    }
}
Also used : ArrayList(java.util.ArrayList) RealParameter(beast.core.parameter.RealParameter) Sequence(beast.evolution.alignment.Sequence) TreeIntervals(beast.evolution.tree.coalescent.TreeIntervals) ConstantPopulation(beast.evolution.tree.coalescent.ConstantPopulation) Alignment(beast.evolution.alignment.Alignment) TreeTraceAnalysis(beast.evolution.tree.TreeTraceAnalysis) RandomTree(beast.evolution.tree.RandomTree) Tree(beast.evolution.tree.Tree) RandomTree(beast.evolution.tree.RandomTree) Coalescent(beast.evolution.tree.coalescent.Coalescent) WilsonBalding(beast.evolution.operators.WilsonBalding) Test(org.junit.Test)

Example 13 with Alignment

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

the class StateNodeInitialiserTest method testNewickTree.

@Test
public void testNewickTree() throws Exception {
    Alignment data = BEASTTestCase.getAlignment();
    Tree tree = new Tree();
    tree.initAndValidate();
    assertEquals(true, tree.getNodeCount() == 1);
    ClusterTree tree2 = new ClusterTree();
    tree2.initByName("initial", tree, "clusterType", "upgma", "taxa", data);
    assertEquals(true, tree.getNodeCount() > 1);
    assertEquals(11, tree.getNodeCount());
}
Also used : Alignment(beast.evolution.alignment.Alignment) ClusterTree(beast.util.ClusterTree) Tree(beast.evolution.tree.Tree) ClusterTree(beast.util.ClusterTree) Test(org.junit.Test)

Example 14 with Alignment

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

the class StateNodeInitialiserTest method testClusterTree.

@Test
public void testClusterTree() throws Exception {
    Alignment data = BEASTTestCase.getAlignment();
    Tree tree = new Tree();
    tree.initAndValidate();
    assertEquals(true, tree.getNodeCount() == 1);
    TreeParser tree2 = new TreeParser();
    tree2.initByName("initial", tree, "taxa", data, "newick", "((((human:0.024003,(chimp:0.010772,bonobo:0.010772):0.013231):0.012035,gorilla:0.036038):0.033087000000000005,orangutan:0.069125):0.030456999999999998,siamang:0.099582);", "IsLabelledNewick", true);
    assertEquals(true, tree.getNodeCount() > 1);
    assertEquals(11, tree.getNodeCount());
}
Also used : Alignment(beast.evolution.alignment.Alignment) TreeParser(beast.util.TreeParser) Tree(beast.evolution.tree.Tree) ClusterTree(beast.util.ClusterTree) Test(org.junit.Test)

Example 15 with Alignment

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

the class TraitSetTest method taxonSet.

public TaxonSet taxonSet(int Nleaves) {
    List<Sequence> seqList = new ArrayList<Sequence>();
    for (int i = 0; i < Nleaves; i++) {
        String taxonID = "t" + i;
        seqList.add(new Sequence(taxonID, "?"));
    }
    Alignment alignment = new Alignment(seqList, "nucleotide");
    TaxonSet taxonSet = new TaxonSet(alignment);
    return taxonSet;
}
Also used : Alignment(beast.evolution.alignment.Alignment) ArrayList(java.util.ArrayList) Sequence(beast.evolution.alignment.Sequence) TaxonSet(beast.evolution.alignment.TaxonSet)

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