use of beast.evolution.alignment.TaxonSet in project beast2 by CompEvol.
the class MRCAPriorInputEditor method getTaxonCandidates.
Set<Taxon> getTaxonCandidates(MRCAPrior prior) {
Set<Taxon> candidates = new HashSet<>();
Tree tree = prior.treeInput.get();
String[] taxa = null;
if (tree.m_taxonset.get() != null) {
try {
TaxonSet set = tree.m_taxonset.get();
set.initAndValidate();
taxa = set.asStringList().toArray(new String[0]);
} catch (Exception e) {
taxa = prior.treeInput.get().getTaxaNames();
}
} else {
taxa = prior.treeInput.get().getTaxaNames();
}
for (String taxon : taxa) {
candidates.add(doc.getTaxon(taxon));
}
return candidates;
}
use of beast.evolution.alignment.TaxonSet in project beast2 by CompEvol.
the class MRCAPriorInputEditor method enableTipSampling.
// add TipDatesRandomWalker (if not present) and add to list of operators
private void enableTipSampling() {
// First, create/find the operator
TipDatesRandomWalker operator = null;
MRCAPrior prior = (MRCAPrior) m_beastObject;
TaxonSet taxonset = prior.taxonsetInput.get();
taxonset.initAndValidate();
// see if an old operator still hangs around -- happens when toggling the TipsOnly checkbox a few times
for (BEASTInterface o : taxonset.getOutputs()) {
if (o instanceof TipDatesRandomWalker) {
operator = (TipDatesRandomWalker) o;
}
}
if (operator == null) {
operator = new TipDatesRandomWalker();
operator.initByName("tree", prior.treeInput.get(), "taxonset", taxonset, "windowSize", 1.0, "weight", 1.0);
}
operator.setID("tipDatesSampler." + taxonset.getID());
doc.mcmc.get().setInputValue("operator", operator);
}
use of beast.evolution.alignment.TaxonSet in project bacter by tgvaughan.
the class TestBase method getTaxonSet.
public TaxonSet getTaxonSet(int nTaxa) {
List<Taxon> taxonList = new ArrayList<>();
for (int i = 0; i < nTaxa; i++) {
try {
taxonList.add(new Taxon("t" + i));
} catch (Exception e) {
System.out.println("Error creating test taxon.");
System.exit(1);
}
}
TaxonSet taxonSet = null;
try {
taxonSet = new TaxonSet(taxonList);
} catch (Exception e) {
System.out.println("Error creating test taxon set.");
System.exit(1);
}
return taxonSet;
}
use of beast.evolution.alignment.TaxonSet in project bacter by tgvaughan.
the class ACGLikelihoodTest method testLikelihoodCaching.
@Test
public void testLikelihoodCaching() throws Exception {
ConstantPopulation popFunc = new ConstantPopulation();
popFunc.initByName("popSize", new RealParameter("1.0"));
Locus locus = new Locus("locus", 10000);
TaxonSet taxonSet = getTaxonSet(10);
ConversionGraph acg = new SimulatedACG();
acg.initByName("rho", 5.0 / locus.getSiteCount(), "delta", 1000.0, "populationModel", popFunc, "locus", locus, "taxonset", taxonSet);
State state = new State();
state.initByName("stateNode", acg);
state.initialise();
System.out.println(acg);
// Site model:
JukesCantor jc = new JukesCantor();
jc.initByName();
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", new RealParameter("1"), "substModel", jc);
// Simulate alignment:
SimulatedAlignment alignment = new SimulatedAlignment();
alignment.initByName("acg", acg, "siteModel", siteModel, "outputFileName", "simulated_alignment.nexus", "useNexus", true);
// Calculate likelihood 1:
ACGLikelihood argLikelihood = new ACGLikelihood();
argLikelihood.initByName("locus", locus, "data", alignment, "tree", acg, "siteModel", siteModel);
ACGLikelihoodSlow argLikelihoodSlow = new ACGLikelihoodSlow();
argLikelihoodSlow.initByName("locus", locus, "data", alignment, "tree", acg, "siteModel", siteModel);
double logP1 = argLikelihood.calculateLogP();
double logP1prime = argLikelihoodSlow.calculateLogP();
double relError = 2.0 * Math.abs(logP1 - logP1prime) / Math.abs(logP1 + logP1prime);
System.out.format("logP=%g\nlogPprime=%g\nrelError=%g\n", logP1, logP1prime, relError);
assertTrue(relError < 1e-13);
// Add a single recombination event
Node node1 = acg.getExternalNodes().get(0);
Node node2 = node1.getParent();
double height1 = 0.5 * (node1.getHeight() + node1.getParent().getHeight());
double height2 = 0.5 * (node2.getHeight() + node2.getParent().getHeight());
int startLocus = 500;
int endLocus = 600;
Conversion recomb1 = new Conversion(node1, height1, node2, height2, startLocus, endLocus, acg, locus);
acg.addConversion(recomb1);
double logP2 = argLikelihood.calculateLogP();
double logP2prime = argLikelihoodSlow.calculateLogP();
relError = 2.0 * Math.abs(logP2 - logP2prime) / Math.abs(logP2 + logP2prime);
System.out.format("logP=%g\nlogPprime=%g\nrelError=%g\n", logP2, logP2prime, relError);
assertTrue(relError < 1e-13);
state.restore();
double logP3 = argLikelihood.calculateLogP();
double logP3prime = argLikelihoodSlow.calculateLogP();
relError = 2.0 * Math.abs(logP3 - logP3prime) / Math.abs(logP3 + logP3prime);
System.out.format("logP=%g\nlogPprime=%g\nrelError=%g\n", logP3, logP3prime, relError);
assertTrue(relError < 1e-13);
}
use of beast.evolution.alignment.TaxonSet in project bacter by tgvaughan.
the class SimulatedAlignmentTest method test.
@Test
public void test() throws Exception {
// Randomizer.setSeed(26);
Randomizer.setSeed(7);
Locus locus = new Locus("locus", 100000);
TaxonSet taxonSet = getTaxonSet(10);
ConstantPopulation popFunc = new ConstantPopulation();
popFunc.initByName("popSize", new RealParameter("1.0"));
ConversionGraph acg = new SimulatedACG();
acg.initByName("rho", 1.0 / 100000, "delta", 1000.0, "populationModel", popFunc, "locus", locus, "taxonset", taxonSet);
System.out.println(acg);
// Site model:
JukesCantor jc = new JukesCantor();
jc.initByName();
SiteModel siteModel = new SiteModel();
siteModel.initByName("mutationRate", new RealParameter("1.0"), "substModel", jc);
// Simulate alignment:
SimulatedAlignment alignment = new SimulatedAlignment();
alignment.initByName("acg", acg, "siteModel", siteModel, "outputFileName", "simulated_alignment.nexus", "useNexus", true);
for (Region region : acg.getRegions(locus)) System.out.println(new MarginalTree(acg, region));
// (Should be enough info here for precise agreement)
for (Region region : acg.getRegions(locus)) {
Alignment margAlign = createMarginalAlignment(alignment, region);
ClusterTree upgmaTree = new ClusterTree();
upgmaTree.initByName("clusterType", "upgma", "taxa", margAlign);
MarginalTree marginalTree = new MarginalTree(acg, region);
// outfMarg.println(marginalTree.getRoot() + ";");
// outfMarg.flush();
//
// outfUPGMA.println(upgmaTree.getRoot() + ";");
// outfUPGMA.flush();
assertTrue(topologiesEquivalent(marginalTree.getRoot(), upgmaTree.getRoot()));
}
// outfMarg.close();
// outfUPGMA.close();
}
Aggregations