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