diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/engine/arguments/StandardCallerArgumentCollection.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/engine/arguments/StandardCallerArgumentCollection.java
index 3f7794b24..731895b70 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/engine/arguments/StandardCallerArgumentCollection.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/engine/arguments/StandardCallerArgumentCollection.java
@@ -46,10 +46,10 @@
package org.broadinstitute.gatk.engine.arguments;
+import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalculatorImplementation;
import org.broadinstitute.gatk.utils.commandline.*;
import org.broadinstitute.gatk.tools.walkers.genotyper.GenotypingOutputMode;
import org.broadinstitute.gatk.tools.walkers.genotyper.OutputMode;
-import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalcFactory;
import org.broadinstitute.gatk.utils.collections.DefaultHashMap;
import htsjdk.variant.variantcontext.VariantContext;
@@ -145,7 +145,7 @@ public class StandardCallerArgumentCollection implements Cloneable {
*/
@Hidden
@Argument(fullName = "p_nonref_model", shortName = "pnrm", doc = "Non-reference probability calculation model to employ", required = false)
- public AFCalcFactory.Calculation requestedAlleleFrequencyCalculationModel;
+ public AFCalculatorImplementation requestedAlleleFrequencyCalculationModel;
@Hidden
@Argument(shortName = "logExactCalls", doc="x", required=false)
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/AFPriorProvider.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/AFPriorProvider.java
new file mode 100644
index 000000000..d998d9241
--- /dev/null
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/AFPriorProvider.java
@@ -0,0 +1,112 @@
+/*
+* By downloading the PROGRAM you agree to the following terms of use:
+*
+* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY
+*
+* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE).
+*
+* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and
+* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions.
+* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows:
+*
+* 1. DEFINITIONS
+* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE.
+*
+* 2. LICENSE
+* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM.
+* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement.
+* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement.
+* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM.
+*
+* 3. OWNERSHIP OF INTELLECTUAL PROPERTY
+* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication.
+* Copyright 2012 Broad Institute, Inc.
+* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc.
+* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes.
+*
+* 4. INDEMNIFICATION
+* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement.
+*
+* 5. NO REPRESENTATIONS OR WARRANTIES
+* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME.
+* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING.
+*
+* 6. ASSIGNMENT
+* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void.
+*
+* 7. MISCELLANEOUS
+* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries.
+* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes.
+* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4.
+* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt.
+* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter.
+* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement.
+* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles.
+*/
+package org.broadinstitute.gatk.tools.walkers.genotyper;
+
+import java.util.Arrays;
+
+/**
+ * Class that produces allele-frequency priors.
+ *
+ *
+ * This class is thread-unsafe for performance and so should be used accordingly.
+ *
+ *
+ * @author Valentin Ruano-Rubio <valentin@broadinstitute.org>
+ */
+public abstract class AFPriorProvider {
+
+ private double[][] priorByTotalPloidy;
+
+ protected AFPriorProvider() {
+
+ }
+
+ /**
+ * Returns the priors given a total-ploidy (the total number of genome copies across all samples).
+ *
+ *
+ * For performance sake the returned value is a direct reference ot the cached prior, so the client code
+ * must not modify its content.
+ *
+ *
+ * @param totalPloidy the requested total ploidy.
+ *
+ * @return never {@code null}, please do not modify its content. An array of {@code totalPloidy + 1} positions where
+ * the ith position is the log10(prior) probability of the an alternative allele AC to be exactly i copies in
+ * a draw of {@code totalPloidy} elements.
+ */
+ public double[] forTotalPloidy(final int totalPloidy) {
+ if (totalPloidy < 0)
+ throw new IllegalArgumentException("the total-ploidy cannot be negative");
+ ensureCapacity(totalPloidy);
+ final double[] cachedResult = priorByTotalPloidy[totalPloidy];
+ if (cachedResult == null)
+ return priorByTotalPloidy[totalPloidy] = buildPriors(totalPloidy);
+ else
+ return cachedResult;
+ }
+
+ /**
+ * Make sure that structures have enough capacity to hold the information up to the given total-ploidy.
+ * @param totalPloidy
+ */
+ protected void ensureCapacity(final int totalPloidy) {
+ if (priorByTotalPloidy == null)
+ priorByTotalPloidy = new double[totalPloidy + 1][]; // just enough for those cases in where we have a fix total-ploidy.
+ else if (priorByTotalPloidy.length - 1 < totalPloidy)
+ priorByTotalPloidy = Arrays.copyOf(priorByTotalPloidy,Math.max(priorByTotalPloidy.length << 1,totalPloidy + 1));
+ }
+
+ /**
+ * Given a total ploidy construct the allele prior probabilities array.
+ * @param totalPloidy the target total-ploidy. Code can assume that is a non-negative number.
+ *
+ * @return never {@code null}, an array of exactly {@code totalPloidy + 1} positions that satisifed the
+ * contract {@link #forTotalPloidy(int) forTotalPloidy(totalPloidy)}.
+ */
+ protected abstract double[] buildPriors(final int totalPloidy);
+
+}
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/CustomAFPriorProvider.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/CustomAFPriorProvider.java
new file mode 100644
index 000000000..a2ea9e17e
--- /dev/null
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/CustomAFPriorProvider.java
@@ -0,0 +1,87 @@
+/*
+* By downloading the PROGRAM you agree to the following terms of use:
+*
+* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY
+*
+* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE).
+*
+* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and
+* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions.
+* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows:
+*
+* 1. DEFINITIONS
+* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE.
+*
+* 2. LICENSE
+* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM.
+* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement.
+* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement.
+* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM.
+*
+* 3. OWNERSHIP OF INTELLECTUAL PROPERTY
+* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication.
+* Copyright 2012 Broad Institute, Inc.
+* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc.
+* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes.
+*
+* 4. INDEMNIFICATION
+* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement.
+*
+* 5. NO REPRESENTATIONS OR WARRANTIES
+* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME.
+* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING.
+*
+* 6. ASSIGNMENT
+* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void.
+*
+* 7. MISCELLANEOUS
+* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries.
+* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes.
+* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4.
+* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt.
+* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter.
+* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement.
+* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles.
+*/
+package org.broadinstitute.gatk.tools.walkers.genotyper;
+
+import java.util.List;
+
+/**
+ * Custom priors provided as an array.
+ */
+public class CustomAFPriorProvider extends AFPriorProvider {
+
+ private final double[] priors;
+
+ /**
+ *
+ * @param priorValues must exactly the number of genomes in the samples (the total ploidy).
+ */
+ public CustomAFPriorProvider(final List priorValues) {
+ if (priorValues == null)
+ throw new IllegalArgumentException("the input prior values cannot be null");
+ priors = new double[priorValues.size() + 1];
+
+ int i = 1;
+ double sum = 0;
+ for (double value : priorValues) {
+ if (value <= 0 || value >= 1)
+ throw new IllegalArgumentException("the AF prior value "+ value + " is out of the valid interval (0,1)");
+ if (Double.isNaN(value))
+ throw new IllegalArgumentException("NaN is not a valid prior AF value");
+ priors[i++] = Math.log10(value);
+ sum += value;
+ }
+ if (sum >= 1)
+ throw new IllegalArgumentException("the AF prior value sum must be less than 1: " + sum);
+ priors[0] = Math.log10(1 - sum);
+ }
+
+ @Override
+ protected double[] buildPriors(final int totalPloidy) {
+ if (totalPloidy != priors.length - 1)
+ throw new IllegalStateException("requesting an invalid prior total ploidy " + totalPloidy + " != " + (priors.length - 1));
+ return priors;
+ }
+}
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/GeneralPloidyGenotypeLikelihoodsCalculationModel.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/GeneralPloidyGenotypeLikelihoodsCalculationModel.java
index 9206fbc37..d649dcc08 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/GeneralPloidyGenotypeLikelihoodsCalculationModel.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/GeneralPloidyGenotypeLikelihoodsCalculationModel.java
@@ -60,6 +60,7 @@ import org.broadinstitute.gatk.utils.collections.Pair;
import org.broadinstitute.gatk.utils.exceptions.ReviewedGATKException;
import org.broadinstitute.gatk.utils.pileup.ReadBackedPileup;
import htsjdk.variant.variantcontext.*;
+import org.broadinstitute.gatk.utils.variant.GATKVariantContextUtils;
import java.util.*;
@@ -286,8 +287,8 @@ public abstract class GeneralPloidyGenotypeLikelihoodsCalculationModel extends G
builder.attributes(attributes);
// create the genotypes; no-call everyone for now
final GenotypesContext genotypes = GenotypesContext.create();
- final List noCall = new ArrayList();
- noCall.add(Allele.NO_CALL);
+ final int ploidy = UAC.genotypeArgs.samplePloidy;
+ final List noCall = GATKVariantContextUtils.noCallAlleles(ploidy);
for ( PoolGenotypeData sampleData : GLs ) {
// extract from multidimensional array
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/GenotypingEngine.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/GenotypingEngine.java
index bf91b41c3..8bb0d1e76 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/GenotypingEngine.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/GenotypingEngine.java
@@ -59,9 +59,9 @@ import org.broadinstitute.gatk.engine.contexts.AlignmentContextUtils;
import org.broadinstitute.gatk.engine.contexts.ReferenceContext;
import org.broadinstitute.gatk.engine.refdata.RefMetaDataTracker;
import org.broadinstitute.gatk.tools.walkers.annotator.VariantAnnotatorEngine;
-import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalc;
-import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalcFactory;
-import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalcResult;
+import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalculator;
+import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalculationResult;
+import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalculatorProvider;
import org.broadinstitute.gatk.utils.GenomeLoc;
import org.broadinstitute.gatk.utils.GenomeLocParser;
import org.broadinstitute.gatk.utils.MathUtils;
@@ -81,8 +81,11 @@ import java.util.*;
public abstract class GenotypingEngine {
public static final String NUMBER_OF_DISCOVERED_ALLELES_KEY = "NDA";
+
public static final String LOW_QUAL_FILTER_NAME = "LowQual";
+ protected final AFCalculatorProvider afCalculatorProvider ;
+
protected Logger logger;
protected final Config configuration;
@@ -94,26 +97,12 @@ public abstract class GenotypingEngine afcm = getAlleleFrequencyCalculatorThreadLocal();
-
- protected ThreadLocal getAlleleFrequencyCalculatorThreadLocal() {
- return new ThreadLocal() {
-
- @Override
- public AFCalc initialValue() {
- return AFCalcFactory.createAFCalc(configuration, numberOfGenomes, false, logger);
- }
- };
- }
-
-
/**
* Construct a new genotyper engine, on a specific subset of samples.
*
@@ -124,19 +113,26 @@ public abstract class GenotypingEngine alleles = afcr.getAllelesUsedInGenotyping();
final int alternativeAlleleCount = alleles.size() - 1;
@@ -496,14 +496,25 @@ public abstract class GenotypingEngine= configuration.genotypeArgs.STANDARD_CONFIDENCE_FOR_CALLING, false);
}
- protected final double[] getAlleleFrequencyPriors( final GenotypeLikelihoodsCalculationModel.Model model ) {
+ /**
+ * Returns the log10 prior probability for all possible allele counts from 0 to N where N is the total number of
+ * genomes (total-ploidy).
+ *
+ * @param vc the target variant-context, use to determine the total ploidy thus the possible ACs.
+ * @param defaultPloidy default ploidy to be assume if we do not have the ploidy for some sample in {@code vc}.
+ * @param model the calculation model (SNP,INDEL or MIXED) whose priors are to be retrieved.
+ * @throws java.lang.NullPointerException if either {@code vc} or {@code model} is {@code null}
+ * @return never {@code null}, an array with exactly total-ploidy(vc) + 1 positions.
+ */
+ protected final double[] getAlleleFrequencyPriors( final VariantContext vc, final int defaultPloidy, final GenotypeLikelihoodsCalculationModel.Model model ) {
+ final int totalPloidy = GATKVariantContextUtils.totalPloidy(vc,defaultPloidy);
switch (model) {
case SNP:
case GENERALPLOIDYSNP:
- return log10AlleleFrequencyPriorsSNPs;
+ return log10AlleleFrequencyPriorsSNPs.forTotalPloidy(totalPloidy);
case INDEL:
case GENERALPLOIDYINDEL:
- return log10AlleleFrequencyPriorsIndels;
+ return log10AlleleFrequencyPriorsIndels.forTotalPloidy(totalPloidy);
default:
throw new IllegalArgumentException("Unexpected GenotypeCalculationModel " + model);
}
@@ -552,38 +563,20 @@ public abstract class GenotypingEngine inputPriors) {
+ private static AFPriorProvider composeAlleleFrequencyPriorProvider(final int N, final double heterozygosity, final List inputPriors) {
final double[] priors = new double[N + 1];
double sum = 0.0;
+ final AFPriorProvider result;
if (!inputPriors.isEmpty()) {
// user-specified priors
if (inputPriors.size() != N)
throw new UserException.BadArgumentValue("inputPrior","Invalid length of inputPrior vector: vector length must be equal to # samples +1 ");
-
- int idx = 1;
- for (final double prior: inputPriors) {
- if (prior < 0.0)
- throw new UserException.BadArgumentValue("Bad argument: negative values not allowed","inputPrior");
- priors[idx++] = Math.log10(prior);
- sum += prior;
- }
+ return new CustomAFPriorProvider(inputPriors);
}
else
- // for each i
- for (int i = 1; i <= N; i++) {
- final double value = heterozygosity / (double)i;
- priors[i] = Math.log10(value);
- sum += value;
- }
-
- // protection against the case of heterozygosity too high or an excessive number of samples (which break population genetics assumptions)
- if (sum > 1.0)
- throw new UserException.BadArgumentValue("heterozygosity","The heterozygosity value is set too high relative to the number of samples to be processed, or invalid values specified if input priors were provided - try reducing heterozygosity value or correct input priors.");
- // null frequency for AF=0 is (1 - sum(all other frequencies))
- priors[0] = Math.log10(1.0 - sum);
- return priors;
+ return new HeterozygosityAFPriorProvider(heterozygosity);
}
/**
@@ -642,7 +635,7 @@ public abstract class GenotypingEngine composeCallAttributes(final boolean inheritAttributesFromInputVC, final VariantContext vc,
final AlignmentContext rawContext, final Map stratifiedContexts, final RefMetaDataTracker tracker, final ReferenceContext refContext, final List alleleCountsofMLE, final boolean bestGuessIsRef,
- final AFCalcResult AFresult, final List allAllelesToUse, final GenotypesContext genotypes,
+ final AFCalculationResult AFresult, final List allAllelesToUse, final GenotypesContext genotypes,
final GenotypeLikelihoodsCalculationModel.Model model, final Map perReadAlleleLikelihoodMap) {
final HashMap attributes = new HashMap<>();
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/HeterozygosityAFPriorProvider.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/HeterozygosityAFPriorProvider.java
new file mode 100644
index 000000000..28e3d4193
--- /dev/null
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/HeterozygosityAFPriorProvider.java
@@ -0,0 +1,92 @@
+/*
+* By downloading the PROGRAM you agree to the following terms of use:
+*
+* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY
+*
+* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE).
+*
+* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and
+* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions.
+* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows:
+*
+* 1. DEFINITIONS
+* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE.
+*
+* 2. LICENSE
+* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM.
+* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement.
+* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement.
+* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM.
+*
+* 3. OWNERSHIP OF INTELLECTUAL PROPERTY
+* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication.
+* Copyright 2012 Broad Institute, Inc.
+* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc.
+* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes.
+*
+* 4. INDEMNIFICATION
+* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement.
+*
+* 5. NO REPRESENTATIONS OR WARRANTIES
+* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME.
+* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING.
+*
+* 6. ASSIGNMENT
+* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void.
+*
+* 7. MISCELLANEOUS
+* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries.
+* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes.
+* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4.
+* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt.
+* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter.
+* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement.
+* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles.
+*/
+package org.broadinstitute.gatk.tools.walkers.genotyper;
+
+import org.broadinstitute.gatk.utils.MathUtils;
+
+import java.util.Arrays;
+
+/**
+ * Allele frequency prior provider based on heterozygosity.
+ *
+ * @author Valentin Ruano-Rubio <valentin@broadinstitute.org>
+ */
+public class HeterozygosityAFPriorProvider extends AFPriorProvider {
+
+ private final double heterozygosity;
+ private final double log10Heterozygosity;
+
+ /**
+ * Construct a new provider given the heterozygosity value.
+ * @param heterozygosity must be a valid heterozygosity between larger than 0 and smaller than 1.
+ * @throws IllegalArgumentException if {@code heterozygosity} is not valid one in the interval (0,1).
+ */
+ public HeterozygosityAFPriorProvider(final double heterozygosity) {
+ if (heterozygosity <= 0)
+ throw new IllegalArgumentException("the heterozygosity must be greater than 0");
+ if (heterozygosity >= 1)
+ throw new IllegalArgumentException("the heterozygosity must be less than 1");
+ if (Double.isNaN(heterozygosity))
+ throw new IllegalArgumentException("the heterozygosity cannot be a NaN");
+ this.heterozygosity = heterozygosity;
+ this.log10Heterozygosity = Math.log10(heterozygosity);
+ }
+
+ @Override
+ protected double[] buildPriors(final int totalPloidy) {
+ final double[] result = new double [totalPloidy + 1];
+ Arrays.fill(result, log10Heterozygosity);
+ result[0] = Double.NEGATIVE_INFINITY;
+ MathUtils.Log10Cache.ensureCacheContains(totalPloidy);
+ for (int i = 1; i <= totalPloidy; i++)
+ result[i] -= MathUtils.Log10Cache.get(i);
+ final double log10Sum = MathUtils.approximateLog10SumLog10(result);
+ if (log10Sum >= 0)
+ throw new IllegalArgumentException("heterosygosity " + heterozygosity + " is too large of total ploidy " + totalPloidy);
+ result[0] = MathUtils.log10OneMinusPow10(log10Sum);
+ return result;
+ }
+}
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/IndelGenotypeLikelihoodsCalculationModel.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/IndelGenotypeLikelihoodsCalculationModel.java
index 73b2d5e99..aaf77d56c 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/IndelGenotypeLikelihoodsCalculationModel.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/IndelGenotypeLikelihoodsCalculationModel.java
@@ -60,6 +60,7 @@ import org.broadinstitute.gatk.utils.genotyper.PerReadAlleleLikelihoodMap;
import org.broadinstitute.gatk.utils.pileup.PileupElement;
import org.broadinstitute.gatk.utils.pileup.ReadBackedPileup;
import htsjdk.variant.variantcontext.*;
+import org.broadinstitute.gatk.utils.variant.GATKVariantContextUtils;
import java.util.*;
@@ -130,8 +131,8 @@ public class IndelGenotypeLikelihoodsCalculationModel extends GenotypeLikelihood
// create the genotypes; no-call everyone for now
GenotypesContext genotypes = GenotypesContext.create();
- final List noCall = new ArrayList();
- noCall.add(Allele.NO_CALL);
+ final int ploidy = UAC.genotypeArgs.samplePloidy;
+ final List noCall = GATKVariantContextUtils.noCallAlleles(ploidy);
// For each sample, get genotype likelihoods based on pileup
// compute prior likelihoods on haplotypes, and initialize haplotype likelihood matrix with them.
@@ -148,6 +149,7 @@ public class IndelGenotypeLikelihoodsCalculationModel extends GenotypeLikelihood
final GenotypeBuilder b = new GenotypeBuilder(sample.getKey());
final double[] genotypeLikelihoods = pairModel.computeDiploidReadHaplotypeLikelihoods(pileup, haplotypeMap, ref, eventLength, perReadAlleleLikelihoodMap.get(sample.getKey()), UAC.getSampleContamination().get(sample.getKey()));
b.PL(genotypeLikelihoods);
+ b.alleles(noCall);
b.DP(getFilteredDepth(pileup));
genotypes.add(b.make());
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/SNPGenotypeLikelihoodsCalculationModel.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/SNPGenotypeLikelihoodsCalculationModel.java
index 5e8914c8e..dad2780cd 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/SNPGenotypeLikelihoodsCalculationModel.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/SNPGenotypeLikelihoodsCalculationModel.java
@@ -64,6 +64,7 @@ import org.broadinstitute.gatk.utils.pileup.PileupElement;
import org.broadinstitute.gatk.utils.pileup.ReadBackedPileup;
import org.broadinstitute.gatk.utils.pileup.ReadBackedPileupImpl;
import htsjdk.variant.variantcontext.*;
+import org.broadinstitute.gatk.utils.variant.GATKVariantContextUtils;
import java.util.*;
@@ -180,7 +181,8 @@ public class SNPGenotypeLikelihoodsCalculationModel extends GenotypeLikelihoodsC
// create the genotypes; no-call everyone for now
final GenotypesContext genotypes = GenotypesContext.create();
-
+ final int ploidy = UAC.genotypeArgs.samplePloidy;
+ final List noCall = GATKVariantContextUtils.noCallAlleles(ploidy);
for ( SampleGenotypeData sampleData : GLs ) {
final double[] allLikelihoods = sampleData.GL.getLikelihoods();
final double[] myLikelihoods = new double[numLikelihoods];
@@ -193,6 +195,7 @@ public class SNPGenotypeLikelihoodsCalculationModel extends GenotypeLikelihoodsC
final double[] genotypeLikelihoods = MathUtils.normalizeFromLog10(myLikelihoods, false, true);
gb.PL(genotypeLikelihoods);
gb.DP(sampleData.depth);
+ gb.alleles(noCall);
if (UAC.annotateAllSitesWithPLs)
gb.attribute(UnifiedGenotypingEngine.PL_FOR_ALL_SNP_ALLELES_KEY,GenotypeLikelihoods.fromLog10Likelihoods(MathUtils.normalizeFromLog10(allLikelihoods, false, true)));
genotypes.add(gb.make());
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyper.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyper.java
index 9a2d123e5..f75c2be05 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyper.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyper.java
@@ -46,10 +46,12 @@
package org.broadinstitute.gatk.tools.walkers.genotyper;
-import org.broadinstitute.gatk.engine.GenomeAnalysisEngine;
-import org.broadinstitute.gatk.engine.walkers.*;
-import org.broadinstitute.gatk.utils.commandline.*;
+import htsjdk.variant.variantcontext.GenotypeLikelihoods;
+import htsjdk.variant.variantcontext.VariantContext;
+import htsjdk.variant.variantcontext.writer.VariantContextWriter;
+import htsjdk.variant.vcf.*;
import org.broadinstitute.gatk.engine.CommandLineGATK;
+import org.broadinstitute.gatk.engine.GenomeAnalysisEngine;
import org.broadinstitute.gatk.engine.arguments.DbsnpArgumentCollection;
import org.broadinstitute.gatk.engine.contexts.AlignmentContext;
import org.broadinstitute.gatk.engine.contexts.ReferenceContext;
@@ -59,18 +61,18 @@ import org.broadinstitute.gatk.engine.filters.BadMateFilter;
import org.broadinstitute.gatk.engine.filters.MappingQualityUnavailableFilter;
import org.broadinstitute.gatk.engine.iterators.ReadTransformer;
import org.broadinstitute.gatk.engine.refdata.RefMetaDataTracker;
+import org.broadinstitute.gatk.engine.walkers.*;
import org.broadinstitute.gatk.tools.walkers.annotator.VariantAnnotatorEngine;
import org.broadinstitute.gatk.tools.walkers.annotator.interfaces.AnnotatorCompatible;
+import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalculatorProvider;
+import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.FixedAFCalculatorProvider;
import org.broadinstitute.gatk.utils.SampleUtils;
import org.broadinstitute.gatk.utils.baq.BAQ;
-import org.broadinstitute.gatk.utils.help.HelpConstants;
-import org.broadinstitute.gatk.utils.variant.GATKVariantContextUtils;
-import htsjdk.variant.vcf.*;
+import org.broadinstitute.gatk.utils.commandline.*;
import org.broadinstitute.gatk.utils.exceptions.UserException;
import org.broadinstitute.gatk.utils.help.DocumentedGATKFeature;
-import htsjdk.variant.variantcontext.GenotypeLikelihoods;
-import htsjdk.variant.variantcontext.VariantContext;
-import htsjdk.variant.variantcontext.writer.VariantContextWriter;
+import org.broadinstitute.gatk.utils.help.HelpConstants;
+import org.broadinstitute.gatk.utils.variant.GATKVariantContextUtils;
import java.io.PrintStream;
import java.util.*;
@@ -284,7 +286,9 @@ public class UnifiedGenotyper extends LocusWalker, Unif
verboseWriter.println("AFINFO\tLOC\tREF\tALT\tMAF\tF\tAFprior\tMLE\tMAP");
final VariantAnnotatorEngine annotationEngine = new VariantAnnotatorEngine(Arrays.asList(annotationClassesToUse), annotationsToUse, annotationsToExclude, this, getToolkit());
- genotypingEngine = new UnifiedGenotypingEngine(UAC, samples, toolkit.getGenomeLocParser(), toolkit.getArguments().BAQMode);
+
+ final AFCalculatorProvider afCalcAFCalculatorProvider = FixedAFCalculatorProvider.createThreadSafeProvider(getToolkit(),UAC,logger);
+ genotypingEngine = new UnifiedGenotypingEngine(UAC, samples, toolkit.getGenomeLocParser(), afCalcAFCalculatorProvider, toolkit.getArguments().BAQMode);
genotypingEngine.setVerboseWriter(verboseWriter);
genotypingEngine.setAnnotationEngine(annotationEngine);
@@ -308,6 +312,8 @@ public class UnifiedGenotyper extends LocusWalker, Unif
writer.writeHeader(new VCFHeader(headerInfo, samplesForHeader));
}
+
+
public static Set getHeaderInfo(final UnifiedArgumentCollection UAC,
final VariantAnnotatorEngine annotationEngine,
final DbsnpArgumentCollection dbsnp) {
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotypingEngine.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotypingEngine.java
index f2bea114a..4522c2809 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotypingEngine.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotypingEngine.java
@@ -54,7 +54,8 @@ import org.broadinstitute.gatk.engine.contexts.AlignmentContext;
import org.broadinstitute.gatk.engine.contexts.AlignmentContextUtils;
import org.broadinstitute.gatk.engine.contexts.ReferenceContext;
import org.broadinstitute.gatk.engine.refdata.RefMetaDataTracker;
-import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalcResult;
+import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalculationResult;
+import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalculatorProvider;
import org.broadinstitute.gatk.utils.BaseUtils;
import org.broadinstitute.gatk.utils.GenomeLocParser;
import org.broadinstitute.gatk.utils.baq.BAQ;
@@ -104,9 +105,9 @@ public class UnifiedGenotypingEngine extends GenotypingEngine composeCallAttributes(final boolean inheritAttributesFromInputVC, final VariantContext vc,
final AlignmentContext rawContext, final Map stratifiedContexts, final RefMetaDataTracker tracker, final ReferenceContext refContext, final List alleleCountsofMLE, final boolean bestGuessIsRef,
- final AFCalcResult AFresult, final List allAllelesToUse, final GenotypesContext genotypes,
+ final AFCalculationResult AFresult, final List allAllelesToUse, final GenotypesContext genotypes,
final GenotypeLikelihoodsCalculationModel.Model model, final Map perReadAlleleLikelihoodMap) {
final Map result = super.composeCallAttributes(inheritAttributesFromInputVC, vc,rawContext,stratifiedContexts,tracker,refContext,alleleCountsofMLE,bestGuessIsRef,
AFresult,allAllelesToUse,genotypes,model,perReadAlleleLikelihoodMap);
@@ -375,7 +376,7 @@ public class UnifiedGenotypingEngine extends GenotypingEngine stratifiedContexts,
final RefMetaDataTracker tracker,
- final ReferenceContext refContext, final AFCalcResult AFresult,
+ final ReferenceContext refContext, final AFCalculationResult AFresult,
final List allAllelesToUse,
final GenotypeLikelihoodsCalculationModel.Model model,
final Map perReadAlleleLikelihoodMap) {
@@ -385,13 +386,13 @@ public class UnifiedGenotypingEngine extends GenotypingEngine= requestedMaxAltAlleles);
- }
-
- public static Calculation getDefaultModel() { return EXACT_INDEPENDENT; }
-
- /**
- * Returns the best (fastest) model give the required ploidy and alternative allele count.
- * @param requiredPloidy required ploidy
- * @param requiredAlternativeAlleleCount required alternative allele count.
- * @param preferredModel a preferred mode if any. A {@code null} indicate that we should be try to use the default instead.
- * @return never {@code null}
- */
- public static Calculation getBestModel(final int requiredPloidy, final int requiredAlternativeAlleleCount, final Calculation preferredModel) {
- final Calculation preferred = preferredModel == null ? getDefaultModel() : preferredModel;
- if (preferred.usableForParams(requiredPloidy,requiredAlternativeAlleleCount))
- return preferred;
- if (EXACT_INDEPENDENT.usableForParams(requiredPloidy,requiredAlternativeAlleleCount))
- return EXACT_INDEPENDENT;
- if (EXACT_REFERENCE.usableForParams(requiredPloidy,requiredAlternativeAlleleCount))
- return EXACT_REFERENCE;
- return EXACT_GENERAL_PLOIDY;
- }
- }
-
- private static final Map> afClasses;
- static {
- afClasses = new PluginManager(AFCalc.class).getPluginsByName();
- }
-
- private AFCalcFactory() {
-
- }
-
- private static Class extends AFCalc> getClassByName(final String name) {
- for ( final Class extends AFCalc> clazz : afClasses.values() ) {
- if ( clazz.getSimpleName().contains(name) ) {
- return clazz;
- }
- }
-
- return null;
- }
-
- /**
- * Create a new AFCalc based on the parameters in the UAC
- *
- * @param UAC the UnifiedArgumentCollection containing the command-line parameters for the caller
- * @param nSamples the number of samples we will be using
- * @param logger an optional (can be null) logger to override the default in the model
- * @return an initialized AFCalc
- */
- public static AFCalc createAFCalc(final StandardCallerArgumentCollection UAC,
- final int nSamples, final boolean emitConfModel,
- final Logger logger) {
- final Calculation afCalculationModel = Calculation.getBestModel(UAC.genotypeArgs.samplePloidy,UAC.genotypeArgs.MAX_ALTERNATE_ALLELES,
- UAC.requestedAlleleFrequencyCalculationModel);
-
- final AFCalc calc = createAFCalc(afCalculationModel, nSamples, UAC.genotypeArgs.MAX_ALTERNATE_ALLELES, UAC.genotypeArgs.samplePloidy);
-
- if ( logger != null ) calc.setLogger(logger);
- if ( UAC.exactCallsLog != null ) calc.enableProcessLog(UAC.exactCallsLog);
-
- return calc;
- }
-
- /**
- * Create a new AFCalc, choosing the best implementation based on the given parameters, assuming
- * that we will only be requesting bi-allelic variants to diploid genotypes
- *
- * @param nSamples the number of samples we'll be using
- *
- * @return an initialized AFCalc
- */
- public static AFCalc createAFCalc(final int nSamples) {
- return createAFCalc(chooseBestCalculation(nSamples, 2, 1), nSamples, 2, 2);
- }
-
- /**
- * Create a new AFCalc that supports maxAltAlleles for all variants and diploid genotypes
- *
- * @param calc the calculation we'd like to use
- * @param nSamples the number of samples we'll be using
- * @param maxAltAlleles the max. alt alleles for both SNPs and indels
- *
- * @return an initialized AFCalc
- */
- public static AFCalc createAFCalc(final Calculation calc, final int nSamples, final int maxAltAlleles) {
- return createAFCalc(calc, nSamples, maxAltAlleles, 2);
- }
-
- /**
- * Create a new AFCalc, choosing the best implementation based on the given parameters
- *
- * @param nSamples the number of samples we'll be using
- * @param maxAltAlleles the max. alt alleles to consider for SNPs
- * @param ploidy the sample ploidy. Must be consistent with the calc
- *
- * @return an initialized AFCalc
- */
- public static AFCalc createAFCalc(final int nSamples, final int maxAltAlleles, final int ploidy) {
- return createAFCalc(chooseBestCalculation(nSamples, ploidy, maxAltAlleles), nSamples, maxAltAlleles, ploidy);
- }
-
- /**
- * Choose the best calculation for nSamples and ploidy
- *
- * @param nSamples
- * @param ploidy
- * @param maxAltAlleles
- * @return
- */
- private static Calculation chooseBestCalculation(final int nSamples, final int ploidy, final int maxAltAlleles) {
- for ( final Calculation calc : Calculation.values() ) {
- if ( calc.usableForParams(ploidy, maxAltAlleles) ) {
- return calc;
- }
- }
-
- throw new IllegalStateException("no calculation found that supports nSamples " + nSamples + " ploidy " + ploidy + " and maxAltAlleles " + maxAltAlleles);
- }
-
- /**
- * Create a new AFCalc
- *
- * @param calc the calculation to use
- * @param nSamples the number of samples we'll be using
- * @param maxAltAlleles the max. alt alleles to consider for SNPs
- * @param ploidy the sample ploidy. Must be consistent with the calc
- *
- * @return an initialized AFCalc
- */
- public static AFCalc createAFCalc(final Calculation calc, final int nSamples, final int maxAltAlleles, final int ploidy) {
- if ( calc == null ) throw new IllegalArgumentException("Calculation cannot be null");
- 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);
- if ( ploidy < 1 ) throw new IllegalArgumentException("sample ploidy must be greater than zero " + ploidy);
-
- if ( ! calc.usableForParams(ploidy, maxAltAlleles) )
- throw new IllegalArgumentException("AFCalc " + calc + " does not support requested ploidy " + ploidy);
-
- final Class extends AFCalc> afClass = getClassByName(calc.className);
- if ( afClass == null )
- throw new IllegalArgumentException("Unexpected AFCalc " + calc);
-
- try {
- Object args[] = new Object[]{nSamples, maxAltAlleles, ploidy};
- Constructor c = afClass.getDeclaredConstructor(int.class, int.class, int.class);
- return (AFCalc)c.newInstance(args);
- } catch (Exception e) {
- throw new ReviewedGATKException("Could not instantiate AFCalc " + calc, e);
- }
- }
-
- protected static List createAFCalcs(final List calcs, final int nSamples, final int maxAltAlleles, final int ploidy) {
- final List AFCalcs = new LinkedList();
-
- for ( final Calculation calc : calcs )
- AFCalcs.add(createAFCalc(calc, nSamples, maxAltAlleles, ploidy));
-
- return AFCalcs;
- }
-}
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcResult.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculationResult.java
similarity index 97%
rename from protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcResult.java
rename to protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculationResult.java
index b4d22592e..00cd9038a 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcResult.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculationResult.java
@@ -63,7 +63,7 @@ import java.util.*;
* Note that all of the values -- i.e. priors -- are checked now that they are meaningful, which means
* that users of this code can rely on the values coming out of these functions.
*/
-public class AFCalcResult {
+public class AFCalculationResult {
private final static int AF0 = 0;
private final static int AF1p = 1;
private final static int LOG_10_ARRAY_SIZES = 2;
@@ -89,12 +89,12 @@ public class AFCalcResult {
/**
* Create a results object capability of storing results for calls with up to maxAltAlleles
*/
- public AFCalcResult(final int[] alleleCountsOfMLE,
- final int nEvaluations,
- final List allelesUsedInGenotyping,
- final double[] log10LikelihoodsOfAC,
- final double[] log10PriorsOfAC,
- final Map log10pRefByAllele) {
+ public AFCalculationResult(final int[] alleleCountsOfMLE,
+ final int nEvaluations,
+ final List allelesUsedInGenotyping,
+ final double[] log10LikelihoodsOfAC,
+ final double[] log10PriorsOfAC,
+ final Map log10pRefByAllele) {
if ( allelesUsedInGenotyping == null || allelesUsedInGenotyping.size() < 1 ) throw new IllegalArgumentException("allelesUsedInGenotyping must be non-null list of at least 1 value " + allelesUsedInGenotyping);
if ( alleleCountsOfMLE == null ) throw new IllegalArgumentException("alleleCountsOfMLE cannot be null");
if ( alleleCountsOfMLE.length != allelesUsedInGenotyping.size() - 1) throw new IllegalArgumentException("alleleCountsOfMLE.length " + alleleCountsOfMLE.length + " != allelesUsedInGenotyping.size() " + allelesUsedInGenotyping.size());
@@ -123,8 +123,8 @@ public class AFCalcResult {
* @param log10PriorsOfAC
* @return
*/
- public AFCalcResult withNewPriors(final double[] log10PriorsOfAC) {
- return new AFCalcResult(alleleCountsOfMLE, nEvaluations, allelesUsedInGenotyping, log10LikelihoodsOfAC, log10PriorsOfAC, log10pRefByAllele);
+ public AFCalculationResult withNewPriors(final double[] log10PriorsOfAC) {
+ return new AFCalculationResult(alleleCountsOfMLE, nEvaluations, allelesUsedInGenotyping, log10LikelihoodsOfAC, log10PriorsOfAC, log10pRefByAllele);
}
/**
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalc.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculator.java
similarity index 82%
rename from protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalc.java
rename to protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculator.java
index ade6de0d6..74249be9d 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalc.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculator.java
@@ -61,35 +61,26 @@ import java.util.List;
/**
* Generic interface for calculating the probability of alleles segregating given priors and genotype likelihoods
*/
-public abstract class AFCalc implements Cloneable {
- private final static Logger defaultLogger = Logger.getLogger(AFCalc.class);
+public abstract class AFCalculator implements Cloneable {
+ private final static Logger defaultLogger = Logger.getLogger(AFCalculator.class);
- protected final int nSamples;
- protected final int maxAlternateAllelesToGenotype;
protected Logger logger = defaultLogger;
private SimpleTimer callTimer = new SimpleTimer();
- private final StateTracker stateTracker;
+ private StateTracker stateTracker;
private ExactCallLogger exactCallLogger = null;
/**
* Create a new AFCalc object capable of calculating the prob. that alleles are
- * segregating among nSamples with up to maxAltAlleles for SNPs and maxAltAllelesForIndels
- * for indels for samples with ploidy
+ * segregating among many samples.
*
- * @param nSamples number of samples, must be > 0
- * @param maxAltAlleles maxAltAlleles for SNPs
- * @param ploidy the ploidy, must be > 0
+ *
+ * Restrictions in ploidy and number of alternative alleles that a instance can handle will be determined
+ * by its implementation class {@link AFCalculatorImplementation}
+ *
*/
- protected AFCalc(final int nSamples, final int maxAltAlleles, final int ploidy) {
- 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);
- if ( ploidy < 1 ) throw new IllegalArgumentException("ploidy must be > 0 but got " + ploidy);
-
- this.nSamples = nSamples;
- this.maxAlternateAllelesToGenotype = maxAltAlleles;
- this.stateTracker = new StateTracker(maxAltAlleles);
+ protected AFCalculator() {
}
/**
@@ -118,19 +109,18 @@ public abstract class AFCalc implements Cloneable {
* @param log10AlleleFrequencyPriors a prior vector nSamples x 2 in length indicating the Pr(AF = i)
* @return result (for programming convenience)
*/
- public AFCalcResult getLog10PNonRef(final VariantContext vc, final double[] log10AlleleFrequencyPriors) {
+ public AFCalculationResult getLog10PNonRef(final VariantContext vc, final int defaultPloidy, final int maximumAlternativeAlleles, final double[] log10AlleleFrequencyPriors) {
if ( vc == null ) throw new IllegalArgumentException("VariantContext cannot be null");
if ( vc.getNAlleles() == 1 ) throw new IllegalArgumentException("VariantContext has only a single reference allele, but getLog10PNonRef requires at least one at all " + vc);
if ( log10AlleleFrequencyPriors == null ) throw new IllegalArgumentException("priors vector cannot be null");
- if ( stateTracker == null ) throw new IllegalArgumentException("Results object cannot be null");
// reset the result, so we can store our new result there
- stateTracker.reset();
+ final StateTracker stateTracker = getStateTracker(true,maximumAlternativeAlleles);
- final VariantContext vcWorking = reduceScope(vc);
+ final VariantContext vcWorking = reduceScope(vc,defaultPloidy, maximumAlternativeAlleles);
callTimer.start();
- final AFCalcResult result = computeLog10PNonRef(vcWorking, log10AlleleFrequencyPriors);
+ final AFCalculationResult result = computeLog10PNonRef(vcWorking, defaultPloidy, log10AlleleFrequencyPriors, stateTracker);
final long nanoTime = callTimer.getElapsedTimeNano();
if ( exactCallLogger != null )
@@ -140,19 +130,19 @@ public abstract class AFCalc implements Cloneable {
}
/**
- * Convert the final state of the state tracker into our result as an AFCalcResult
+ * Convert the final state of the state tracker into our result as an AFCalculationResult
*
* Assumes that stateTracker has been updated accordingly
*
* @param vcWorking the VariantContext we actually used as input to the calc model (after reduction)
* @param log10AlleleFrequencyPriors the priors by AC vector
- * @return a AFCalcResult describing the result of this calculation
+ * @return a AFCalculationResult describing the result of this calculation
*/
@Requires("stateTracker.getnEvaluations() >= 0")
@Ensures("result != null")
- protected AFCalcResult getResultFromFinalState(final VariantContext vcWorking, final double[] log10AlleleFrequencyPriors) {
+ protected AFCalculationResult getResultFromFinalState(final VariantContext vcWorking, final double[] log10AlleleFrequencyPriors, final StateTracker stateTracker) {
stateTracker.setAllelesUsedInGenotyping(vcWorking.getAlleles());
- return stateTracker.toAFCalcResult(log10AlleleFrequencyPriors);
+ return stateTracker.toAFCalculationResult(log10AlleleFrequencyPriors);
}
// ---------------------------------------------------------------------------
@@ -174,7 +164,7 @@ public abstract class AFCalc implements Cloneable {
*/
@Requires({"vc != null", "vc.getNAlleles() > 1"})
@Ensures("result != null")
- protected abstract VariantContext reduceScope(final VariantContext vc);
+ protected abstract VariantContext reduceScope(final VariantContext vc, final int defaultPloidy, final int maximumAlternativeAlleles);
/**
* Actually carry out the log10PNonRef calculation on vc, storing results in results
@@ -185,8 +175,8 @@ public abstract class AFCalc implements Cloneable {
* @return a AFCalcResult object describing the results of this calculation
*/
@Requires({"vc != null", "log10AlleleFrequencyPriors != null", "vc.getNAlleles() > 1"})
- protected abstract AFCalcResult computeLog10PNonRef(final VariantContext vc,
- final double[] log10AlleleFrequencyPriors);
+ protected abstract AFCalculationResult computeLog10PNonRef(final VariantContext vc, final int defaultPloidy,
+ final double[] log10AlleleFrequencyPriors, final StateTracker stateTracker);
/**
* Subset VC to the just allelesToUse, updating genotype likelihoods
@@ -194,15 +184,15 @@ public abstract class AFCalc implements Cloneable {
* Must be overridden by concrete subclasses
*
* @param vc variant context with alleles and genotype likelihoods
+ * @param defaultPloidy default ploidy to assume in case {@code vc} does not indicate it for a sample.
* @param allelesToUse alleles to subset
* @param assignGenotypes
- * @param ploidy
* @return GenotypesContext object
*/
public abstract GenotypesContext subsetAlleles(final VariantContext vc,
+ final int defaultPloidy,
final List allelesToUse,
- final boolean assignGenotypes,
- final int ploidy);
+ final boolean assignGenotypes);
// ---------------------------------------------------------------------------
//
@@ -210,12 +200,41 @@ public abstract class AFCalc implements Cloneable {
//
// ---------------------------------------------------------------------------
- public int getMaxAltAlleles() {
- return maxAlternateAllelesToGenotype;
- }
- protected StateTracker getStateTracker() {
+ /**
+ * Retrieves the state tracker.
+ *
+ *
+ * The tracker will be reset if so requested or if it needs to be resized due to an increase in the
+ * maximum number of alleles is must be able to handle.
+ *
+ *
+ * @param reset make sure the tracker is reset.
+ * @param maximumAlternativeAlleleCount the maximum alternative allele count it must be able to handle. Has no effect if
+ * the current tracker is able to handle that number.
+ *
+ * @return never {@code null}
+ */
+ protected StateTracker getStateTracker(final boolean reset, final int maximumAlternativeAlleleCount) {
+ if (stateTracker == null)
+ stateTracker = new StateTracker(maximumAlternativeAlleleCount);
+ else if (reset)
+ stateTracker.reset(maximumAlternativeAlleleCount);
+ else
+ stateTracker.ensureMaximumAlleleCapacity(maximumAlternativeAlleleCount);
return stateTracker;
}
+ /**
+ * Used by testing code.
+ *
+ * Please don't use this method in production.
+ *
+ * @deprecated
+ */
+ @Deprecated
+ protected int getAltAlleleCountOfMAP(final int allele) {
+ return getStateTracker(false,allele + 1).getAlleleCountsOfMAP()[allele];
+ }
+
}
\ No newline at end of file
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculatorFactory.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculatorFactory.java
new file mode 100644
index 000000000..7630c4aed
--- /dev/null
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculatorFactory.java
@@ -0,0 +1,135 @@
+/*
+* By downloading the PROGRAM you agree to the following terms of use:
+*
+* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY
+*
+* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE).
+*
+* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and
+* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions.
+* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows:
+*
+* 1. DEFINITIONS
+* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE.
+*
+* 2. LICENSE
+* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM.
+* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement.
+* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement.
+* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM.
+*
+* 3. OWNERSHIP OF INTELLECTUAL PROPERTY
+* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication.
+* Copyright 2012 Broad Institute, Inc.
+* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc.
+* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes.
+*
+* 4. INDEMNIFICATION
+* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement.
+*
+* 5. NO REPRESENTATIONS OR WARRANTIES
+* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME.
+* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING.
+*
+* 6. ASSIGNMENT
+* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void.
+*
+* 7. MISCELLANEOUS
+* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries.
+* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes.
+* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4.
+* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt.
+* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter.
+* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement.
+* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles.
+*/
+
+package org.broadinstitute.gatk.tools.walkers.genotyper.afcalc;
+
+/**
+ * Factory to make AFCalculations
+ */
+public class AFCalculatorFactory {
+
+
+
+ /**
+ * Create a new AFCalc, choosing the best implementation based on the given parameters, assuming
+ * that we will only be requesting bi-allelic variants to diploid genotypes
+ *
+ * @return an initialized AFCalc
+ *
+ * @deprecated hardcoded special reference to diploid analysis... eventually using code must explicitly indicate the
+ * ploidy as this is a sign of a hidden diploid assumption which is bad.
+ */
+ @Deprecated
+ public static AFCalculator createCalculatorForDiploidBiAllelicAnalysis() {
+ return AFCalculatorImplementation.bestValue(2,1,null).newInstance();
+ }
+
+ /**
+ * Create a new AFCalc that supports maxAltAlleles for all variants and diploid genotypes
+ *
+ *
+ * @deprecated hardcoded special reference to diploid analysis... eventually using code must explicitly indicate the
+ * ploidy as this is a sign of a hidden diploid assumption which is bad.
+ * @return an initialized AFCalc
+ */
+ @Deprecated
+ public static AFCalculator createCalculatorForDiploidAnalysis() {
+ return AFCalculatorImplementation.bestValue(2,AFCalculatorImplementation.UNBOUND_ALTERNATIVE_ALLELE_COUNT,null).newInstance();
+ }
+
+ /**
+ * Create a new AFCalc, choosing the best implementation based on the given parameters
+ *
+ * @param nSamples the number of samples we'll be using
+ * @param maxAltAlleles the max. alt alleles to consider for SNPs
+ * @param ploidy the sample ploidy. Must be consistent with the calc
+ *
+ * @return an initialized AFCalc
+ */
+ public static AFCalculator createCalculator(final int nSamples, final int maxAltAlleles, final int ploidy) {
+ return createCalculator(chooseBestImplementation(ploidy, maxAltAlleles), nSamples, maxAltAlleles, ploidy);
+ }
+
+ /**
+ * Choose the best calculation for nSamples and ploidy
+ *
+ * @param ploidy
+ * @param maxAltAlleles
+ * @return
+ */
+ private static AFCalculatorImplementation chooseBestImplementation(final int ploidy, final int maxAltAlleles) {
+ for ( final AFCalculatorImplementation calc : AFCalculatorImplementation.values() ) {
+ if ( calc.usableForParams(ploidy, maxAltAlleles) ) {
+ return calc;
+ }
+ }
+
+ throw new IllegalStateException("no calculation found that supports nSamples " + ploidy + " and maxAltAlleles " + maxAltAlleles);
+ }
+
+ /**
+ * Create a new AFCalc
+ *
+ * @param implementation the calculation to use
+ * @param nSamples the number of samples we'll be using
+ * @param maxAltAlleles the max. alt alleles to consider for SNPs
+ * @param ploidy the sample ploidy. Must be consistent with the implementation
+ *
+ * @return an initialized AFCalc
+ */
+ public static AFCalculator createCalculator(final AFCalculatorImplementation implementation, final int nSamples, final int maxAltAlleles, final int ploidy) {
+ if ( implementation == null ) throw new IllegalArgumentException("Calculation cannot be null");
+ 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);
+ if ( ploidy < 1 ) throw new IllegalArgumentException("sample ploidy must be greater than zero " + ploidy);
+
+ if ( ! implementation.usableForParams(ploidy, maxAltAlleles) )
+ throw new IllegalArgumentException("AFCalc " + implementation + " does not support requested ploidy " + ploidy);
+
+ return implementation.newInstance();
+ }
+
+}
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculatorImplementation.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculatorImplementation.java
new file mode 100644
index 000000000..b227189a0
--- /dev/null
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculatorImplementation.java
@@ -0,0 +1,236 @@
+/*
+* By downloading the PROGRAM you agree to the following terms of use:
+*
+* BROAD INSTITUTE - SOFTWARE LICENSE AGREEMENT - FOR ACADEMIC NON-COMMERCIAL RESEARCH PURPOSES ONLY
+*
+* This Agreement is made between the Broad Institute, Inc. with a principal address at 7 Cambridge Center, Cambridge, MA 02142 (BROAD) and the LICENSEE and is effective at the date the downloading is completed (EFFECTIVE DATE).
+*
+* WHEREAS, LICENSEE desires to license the PROGRAM, as defined hereinafter, and BROAD wishes to have this PROGRAM utilized in the public interest, subject only to the royalty-free, nonexclusive, nontransferable license rights of the United States Government pursuant to 48 CFR 52.227-14; and
+* WHEREAS, LICENSEE desires to license the PROGRAM and BROAD desires to grant a license on the following terms and conditions.
+* NOW, THEREFORE, in consideration of the promises and covenants made herein, the parties hereto agree as follows:
+*
+* 1. DEFINITIONS
+* 1.1 PROGRAM shall mean copyright in the object code and source code known as GATK2 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute/GATK on the EFFECTIVE DATE.
+*
+* 2. LICENSE
+* 2.1 Grant. Subject to the terms of this Agreement, BROAD hereby grants to LICENSEE, solely for academic non-commercial research purposes, a non-exclusive, non-transferable license to: (a) download, execute and display the PROGRAM and (b) create bug fixes and modify the PROGRAM.
+* The LICENSEE may apply the PROGRAM in a pipeline to data owned by users other than the LICENSEE and provide these users the results of the PROGRAM provided LICENSEE does so for academic non-commercial purposes only. For clarification purposes, academic sponsored research is not a commercial use under the terms of this Agreement.
+* 2.2 No Sublicensing or Additional Rights. LICENSEE shall not sublicense or distribute the PROGRAM, in whole or in part, without prior written permission from BROAD. LICENSEE shall ensure that all of its users agree to the terms of this Agreement. LICENSEE further agrees that it shall not put the PROGRAM on a network, server, or other similar technology that may be accessed by anyone other than the LICENSEE and its employees and users who have agreed to the terms of this agreement.
+* 2.3 License Limitations. Nothing in this Agreement shall be construed to confer any rights upon LICENSEE by implication, estoppel, or otherwise to any computer software, trademark, intellectual property, or patent rights of BROAD, or of any other entity, except as expressly granted herein. LICENSEE agrees that the PROGRAM, in whole or part, shall not be used for any commercial purpose, including without limitation, as the basis of a commercial software or hardware product or to provide services. LICENSEE further agrees that the PROGRAM shall not be copied or otherwise adapted in order to circumvent the need for obtaining a license for use of the PROGRAM.
+*
+* 3. OWNERSHIP OF INTELLECTUAL PROPERTY
+* LICENSEE acknowledges that title to the PROGRAM shall remain with BROAD. The PROGRAM is marked with the following BROAD copyright notice and notice of attribution to contributors. LICENSEE shall retain such notice on all copies. LICENSEE agrees to include appropriate attribution if any results obtained from use of the PROGRAM are included in any publication.
+* Copyright 2012 Broad Institute, Inc.
+* Notice of attribution: The GATK2 program was made available through the generosity of Medical and Population Genetics program at the Broad Institute, Inc.
+* LICENSEE shall not use any trademark or trade name of BROAD, or any variation, adaptation, or abbreviation, of such marks or trade names, or any names of officers, faculty, students, employees, or agents of BROAD except as states above for attribution purposes.
+*
+* 4. INDEMNIFICATION
+* LICENSEE shall indemnify, defend, and hold harmless BROAD, and their respective officers, faculty, students, employees, associated investigators and agents, and their respective successors, heirs and assigns, (Indemnitees), against any liability, damage, loss, or expense (including reasonable attorneys fees and expenses) incurred by or imposed upon any of the Indemnitees in connection with any claims, suits, actions, demands or judgments arising out of any theory of liability (including, without limitation, actions in the form of tort, warranty, or strict liability and regardless of whether such action has any factual basis) pursuant to any right or license granted under this Agreement.
+*
+* 5. NO REPRESENTATIONS OR WARRANTIES
+* THE PROGRAM IS DELIVERED AS IS. BROAD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE PROGRAM OR THE COPYRIGHT, EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF LATENT OR OTHER DEFECTS, WHETHER OR NOT DISCOVERABLE. BROAD EXTENDS NO WARRANTIES OF ANY KIND AS TO PROGRAM CONFORMITY WITH WHATEVER USER MANUALS OR OTHER LITERATURE MAY BE ISSUED FROM TIME TO TIME.
+* IN NO EVENT SHALL BROAD OR ITS RESPECTIVE DIRECTORS, OFFICERS, EMPLOYEES, AFFILIATED INVESTIGATORS AND AFFILIATES BE LIABLE FOR INCIDENTAL OR CONSEQUENTIAL DAMAGES OF ANY KIND, INCLUDING, WITHOUT LIMITATION, ECONOMIC DAMAGES OR INJURY TO PROPERTY AND LOST PROFITS, REGARDLESS OF WHETHER BROAD SHALL BE ADVISED, SHALL HAVE OTHER REASON TO KNOW, OR IN FACT SHALL KNOW OF THE POSSIBILITY OF THE FOREGOING.
+*
+* 6. ASSIGNMENT
+* This Agreement is personal to LICENSEE and any rights or obligations assigned by LICENSEE without the prior written consent of BROAD shall be null and void.
+*
+* 7. MISCELLANEOUS
+* 7.1 Export Control. LICENSEE gives assurance that it will comply with all United States export control laws and regulations controlling the export of the PROGRAM, including, without limitation, all Export Administration Regulations of the United States Department of Commerce. Among other things, these laws and regulations prohibit, or require a license for, the export of certain types of software to specified countries.
+* 7.2 Termination. LICENSEE shall have the right to terminate this Agreement for any reason upon prior written notice to BROAD. If LICENSEE breaches any provision hereunder, and fails to cure such breach within thirty (30) days, BROAD may terminate this Agreement immediately. Upon termination, LICENSEE shall provide BROAD with written assurance that the original and all copies of the PROGRAM have been destroyed, except that, upon prior written authorization from BROAD, LICENSEE may retain a copy for archive purposes.
+* 7.3 Survival. The following provisions shall survive the expiration or termination of this Agreement: Articles 1, 3, 4, 5 and Sections 2.2, 2.3, 7.3, and 7.4.
+* 7.4 Notice. Any notices under this Agreement shall be in writing, shall specifically refer to this Agreement, and shall be sent by hand, recognized national overnight courier, confirmed facsimile transmission, confirmed electronic mail, or registered or certified mail, postage prepaid, return receipt requested. All notices under this Agreement shall be deemed effective upon receipt.
+* 7.5 Amendment and Waiver; Entire Agreement. This Agreement may be amended, supplemented, or otherwise modified only by means of a written instrument signed by all parties. Any waiver of any rights or failure to act in a specific instance shall relate only to such instance and shall not be construed as an agreement to waive any rights or fail to act in any other instance, whether or not similar. This Agreement constitutes the entire agreement among the parties with respect to its subject matter and supersedes prior agreements or understandings between the parties relating to its subject matter.
+* 7.6 Binding Effect; Headings. This Agreement shall be binding upon and inure to the benefit of the parties and their respective permitted successors and assigns. All headings are for convenience only and shall not affect the meaning of any provision of this Agreement.
+* 7.7 Governing Law. This Agreement shall be construed, governed, interpreted and applied in accordance with the internal laws of the Commonwealth of Massachusetts, U.S.A., without regard to conflict of laws principles.
+*/
+package org.broadinstitute.gatk.tools.walkers.genotyper.afcalc;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Enumeration of usable AF calculation, their constraints (i.e. ploidy).
+ *
+ * Note that the order these occur in the enum is the order of preference, so
+ * the first value is taken over the second when multiple calculations satisfy
+ * the needs of the request (i.e., considering ploidy).
+ */
+public enum AFCalculatorImplementation {
+
+ /** default implementation */
+ EXACT_INDEPENDENT(IndependentAllelesDiploidExactAFCalculator.class, 2),
+
+ /** reference implementation of multi-allelic EXACT model. Extremely slow for many alternate alleles */
+ EXACT_REFERENCE(ReferenceDiploidExactAFCalculator.class, 2),
+
+ /** original biallelic exact model, for testing only */
+ EXACT_ORIGINAL(OriginalDiploidExactAFCalculator.class, 2, 2),
+
+ /** implementation that supports any sample ploidy. Currently not available for the HaplotypeCaller */
+ EXACT_GENERAL_PLOIDY(GeneralPloidyExactAFCalculator.class);
+
+ /**
+ * Special max alt allele count indicating that this maximum is in fact unbound (can be anything).
+ */
+ public final static int UNBOUND_ALTERNATIVE_ALLELE_COUNT = -1;
+
+ /**
+ * Special ploidy constant that indicates that in fact the ploidy is unbound (can be anything).
+ */
+ public final static int UNBOUND_PLOIDY = -1;
+
+ private static Map,AFCalculatorImplementation> calculatorClassToValue = buildCalculatorClassToValueMap();
+
+ /**
+ * Reference to the calculator class.
+ */
+ public final Class extends AFCalculator> calculatorClass;
+
+ /**
+ * Maximum number of supported alternative alleles.
+ */
+ public final int maxAltAlleles;
+
+ /**
+ * Reference to the constructor to instantiate a calculator for this implementation.
+ */
+ protected final Constructor extends AFCalculator> constructor;
+
+ /**
+ * Supported ploidy.
+ *
+ * This is equal to {@link #UNBOUND_PLOIDY} if the class can handle any ploidy.
+ */
+ public final int requiredPloidy;
+
+ /**
+ * Reference to the default implementation.
+ */
+ public final static AFCalculatorImplementation DEFAULT = EXACT_INDEPENDENT;
+
+
+ /**
+ * Constructs a new instance given all its properties
+ * @param clazz the calculator class that realizes this implementation.
+ * @param requiredPloidy the required ploidy; zero or greater or {@link #UNBOUND_PLOIDY} to indicate that any ploidy is supported.
+ * @param maxAltAlleles the maximum alternative alleles; zero or greater or {@link #UNBOUND_ALTERNATIVE_ALLELE_COUNT} to indicate that any maximum number of alternative alleles is supported.
+ */
+ AFCalculatorImplementation(final Class extends AFCalculator> clazz, final int requiredPloidy, final int maxAltAlleles) {
+ calculatorClass = clazz;
+ this.requiredPloidy = requiredPloidy;
+ this.maxAltAlleles = maxAltAlleles;
+ this.constructor = findInstantiationConstructor(calculatorClass);
+ }
+
+ /**
+ * Constructs a new instance leaving ploidy and max-allele count unbound.
+ * @param clazz the calculator class that realizes this implementation.
+ */
+ AFCalculatorImplementation(final Class extends AFCalculator> clazz) {
+ this(clazz,UNBOUND_PLOIDY, UNBOUND_ALTERNATIVE_ALLELE_COUNT);
+ }
+
+ /** Constructs a new instance leaving max-allele count unbound.
+ * @param clazz the calculator class that realizes this implementation.
+ * @param requiredPloidy the required ploidy; zero or greater or {@link #UNBOUND_PLOIDY} to indicate that any ploidy is supported.
+ */
+ AFCalculatorImplementation(final Class extends AFCalculator> clazz, final int requiredPloidy) {
+ this(clazz,requiredPloidy,UNBOUND_PLOIDY);
+ }
+
+ /**
+ * Checks whether a given ploidy and max alternative alleles combination is supported or not.
+ * @param requestedPloidy the targeted ploidy.
+ * @param requestedMaxAltAlleles the targeted max alternative alleles.
+ * @return {@code true} iff this calculator implementation satisfies both requirements.
+ */
+ public boolean usableForParams(final int requestedPloidy, final int requestedMaxAltAlleles) {
+ return (requiredPloidy == UNBOUND_PLOIDY || requiredPloidy == requestedPloidy)
+ && (maxAltAlleles == UNBOUND_ALTERNATIVE_ALLELE_COUNT || maxAltAlleles >= requestedMaxAltAlleles);
+ }
+
+ /**
+ * Resolve the constructor to use to instantiate calculators.
+ *
+ * @param clazz target class. Assume not to be {@code null}.
+ */
+ private Constructor extends AFCalculator> findInstantiationConstructor(final Class extends AFCalculator> clazz) {
+ if (Modifier.isAbstract(clazz.getModifiers()))
+ throw new IllegalStateException("AF calculator implementation class cannot be abstract");
+
+ final Constructor extends AFCalculator> result;
+ try {
+ result = clazz.getDeclaredConstructor();
+ } catch (final NoSuchMethodException e) {
+ throw new IllegalStateException("cannot find a suitable (int,int) constructor for the AFCalculator implementation " + this + " class " + clazz.getName());
+ }
+
+ // Check whether there will be issue calling the constructor just due to protections:
+ if (Modifier.isPrivate(result.getModifiers()) || (!Modifier.isPublic(result.getModifiers()) && !clazz.getPackage().equals(getClass().getPackage())))
+ throw new IllegalStateException("triple int constructor for AFCalculator implementation " + this + " class " + clazz.getName() + " is not public ");
+ return result;
+ }
+
+ /**
+ * Creates new instance
+ *
+ * @throws IllegalStateException if the instance could not be create due to some exception. The {@link Exception#getCause() cause} will hold a reference to the actual exception.
+ * @return never {@code null}.
+ */
+ public AFCalculator newInstance() {
+ try {
+ return constructor.newInstance();
+ } catch (final Throwable e) {
+ throw new IllegalStateException("could not instantiate AFCalculator for implementation " + this + " class " + calculatorClass.getName());
+ }
+ }
+
+ /**
+ * Returns the best (fastest) model give the required ploidy and alternative allele count.
+ *
+ * @param requiredPloidy required ploidy
+ * @param requiredAlternativeAlleleCount required alternative allele count.
+ * @param preferred a preferred mode if any. A {@code null} indicate that we should be try to use the default instead.
+ * @return never {@code null}
+ */
+ public static AFCalculatorImplementation bestValue(final int requiredPloidy, final int requiredAlternativeAlleleCount, final AFCalculatorImplementation preferred) {
+ final AFCalculatorImplementation preferredValue = preferred == null ? DEFAULT : preferred;
+ if (preferredValue.usableForParams(requiredPloidy,requiredAlternativeAlleleCount))
+ return preferredValue;
+ if (EXACT_INDEPENDENT.usableForParams(requiredPloidy,requiredAlternativeAlleleCount))
+ return EXACT_INDEPENDENT;
+ if (EXACT_REFERENCE.usableForParams(requiredPloidy,requiredAlternativeAlleleCount))
+ return EXACT_REFERENCE;
+ return EXACT_GENERAL_PLOIDY;
+ }
+
+ /**
+ * Returns the value that corresponds to a given implementation calculator class.
+ *
+ * @param clazz the target class.
+ *
+ * @throws IllegalArgumentException if {@code clazz} is {@code null} or if it is abstract.
+ * @throws IllegalStateException if
+ *
+ * @return never {@code null}.
+ */
+ public static AFCalculatorImplementation fromCalculatorClass(final Class extends AFCalculator> clazz) {
+ if (clazz == null)
+ throw new IllegalArgumentException("input class cannot be null");
+ final AFCalculatorImplementation result = calculatorClassToValue.get(clazz);
+ if (result == null)
+ throw new IllegalStateException("Attempt to retrieve AFCalculatorImplementation instance from a non-registered calculator class " + clazz.getName());
+ return result;
+ }
+
+ // Initializes the content of the class to value map.
+ private static Map, AFCalculatorImplementation> buildCalculatorClassToValueMap() {
+ final Map,AFCalculatorImplementation> result = new HashMap<>(values().length);
+ for (final AFCalculatorImplementation value : values())
+ if (result.put(value.calculatorClass,value) != null)
+ throw new IllegalStateException("more than one value associated with class " + value.calculatorClass.getName());
+ return result;
+ }
+}
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcPerformanceTest.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculatorPerformanceTest.java
similarity index 87%
rename from protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcPerformanceTest.java
rename to protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculatorPerformanceTest.java
index 4895ab303..2b1f1b17e 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalcPerformanceTest.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/AFCalculatorPerformanceTest.java
@@ -60,6 +60,7 @@ import htsjdk.variant.variantcontext.Allele;
import htsjdk.variant.variantcontext.Genotype;
import htsjdk.variant.variantcontext.VariantContext;
import htsjdk.variant.variantcontext.VariantContextBuilder;
+import org.broadinstitute.gatk.utils.variant.HomoSapiensConstants;
import java.io.*;
import java.util.*;
@@ -68,8 +69,8 @@ import java.util.*;
* A simple GATK utility (i.e, runs from command-line) for assessing the performance of
* the exact model
*/
-public class AFCalcPerformanceTest {
- final static Logger logger = Logger.getLogger(AFCalcPerformanceTest.class);
+public class AFCalculatorPerformanceTest {
+ final static Logger logger = Logger.getLogger(AFCalculatorPerformanceTest.class);
private static abstract class Analysis {
final GATKReport report;
@@ -78,7 +79,7 @@ public class AFCalcPerformanceTest {
report = GATKReport.newSimpleReport(name, columns);
}
- public abstract void run(final AFCalcTestBuilder testBuilder,
+ public abstract void run(final AFCalculatorTestBuilder testBuilder,
final List