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;
}
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;
}
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]) + ")");
}
}
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;
}
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;
}
Aggregations