diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/annotator/AlleleCountBySample.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/annotator/AlleleCountBySample.java
new file mode 100644
index 000000000..5d1bc10d2
--- /dev/null
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/annotator/AlleleCountBySample.java
@@ -0,0 +1,130 @@
+/*
+* 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.annotator;
+
+import htsjdk.variant.variantcontext.Genotype;
+import htsjdk.variant.variantcontext.GenotypeBuilder;
+import htsjdk.variant.variantcontext.VariantContext;
+import htsjdk.variant.vcf.VCFConstants;
+import htsjdk.variant.vcf.VCFFormatHeaderLine;
+import htsjdk.variant.vcf.VCFHeaderLineCount;
+import htsjdk.variant.vcf.VCFHeaderLineType;
+import org.broadinstitute.gatk.engine.contexts.AlignmentContext;
+import org.broadinstitute.gatk.engine.contexts.ReferenceContext;
+import org.broadinstitute.gatk.engine.refdata.RefMetaDataTracker;
+import org.broadinstitute.gatk.tools.walkers.annotator.interfaces.AnnotatorCompatible;
+import org.broadinstitute.gatk.tools.walkers.annotator.interfaces.GenotypeAnnotation;
+import org.broadinstitute.gatk.tools.walkers.genotyper.GenotypeAlleleCounts;
+import org.broadinstitute.gatk.tools.walkers.genotyper.GenotypeLikelihoodCalculator;
+import org.broadinstitute.gatk.tools.walkers.genotyper.GenotypeLikelihoodCalculators;
+import org.broadinstitute.gatk.utils.MathUtils;
+import org.broadinstitute.gatk.utils.Utils;
+import org.broadinstitute.gatk.utils.genotyper.PerReadAlleleLikelihoodMap;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Implements the per sample allele count and frequency expectation typically with keys MLPSAC and MLPSAF.
+ *
+ * @author Valentin Ruano-Rubio <valentin@broadinstitute.org>
+ */
+@SuppressWarnings("unused")
+public final class AlleleCountBySample extends GenotypeAnnotation {
+
+ private final static List keyNames = Collections.unmodifiableList(Arrays.asList(VCFConstants.MLE_PER_SAMPLE_ALLELE_COUNT_KEY,VCFConstants.MLE_PER_SAMPLE_ALLELE_FRACTION_KEY));
+
+ private final static List descriptors = Collections.unmodifiableList(Arrays.asList(
+ new VCFFormatHeaderLine(VCFConstants.MLE_PER_SAMPLE_ALLELE_COUNT_KEY, VCFHeaderLineCount.A, VCFHeaderLineType.Integer, "Maximum likelihood expectation (MLE) for the alternate allele count, in the same order as listed, for each individual sample"),
+ new VCFFormatHeaderLine(VCFConstants.MLE_PER_SAMPLE_ALLELE_FRACTION_KEY, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "Maximum likelihood expectation (MLE) for the alternate allele fraction, in the same order as listed, for each individual sample")
+ ));
+
+ @Override
+ public void annotate(final RefMetaDataTracker tracker,
+ final AnnotatorCompatible walker,
+ final ReferenceContext ref,
+ final AlignmentContext stratifiedContext,
+ final VariantContext vc,
+ final Genotype g,
+ final GenotypeBuilder gb,
+ final PerReadAlleleLikelihoodMap alleleLikelihoodMap) {
+
+ if (!g.hasPL())
+ return;
+ final int[] PL = g.getPL();
+ if (PL.length == 0)
+ return;
+
+ final int bestLikelihoodIndex = MathUtils.minElementIndex(PL);
+ final int numberOfAlleles = vc.getNAlleles();
+ final int ploidy = g.getPloidy();
+ final GenotypeLikelihoodCalculator calculator = GenotypeLikelihoodCalculators.getInstance(ploidy, numberOfAlleles);
+ final GenotypeAlleleCounts genotypeAlleleCounts = calculator.genotypeAlleleCountsAt(bestLikelihoodIndex);
+ final int[] AC = new int[numberOfAlleles - 1];
+ final double[] AF = new double[numberOfAlleles - 1];
+ final int allelesPresentCount = genotypeAlleleCounts.distinctAlleleCount();
+ for (int i = 0; i < allelesPresentCount; i++) {
+ final int alleleIndex = genotypeAlleleCounts.alleleIndexAt(i);
+ if (alleleIndex == 0) continue; // skip the reference allele.
+ final int alleleCount = genotypeAlleleCounts.alleleCountAt(i);
+ AC[alleleIndex - 1] = alleleCount;
+ AF[alleleIndex - 1] = ((double) alleleCount) / (double) ploidy;
+ }
+ gb.attribute(VCFConstants.MLE_PER_SAMPLE_ALLELE_COUNT_KEY, Utils.asList(AC));
+ gb.attribute(VCFConstants.MLE_PER_SAMPLE_ALLELE_FRACTION_KEY, Utils.asList(AF));
+ }
+
+ @Override
+ public List getDescriptions() {
+ return descriptors;
+ }
+
+ @Override
+ public List getKeyNames() {
+ return keyNames;
+ }
+}
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/GenotypeAlleleCounts.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/GenotypeAlleleCounts.java
index f055362fa..e17a8df64 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/GenotypeAlleleCounts.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/GenotypeAlleleCounts.java
@@ -46,9 +46,12 @@
package org.broadinstitute.gatk.tools.walkers.genotyper;
+import htsjdk.variant.variantcontext.Allele;
import org.broadinstitute.gatk.utils.MathUtils;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
/**
* Collection of allele counts for a genotype. It encompasses what alleles are present in the genotype and in what number.
@@ -702,6 +705,46 @@ public class GenotypeAlleleCounts implements Comparable, C
*/
@Override
protected GenotypeAlleleCounts clone() {
- return new GenotypeAlleleCounts(ploidy,index,Arrays.copyOf(sortedAlleleCounts,distinctAlleleCount << 1));
+ final GenotypeAlleleCounts result;
+ try {
+ result = (GenotypeAlleleCounts) super.clone();
+ } catch (final CloneNotSupportedException e) {
+ throw new IllegalStateException(e);
+ }
+ result.sortedAlleleCounts = Arrays.copyOf(sortedAlleleCounts,distinctAlleleCount << 1);
+ return result;
+ }
+
+ /**
+ * Composes a list with the alleles.
+ *
+ * @param allelesToUse alleles to use.
+ *
+ * @throws IllegalArgumentException if {@code allelesToUse} is {@code null},
+ * or does not contain enough elements to accommodate the maximum allele index in this allele-counts.
+ *
+ * @return never null, but it might be restricted (unmodifiable or non-expandable).
+ */
+ public List asAlleleList(final List allelesToUse) {
+ if (allelesToUse == null)
+ throw new IllegalArgumentException("the input allele list cannot be null");
+ if (allelesToUse.size() < maximumAlleleIndex())
+ throw new IllegalArgumentException("the provided alleles to use does not contain an element for the maximum allele ");
+ if (distinctAlleleCount == 1 ) {
+ if (ploidy == 1)
+ return Collections.singletonList(allelesToUse.get(sortedAlleleCounts[0]));
+ else
+ return Collections.nCopies(ploidy,allelesToUse.get(sortedAlleleCounts[0]));
+ } else {
+ final Allele[] myAlleles = new Allele[ploidy];
+ int nextIndex = 0;
+ for (int i = 0, ii = 0; i < distinctAlleleCount; i++) {
+ final Allele allele = allelesToUse.get(sortedAlleleCounts[ii++]);
+ final int repeats = sortedAlleleCounts[ii++];
+ for (int j = 0; j < repeats; j++)
+ myAlleles[nextIndex++] = allele;
+ }
+ return (List) Arrays.asList(myAlleles);
+ }
}
}
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/GeneralPloidyExactAFCalc.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/GeneralPloidyExactAFCalc.java
index 00a20cc43..f1cf88f63 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/GeneralPloidyExactAFCalc.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/genotyper/afcalc/GeneralPloidyExactAFCalc.java
@@ -46,12 +46,14 @@
package org.broadinstitute.gatk.tools.walkers.genotyper.afcalc;
-import org.broadinstitute.gatk.tools.walkers.genotyper.GeneralPloidyGenotypeLikelihoods;
-import org.broadinstitute.gatk.utils.MathUtils;
-import org.broadinstitute.gatk.utils.variant.GATKVariantContextUtils;
-import htsjdk.variant.vcf.VCFConstants;
-import org.broadinstitute.gatk.utils.exceptions.ReviewedGATKException;
import htsjdk.variant.variantcontext.*;
+import org.broadinstitute.gatk.tools.walkers.genotyper.GeneralPloidyGenotypeLikelihoods;
+import org.broadinstitute.gatk.tools.walkers.genotyper.GenotypeAlleleCounts;
+import org.broadinstitute.gatk.tools.walkers.genotyper.GenotypeLikelihoodCalculator;
+import org.broadinstitute.gatk.tools.walkers.genotyper.GenotypeLikelihoodCalculators;
+import org.broadinstitute.gatk.utils.MathUtils;
+import org.broadinstitute.gatk.utils.exceptions.ReviewedGATKException;
+import org.broadinstitute.gatk.utils.variant.GATKVariantContextUtils;
import java.util.*;
@@ -548,42 +550,17 @@ public class GeneralPloidyExactAFCalc extends ExactAFCalc {
final int numChromosomes) {
final int numNewAltAlleles = allelesToUse.size() - 1;
-
-
// find the genotype with maximum likelihoods
final int PLindex = numNewAltAlleles == 0 ? 0 : MathUtils.maxElementIndex(newLikelihoods);
+ final GenotypeLikelihoodCalculator calculator = GenotypeLikelihoodCalculators.getInstance(numChromosomes,allelesToUse.size());
+ final GenotypeAlleleCounts alleleCounts = calculator.genotypeAlleleCountsAt(PLindex);
- final int[] mlAlleleCount = GeneralPloidyGenotypeLikelihoods.getAlleleCountFromPLIndex(allelesToUse.size(), numChromosomes, PLindex);
- final ArrayList alleleFreqs = new ArrayList<>();
- final ArrayList alleleCounts = new ArrayList<>();
-
-
- for (int k=1; k < mlAlleleCount.length; k++) {
- alleleCounts.add(mlAlleleCount[k]);
- final double freq = (double)mlAlleleCount[k] / (double)numChromosomes;
- alleleFreqs.add(freq);
-
- }
-
- // per-pool logging of AC and AF
- gb.attribute(VCFConstants.MLE_PER_SAMPLE_ALLELE_COUNT_KEY, alleleCounts.size() == 1 ? alleleCounts.get(0) : alleleCounts);
- gb.attribute(VCFConstants.MLE_PER_SAMPLE_ALLELE_FRACTION_KEY, alleleFreqs.size() == 1 ? alleleFreqs.get(0) : alleleFreqs);
+ gb.alleles(alleleCounts.asAlleleList(allelesToUse));
// remove PLs if necessary
if (newLikelihoods.length > MAX_LENGTH_FOR_POOL_PL_LOGGING)
gb.noPL();
- ArrayList myAlleles = new ArrayList();
-
- // add list of called ML genotypes to alleles list
- // TODO - too unwieldy?
- int idx = 0;
- for (int mlind = 0; mlind < mlAlleleCount.length; mlind++) {
- for (int k=0; k < mlAlleleCount[mlind]; k++)
- myAlleles.add(idx++,allelesToUse.get(mlind));
- }
- gb.alleles(myAlleles);
-
// TODO - deprecated so what is the appropriate method to call?
if ( numNewAltAlleles > 0 )
gb.log10PError(GenotypeLikelihoods.getGQLog10FromLikelihoods(PLindex, newLikelihoods));
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCaller.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCaller.java
index 2c12b4887..9037d7f3c 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCaller.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCaller.java
@@ -68,7 +68,6 @@ 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.*;
-import org.broadinstitute.gatk.tools.walkers.genotyper.afcalc.AFCalcFactory;
import org.broadinstitute.gatk.tools.walkers.haplotypecaller.readthreading.ReadThreadingAssembler;
import org.broadinstitute.gatk.utils.GenomeLoc;
import org.broadinstitute.gatk.utils.GenomeLocParser;
@@ -627,8 +626,6 @@ public class HaplotypeCaller extends ActiveRegionWalker, In
public void initialize() {
super.initialize();
-
-
if (dontGenotype && emitReferenceConfidence())
throw new UserException("You cannot request gVCF output and do not genotype at the same time");
@@ -708,11 +705,6 @@ public class HaplotypeCaller extends ActiveRegionWalker, In
headerInfo.add(new VCFFormatHeaderLine(HAPLOTYPE_CALLER_PHASING_GT_KEY, 1, VCFHeaderLineType.String, "Physical phasing haplotype information, describing how the alternate alleles are phased in relation to one another"));
}
- if (SCAC.genotypeArgs.samplePloidy != HomoSapiensConstants.DEFAULT_PLOIDY || SCAC.requestedAlleleFrequencyCalculationModel == AFCalcFactory.Calculation.EXACT_GENERAL_PLOIDY) {
- headerInfo.add(new VCFFormatHeaderLine(VCFConstants.MLE_PER_SAMPLE_ALLELE_COUNT_KEY, VCFHeaderLineCount.A, VCFHeaderLineType.Integer, "Maximum likelihood expectation (MLE) for the alternate allele count, in the same order as listed, for each individual sample"));
- headerInfo.add(new VCFFormatHeaderLine(VCFConstants.MLE_PER_SAMPLE_ALLELE_FRACTION_KEY, VCFHeaderLineCount.A, VCFHeaderLineType.Float, "Maximum likelihood expectation (MLE) for the alternate allele fraction, in the same order as listed, for each individual sample"));
- }
-
// FILTER fields are added unconditionally as it's not always 100% certain the circumstances
// where the filters are used. For example, in emitting all sites the lowQual field is used
headerInfo.add(new VCFFilterHeaderLine(UnifiedGenotypingEngine.LOW_QUAL_FILTER_NAME, "Low quality"));
diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/variantutils/GenotypeGVCFs.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/variantutils/GenotypeGVCFs.java
index 98b849891..6d83bbbf0 100644
--- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/variantutils/GenotypeGVCFs.java
+++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/variantutils/GenotypeGVCFs.java
@@ -177,10 +177,6 @@ public class GenotypeGVCFs extends RodWalker= current.minimumAlleleIndex() + 1) expected[current.minimumAlleleIndex() + 1] = 1;
@@ -205,6 +212,16 @@ public class GenotypeAlleleCountsUnitTest {
Assert.assertFalse(current.equals(next));
Assert.assertEquals(next.index(),current.index() + 1);
Assert.assertEquals(next.ploidy(),ploidy);
+
+ //Check asAlleleList.
+ final List expectedList = new ArrayList<>(ploidy);
+ for (int i = 0; i < next.distinctAlleleCount(); i++) {
+ for (int j = 0; j < next.alleleCountAt(i); j++) {
+ expectedList.add(testAlleles.get(next.alleleIndexAt(i)));
+ }
+ }
+ Assert.assertEquals(next.asAlleleList(testAlleles),expectedList);
+
current = next;
}
}
@@ -317,6 +334,18 @@ public class GenotypeAlleleCountsUnitTest {
private static final int MAXIMUM_ALLELE_INDEX = 10;
+ private static final List testAlleles;
+
+ static {
+ final StringBuilder sb = new StringBuilder(51);
+ testAlleles = new ArrayList<>(51);
+ sb.append('A');
+ for (int i = 0; i <= 50; i++) {
+ testAlleles.add(Allele.create(sb.toString().getBytes(), i == 0));
+ sb.append('A');
+ }
+ }
+
private static final int[] PLOIDY = new int[] { 1, 2, 3, 7, 10};
@DataProvider(name="ploidyData")
diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite1IntegrationTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite1IntegrationTest.java
index 0437eb375..272a6f766 100644
--- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite1IntegrationTest.java
+++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite1IntegrationTest.java
@@ -64,21 +64,21 @@ public class UnifiedGenotyperGeneralPloidySuite1IntegrationTest extends WalkerTe
@Test(enabled = true)
public void testSNP_ACS_Pools() {
- executor.PC_LSV_Test_short(" -maxAltAlleles 1 -ploidy 6 -out_mode EMIT_ALL_CONFIDENT_SITES", "LSV_SNP_ACS", "SNP", "df0e67c975ef74d593f1c704daab1705");
+ executor.PC_LSV_Test_short("-A AlleleCountBySample -maxAltAlleles 1 -ploidy 6 -out_mode EMIT_ALL_CONFIDENT_SITES", "LSV_SNP_ACS", "SNP", "df0e67c975ef74d593f1c704daab1705");
}
@Test(enabled = true)
public void testBOTH_GGA_Pools() {
- executor.PC_LSV_Test(String.format(" -maxAltAlleles 2 -ploidy 24 -gt_mode GENOTYPE_GIVEN_ALLELES -out_mode EMIT_ALL_SITES -alleles %s", LSV_ALLELES), "LSV_BOTH_GGA", "BOTH", "4b646b6fc9c5c2ef88433a5b350310fe");
+ executor.PC_LSV_Test(String.format("-A AlleleCountBySample -maxAltAlleles 2 -ploidy 24 -gt_mode GENOTYPE_GIVEN_ALLELES -out_mode EMIT_ALL_SITES -alleles %s", LSV_ALLELES), "LSV_BOTH_GGA", "BOTH", "2d3067587de19fbb3b0bb9afbc12256d");
}
@Test(enabled = true)
public void testINDEL_GGA_Pools() {
- executor.PC_LSV_Test(String.format(" -maxAltAlleles 1 -ploidy 24 -gt_mode GENOTYPE_GIVEN_ALLELES -out_mode EMIT_ALL_SITES -alleles %s", LSV_ALLELES), "LSV_INDEL_GGA", "INDEL", "171355e4d0648fdd50d7d56de950d338");
+ executor.PC_LSV_Test(String.format("-A AlleleCountBySample -maxAltAlleles 1 -ploidy 24 -gt_mode GENOTYPE_GIVEN_ALLELES -out_mode EMIT_ALL_SITES -alleles %s", LSV_ALLELES), "LSV_INDEL_GGA", "INDEL", "171355e4d0648fdd50d7d56de950d338");
}
@Test(enabled = true)
public void testINDEL_maxAltAlleles2_ploidy1_Pools_noRef() {
- executor.PC_LSV_Test_NoRef(" -maxAltAlleles 2 -ploidy 1", "LSV_INDEL_DISC_NOREF_p1", "INDEL", "ae90d6be28c19e455083a47bc95c3b1b");
+ executor.PC_LSV_Test_NoRef("-A AlleleCountBySample -maxAltAlleles 2 -ploidy 1", "LSV_INDEL_DISC_NOREF_p1", "INDEL", "ae90d6be28c19e455083a47bc95c3b1b");
}
}
diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite2IntegrationTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite2IntegrationTest.java
index bd1daa714..d8cca1392 100644
--- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite2IntegrationTest.java
+++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/genotyper/UnifiedGenotyperGeneralPloidySuite2IntegrationTest.java
@@ -58,16 +58,16 @@ public class UnifiedGenotyperGeneralPloidySuite2IntegrationTest extends WalkerTe
@Test(enabled = true)
public void testINDEL_maxAltAlleles2_ploidy3_Pools_noRef() {
- executor.PC_LSV_Test_NoRef(" -maxAltAlleles 2 -ploidy 3","LSV_INDEL_DISC_NOREF_p3","INDEL","9fc4f04105bde31bafc93548745cb67e");
+ executor.PC_LSV_Test_NoRef("-A AlleleCountBySample -maxAltAlleles 2 -ploidy 3","LSV_INDEL_DISC_NOREF_p3","INDEL","9fc4f04105bde31bafc93548745cb67e");
}
@Test(enabled = true)
public void testMT_SNP_DISCOVERY_sp4() {
- executor.PC_MT_Test(CEUTRIO_BAM, " -maxAltAlleles 1 -ploidy 8", "MT_SNP_DISCOVERY_sp4","f5bd19784f482efe7254b04209224dca");
+ executor.PC_MT_Test(CEUTRIO_BAM, "-A AlleleCountBySample -maxAltAlleles 1 -ploidy 8", "MT_SNP_DISCOVERY_sp4","f5bd19784f482efe7254b04209224dca");
}
@Test(enabled = true)
public void testMT_SNP_GGA_sp10() {
- executor.PC_MT_Test(CEUTRIO_BAM, String.format(" -maxAltAlleles 1 -ploidy 20 -gt_mode GENOTYPE_GIVEN_ALLELES -out_mode EMIT_ALL_SITES -alleles %s",NA12891_CALLS), "MT_SNP_GGA_sp10", "0f6fdf60d7f93b2db8c8cb92c1fd3e00");
+ executor.PC_MT_Test(CEUTRIO_BAM, String.format("-A AlleleCountBySample -maxAltAlleles 1 -ploidy 20 -gt_mode GENOTYPE_GIVEN_ALLELES -out_mode EMIT_ALL_SITES -alleles %s",NA12891_CALLS), "MT_SNP_GGA_sp10", "0f6fdf60d7f93b2db8c8cb92c1fd3e00");
}
}
diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGVCFIntegrationTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGVCFIntegrationTest.java
index cb77eb762..7b3c8f182 100644
--- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGVCFIntegrationTest.java
+++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerGVCFIntegrationTest.java
@@ -66,12 +66,12 @@ public class HaplotypeCallerGVCFIntegrationTest extends WalkerTest {
final String WExIntervals = "-L 20:10,000,000-10,100,000 -isr INTERSECTION -L " + hg19Chr20Intervals;
// this functionality can be adapted to provide input data for whatever you might want in your data
- tests.add(new Object[]{NA12878_PCRFREE, ReferenceConfidenceMode.NONE, PCRFreeIntervals, "3ea86317a90452eaf7c075f7a3aae77a"});
- tests.add(new Object[]{NA12878_PCRFREE, ReferenceConfidenceMode.BP_RESOLUTION, PCRFreeIntervals, "14e6011cc71541be5a6e70fecf6ce455"});
- tests.add(new Object[]{NA12878_PCRFREE, ReferenceConfidenceMode.GVCF, PCRFreeIntervals, "7e51552ac313840ae16c9b8187b01091"});
- tests.add(new Object[]{NA12878_WEx, ReferenceConfidenceMode.NONE, WExIntervals, "a4a89693cc1b5385b17c805a8b655cc0"});
- tests.add(new Object[]{NA12878_WEx, ReferenceConfidenceMode.BP_RESOLUTION, WExIntervals, "1a6d0dc9afd3394ebec99480cb97eb7a"});
- tests.add(new Object[]{NA12878_WEx, ReferenceConfidenceMode.GVCF, WExIntervals, "e462b6527ed9eb1c09261b453a7dadc4"});
+ tests.add(new Object[]{NA12878_PCRFREE, ReferenceConfidenceMode.NONE, PCRFreeIntervals, "ebf7706007ff609ce34801cb847db46c"});
+ tests.add(new Object[]{NA12878_PCRFREE, ReferenceConfidenceMode.BP_RESOLUTION, PCRFreeIntervals, "41892abdb9c04e1a25598f3e72966bfe"});
+ tests.add(new Object[]{NA12878_PCRFREE, ReferenceConfidenceMode.GVCF, PCRFreeIntervals, "efe4b4c7ffbdba14ccca2a45a6903ac5"});
+ tests.add(new Object[]{NA12878_WEx, ReferenceConfidenceMode.NONE, WExIntervals, "a24405faed1002a5cd9e630150044505"});
+ tests.add(new Object[]{NA12878_WEx, ReferenceConfidenceMode.BP_RESOLUTION, WExIntervals, "edf7526c70dcaa6e7c0b914fe9d91ed3"});
+ tests.add(new Object[]{NA12878_WEx, ReferenceConfidenceMode.GVCF, WExIntervals, "c701f8a4f90691ed044243aa851207ac"});
return tests.toArray(new Object[][]{});
}
@@ -103,12 +103,12 @@ public class HaplotypeCallerGVCFIntegrationTest extends WalkerTest {
final String WExIntervals = "-L 20:10,000,000-10,100,000 -isr INTERSECTION -L " + hg19Chr20Intervals;
// this functionality can be adapted to provide input data for whatever you might want in your data
- tests.add(new Object[]{NA12878_PCRFREE, ReferenceConfidenceMode.NONE, PCRFreeIntervals, "efe4e8e4d28d419e40945a948fd5bdd0"});
- tests.add(new Object[]{NA12878_PCRFREE, ReferenceConfidenceMode.BP_RESOLUTION, PCRFreeIntervals, "8deed579c166443851d8fe7e3c521197"});
- tests.add(new Object[]{NA12878_PCRFREE, ReferenceConfidenceMode.GVCF, PCRFreeIntervals, "384e41d7c962e7a9c191c3646239b9f3"});
- tests.add(new Object[]{NA12878_WEx, ReferenceConfidenceMode.NONE, WExIntervals, "207ad9fdcc8d557010ec1bf2ae9f65dc"});
- tests.add(new Object[]{NA12878_WEx, ReferenceConfidenceMode.BP_RESOLUTION, WExIntervals, "d5b914a994b8c2f2d70960bd444fcbba"});
- tests.add(new Object[]{NA12878_WEx, ReferenceConfidenceMode.GVCF, WExIntervals, "34e76939b6aaa206fa42548a225b15c4"});
+ tests.add(new Object[]{NA12878_PCRFREE, ReferenceConfidenceMode.NONE, PCRFreeIntervals, "06885cff1d0899f48bee9057eae36eac"});
+ tests.add(new Object[]{NA12878_PCRFREE, ReferenceConfidenceMode.BP_RESOLUTION, PCRFreeIntervals, "fa48ebdb25e876431bd79be34502f848"});
+ tests.add(new Object[]{NA12878_PCRFREE, ReferenceConfidenceMode.GVCF, PCRFreeIntervals, "fd18cafabf0d8fb0ee3118c4cfe1f83b"});
+ tests.add(new Object[]{NA12878_WEx, ReferenceConfidenceMode.NONE, WExIntervals, "c245b46adb12bcc8491337b84a742b57"});
+ tests.add(new Object[]{NA12878_WEx, ReferenceConfidenceMode.BP_RESOLUTION, WExIntervals, "2951d85daebfe5354ba4c20eb99c777f"});
+ tests.add(new Object[]{NA12878_WEx, ReferenceConfidenceMode.GVCF, WExIntervals, "8ef4baadf5bc9058377ad8b1f8d69701"});
return tests.toArray(new Object[][]{});
}
diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerIntegrationTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerIntegrationTest.java
index 37c9cbe02..7d0f9d385 100644
--- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerIntegrationTest.java
+++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerIntegrationTest.java
@@ -96,17 +96,17 @@ public class HaplotypeCallerIntegrationTest extends WalkerTest {
@Test
public void testHaplotypeCallerMultiSampleHaploid() {
HCTest(CEUTRIO_BAM,
- "-ploidy 1", "b9e43506af628768fc9fd1ced49822b1");
+ "-ploidy 1", "b12bb4ccc8c86202550d59c9350d93e5");
}
@Test
public void testHaplotypeCallerSingleSampleHaploid() {
- HCTest(NA12878_BAM, "-ploidy 1", "fb584b8c3f371ee2e438a3fc2335b26f");
+ HCTest(NA12878_BAM, "-ploidy 1", "e97604190cb3f91c52746a32bce8293f");
}
@Test
public void testHaplotypeCallerSingleSampleTetraploid() {
- HCTest(NA12878_BAM, "-ploidy 4", "d450b486c76520f9c803c603f25563e4");
+ HCTest(NA12878_BAM, "-ploidy 4", "9f2da06419b29f89605b90943aea0de4");
}
@Test
@@ -116,12 +116,12 @@ public class HaplotypeCallerIntegrationTest extends WalkerTest {
@Test
public void testHaplotypeCallerMinBaseQualityHaploid() {
- HCTest(NA12878_BAM, "-mbq 15 -ploidy 1", "40259040f6febd8ea5931132cf5d8958");
+ HCTest(NA12878_BAM, "-mbq 15 -ploidy 1", "3b9f1b1fffcea0edee47803e9f4f868c");
}
@Test
public void testHaplotypeCallerMinBaseQualityTetraploid() {
- HCTest(NA12878_BAM, "-mbq 15 -ploidy 4", "ca11eae5def67ca9717d129348e4cda7");
+ HCTest(NA12878_BAM, "-mbq 15 -ploidy 4", "f551c2d2b82145bb827a2c7e01a70a5b");
}
@Test
@@ -131,7 +131,7 @@ public class HaplotypeCallerIntegrationTest extends WalkerTest {
@Test
public void testHaplotypeCallerGraphBasedMultiSampleHaploid() {
- HCTest(CEUTRIO_BAM, "-likelihoodEngine GraphBased -ploidy 1", "f0677e5a2882f947f437e8d2049172cb");
+ HCTest(CEUTRIO_BAM, "-likelihoodEngine GraphBased -ploidy 1", "a7c0848813773a0a21fa7bb18732c504");
}
@Test
@@ -154,13 +154,13 @@ public class HaplotypeCallerIntegrationTest extends WalkerTest {
@Test
public void testHaplotypeCallerMultiSampleGGAHaploid() {
HCTest(CEUTRIO_BAM, "--max_alternate_alleles 3 -gt_mode GENOTYPE_GIVEN_ALLELES -ploidy 1 -alleles " + validationDataLocation + "combined.phase1.chr20.raw.indels.sites.vcf",
- "e50c55c65db3fa55c75ba03b4dd2f1a8");
+ "d02d67d13a289d05b26b57cd3ae0346b");
}
@Test
public void testHaplotypeCallerMultiSampleGGATetraploid() {
HCTest(CEUTRIO_BAM, "--max_alternate_alleles 3 -gt_mode GENOTYPE_GIVEN_ALLELES -ploidy 4 -alleles " + validationDataLocation + "combined.phase1.chr20.raw.indels.sites.vcf",
- "374d6db6e5f3f4fdb5ede26a529caa8b");
+ "d842dcacdacd2be5b1e7f4efd17e7266");
}
@Test
diff --git a/public/gatk-tools-public/src/main/java/org/broadinstitute/gatk/utils/Utils.java b/public/gatk-tools-public/src/main/java/org/broadinstitute/gatk/utils/Utils.java
index b4c0c75fa..d664ef689 100644
--- a/public/gatk-tools-public/src/main/java/org/broadinstitute/gatk/utils/Utils.java
+++ b/public/gatk-tools-public/src/main/java/org/broadinstitute/gatk/utils/Utils.java
@@ -283,6 +283,52 @@ public class Utils {
}
}
+ /**
+ * Returns a {@link List List<Integer>} representation of an primitive int array.
+ * @param values the primitive int array to represent.
+ * @return never code {@code null}. The returned list will be unmodifiable yet it will reflect changes in values in the original array yet
+ * you cannot change the values
+ */
+ public static List asList(final int ... values) {
+ if (values == null)
+ throw new IllegalArgumentException("the input array cannot be null");
+ return new AbstractList() {
+
+ @Override
+ public Integer get(final int index) {
+ return values[index];
+ }
+
+ @Override
+ public int size() {
+ return values.length;
+ }
+ };
+ }
+
+ /**
+ * Returns a {@link List List<Double>} representation of an primitive double array.
+ * @param values the primitive int array to represent.
+ * @return never code {@code null}. The returned list will be unmodifiable yet it will reflect changes in values in the original array yet
+ * you cannot change the values.
+ */
+ public static List asList(final double ... values) {
+ if (values == null)
+ throw new IllegalArgumentException("the input array cannot be null");
+ return new AbstractList() {
+
+ @Override
+ public Double get(final int index) {
+ return values[index];
+ }
+
+ @Override
+ public int size() {
+ return values.length;
+ }
+ };
+ }
+
public static String join(final String separator, final T ... objects) {
return join(separator, Arrays.asList(objects));
}
diff --git a/public/gatk-tools-public/src/test/java/org/broadinstitute/gatk/utils/UtilsUnitTest.java b/public/gatk-tools-public/src/test/java/org/broadinstitute/gatk/utils/UtilsUnitTest.java
index 8fd4c3c3a..a303f2c8b 100644
--- a/public/gatk-tools-public/src/test/java/org/broadinstitute/gatk/utils/UtilsUnitTest.java
+++ b/public/gatk-tools-public/src/test/java/org/broadinstitute/gatk/utils/UtilsUnitTest.java
@@ -26,6 +26,7 @@
package org.broadinstitute.gatk.utils;
import org.apache.commons.io.FileUtils;
+import org.broadinstitute.gatk.engine.GenomeAnalysisEngine;
import org.broadinstitute.gatk.utils.io.IOUtils;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
@@ -178,6 +179,54 @@ public class UtilsUnitTest extends BaseTest {
Assert.assertEquals(actual, expected);
}
+ @Test(dataProvider = "asIntegerListData")
+ public void testAsIntegerList(final int[] values) {
+ if (values == null) {
+ try {
+ Utils.asList((int[]) null);
+ Assert.fail("Should have thrown an exception");
+ } catch (final IllegalArgumentException ex) {
+ // good.
+ }
+ } else {
+ final Random rdn = GenomeAnalysisEngine.getRandomGenerator();
+ final int[] valuesClone = values.clone();
+ final List list = Utils.asList(valuesClone);
+ Assert.assertNotNull(list);
+ Assert.assertEquals(list.size(),values.length);
+ for (int i = 0; i < values.length; i++)
+ Assert.assertEquals((int) list.get(i),values[i]);
+ for (int i = 0; i < values.length; i++)
+ valuesClone[rdn.nextInt(values.length)] = rdn.nextInt(1000);
+ for (int i = 0; i < values.length; i++)
+ Assert.assertEquals((int) list.get(i),valuesClone[i]);
+ }
+ }
+
+ @Test(dataProvider = "asDoubleListData")
+ public void testAsDoubleList(final double[] values) {
+ if (values == null) {
+ try {
+ Utils.asList((int[]) null);
+ Assert.fail("Should have thrown an exception");
+ } catch (final IllegalArgumentException ex) {
+ // good.
+ }
+ } else {
+ final Random rdn = GenomeAnalysisEngine.getRandomGenerator();
+ final double[] valuesClone = values.clone();
+ final List list = Utils.asList(valuesClone);
+ Assert.assertNotNull(list);
+ Assert.assertEquals(list.size(),values.length);
+ for (int i = 0; i < values.length; i++)
+ Assert.assertEquals((double) list.get(i),values[i]);
+ for (int i = 0; i < values.length; i++)
+ valuesClone[rdn.nextInt(values.length)] = rdn.nextDouble() * 1000;
+ for (int i = 0; i < values.length; i++)
+ Assert.assertEquals((double) list.get(i),valuesClone[i]);
+ }
+ }
+
@Test
public void testCalcMD5() throws Exception {
final File source = new File(publicTestDir + "exampleFASTA.fasta");
@@ -287,4 +336,28 @@ public class UtilsUnitTest extends BaseTest {
{"romeo+juliette" , "01111010111001" },
};
}
+
+
+ @DataProvider(name = "asIntegerListData")
+ public Object[][] asIntegerListData() {
+ return new Object[][] {
+ { null },
+ {new int[0]},
+ {new int[]{1, 2, 3, 4, 5}},
+ {new int[]{2}},
+ {new int[]{3,4}}
+ };
+ }
+
+ @DataProvider(name = "asDoubleListData")
+ public Object[][] asDoubleListData() {
+ return new Object[][] {
+ { null },
+ {new double[0]},
+ {new double[]{1, 2, 3, 4, 5}},
+ {new double[]{2}},
+ {new double[]{3,4}},
+ {new double[]{Double.NaN, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}}
+ };
+ }
}