Search in sources :

Example 1 with ACGCoalescent

use of bacter.model.ACGCoalescent in project bacter by tgvaughan.

the class AddRemoveConversionTest method testProbability.

/**
 * Tests whether probability of proposing a conversion lines up with
 * conversion probability found in ACGCoalescent.
 * @throws java.lang.Exception
 */
@Test
public void testProbability() throws Exception {
    ConstantPopulation popFunc = new ConstantPopulation();
    popFunc.initByName("popSize", new RealParameter("1.0"));
    Locus locus = new Locus("locus", 10000);
    TaxonSet taxonSet = getTaxonSet(10);
    SimulatedACG acg = new SimulatedACG();
    acg.initByName("rho", 1.0 / locus.getSiteCount(), "delta", 50.0, "locus", locus, "taxonset", taxonSet, "populationModel", popFunc);
    RealParameter rho = new RealParameter(Double.toString(1.0 / locus.getSiteCount()));
    RealParameter delta = new RealParameter("50.0");
    AddRemoveConversion operator = new AddRemoveConversion();
    operator.initByName("weight", 1.0, "acg", acg, "delta", delta, "populationModel", popFunc);
    ACGCoalescent coal = new ACGCoalescent();
    coal.initByName("tree", acg, "populationModel", popFunc, "rho", rho, "delta", delta);
    double logP1 = 0.0;
    double logP2 = 0.0;
    for (Conversion conv : acg.getConversions(locus)) {
        logP1 += operator.getConversionProb(conv);
        logP2 += coal.calculateConversionLogP(conv);
    }
    System.out.println("logP1 = " + logP1);
    System.out.println("logP2 = " + logP2);
    assertTrue(Math.abs(logP1 - logP2) < 1e-10);
}
Also used : ConstantPopulation(beast.evolution.tree.coalescent.ConstantPopulation) ACGCoalescent(bacter.model.ACGCoalescent) SimulatedACG(bacter.model.SimulatedACG) RealParameter(beast.core.parameter.RealParameter) Locus(bacter.Locus) TaxonSet(beast.evolution.alignment.TaxonSet) Conversion(bacter.Conversion) Test(org.junit.Test)

Example 2 with ACGCoalescent

use of bacter.model.ACGCoalescent in project bacter by tgvaughan.

the class CustomConnectors method applyRestrictions.

public static void applyRestrictions(BeautiDoc doc) {
    for (BEASTInterface p : doc.getPartitions("Tree")) {
        ACGLikelihood acgLikelihood = (ACGLikelihood) p;
        SimulatedACG acg = (SimulatedACG) ((ACGLikelihood) p).treeInput.get();
        ACGCoalescent coalescent = null;
        for (BEASTInterface output : acg.getOutputs()) {
            if (output instanceof ACGCoalescent) {
                coalescent = (ACGCoalescent) output;
                break;
            }
        }
        if (coalescent == null)
            continue;
        acg.setWholeLocusMode(coalescent.wholeLocusConversionsInput.get());
    }
}
Also used : ACGLikelihood(bacter.model.ACGLikelihood) ACGCoalescent(bacter.model.ACGCoalescent) SimulatedACG(bacter.model.SimulatedACG) BEASTInterface(beast.core.BEASTInterface)

Aggregations

ACGCoalescent (bacter.model.ACGCoalescent)2 SimulatedACG (bacter.model.SimulatedACG)2 Conversion (bacter.Conversion)1 Locus (bacter.Locus)1 ACGLikelihood (bacter.model.ACGLikelihood)1 BEASTInterface (beast.core.BEASTInterface)1 RealParameter (beast.core.parameter.RealParameter)1 TaxonSet (beast.evolution.alignment.TaxonSet)1 ConstantPopulation (beast.evolution.tree.coalescent.ConstantPopulation)1 Test (org.junit.Test)1