Search in sources :

Example 11 with SitePatterns

use of dr.evolution.alignment.SitePatterns in project beast-mcmc by beast-dev.

the class AscertainmentCorrectedLikelihoodTest method testMissingPatterns.

public void testMissingPatterns() {
    SitePatterns patterns = new SitePatterns(alignment, null, 10, -1, 1, true);
    System.out.println("Using " + patterns.getPatternCount() + " patterns");
    double total = computeSumOfPatterns(patterns);
    System.out.println("Total of 10 missing (uncorrected) probabilities = " + total);
    assertEquals("uncorrected", 0.78287044, total, tolerance);
}
Also used : SitePatterns(dr.evolution.alignment.SitePatterns) AscertainedSitePatterns(dr.evolution.alignment.AscertainedSitePatterns)

Example 12 with SitePatterns

use of dr.evolution.alignment.SitePatterns in project beast-mcmc by beast-dev.

the class AscertainmentCorrectedLikelihoodTest method testAllPatterns.

public void testAllPatterns() {
    SitePatterns patterns = new SitePatterns(alignment, null, 0, -1, 1, true);
    System.out.println("Using " + patterns.getPatternCount() + " patterns");
    double total = computeSumOfPatterns(patterns);
    System.out.println("Total of all (uncorrected) probabilities = " + total);
    assertEquals("uncorrected", 1.0, total, tolerance);
}
Also used : SitePatterns(dr.evolution.alignment.SitePatterns) AscertainedSitePatterns(dr.evolution.alignment.AscertainedSitePatterns)

Example 13 with SitePatterns

use of dr.evolution.alignment.SitePatterns in project beast-mcmc by beast-dev.

the class LikelihoodTest method testLikelihoodJC69.

public void testLikelihoodJC69() {
    System.out.println("\nTest Likelihood using JC69:");
    // Sub model
    Parameter freqs = new Parameter.Default(new double[] { 0.25, 0.25, 0.25, 0.25 });
    Parameter kappa = new Parameter.Default(HKYParser.KAPPA, 1.0, 0, 100);
    FrequencyModel f = new FrequencyModel(Nucleotides.INSTANCE, freqs);
    HKY hky = new HKY(kappa, f);
    //siteModel
    GammaSiteModel siteModel = new GammaSiteModel(hky);
    Parameter mu = new Parameter.Default(GammaSiteModelParser.MUTATION_RATE, 1.0, 0, Double.POSITIVE_INFINITY);
    siteModel.setMutationRateParameter(mu);
    //treeLikelihood
    SitePatterns patterns = new SitePatterns(alignment, null, 0, -1, 1, true);
    TreeLikelihood treeLikelihood = new TreeLikelihood(patterns, treeModel, siteModel, null, null, false, false, true, false, false);
    assertEquals("treeLikelihoodJC69", format.format(-1992.20564), format.format(treeLikelihood.getLogLikelihood()));
}
Also used : FrequencyModel(dr.oldevomodel.substmodel.FrequencyModel) SitePatterns(dr.evolution.alignment.SitePatterns) GammaSiteModel(dr.oldevomodel.sitemodel.GammaSiteModel) HKY(dr.oldevomodel.substmodel.HKY) TreeLikelihood(dr.oldevomodel.treelikelihood.TreeLikelihood) Parameter(dr.inference.model.Parameter)

Example 14 with SitePatterns

use of dr.evolution.alignment.SitePatterns in project beast-mcmc by beast-dev.

the class SlidingPatternsOperator method doOperation.

public double doOperation() {
    // Select boundary to update, 0 => btw partition 0 and 1,  1 => btw partition 1 and 2, etc.
    int whichBoundary = MathUtils.nextInt(breakPoints.getDimension());
    int cBreakPt = (int) breakPoints.getParameterValue(whichBoundary);
    SitePatterns left = partitions.get(whichBoundary);
    SitePatterns right = partitions.get(whichBoundary + 1);
    int min = left.getFrom();
    int max = right.getTo();
    int pBreakPt = min;
    while (pBreakPt <= min || pBreakPt >= max) {
        // cBreakPt + [windowSize-1, windowSize+1] (and not 0)
        if (MathUtils.nextBoolean())
            pBreakPt = cBreakPt + MathUtils.nextInt(windowSize) + 1;
        else
            pBreakPt = cBreakPt - MathUtils.nextInt(windowSize) - 1;
    }
    return 0;
}
Also used : SitePatterns(dr.evolution.alignment.SitePatterns)

