Simpler naming convention for AlleleFrequencyCalculation => AFCalc

This commit is contained in:
Mark DePristo 2012-10-05 15:56:06 -07:00
parent cf3f9d6ee8
commit ee2f12e2ac
17 changed files with 123 additions and 122 deletions

View File

@ -53,14 +53,14 @@ public class ExactAFCalculationPerformanceTest {
final SimpleTimer timer = new SimpleTimer();
for ( final int nonTypePL : Arrays.asList(10, 100, 1000) ) {
final ExactAFCalculation calc = testBuilder.makeModel();
final ExactAFCalc calc = testBuilder.makeModel();
final double[] priors = testBuilder.makePriors();
for ( int[] ACs : makeACs(testBuilder.numAltAlleles, testBuilder.nSamples*2) ) {
final VariantContext vc = testBuilder.makeACTest(ACs, 0, nonTypePL);
timer.start();
final AlleleFrequencyCalculationResult result = calc.getLog10PNonRef(vc, priors);
final AFCalcResult result = calc.getLog10PNonRef(vc, priors);
final long runtime = timer.getElapsedTimeNano();
int otherAC = 0;
@ -109,7 +109,7 @@ public class ExactAFCalculationPerformanceTest {
final SimpleTimer timer = new SimpleTimer();
for ( final int nonTypePL : Arrays.asList(100) ) {
final ExactAFCalculation calc = testBuilder.makeModel();
final ExactAFCalc calc = testBuilder.makeModel();
final double[] priors = testBuilder.makePriors();
final int[] ac = new int[testBuilder.numAltAlleles];
@ -123,7 +123,7 @@ public class ExactAFCalculationPerformanceTest {
vcb.genotypes(genotypes);
timer.start();
final AlleleFrequencyCalculationResult result = calc.getLog10PNonRef(vcb.make(), priors);
final AFCalcResult result = calc.getLog10PNonRef(vcb.make(), priors);
final long runtime = timer.getElapsedTimeNano();
final List<Object> columns = new LinkedList<Object>(coreValues);
@ -143,7 +143,7 @@ public class ExactAFCalculationPerformanceTest {
final SimpleTimer timer = new SimpleTimer();
for ( final int nonTypePL : Arrays.asList(100) ) {
final ExactAFCalculation calc = testBuilder.makeModel();
final ExactAFCalc calc = testBuilder.makeModel();
final double[] priors = testBuilder.makePriors();
final int[] ac = new int[testBuilder.numAltAlleles];
@ -153,7 +153,7 @@ public class ExactAFCalculationPerformanceTest {
final VariantContext vc = testBuilder.makeACTest(ac, nNonInformative, nonTypePL);
timer.start();
final AlleleFrequencyCalculationResult result = calc.getLog10PNonRef(vc, priors);
final AFCalcResult result = calc.getLog10PNonRef(vc, priors);
final long runtime = timer.getElapsedTimeNano();
final List<Object> columns = new LinkedList<Object>(coreValues);

View File

@ -47,11 +47,11 @@ public class ExactAFCalculationTestBuilder {
return nSamples;
}
public ExactAFCalculation makeModel() {
public ExactAFCalc makeModel() {
switch (modelType) {
case ReferenceDiploidExact: return new ReferenceDiploidExactAFCalculation(nSamples, 4);
case ConstrainedDiploidExact: return new ConstrainedDiploidExactAFCalculation(nSamples, 4);
case GeneralExact: return new GeneralPloidyExactAFCalculation(nSamples, 4, 2);
case ReferenceDiploidExact: return new ReferenceDiploidExactAFCalc(nSamples, 4);
case ConstrainedDiploidExact: return new ConstrainedDiploidExactAFCalc(nSamples, 4);
case GeneralExact: return new GeneralPloidyExactAFCalc(nSamples, 4, 2);
default: throw new RuntimeException("Unexpected type " + modelType);
}
}

View File

@ -37,19 +37,19 @@ import org.broadinstitute.sting.utils.variantcontext.*;
import java.io.PrintStream;
import java.util.*;
public class GeneralPloidyExactAFCalculation extends ExactAFCalculation {
public class GeneralPloidyExactAFCalc extends ExactAFCalc {
static final int MAX_LENGTH_FOR_POOL_PL_LOGGING = 10; // if PL vectors longer than this # of elements, don't log them
private final int ploidy;
private final static double MAX_LOG10_ERROR_TO_STOP_EARLY = 6; // we want the calculation to be accurate to 1 / 10^6
private final static boolean VERBOSE = false;
protected GeneralPloidyExactAFCalculation(UnifiedArgumentCollection UAC, int N, Logger logger, PrintStream verboseWriter) {
protected GeneralPloidyExactAFCalc(UnifiedArgumentCollection UAC, int N, Logger logger, PrintStream verboseWriter) {
super(UAC, N, logger, verboseWriter);
ploidy = UAC.samplePloidy;
}
public GeneralPloidyExactAFCalculation(final int nSamples, final int maxAltAlleles, final int ploidy) {
public GeneralPloidyExactAFCalc(final int nSamples, final int maxAltAlleles, final int ploidy) {
super(nSamples, maxAltAlleles, maxAltAlleles, null, null, null);
this.ploidy = ploidy;
}
@ -78,7 +78,7 @@ public class GeneralPloidyExactAFCalculation extends ExactAFCalculation {
@Override
public void computeLog10PNonRef(final VariantContext vc,
final double[] log10AlleleFrequencyPriors,
final AlleleFrequencyCalculationResult result) {
final AFCalcResult result) {
combineSinglePools(vc.getGenotypes(), vc.getNAlleles(), ploidy, log10AlleleFrequencyPriors, result);
}
@ -186,7 +186,7 @@ public class GeneralPloidyExactAFCalculation extends ExactAFCalculation {
final int numAlleles,
final int ploidyPerPool,
final double[] log10AlleleFrequencyPriors,
final AlleleFrequencyCalculationResult result) {
final AFCalcResult result) {
final ArrayList<double[]> genotypeLikelihoods = getGLs(GLs);
@ -213,7 +213,7 @@ public class GeneralPloidyExactAFCalculation extends ExactAFCalculation {
public static CombinedPoolLikelihoods fastCombineMultiallelicPool(final CombinedPoolLikelihoods originalPool, double[] newGL, int originalPloidy, int newGLPloidy, int numAlleles,
final double[] log10AlleleFrequencyPriors,
final AlleleFrequencyCalculationResult result) {
final AFCalcResult result) {
@ -276,7 +276,7 @@ public class GeneralPloidyExactAFCalculation extends ExactAFCalculation {
final double[] log10AlleleFrequencyPriors,
final int originalPloidy,
final int newGLPloidy,
final AlleleFrequencyCalculationResult result,
final AFCalcResult result,
final StateTracker stateTracker,
final LinkedList<ExactACset> ACqueue,
final HashMap<ExactACcounts, ExactACset> indexesToACset) {
@ -343,7 +343,7 @@ public class GeneralPloidyExactAFCalculation extends ExactAFCalculation {
*/
public static void combineMultiallelicPoolNaively(CombinedPoolLikelihoods originalPool, double[] yy, int ploidy1, int ploidy2, int numAlleles,
final double[] log10AlleleFrequencyPriors,
final AlleleFrequencyCalculationResult result) {
final AFCalcResult result) {
/*
final int dim1 = GenotypeLikelihoods.numLikelihoods(numAlleles, ploidy1);
final int dim2 = GenotypeLikelihoods.numLikelihoods(numAlleles, ploidy2);
@ -405,7 +405,7 @@ public class GeneralPloidyExactAFCalculation extends ExactAFCalculation {
final double[] secondGL,
final double[] log10AlleleFrequencyPriors,
final int numAlleles, final int ploidy1, final int ploidy2,
final AlleleFrequencyCalculationResult result) {
final AFCalcResult result) {
final int newPloidy = ploidy1 + ploidy2;
@ -511,7 +511,7 @@ public class GeneralPloidyExactAFCalculation extends ExactAFCalculation {
*/
public static ProbabilityVector combineBiallelicPoolsNaively(final ProbabilityVector originalPool, final double[] newPLVector,
final int ploidy1, final int ploidy2, final double[] log10AlleleFrequencyPriors,
final AlleleFrequencyCalculationResult result) {
final AFCalcResult result) {
final int newPloidy = ploidy1 + ploidy2;

View File

@ -53,16 +53,16 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
private class GetGLsTest extends TestDataProvider {
GenotypesContext GLs;
int numAltAlleles;
final ExactAFCalculation calc;
final ExactAFCalc calc;
final int[] expectedACs;
final double[] priors;
final String priorName;
private GetGLsTest(final ExactAFCalculation calculation, int numAltAlleles, List<Genotype> arg, final double[] priors, final String priorName) {
private GetGLsTest(final ExactAFCalc calc, int numAltAlleles, List<Genotype> arg, final double[] priors, final String priorName) {
super(GetGLsTest.class);
GLs = GenotypesContext.create(new ArrayList<Genotype>(arg));
this.numAltAlleles = numAltAlleles;
this.calc = calculation;
this.calc = calc;
this.priors = priors;
this.priorName = priorName;
@ -76,12 +76,12 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
}
}
public AlleleFrequencyCalculationResult execute() {
public AFCalcResult execute() {
return getCalc().getLog10PNonRef(getVC(), getPriors());
}
public AlleleFrequencyCalculationResult executeRef() {
final ExactAFCalculation ref = new ReferenceDiploidExactAFCalculation(getCalc().nSamples, getCalc().getMaxAltAlleles());
public AFCalcResult executeRef() {
final ExactAFCalc ref = new ReferenceDiploidExactAFCalc(getCalc().nSamples, getCalc().getMaxAltAlleles());
return ref.getLog10PNonRef(getVC(), getPriors());
}
@ -89,7 +89,7 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
return priors;
}
public ExactAFCalculation getCalc() {
public ExactAFCalc getCalc() {
return calc;
}
@ -122,9 +122,9 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
final List<Genotype> triAllelicSamples = Arrays.asList(AA2, AB2, BB2, AC2, BC2, CC2);
for ( final int nSamples : Arrays.asList(1, 2, 3, 4) ) {
final ExactAFCalculation diploidCalc = new ReferenceDiploidExactAFCalculation(nSamples, 4);
final ExactAFCalculation optDiploidCalc = new ConstrainedDiploidExactAFCalculation(nSamples, 4);
final ExactAFCalculation generalCalc = new GeneralPloidyExactAFCalculation(nSamples, 4, 2);
final ExactAFCalc diploidCalc = new ReferenceDiploidExactAFCalc(nSamples, 4);
final ExactAFCalc optDiploidCalc = new ConstrainedDiploidExactAFCalc(nSamples, 4);
final ExactAFCalc generalCalc = new GeneralPloidyExactAFCalc(nSamples, 4, 2);
final int nPriorValues = 2*nSamples+1;
final double[] flatPriors = MathUtils.normalizeFromLog10(new double[nPriorValues], true); // flat priors
@ -132,7 +132,7 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
UnifiedGenotyperEngine.computeAlleleFrequencyPriors(nPriorValues - 1, humanPriors, 0.001);
for ( final double[] priors : Arrays.asList(flatPriors, humanPriors) ) { // , humanPriors) ) {
for ( ExactAFCalculation model : Arrays.asList(diploidCalc, generalCalc, optDiploidCalc) ) {
for ( ExactAFCalc model : Arrays.asList(diploidCalc, generalCalc, optDiploidCalc) ) {
final String priorName = priors == humanPriors ? "human" : "flat";
// bi-allelic
@ -179,12 +179,12 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
samples.addAll(Collections.nCopies(nNonInformative, testData.nonInformative));
final int nSamples = samples.size();
final ExactAFCalculation diploidCalc = new ReferenceDiploidExactAFCalculation(nSamples, 4);
final ExactAFCalculation optDiploidCalc = new ConstrainedDiploidExactAFCalculation(nSamples, 4);
final ExactAFCalculation generalCalc = new GeneralPloidyExactAFCalculation(nSamples, 4, 2);
final ExactAFCalc diploidCalc = new ReferenceDiploidExactAFCalc(nSamples, 4);
final ExactAFCalc optDiploidCalc = new ConstrainedDiploidExactAFCalc(nSamples, 4);
final ExactAFCalc generalCalc = new GeneralPloidyExactAFCalc(nSamples, 4, 2);
final double[] priors = new double[2*nSamples+1]; // flat priors
for ( ExactAFCalculation model : Arrays.asList(diploidCalc, optDiploidCalc, generalCalc) ) {
for ( ExactAFCalc model : Arrays.asList(diploidCalc, optDiploidCalc, generalCalc) ) {
final GetGLsTest onlyInformative = new GetGLsTest(model, testData.nAltAlleles, testData.called, priors, "flat");
for ( int rotation = 0; rotation < nSamples; rotation++ ) {
@ -206,8 +206,8 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
@Test(enabled = true, dataProvider = "GLsWithNonInformative", dependsOnMethods = "testGLs")
public void testGLsWithNonInformative(GetGLsTest onlyInformative, GetGLsTest withNonInformative) {
final AlleleFrequencyCalculationResult expected = onlyInformative.execute();
final AlleleFrequencyCalculationResult actual = withNonInformative.execute();
final AFCalcResult expected = onlyInformative.execute();
final AFCalcResult actual = withNonInformative.execute();
testResultSimple(withNonInformative);
@ -222,8 +222,8 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
}
private void testResultSimple(final GetGLsTest cfg) {
final AlleleFrequencyCalculationResult refResult = cfg.executeRef();
final AlleleFrequencyCalculationResult result = cfg.execute();
final AFCalcResult refResult = cfg.executeRef();
final AFCalcResult result = cfg.execute();
compareToRefResult(refResult, result);
@ -254,8 +254,8 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
// }
}
private void compareToRefResult(final AlleleFrequencyCalculationResult refResult,
final AlleleFrequencyCalculationResult result) {
private void compareToRefResult(final AFCalcResult refResult,
final AFCalcResult result) {
final double TOLERANCE = 1;
// MAP may not be equal
// Assert.assertEquals(result.getAlleleCountsOfMAP(), refResult.getAlleleCountsOfMAP());
@ -271,23 +271,23 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
}
@Test(enabled = true, dataProvider = "Models")
public void testLargeGLs(final ExactAFCalculation calc) {
public void testLargeGLs(final ExactAFCalc calc) {
final Genotype BB = makePL(Arrays.asList(C, C), 20000000, 20000000, 0);
GetGLsTest cfg = new GetGLsTest(calc, 1, Arrays.asList(BB, BB, BB), FLAT_3SAMPLE_PRIORS, "flat");
final AlleleFrequencyCalculationResult result = cfg.execute();
final AFCalcResult result = cfg.execute();
int calculatedAlleleCount = result.getAlleleCountsOfMAP()[0];
Assert.assertEquals(calculatedAlleleCount, 6);
}
@Test(enabled = true, dataProvider = "Models")
public void testMismatchedGLs(final ExactAFCalculation calc) {
public void testMismatchedGLs(final ExactAFCalc calc) {
final Genotype AB = makePL(Arrays.asList(A, C), 2000, 0, 2000, 2000, 2000, 2000);
final Genotype AC = makePL(Arrays.asList(A, G), 100, 100, 100, 0, 100, 100);
GetGLsTest cfg = new GetGLsTest(calc, 2, Arrays.asList(AB, AC), FLAT_3SAMPLE_PRIORS, "flat");
final AlleleFrequencyCalculationResult result = cfg.execute();
final AFCalcResult result = cfg.execute();
Assert.assertEquals(result.getAlleleCountsOfMAP()[0], 1);
Assert.assertEquals(result.getAlleleCountsOfMAP()[1], 1);
@ -297,15 +297,15 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
public Object[][] makeModels() {
List<Object[]> tests = new ArrayList<Object[]>();
tests.add(new Object[]{new ReferenceDiploidExactAFCalculation(2, 4)});
// tests.add(new Object[]{new ConstrainedDiploidExactAFCalculation(2, 4)});
// tests.add(new Object[]{new GeneralPloidyExactAFCalculation(2, 4, 2)});
tests.add(new Object[]{new ReferenceDiploidExactAFCalc(2, 4)});
// tests.add(new Object[]{new ConstrainedDiploidExactAFCalc(2, 4)});
// tests.add(new Object[]{new GeneralPloidyExactAFCalc(2, 4, 2)});
return tests.toArray(new Object[][]{});
}
@Test(enabled = true, dataProvider = "Models")
public void testBiallelicPriors(final ExactAFCalculation model) {
public void testBiallelicPriors(final ExactAFCalc model) {
final int REF_PL = 10;
final Genotype AB = makePL(Arrays.asList(A,C), REF_PL, 0, 10000);
@ -313,7 +313,7 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
final double refPrior = 1 - QualityUtils.qualToErrorProb(log10NonRefPrior);
final double[] priors = MathUtils.toLog10(new double[]{refPrior, (1-refPrior) / 2, (1-refPrior) / 2});
GetGLsTest cfg = new GetGLsTest(model, 1, Arrays.asList(AB), priors, "pNonRef" + log10NonRefPrior);
final AlleleFrequencyCalculationResult result = cfg.execute();
final AFCalcResult result = cfg.execute();
final int actualAC = result.getAlleleCountsOfMAP()[0];
final double pRefWithPrior = AB.getLikelihoods().getAsVector()[0] + priors[0];
@ -333,7 +333,7 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
}
@Test(enabled = false, dataProvider = "Models")
public void testTriallelicPriors(final ExactAFCalculation model) {
public void testTriallelicPriors(final ExactAFCalc model) {
// TODO
// TODO
// TODO THIS SEEMS TO ID A BUG IN THE EXACT MODEL FOR MULTI-ALLELICS, AS THE
@ -349,7 +349,7 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
final double nonRefPrior = (1-refPrior) / 2;
final double[] priors = MathUtils.toLog10(new double[]{refPrior, nonRefPrior, nonRefPrior, nonRefPrior, nonRefPrior, nonRefPrior});
GetGLsTest cfg = new GetGLsTest(model, 2, Arrays.asList(AB, AC), priors, "pNonRef" + log10NonRefPrior);
final AlleleFrequencyCalculationResult result = cfg.execute();
final AFCalcResult result = cfg.execute();
final int actualAC_AB = result.getAlleleCountsOfMAP()[0];
final double pRefABWithPrior = AB.getLikelihoods().getAsVector()[0] + priors[0];
@ -401,7 +401,7 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
ExactAFCalculationTestBuilder.PriorType.human);
final VariantContext vc = testBuilder.makeACTest(requestedACs, nNonInformative, 100);
final int[] maxACsToVisit = ((ConstrainedDiploidExactAFCalculation)testBuilder.makeModel()).computeMaxACs(vc);
final int[] maxACsToVisit = ((ConstrainedDiploidExactAFCalc)testBuilder.makeModel()).computeMaxACs(vc);
testExpectedACs(vc, maxACsToVisit);
}
@ -466,7 +466,7 @@ public class ExactAFCalculationModelUnitTest extends BaseTest {
final ExactAFCalculationTestBuilder testBuilder
= new ExactAFCalculationTestBuilder(1, vc.getNAlleles()-1, modelType,
ExactAFCalculationTestBuilder.PriorType.human);
final int[] maxACsToVisit = ((ConstrainedDiploidExactAFCalculation)testBuilder.makeModel()).computeMaxACs(vc);
final int[] maxACsToVisit = ((ConstrainedDiploidExactAFCalc)testBuilder.makeModel()).computeMaxACs(vc);
testExpectedACs(vc, maxACsToVisit);
}
}

View File

@ -138,11 +138,11 @@ public class GeneralPloidyAFCalculationModelUnitTest extends BaseTest {
@Test(dataProvider = "getGLs")
public void testGLs(GetGLsTest cfg) {
final AlleleFrequencyCalculationResult result = new AlleleFrequencyCalculationResult(cfg.numAltAlleles);
final AFCalcResult result = new AFCalcResult(cfg.numAltAlleles);
final int len = GeneralPloidyGenotypeLikelihoods.getNumLikelihoodElements(1 + cfg.numAltAlleles, cfg.ploidy * cfg.GLs.size());
double[] priors = new double[len]; // flat priors
GeneralPloidyExactAFCalculation.combineSinglePools(cfg.GLs, 1 + cfg.numAltAlleles, cfg.ploidy, priors, result);
GeneralPloidyExactAFCalc.combineSinglePools(cfg.GLs, 1 + cfg.numAltAlleles, cfg.ploidy, priors, result);
int nameIndex = 1;
for ( int allele = 0; allele < cfg.numAltAlleles; allele++, nameIndex+=2 ) {
int expectedAlleleCount = Integer.valueOf(cfg.name.substring(nameIndex, nameIndex+1));

View File

@ -27,7 +27,7 @@ package org.broadinstitute.sting.gatk.walkers.genotyper;
import org.broadinstitute.sting.commandline.*;
import org.broadinstitute.sting.gatk.arguments.StandardCallerArgumentCollection;
import org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.AlleleFrequencyCalculation;
import org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.AFCalc;
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
import org.broadinstitute.sting.utils.variantcontext.VariantContextUtils;
@ -42,7 +42,7 @@ public class UnifiedArgumentCollection extends StandardCallerArgumentCollection
*/
@Advanced
@Argument(fullName = "p_nonref_model", shortName = "pnrm", doc = "Non-reference probability calculation model to employ", required = false)
protected AlleleFrequencyCalculation.Model AFmodel = AlleleFrequencyCalculation.Model.EXACT;
protected AFCalc.Model AFmodel = AFCalc.Model.EXACT;
/**
* The PCR error rate is independent of the sequencing error rate, which is necessary because we cannot necessarily

View File

@ -249,7 +249,7 @@ public class UnifiedGenotyper extends LocusWalker<List<VariantCallContext>, Unif
throw new UserException("Incorrect genotype calculation model chosen. Only [POOLSNP|POOLINDEL|POOLBOTH] supported with this walker if sample ploidy != 2");
}
if (UAC.AFmodel != AlleleFrequencyCalculation.Model.POOL)
if (UAC.AFmodel != AFCalc.Model.POOL)
throw new UserException("Incorrect AF Calculation model. Only POOL model supported if sample ploidy != 2");
}

View File

@ -34,8 +34,8 @@ import org.broadinstitute.sting.gatk.contexts.AlignmentContextUtils;
import org.broadinstitute.sting.gatk.contexts.ReferenceContext;
import org.broadinstitute.sting.gatk.refdata.RefMetaDataTracker;
import org.broadinstitute.sting.gatk.walkers.annotator.VariantAnnotatorEngine;
import org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.AlleleFrequencyCalculation;
import org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.AlleleFrequencyCalculationResult;
import org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.AFCalc;
import org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.AFCalcResult;
import org.broadinstitute.sting.utils.*;
import org.broadinstitute.sting.utils.baq.BAQ;
import org.broadinstitute.sting.utils.classloader.PluginManager;
@ -80,10 +80,10 @@ public class UnifiedGenotyperEngine {
private ThreadLocal<Map<String, GenotypeLikelihoodsCalculationModel>> glcm = new ThreadLocal<Map<String, GenotypeLikelihoodsCalculationModel>>();
// the model used for calculating p(non-ref)
private ThreadLocal<AlleleFrequencyCalculation> afcm = new ThreadLocal<AlleleFrequencyCalculation>();
private ThreadLocal<AFCalc> afcm = new ThreadLocal<AFCalc>();
// the allele frequency likelihoods and posteriors (allocated once as an optimization)
private ThreadLocal<AlleleFrequencyCalculationResult> alleleFrequencyCalculationResult = new ThreadLocal<AlleleFrequencyCalculationResult>();
private ThreadLocal<AFCalcResult> alleleFrequencyCalculationResult = new ThreadLocal<AFCalcResult>();
// because the allele frequency priors are constant for a given i, we cache the results to avoid having to recompute everything
private final double[] log10AlleleFrequencyPriorsSNPs;
@ -355,9 +355,9 @@ public class UnifiedGenotyperEngine {
// initialize the data for this thread if that hasn't been done yet
if ( afcm.get() == null ) {
afcm.set(getAlleleFrequencyCalculationObject(N, logger, verboseWriter, UAC));
alleleFrequencyCalculationResult.set(new AlleleFrequencyCalculationResult(UAC.MAX_ALTERNATE_ALLELES));
alleleFrequencyCalculationResult.set(new AFCalcResult(UAC.MAX_ALTERNATE_ALLELES));
}
AlleleFrequencyCalculationResult AFresult = alleleFrequencyCalculationResult.get();
AFCalcResult AFresult = alleleFrequencyCalculationResult.get();
// estimate our confidence in a reference call and return
if ( vc.getNSamples() == 0 ) {
@ -743,9 +743,9 @@ public class UnifiedGenotyperEngine {
return glcm;
}
private static AlleleFrequencyCalculation getAlleleFrequencyCalculationObject(int N, Logger logger, PrintStream verboseWriter, UnifiedArgumentCollection UAC) {
private static AFCalc getAlleleFrequencyCalculationObject(int N, Logger logger, PrintStream verboseWriter, UnifiedArgumentCollection UAC) {
List<Class<? extends AlleleFrequencyCalculation>> afClasses = new PluginManager<AlleleFrequencyCalculation>(AlleleFrequencyCalculation.class).getPlugins();
List<Class<? extends AFCalc>> afClasses = new PluginManager<AFCalc>(AFCalc.class).getPlugins();
// user-specified name
String afModelName = UAC.AFmodel.implementationName;
@ -756,21 +756,21 @@ public class UnifiedGenotyperEngine {
afModelName = "Diploid" + afModelName;
for (int i = 0; i < afClasses.size(); i++) {
Class<? extends AlleleFrequencyCalculation> afClass = afClasses.get(i);
Class<? extends AFCalc> afClass = afClasses.get(i);
String key = afClass.getSimpleName().replace("AFCalculationModel","").toUpperCase();
if (afModelName.equalsIgnoreCase(key)) {
try {
Object args[] = new Object[]{UAC,N,logger,verboseWriter};
Constructor c = afClass.getDeclaredConstructor(UnifiedArgumentCollection.class, int.class, Logger.class, PrintStream.class);
return (AlleleFrequencyCalculation)c.newInstance(args);
return (AFCalc)c.newInstance(args);
}
catch (Exception e) {
throw new IllegalArgumentException("Unexpected AlleleFrequencyCalculation " + UAC.AFmodel);
throw new IllegalArgumentException("Unexpected AFCalc " + UAC.AFmodel);
}
}
}
throw new IllegalArgumentException("Unexpected AlleleFrequencyCalculation " + UAC.AFmodel);
throw new IllegalArgumentException("Unexpected AFCalc " + UAC.AFmodel);
}
public static VariantContext getVCFromAllelesRod(RefMetaDataTracker tracker, ReferenceContext ref, GenomeLoc loc, boolean requireSNP, Logger logger, final RodBinding<VariantContext> allelesBinding) {

View File

@ -48,12 +48,12 @@ import java.util.List;
/**
* Generic interface for calculating the probability of alleles segregating given priors and genotype likelihoods
*/
public abstract class AlleleFrequencyCalculation implements Cloneable {
private final static Logger defaultLogger = Logger.getLogger(AlleleFrequencyCalculation.class);
public abstract class AFCalc implements Cloneable {
private final static Logger defaultLogger = Logger.getLogger(AFCalc.class);
public enum Model {
/** The default model with the best performance in all cases */
EXACT("ExactAFCalculation");
EXACT("ExactAFCalc");
public final String implementationName;
@ -74,16 +74,16 @@ public abstract class AlleleFrequencyCalculation implements Cloneable {
private SimpleTimer callTimer = new SimpleTimer();
private PrintStream callReport = null;
protected AlleleFrequencyCalculation(final UnifiedArgumentCollection UAC, final int nSamples, final Logger logger, final PrintStream verboseWriter) {
protected AFCalc(final UnifiedArgumentCollection UAC, final int nSamples, final Logger logger, final PrintStream verboseWriter) {
this(nSamples, UAC.MAX_ALTERNATE_ALLELES, UAC.MAX_ALTERNATE_ALLELES_FOR_INDELS, UAC.exactCallsLog, logger, verboseWriter);
}
protected AlleleFrequencyCalculation(final int nSamples,
final int maxAltAlleles,
final int maxAltAllelesForIndels,
final File exactCallsLog,
final Logger logger,
final PrintStream verboseWriter) {
protected AFCalc(final int nSamples,
final int maxAltAlleles,
final int maxAltAllelesForIndels,
final File exactCallsLog,
final Logger logger,
final PrintStream verboseWriter) {
if ( nSamples < 0 ) throw new IllegalArgumentException("nSamples must be greater than zero " + nSamples);
if ( maxAltAlleles < 1 ) throw new IllegalArgumentException("maxAltAlleles must be greater than zero " + maxAltAlleles);
@ -97,13 +97,13 @@ public abstract class AlleleFrequencyCalculation implements Cloneable {
}
/**
* @see #getLog10PNonRef(org.broadinstitute.sting.utils.variantcontext.VariantContext, double[], AlleleFrequencyCalculationResult)
* @see #getLog10PNonRef(org.broadinstitute.sting.utils.variantcontext.VariantContext, double[], AFCalcResult)
*
* Allocates a new results object. Useful for testing but slow in practice.
*/
public final AlleleFrequencyCalculationResult getLog10PNonRef(final VariantContext vc,
public final AFCalcResult getLog10PNonRef(final VariantContext vc,
final double[] log10AlleleFrequencyPriors) {
return getLog10PNonRef(vc, log10AlleleFrequencyPriors, new AlleleFrequencyCalculationResult(getMaxAltAlleles()));
return getLog10PNonRef(vc, log10AlleleFrequencyPriors, new AFCalcResult(getMaxAltAlleles()));
}
/**
@ -114,9 +114,9 @@ public abstract class AlleleFrequencyCalculation implements Cloneable {
* @param result a pre-allocated (for efficiency) object to hold the result of the calculation
* @return result (for programming convenience)
*/
public final AlleleFrequencyCalculationResult getLog10PNonRef(final VariantContext vc,
public final AFCalcResult getLog10PNonRef(final VariantContext vc,
final double[] log10AlleleFrequencyPriors,
final AlleleFrequencyCalculationResult result) {
final AFCalcResult result) {
if ( vc == null ) throw new IllegalArgumentException("VariantContext cannot be null");
if ( log10AlleleFrequencyPriors == null ) throw new IllegalArgumentException("priors vector cannot be null");
if ( result == null ) throw new IllegalArgumentException("Results object cannot be null");
@ -168,7 +168,7 @@ public abstract class AlleleFrequencyCalculation implements Cloneable {
// TODO -- add consistent requires among args
public abstract void computeLog10PNonRef(final VariantContext vc,
final double[] log10AlleleFrequencyPriors,
final AlleleFrequencyCalculationResult result);
final AFCalcResult result);
/**
* Must be overridden by concrete subclasses

View File

@ -41,7 +41,7 @@ import java.util.List;
*
* TODO -- WHAT IS THE CONTRACT ON MAP AC AND P NON REF?
*/
public class AlleleFrequencyCalculationResult {
public class AFCalcResult {
// These variables are intended to contain the MLE and MAP (and their corresponding allele counts) of the site over all alternate alleles
private double log10MLE;
private double log10MAP;
@ -71,7 +71,7 @@ public class AlleleFrequencyCalculationResult {
*
* @param maxAltAlleles an integer >= 1
*/
public AlleleFrequencyCalculationResult(final int maxAltAlleles) {
public AFCalcResult(final int maxAltAlleles) {
if ( maxAltAlleles < 1 ) throw new IllegalArgumentException("maxAltAlleles must be >= 0, saw " + maxAltAlleles);
alleleCountsOfMLE = new int[maxAltAlleles];
@ -227,7 +227,7 @@ public class AlleleFrequencyCalculationResult {
* Resetting of the data is done by the calculation model itself, so shouldn't be done by callers any longer
*/
protected void reset() {
log10MLE = log10MAP = log10LikelihoodOfAFzero = log10PosteriorOfAFzero = AlleleFrequencyCalculation.VALUE_NOT_CALCULATED;
log10MLE = log10MAP = log10LikelihoodOfAFzero = log10PosteriorOfAFzero = AFCalc.VALUE_NOT_CALCULATED;
for ( int i = 0; i < alleleCountsOfMLE.length; i++ ) {
alleleCountsOfMLE[i] = 0;
alleleCountsOfMAP[i] = 0;

View File

@ -10,16 +10,16 @@ import org.broadinstitute.sting.utils.variantcontext.VariantContext;
import java.io.PrintStream;
public class ConstrainedDiploidExactAFCalculation extends DiploidExactAFCalculation {
public ConstrainedDiploidExactAFCalculation(final int nSamples, final int maxAltAlleles) {
public class ConstrainedDiploidExactAFCalc extends DiploidExactAFCalc {
public ConstrainedDiploidExactAFCalc(final int nSamples, final int maxAltAlleles) {
super(nSamples, maxAltAlleles);
}
public ConstrainedDiploidExactAFCalculation(UnifiedArgumentCollection UAC, int N, Logger logger, PrintStream verboseWriter) {
public ConstrainedDiploidExactAFCalc(UnifiedArgumentCollection UAC, int N, Logger logger, PrintStream verboseWriter) {
super(UAC, N, logger, verboseWriter);
}
protected StateTracker makeMaxLikelihood(final VariantContext vc, final AlleleFrequencyCalculationResult result) {
protected StateTracker makeMaxLikelihood(final VariantContext vc, final AFCalcResult result) {
final int[] maxACsToConsider = computeMaxACs(vc);
result.setAClimits(maxACsToConsider);
return new StateTracker(maxACsToConsider);

View File

@ -33,21 +33,21 @@ import org.broadinstitute.sting.utils.variantcontext.*;
import java.io.PrintStream;
import java.util.*;
public abstract class DiploidExactAFCalculation extends ExactAFCalculation {
public DiploidExactAFCalculation(final int nSamples, final int maxAltAlleles) {
public abstract class DiploidExactAFCalc extends ExactAFCalc {
public DiploidExactAFCalc(final int nSamples, final int maxAltAlleles) {
super(nSamples, maxAltAlleles, maxAltAlleles, null, null, null);
}
public DiploidExactAFCalculation(UnifiedArgumentCollection UAC, int N, Logger logger, PrintStream verboseWriter) {
public DiploidExactAFCalc(UnifiedArgumentCollection UAC, int N, Logger logger, PrintStream verboseWriter) {
super(UAC, N, logger, verboseWriter);
}
protected abstract StateTracker makeMaxLikelihood(final VariantContext vc, final AlleleFrequencyCalculationResult result);
protected abstract StateTracker makeMaxLikelihood(final VariantContext vc, final AFCalcResult result);
@Override
public void computeLog10PNonRef(final VariantContext vc,
final double[] log10AlleleFrequencyPriors,
final AlleleFrequencyCalculationResult result) {
final AFCalcResult result) {
final int numAlternateAlleles = vc.getNAlleles() - 1;
final ArrayList<double[]> genotypeLikelihoods = getGLs(vc.getGenotypes());
final int numSamples = genotypeLikelihoods.size()-1;
@ -161,7 +161,7 @@ public abstract class DiploidExactAFCalculation extends ExactAFCalculation {
final LinkedList<ExactACset> ACqueue,
final HashMap<ExactACcounts, ExactACset> indexesToACset,
final double[] log10AlleleFrequencyPriors,
final AlleleFrequencyCalculationResult result) {
final AFCalcResult result) {
//if ( DEBUG )
// System.out.printf(" *** computing LofK for set=%s%n", set.ACcounts);
@ -250,7 +250,7 @@ public abstract class DiploidExactAFCalculation extends ExactAFCalculation {
private void computeLofK(final ExactACset set,
final ArrayList<double[]> genotypeLikelihoods,
final double[] log10AlleleFrequencyPriors,
final AlleleFrequencyCalculationResult result) {
final AFCalcResult result) {
set.getLog10Likelihoods()[0] = 0.0; // the zero case
final int totalK = set.getACsum();

View File

@ -1,5 +1,7 @@
package org.broadinstitute.sting.gatk.walkers.genotyper.afcalc;
import org.broadinstitute.sting.utils.MathUtils;
import java.util.Arrays;
/**
@ -21,16 +23,15 @@ public final class ExactACset {
public ExactACset(final int size, final ExactACcounts ACcounts) {
this.ACcounts = ACcounts;
log10Likelihoods = new double[size];
Arrays.fill(getLog10Likelihoods(), Double.NEGATIVE_INFINITY);
Arrays.fill(log10Likelihoods, Double.NEGATIVE_INFINITY);
}
// sum of all the non-reference alleles
/**
* sum of all the non-reference alleles
*/
public int getACsum() {
if ( sum == -1 ) {
sum = 0;
for ( int count : getACcounts().getCounts() )
sum += count;
}
if ( sum == -1 )
sum = (int)MathUtils.sum(getACcounts().getCounts());
return sum;
}

View File

@ -40,14 +40,14 @@ import java.util.ArrayList;
/**
* Uses the Exact calculation of Heng Li
*/
abstract class ExactAFCalculation extends AlleleFrequencyCalculation {
abstract class ExactAFCalc extends AFCalc {
protected static final int HOM_REF_INDEX = 0; // AA likelihoods are always first
protected ExactAFCalculation(final UnifiedArgumentCollection UAC, final int nSamples, final Logger logger, final PrintStream verboseWriter) {
protected ExactAFCalc(final UnifiedArgumentCollection UAC, final int nSamples, final Logger logger, final PrintStream verboseWriter) {
super(UAC, nSamples, logger, verboseWriter);
}
protected ExactAFCalculation(final int nSamples, int maxAltAlleles, int maxAltAllelesForIndels, File exactCallsLog, Logger logger, PrintStream verboseWriter) {
protected ExactAFCalc(final int nSamples, int maxAltAlleles, int maxAltAllelesForIndels, File exactCallsLog, Logger logger, PrintStream verboseWriter) {
super(nSamples, maxAltAlleles, maxAltAllelesForIndels, exactCallsLog, logger, verboseWriter);
}

View File

@ -6,16 +6,16 @@ import org.broadinstitute.sting.utils.variantcontext.VariantContext;
import java.io.PrintStream;
public class ReferenceDiploidExactAFCalculation extends DiploidExactAFCalculation {
public ReferenceDiploidExactAFCalculation(final int nSamples, final int maxAltAlleles) {
public class ReferenceDiploidExactAFCalc extends DiploidExactAFCalc {
public ReferenceDiploidExactAFCalc(final int nSamples, final int maxAltAlleles) {
super(nSamples, maxAltAlleles);
}
public ReferenceDiploidExactAFCalculation(UnifiedArgumentCollection UAC, int N, Logger logger, PrintStream verboseWriter) {
public ReferenceDiploidExactAFCalc(UnifiedArgumentCollection UAC, int N, Logger logger, PrintStream verboseWriter) {
super(UAC, N, logger, verboseWriter);
}
protected StateTracker makeMaxLikelihood(final VariantContext vc, final AlleleFrequencyCalculationResult result) {
protected StateTracker makeMaxLikelihood(final VariantContext vc, final AFCalcResult result) {
return new StateTracker();
}
}

View File

@ -21,7 +21,7 @@ final class StateTracker {
}
/**
* Update the maximum log10L seen, if log10LofKs is higher
* Update the maximum log10L seen, if log10LofKs is higher, and the corresponding ACs of this state
*
* @param log10LofKs the likelihood of our current configuration state
*/

View File

@ -23,9 +23,9 @@
*/
package org.broadinstitute.sting.gatk.walkers.validation.validationsiteselector;
import org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.AlleleFrequencyCalculationResult;
import org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.DiploidExactAFCalculation;
import org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.ReferenceDiploidExactAFCalculation;
import org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.AFCalcResult;
import org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.DiploidExactAFCalc;
import org.broadinstitute.sting.gatk.walkers.genotyper.afcalc.ReferenceDiploidExactAFCalc;
import org.broadinstitute.sting.utils.variantcontext.VariantContext;
import java.util.TreeSet;
@ -34,7 +34,7 @@ import java.util.TreeSet;
public class GLBasedSampleSelector extends SampleSelector {
double[] flatPriors = null;
final double referenceLikelihood;
DiploidExactAFCalculation AFCalculator;
DiploidExactAFCalc AFCalculator;
public GLBasedSampleSelector(TreeSet<String> sm, double refLik) {
super(sm);
@ -52,9 +52,9 @@ public class GLBasedSampleSelector extends SampleSelector {
// do we want to apply a prior? maybe user-spec?
if ( flatPriors == null ) {
flatPriors = new double[1+2*samples.size()];
AFCalculator = new ReferenceDiploidExactAFCalculation(samples.size(), 4);
AFCalculator = new ReferenceDiploidExactAFCalc(samples.size(), 4);
}
AlleleFrequencyCalculationResult result = new AlleleFrequencyCalculationResult(vc.getAlternateAlleles().size());
AFCalcResult result = new AFCalcResult(vc.getAlternateAlleles().size());
AFCalculator.computeLog10PNonRef(subContext, flatPriors, result);
// do we want to let this qual go up or down?
if ( result.getLog10PosteriorOfAFzero() < referenceLikelihood ) {