Search in sources :

Example 1 with Sequence

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

the class FilteredAlignmentTest method getAlignment2.

public static Alignment getAlignment2() throws Exception {
    // reordered from getAlignment()
    Sequence human = new Sequence("0human", "AAAACCCCTTTTGGGG");
    Sequence chimp = new Sequence("1chimp", "ACTGACGTACGTACGT");
    Alignment data = new Alignment();
    data.initByName("sequence", human, "sequence", chimp, "dataType", "nucleotide");
    return data;
}
Also used : Alignment(beast.evolution.alignment.Alignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Sequence(beast.evolution.alignment.Sequence)

Example 2 with Sequence

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

the class FilteredAlignmentTest method getAlignment.

public static Alignment getAlignment() throws Exception {
    Sequence human = new Sequence("0human", "AAAACCCCGGGGTTTT");
    Sequence chimp = new Sequence("1chimp", "ACGTACGTACGTACGT");
    Alignment data = new Alignment();
    data.initByName("sequence", human, "sequence", chimp, "dataType", "nucleotide");
    return data;
}
Also used : Alignment(beast.evolution.alignment.Alignment) FilteredAlignment(beast.evolution.alignment.FilteredAlignment) Sequence(beast.evolution.alignment.Sequence)

Example 3 with Sequence

use of beast.evolution.alignment.Sequence 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 4 with Sequence

use of beast.evolution.alignment.Sequence 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)

Example 5 with Sequence

use of beast.evolution.alignment.Sequence 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)

Aggregations

Sequence (beast.evolution.alignment.Sequence)34 Alignment (beast.evolution.alignment.Alignment)31 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)10 FilteredAlignment (beast.evolution.alignment.FilteredAlignment)6 SiteModel (beast.evolution.sitemodel.SiteModel)6 RealParameter (beast.core.parameter.RealParameter)5 BeagleTreeLikelihood (beast.evolution.likelihood.BeagleTreeLikelihood)5 Tree (beast.evolution.tree.Tree)5 TreeLikelihood (beast.evolution.likelihood.TreeLikelihood)4 UncertainAlignmentTest (test.beast.evolution.alignment.UncertainAlignmentTest)4 TaxonSet (beast.evolution.alignment.TaxonSet)3 DataType (beast.evolution.datatype.DataType)3 Frequencies (beast.evolution.substitutionmodel.Frequencies)3 JukesCantor (beast.evolution.substitutionmodel.JukesCantor)3 TreeParser (beast.util.TreeParser)3 GeneralSubstitutionModel (beast.evolution.substitutionmodel.GeneralSubstitutionModel)2 RandomTree (beast.evolution.tree.RandomTree)2 ConstantPopulation (beast.evolution.tree.coalescent.ConstantPopulation)2 TreeIntervals (beast.evolution.tree.coalescent.TreeIntervals)2