Example 15 with SitePatterns

use of dr.evolution.alignment.SitePatterns in project beast-mcmc by beast-dev.

the class PatternListGenerator method writePatternList.

/**
     * Write a single pattern list
     *
     * @param partition the partition to write a pattern list for
     * @param offset    offset by
     * @param every     skip every
     * @param writer    the writer
     */
private void writePatternList(final PartitionData partition, int offset, int every, final String codonPrefix, final boolean unique, final boolean strip, final XMLWriter writer) {
    Alignment alignment = partition.getAlignment();
    int from = partition.getFromSite();
    int to = partition.getToSite();
    int partEvery = partition.getEvery();
    if (partEvery > 1 && every > 1)
        throw new IllegalArgumentException();
    if (from < 1)
        from = 1;
    every = Math.max(partEvery, every);
    from += offset;
    // this object is created solely to calculate the number of patterns in the alignment
    SitePatterns patterns = new SitePatterns(alignment, null, from - 1, to - 1, every, strip, unique);
    writer.writeComment("The " + (unique ? "unique " : "") + "patterns from " + from + " to " + (to > 0 ? to : "end") + ((every > 1) ? " every " + every : ""), "npatterns=" + patterns.getPatternCount());
    List<Attribute> attributes = new ArrayList<Attribute>();
    // no 11 of 112 codon, which uses mergePatterns id instead
    if (codonPrefix != null) {
        attributes.add(new Attribute.Default<String>(XMLParser.ID, partition.getPrefix() + codonPrefix + SitePatternsParser.PATTERNS));
    }
    attributes.add(new Attribute.Default<String>("from", "" + from));
    if (to >= 0)
        attributes.add(new Attribute.Default<String>("to", "" + to));
    if (every > 1) {
        attributes.add(new Attribute.Default<String>("every", "" + every));
    }
    if (!unique) {
        attributes.add(new Attribute.Default<Boolean>(SitePatternsParser.UNIQUE, false));
    }
    if (strip) {
        // default true
        attributes.add(new Attribute.Default<Boolean>(SitePatternsParser.STRIP, false));
    }
    // generate <patterns>
    writer.writeOpenTag(SitePatternsParser.PATTERNS, attributes);
    writer.writeIDref(AlignmentParser.ALIGNMENT, alignment.getId());
    writer.writeCloseTag(SitePatternsParser.PATTERNS);
}
Also used : SitePatterns(dr.evolution.alignment.SitePatterns) Alignment(dr.evolution.alignment.Alignment) Attribute(dr.util.Attribute) ArrayList(java.util.ArrayList)

Aggregations

SitePatterns (dr.evolution.alignment.SitePatterns)30 Parameter (dr.inference.model.Parameter)20 FrequencyModel (dr.oldevomodel.substmodel.FrequencyModel)16 GammaSiteModel (dr.oldevomodel.sitemodel.GammaSiteModel)15 TreeLikelihood (dr.oldevomodel.treelikelihood.TreeLikelihood)15 HKY (dr.oldevomodel.substmodel.HKY)11 ArrayList (java.util.ArrayList)7 BranchRateModel (dr.evomodel.branchratemodel.BranchRateModel)6 GammaSiteRateModel (dr.evomodel.siteratemodel.GammaSiteRateModel)6 TaxonList (dr.evolution.util.TaxonList)5 BranchModel (dr.evomodel.branchmodel.BranchModel)5 ExchangeOperator (dr.evomodel.operators.ExchangeOperator)5 SubtreeSlideOperator (dr.evomodel.operators.SubtreeSlideOperator)5 WilsonBalding (dr.evomodel.operators.WilsonBalding)5 TreeModel (dr.evomodel.tree.TreeModel)5 ArrayLogFormatter (dr.inference.loggers.ArrayLogFormatter)5 MCLogger (dr.inference.loggers.MCLogger)5 TabDelimitedFormatter (dr.inference.loggers.TabDelimitedFormatter)5 MCMC (dr.inference.mcmc.MCMC)5 MCMCOptions (dr.inference.mcmc.MCMCOptions)5