Search in sources :

Example 1 with SimulatedACG

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

the class AddRemoveConversionTest method testHR.

/**
 * Tests that probability density of forward move calculated
 * by drawNewConversion() matches probability density of backward
 * move calculated by getConversionProb().
 *
 * @throws Exception
 */
@Test
public void testHR() 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);
    AddRemoveConversion operator = new AddRemoveConversion();
    // Loop until a valid proposal is made
    double logP1;
    List<Conversion> oldConversions;
    do {
        operator.initByName("weight", 1.0, "acg", acg, "delta", new RealParameter("50.0"), "populationModel", popFunc);
        oldConversions = Lists.newArrayList(acg.getConversions(locus));
        logP1 = operator.drawNewConversion();
    } while (Double.isInfinite(logP1));
    System.out.println("logP1 = " + logP1);
    // Identify new recomination
    Conversion newRecomb = null;
    for (Conversion recomb : acg.getConversions(locus)) {
        if (!oldConversions.contains(recomb))
            newRecomb = recomb;
    }
    assertNotNull(newRecomb);
    double logP2 = operator.getConversionProb(newRecomb);
    System.out.println("logP2 = " + logP2);
    assertTrue(Math.abs(logP1 - logP2) < 1e-10);
}
Also used : ConstantPopulation(beast.evolution.tree.coalescent.ConstantPopulation) 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 SimulatedACG

use of bacter.model.SimulatedACG 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 3 with SimulatedACG

use of bacter.model.SimulatedACG 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

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