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