Merge pull request #719 from broadinstitute/vrr_generalize_ploidy_in_genotype_gvcfs
Adds support for omniploidy to GenotypeGVCFs and CombineGVCFs.
This commit is contained in:
commit
c7925f6e5c
|
|
@ -1,45 +1,45 @@
|
|||
/*
|
||||
* 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.
|
||||
* 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
|
||||
* 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.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.
|
||||
*/
|
||||
|
|
@ -747,4 +747,37 @@ public class GenotypeAlleleCounts implements Comparable<GenotypeAlleleCounts>, C
|
|||
return (List<T>) Arrays.asList(myAlleles);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with the allele indices repeated based on the number of occurrences in the genotype.
|
||||
*
|
||||
* <p>
|
||||
* indices are sorted from the smallest to the greatest.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* If a sufficiently large array is provided as {@code dest}, this is used as the destination. Unecessary
|
||||
* positions at the back of the array are left untouched.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
* However if {@code dest} is {@code null} or it does not have enough space, a new array of with length equal to
|
||||
* the ploidy will be used and returned instead.
|
||||
* </p>
|
||||
*
|
||||
* @param dest destination array. Can be {@code null} or not have sufficient positions (ploidy); in that case a new
|
||||
* one is created.
|
||||
* @return never {@code null}, {@code dest} if sufficiently large otherwise an array of ploidy positions.
|
||||
*/
|
||||
public int[] toAlleleIndicesArray(final int[] dest) {
|
||||
final int[] result = dest == null || dest.length < ploidy ? new int[ploidy] : dest;
|
||||
int k = 0;
|
||||
for (int i = 0,ii = 0; i < distinctAlleleCount; i++) {
|
||||
final int index = sortedAlleleCounts[ii++];
|
||||
final int repeats = sortedAlleleCounts[ii++];
|
||||
for (int j = 0; j < repeats; j++)
|
||||
result[k++] = index;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
* 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 htsjdk.variant.variantcontext.Allele;
|
||||
|
|
@ -548,6 +549,11 @@ public class GenotypeLikelihoodCalculator {
|
|||
|
||||
/**
|
||||
* Transforms the content of the heap into an index.
|
||||
*
|
||||
* <p>
|
||||
* The heap contents are flushed as a result, so is left ready for another use.
|
||||
* </p>
|
||||
*
|
||||
* @return a valid likelihood index.
|
||||
*/
|
||||
private int alleleHeapToIndex() {
|
||||
|
|
@ -564,4 +570,65 @@ public class GenotypeLikelihoodCalculator {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Composes a genotype index map given a allele index recoding.
|
||||
*
|
||||
* @param oldToNewAlleleIndexMap allele recoding. The ith entry indicates the index of the allele in original encoding
|
||||
* that corresponds to the ith allele index in the final encoding.
|
||||
*
|
||||
* @throws IllegalArgumentException if this calculator cannot handle the recoding provided. This is
|
||||
* the case when either {@code oldToNewAlleleIndexMap}'s length or any of its element (+ 1 as they are 0-based) is larger
|
||||
* this calculator's {@link #alleleCount()}. Also if any {@code oldToNewAllelesIndexMap} element is negative.
|
||||
*
|
||||
* @return never {@code null}.
|
||||
*/
|
||||
public int[] genotypeIndexMap(final int[] oldToNewAlleleIndexMap) {
|
||||
if (oldToNewAlleleIndexMap == null)
|
||||
throw new IllegalArgumentException("the input encoding array cannot be null");
|
||||
|
||||
final int resultAlleleCount = oldToNewAlleleIndexMap.length;
|
||||
if (resultAlleleCount > alleleCount)
|
||||
throw new IllegalArgumentException("this calculator does not have enough capacity for handling "
|
||||
+ resultAlleleCount + " alleles ");
|
||||
final int resultLength = resultAlleleCount == alleleCount
|
||||
? genotypeCount : GenotypeLikelihoodCalculators.genotypeCount(ploidy,resultAlleleCount);
|
||||
|
||||
final int[] result = new int[resultLength];
|
||||
final int[] sortedAlleleCounts = new int[Math.max(ploidy,alleleCount) << 1];
|
||||
alleleHeap.clear();
|
||||
GenotypeAlleleCounts alleleCounts = genotypeAlleleCounts[0];
|
||||
for (int i = 0; i < resultLength; i++) {
|
||||
genotypeIndexMapPerGenotypeIndex(i,alleleCounts, oldToNewAlleleIndexMap, result, sortedAlleleCounts);
|
||||
if (i < resultLength - 1)
|
||||
alleleCounts = nextGenotypeAlleleCounts(alleleCounts);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the genotype mapping per new genotype index.
|
||||
*
|
||||
* @param newGenotypeIndex the target new genotype index.
|
||||
* @param alleleCounts tha correspond to {@code newGenotypeIndex}.
|
||||
* @param oldToNewAlleleIndexMap the allele mapping.
|
||||
* @param destination where to store the new genotype index mapping to old.
|
||||
* @param sortedAlleleCountsBuffer a buffer to re-use to get the genotype-allele-count's sorted allele counts.
|
||||
*/
|
||||
private void genotypeIndexMapPerGenotypeIndex(final int newGenotypeIndex, final GenotypeAlleleCounts alleleCounts, final int[] oldToNewAlleleIndexMap, final int[] destination, final int[] sortedAlleleCountsBuffer) {
|
||||
final int distinctAlleleCount = alleleCounts.distinctAlleleCount();
|
||||
alleleCounts.copyAlleleCounts(sortedAlleleCountsBuffer,0);
|
||||
for (int j = 0, jj = 0; j < distinctAlleleCount; j++) {
|
||||
final int oldIndex = sortedAlleleCountsBuffer[jj++];
|
||||
final int repeats = sortedAlleleCountsBuffer[jj++];
|
||||
final int newIndex = oldToNewAlleleIndexMap[oldIndex];
|
||||
if (newIndex < 0 || newIndex >= alleleCount)
|
||||
throw new IllegalArgumentException("found invalid new allele index (" + newIndex + ") for old index (" + oldIndex + ")");
|
||||
for (int k = 0; k < repeats; k++)
|
||||
alleleHeap.add(newIndex);
|
||||
}
|
||||
final int genotypeIndex = alleleHeapToIndex(); // this cleans the heap for the next use.
|
||||
destination[newGenotypeIndex] = genotypeIndex;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,45 +1,45 @@
|
|||
/*
|
||||
* 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.
|
||||
* 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
|
||||
* 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.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.
|
||||
*/
|
||||
|
|
@ -407,4 +407,19 @@ public class GenotypeLikelihoodCalculators {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of possible genotypes given the ploidy and number of different alleles.
|
||||
* @param ploidy the requested ploidy.
|
||||
* @param alleleCount the requested number of alleles.
|
||||
*
|
||||
* @throws IllegalArgumentException if {@code ploidy} or {@code alleleCount} is negative.
|
||||
*
|
||||
* @return 0 or greater.
|
||||
*/
|
||||
public final static int genotypeCount(final int ploidy, final int alleleCount) {
|
||||
checkPloidyAndMaximumAllele(ploidy, alleleCount);
|
||||
if (ploidy > maximumPloidy || alleleCount > maximumAllele)
|
||||
ensureCapacity(alleleCount,ploidy);
|
||||
return alleleFirstGenotypeOffsetByPloidy[ploidy][alleleCount];
|
||||
}
|
||||
}
|
||||
|
|
@ -64,6 +64,7 @@ import org.broadinstitute.gatk.utils.variant.GATKVariantContextUtils;
|
|||
import htsjdk.variant.variantcontext.*;
|
||||
import htsjdk.variant.variantcontext.writer.VariantContextWriter;
|
||||
import htsjdk.variant.vcf.*;
|
||||
import org.broadinstitute.gatk.utils.variant.ReferenceConfidenceVariantContextMerger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -256,7 +257,7 @@ public class CombineGVCFs extends RodWalker<CombineGVCFs.PositionalState, Combin
|
|||
// we need the specialized merge if the site contains anything other than ref blocks
|
||||
final VariantContext mergedVC;
|
||||
if ( containsTrueAltAllele(stoppedVCs) )
|
||||
mergedVC = GATKVariantContextUtils.referenceConfidenceMerge(stoppedVCs, gLoc, refBase, false);
|
||||
mergedVC = ReferenceConfidenceVariantContextMerger.merge(stoppedVCs, gLoc, refBase, false);
|
||||
else
|
||||
mergedVC = referenceBlockMerge(stoppedVCs, state, pos);
|
||||
|
||||
|
|
|
|||
|
|
@ -46,16 +46,13 @@
|
|||
|
||||
package org.broadinstitute.gatk.tools.walkers.variantutils;
|
||||
|
||||
import org.broadinstitute.gatk.engine.GenomeAnalysisEngine;
|
||||
import org.broadinstitute.gatk.engine.arguments.GenotypeCalculationArgumentCollection;
|
||||
import org.broadinstitute.gatk.tools.walkers.genotyper.GenotypingEngine;
|
||||
import org.broadinstitute.gatk.tools.walkers.genotyper.IndexedSampleList;
|
||||
import org.broadinstitute.gatk.tools.walkers.genotyper.SampleList;
|
||||
import org.broadinstitute.gatk.tools.walkers.genotyper.SampleListUtils;
|
||||
import org.broadinstitute.gatk.tools.walkers.haplotypecaller.HaplotypeCaller;
|
||||
import org.broadinstitute.gatk.utils.commandline.*;
|
||||
import htsjdk.variant.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.arguments.GenotypeCalculationArgumentCollection;
|
||||
import org.broadinstitute.gatk.engine.contexts.AlignmentContext;
|
||||
import org.broadinstitute.gatk.engine.contexts.ReferenceContext;
|
||||
import org.broadinstitute.gatk.engine.refdata.RefMetaDataTracker;
|
||||
|
|
@ -65,17 +62,17 @@ import org.broadinstitute.gatk.engine.walkers.TreeReducible;
|
|||
import org.broadinstitute.gatk.engine.walkers.Window;
|
||||
import org.broadinstitute.gatk.tools.walkers.annotator.VariantAnnotatorEngine;
|
||||
import org.broadinstitute.gatk.tools.walkers.annotator.interfaces.AnnotatorCompatible;
|
||||
import org.broadinstitute.gatk.tools.walkers.genotyper.UnifiedArgumentCollection;
|
||||
import org.broadinstitute.gatk.tools.walkers.genotyper.UnifiedGenotypingEngine;
|
||||
import org.broadinstitute.gatk.tools.walkers.genotyper.*;
|
||||
import org.broadinstitute.gatk.tools.walkers.haplotypecaller.HaplotypeCaller;
|
||||
import org.broadinstitute.gatk.utils.GenomeLoc;
|
||||
import org.broadinstitute.gatk.utils.SampleUtils;
|
||||
import org.broadinstitute.gatk.utils.commandline.*;
|
||||
import org.broadinstitute.gatk.utils.exceptions.UserException;
|
||||
import org.broadinstitute.gatk.utils.help.DocumentedGATKFeature;
|
||||
import org.broadinstitute.gatk.utils.help.HelpConstants;
|
||||
import org.broadinstitute.gatk.utils.variant.GATKVCFUtils;
|
||||
import org.broadinstitute.gatk.utils.variant.GATKVariantContextUtils;
|
||||
import htsjdk.variant.variantcontext.*;
|
||||
import htsjdk.variant.variantcontext.writer.VariantContextWriter;
|
||||
import htsjdk.variant.vcf.*;
|
||||
import org.broadinstitute.gatk.utils.variant.ReferenceConfidenceVariantContextMerger;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -192,13 +189,26 @@ public class GenotypeGVCFs extends RodWalker<VariantContext, VariantContextWrite
|
|||
return null;
|
||||
|
||||
final GenomeLoc loc = ref.getLocus();
|
||||
final VariantContext combinedVC = GATKVariantContextUtils.referenceConfidenceMerge(tracker.getPrioritizedValue(variants, loc), loc, INCLUDE_NON_VARIANTS ? ref.getBase() : null, true);
|
||||
final VariantContext combinedVC = ReferenceConfidenceVariantContextMerger.merge(tracker.getPrioritizedValue(variants, loc), loc, INCLUDE_NON_VARIANTS ? ref.getBase() : null, true);
|
||||
if ( combinedVC == null )
|
||||
return null;
|
||||
|
||||
checkPloidy(combinedVC);
|
||||
|
||||
return regenotypeVC(tracker, ref, combinedVC);
|
||||
}
|
||||
|
||||
private void checkPloidy(final VariantContext combinedVC) {
|
||||
final int requiredPloidy = genotypeArgs.samplePloidy;
|
||||
for (final Genotype g : combinedVC.getGenotypes()) {
|
||||
if (g.getPloidy() != requiredPloidy) {
|
||||
throw new UserException.BadArgumentValue("ploidy",
|
||||
"the input variant data contains calls with a different ploidy than the one specified (" + requiredPloidy
|
||||
+ "). For example sample (" + g.getSampleName() + ") at (" + combinedVC.getChr() + ":" + combinedVC.getStart() + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Re-genotype (and re-annotate) a combined genomic VC
|
||||
*
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
* 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.utils.collections;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,411 @@
|
|||
/*
|
||||
* 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.utils.variant;
|
||||
|
||||
import htsjdk.variant.variantcontext.*;
|
||||
import htsjdk.variant.vcf.VCFConstants;
|
||||
import org.broadinstitute.gatk.tools.walkers.genotyper.GenotypeLikelihoodCalculators;
|
||||
import org.broadinstitute.gatk.utils.GenomeLoc;
|
||||
import org.broadinstitute.gatk.utils.MathUtils;
|
||||
import org.broadinstitute.gatk.utils.Utils;
|
||||
import org.broadinstitute.gatk.utils.collections.Pair;
|
||||
import org.broadinstitute.gatk.utils.exceptions.UserException;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Variant context utilities related to merging variant-context instances.
|
||||
*
|
||||
* @author Valentin Ruano-Rubio <valentin@broadinstitute.org>
|
||||
*/
|
||||
public class ReferenceConfidenceVariantContextMerger {
|
||||
|
||||
private static Comparable combineAnnotationValues( final List<Comparable> array ) {
|
||||
return MathUtils.median(array); // right now we take the median but other options could be explored
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges VariantContexts from gVCFs into a single hybrid.
|
||||
* Assumes that none of the input records are filtered.
|
||||
*
|
||||
* @param VCs collection of unsorted genomic VCs
|
||||
* @param loc the current location
|
||||
* @param refBase the reference allele to use if all contexts in the VC are spanning (i.e. don't start at the location in loc); if null, we'll return null in this case
|
||||
* @param removeNonRefSymbolicAllele if true, remove the <NON_REF> allele from the merged VC
|
||||
* @return new VariantContext representing the merge of all VCs or null if it not relevant
|
||||
*/
|
||||
public static VariantContext merge(final List<VariantContext> VCs, final GenomeLoc loc, final Byte refBase, final boolean removeNonRefSymbolicAllele) {
|
||||
// this can happen if e.g. you are using a dbSNP file that spans a region with no gVCFs
|
||||
if ( VCs == null || VCs.size() == 0 )
|
||||
return null;
|
||||
|
||||
// establish the baseline info (sometimes from the first VC)
|
||||
final VariantContext first = VCs.get(0);
|
||||
final String name = first.getSource();
|
||||
|
||||
// ref allele
|
||||
final Allele refAllele = determineReferenceAlleleGivenReferenceBase(VCs, loc, refBase);
|
||||
if ( refAllele == null )
|
||||
return null;
|
||||
|
||||
// FinalAlleleSet contains the alleles of the new resulting VC
|
||||
// Using linked set in order to guarantee a stable order
|
||||
final LinkedHashSet<Allele> finalAlleleSet = new LinkedHashSet<>(10);
|
||||
// Reference goes first
|
||||
finalAlleleSet.add(refAllele);
|
||||
|
||||
final Map<String, Object> attributes = new LinkedHashMap<>();
|
||||
final Set<String> rsIDs = new LinkedHashSet<>(1); // most of the time there's one id
|
||||
int depth = 0;
|
||||
final Map<String, List<Comparable>> annotationMap = new LinkedHashMap<>();
|
||||
final GenotypesContext genotypes = GenotypesContext.create();
|
||||
|
||||
final int variantContextCount = VCs.size();
|
||||
// In this list we hold the mapping of each variant context alleles.
|
||||
final List<Pair<VariantContext,List<Allele>>> vcAndNewAllelePairs = new ArrayList<>(variantContextCount);
|
||||
// cycle through and add info from the other VCs
|
||||
for ( final VariantContext vc : VCs ) {
|
||||
|
||||
// if this context doesn't start at the current location then it must be a spanning event (deletion or ref block)
|
||||
final boolean isSpanningEvent = loc.getStart() != vc.getStart();
|
||||
|
||||
vcAndNewAllelePairs.add(new Pair<>(vc,isSpanningEvent ? replaceWithNoCalls(vc.getAlleles())
|
||||
: remapAlleles(vc.getAlleles(), refAllele, finalAlleleSet)));
|
||||
}
|
||||
|
||||
// Add <NON_REF> to the end if at all required in in the output.
|
||||
if (!removeNonRefSymbolicAllele) finalAlleleSet.add(GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
|
||||
final List<Allele> allelesList = new ArrayList<>(finalAlleleSet);
|
||||
|
||||
for ( final Pair<VariantContext,List<Allele>> pair : vcAndNewAllelePairs ) {
|
||||
final VariantContext vc = pair.getFirst();
|
||||
final List<Allele> remappedAlleles = pair.getSecond();
|
||||
|
||||
mergeRefConfidenceGenotypes(genotypes, vc, remappedAlleles, allelesList);
|
||||
|
||||
// special case DP (add it up) for all events
|
||||
if ( vc.hasAttribute(VCFConstants.DEPTH_KEY) ) {
|
||||
depth += vc.getAttributeAsInt(VCFConstants.DEPTH_KEY, 0);
|
||||
} else { // handle the gVCF case from the HaplotypeCaller
|
||||
for( final Genotype gt : vc.getGenotypes() ) {
|
||||
depth += (gt.hasExtendedAttribute("MIN_DP") ? Integer.parseInt((String)gt.getAnyAttribute("MIN_DP")) : (gt.hasDP() ? gt.getDP() : 0));
|
||||
}
|
||||
}
|
||||
|
||||
if ( loc.getStart() != vc.getStart() )
|
||||
continue;
|
||||
|
||||
// special case ID (just preserve it)
|
||||
if ( vc.hasID() ) rsIDs.add(vc.getID());
|
||||
|
||||
// add attributes
|
||||
addReferenceConfidenceAttributes(vc.getAttributes(), annotationMap);
|
||||
}
|
||||
|
||||
// when combining annotations use the median value from all input VCs which had annotations provided
|
||||
for ( final Map.Entry<String, List<Comparable>> p : annotationMap.entrySet() ) {
|
||||
if ( ! p.getValue().isEmpty() ) {
|
||||
attributes.put(p.getKey(), combineAnnotationValues(p.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
if ( depth > 0 )
|
||||
attributes.put(VCFConstants.DEPTH_KEY, String.valueOf(depth));
|
||||
|
||||
// remove stale AC and AF based attributes
|
||||
removeStaleAttributesAfterMerge(attributes);
|
||||
|
||||
final String ID = rsIDs.isEmpty() ? VCFConstants.EMPTY_ID_FIELD : Utils.join(",", rsIDs);
|
||||
|
||||
final VariantContextBuilder builder = new VariantContextBuilder().source(name).id(ID).alleles(allelesList)
|
||||
.chr(loc.getContig()).start(loc.getStart()).computeEndFromAlleles(allelesList, loc.getStart(), loc.getStart())
|
||||
.genotypes(genotypes).unfiltered().attributes(new TreeMap<>(attributes)).log10PError(CommonInfo.NO_LOG10_PERROR); // we will need to re-genotype later
|
||||
|
||||
return builder.make();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the ref allele given the provided reference base at this position
|
||||
*
|
||||
* @param VCs collection of unsorted genomic VCs
|
||||
* @param loc the current location
|
||||
* @param refBase the reference allele to use if all contexts in the VC are spanning
|
||||
* @return new Allele or null if no reference allele/base is available
|
||||
*/
|
||||
private static Allele determineReferenceAlleleGivenReferenceBase(final List<VariantContext> VCs, final GenomeLoc loc, final Byte refBase) {
|
||||
final Allele refAllele = GATKVariantContextUtils.determineReferenceAllele(VCs, loc);
|
||||
if ( refAllele == null )
|
||||
return ( refBase == null ? null : Allele.create(refBase, true) );
|
||||
return refAllele;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the stale attributes from the merged set
|
||||
*
|
||||
* @param attributes the attribute map
|
||||
*/
|
||||
private static void removeStaleAttributesAfterMerge(final Map<String, Object> attributes) {
|
||||
attributes.remove(VCFConstants.ALLELE_COUNT_KEY);
|
||||
attributes.remove(VCFConstants.ALLELE_FREQUENCY_KEY);
|
||||
attributes.remove(VCFConstants.ALLELE_NUMBER_KEY);
|
||||
attributes.remove(VCFConstants.MLE_ALLELE_COUNT_KEY);
|
||||
attributes.remove(VCFConstants.MLE_ALLELE_FREQUENCY_KEY);
|
||||
attributes.remove(VCFConstants.END_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds attributes to the global map from the new context in a sophisticated manner
|
||||
*
|
||||
* @param myAttributes attributes to add from
|
||||
* @param annotationMap map of annotations for combining later
|
||||
*/
|
||||
private static void addReferenceConfidenceAttributes(final Map<String, Object> myAttributes,
|
||||
final Map<String, List<Comparable>> annotationMap) {
|
||||
for ( final Map.Entry<String, Object> p : myAttributes.entrySet() ) {
|
||||
final String key = p.getKey();
|
||||
final Object value = p.getValue();
|
||||
|
||||
// add the annotation values to a list for combining later
|
||||
List<Comparable> values = annotationMap.get(key);
|
||||
if( values == null ) {
|
||||
values = new ArrayList<>();
|
||||
annotationMap.put(key, values);
|
||||
}
|
||||
try {
|
||||
final String stringValue = value.toString();
|
||||
// Branch to avoid unintentional, implicit type conversions that occur with the ? operator.
|
||||
if (stringValue.contains("."))
|
||||
values.add(Double.parseDouble(stringValue));
|
||||
else
|
||||
values.add(Integer.parseInt(stringValue));
|
||||
} catch (final NumberFormatException e) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method does a couple of things:
|
||||
* <ul><li>
|
||||
* remaps the vc alleles considering the differences between the final reference allele and its own reference,</li>
|
||||
* <li>
|
||||
* collects alternative alleles present in variant context and add them to the {@code finalAlleles} set.
|
||||
* </li></ul>
|
||||
*
|
||||
* @param vcAlleles the variant context allele list.
|
||||
* @param refAllele final reference allele.
|
||||
* @param finalAlleles where to add the final set of non-ref called alleles.
|
||||
* @return never {@code null}
|
||||
*/
|
||||
//TODO as part of a larger refactoring effort {@link #remapAlleles} can be merged with {@link GATKVariantContextUtils#remapAlleles}.
|
||||
private static List<Allele> remapAlleles(final List<Allele> vcAlleles, final Allele refAllele, final LinkedHashSet<Allele> finalAlleles) {
|
||||
final Allele vcRef = vcAlleles.get(0);
|
||||
if (!vcRef.isReference()) throw new IllegalStateException("the first allele of the vc allele list must be reference");
|
||||
final byte[] refBases = refAllele.getBases();
|
||||
final int extraBaseCount = refBases.length - vcRef.getBases().length;
|
||||
if (extraBaseCount < 0) throw new IllegalStateException("the wrong reference was selected");
|
||||
final List<Allele> result = new ArrayList<>(vcAlleles.size());
|
||||
|
||||
for (final Allele a : vcAlleles) {
|
||||
if (a.isReference()) {
|
||||
result.add(refAllele);
|
||||
} else if (a.isSymbolic()) {
|
||||
result.add(a);
|
||||
// we always skip <NON_REF> when adding to finalAlleles this is done outside if applies.
|
||||
if (!a.equals(GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE))
|
||||
finalAlleles.add(a);
|
||||
} else if (a.isCalled()) {
|
||||
final Allele newAllele;
|
||||
if (extraBaseCount > 0) {
|
||||
final byte[] oldBases = a.getBases();
|
||||
final byte[] newBases = Arrays.copyOf(oldBases,oldBases.length + extraBaseCount);
|
||||
System.arraycopy(refBases,refBases.length - extraBaseCount,newBases,oldBases.length,extraBaseCount);
|
||||
newAllele = Allele.create(newBases,false);
|
||||
} else
|
||||
newAllele = a;
|
||||
result.add(newAllele);
|
||||
finalAlleles.add(newAllele);
|
||||
} else { // NO_CALL and strange miscellanea
|
||||
result.add(a);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces any alleles in the list with NO CALLS, except for the generic ALT allele
|
||||
*
|
||||
* @param alleles list of alleles to replace
|
||||
* @return non-null list of alleles
|
||||
*/
|
||||
private static List<Allele> replaceWithNoCalls(final List<Allele> alleles) {
|
||||
if ( alleles == null ) throw new IllegalArgumentException("list of alleles cannot be null");
|
||||
|
||||
final List<Allele> result = new ArrayList<>(alleles.size());
|
||||
for ( final Allele allele : alleles )
|
||||
result.add(allele.equals(GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE) ? allele : Allele.NO_CALL);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge into the context a new genotype represented by the given VariantContext for the provided list of target alleles.
|
||||
* This method assumes that none of the alleles in the VC overlaps with any of the alleles in the set.
|
||||
*
|
||||
* @param mergedGenotypes the genotypes context to add to
|
||||
* @param VC the Variant Context for the sample
|
||||
* @param remappedAlleles the list of remapped alleles for the sample
|
||||
* @param targetAlleles the list of target alleles
|
||||
*/
|
||||
private static void mergeRefConfidenceGenotypes(final GenotypesContext mergedGenotypes,
|
||||
final VariantContext VC,
|
||||
final List<Allele> remappedAlleles,
|
||||
final List<Allele> targetAlleles) {
|
||||
final int maximumPloidy = VC.getMaxPloidy(GATKVariantContextUtils.DEFAULT_PLOIDY);
|
||||
// the map is different depending on the ploidy, so in order to keep this method flexible (mixed ploidies)
|
||||
// we need to get a map done (lazily inside the loop) for each ploidy, up to the maximum possible.
|
||||
final int[][] genotypeIndexMapsByPloidy = new int[maximumPloidy + 1][];
|
||||
final int maximumAlleleCount = Math.max(remappedAlleles.size(),targetAlleles.size());
|
||||
final int[] indexesOfRelevantAlleles = getIndexesOfRelevantAlleles(remappedAlleles, targetAlleles, VC.getStart());
|
||||
|
||||
for ( final Genotype g : VC.getGenotypes() ) {
|
||||
final String name = g.getSampleName();
|
||||
if ( mergedGenotypes.containsSample(name) )
|
||||
continue;
|
||||
final int ploidy = g.getPloidy();
|
||||
final GenotypeBuilder genotypeBuilder = new GenotypeBuilder(g).alleles(GATKVariantContextUtils.noCallAlleles(g.getPloidy()));
|
||||
if (g.hasPL()) {
|
||||
// lazy initialization of the genotype index map by ploidy.
|
||||
final int[] genotypeIndexMapByPloidy = genotypeIndexMapsByPloidy[ploidy] == null
|
||||
? GenotypeLikelihoodCalculators.getInstance(ploidy, maximumAlleleCount).genotypeIndexMap(indexesOfRelevantAlleles)
|
||||
: genotypeIndexMapsByPloidy[ploidy];
|
||||
final int[] PLs = generatePL(g, genotypeIndexMapByPloidy);
|
||||
final int[] AD = g.hasAD() ? generateAD(g.getAD(), indexesOfRelevantAlleles) : null;
|
||||
genotypeBuilder.PL(PLs).AD(AD).noGQ();
|
||||
}
|
||||
mergedGenotypes.add(genotypeBuilder.make());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Composes a new likelihood array given the original genotype and the genotype index map.
|
||||
*
|
||||
* @param g the original genotype.
|
||||
* @param genotypeIndexMapByPloidy genotype index map. The ith element indicates what genotype in {@code g} corresponds
|
||||
* to the ith genotype in the return likelihoods array.
|
||||
*
|
||||
* @throws NullPointerException if {@code g} or {@code genotypeIndexMapByPloidy} is {@code null}, or if {@code g}
|
||||
* does not contain likelihoods.
|
||||
* @throws IndexOutOfBoundsException if {@code genotypeIndexMapByPloidy} contain non valid
|
||||
* genotype indices given the likelihood array in {@code g}.
|
||||
*
|
||||
* @return never {@code null} but an array of exactly {@code genotypeIndexMapByPloidy.length} positions.
|
||||
*/
|
||||
private static int[] generatePL(final Genotype g, final int[] genotypeIndexMapByPloidy) {
|
||||
final int[] PLs = new int[genotypeIndexMapByPloidy.length];
|
||||
final int[] oldPLs = g.getPL();
|
||||
for (int i = 0; i < PLs.length; i++)
|
||||
PLs[i] = oldPLs[genotypeIndexMapByPloidy[i]];
|
||||
return PLs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the allele mapping from myAlleles to the targetAlleles, substituting the generic "<ALT>" as appropriate.
|
||||
* If the myAlleles set does not contain "<ALT>" as an allele, it throws an exception.
|
||||
*
|
||||
* @param remappedAlleles the list of alleles to evaluate
|
||||
* @param targetAlleles the target list of alleles
|
||||
* @param position position to use for error messages
|
||||
* @return non-null array of ints representing indexes
|
||||
*/
|
||||
protected static int[] getIndexesOfRelevantAlleles(final List<Allele> remappedAlleles, final List<Allele> targetAlleles, final int position) {
|
||||
|
||||
if ( remappedAlleles == null || remappedAlleles.size() == 0 ) throw new IllegalArgumentException("The list of input alleles must not be null or empty");
|
||||
if ( targetAlleles == null || targetAlleles.size() == 0 ) throw new IllegalArgumentException("The list of target alleles must not be null or empty");
|
||||
|
||||
if ( !remappedAlleles.contains(GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE) )
|
||||
throw new UserException("The list of input alleles must contain " + GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE + " as an allele but that is not the case at position " + position + "; please use the Haplotype Caller with gVCF output to generate appropriate records");
|
||||
final int indexOfGenericAlt = remappedAlleles.indexOf(GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
|
||||
final int[] indexMapping = new int[targetAlleles.size()];
|
||||
|
||||
// the reference alleles always match up (even if they don't appear to)
|
||||
indexMapping[0] = 0;
|
||||
|
||||
// create the index mapping, using the <ALT> allele whenever such a mapping doesn't exist
|
||||
for ( int i = 1; i < targetAlleles.size(); i++ ) {
|
||||
final int indexOfRemappedAllele = remappedAlleles.indexOf(targetAlleles.get(i));
|
||||
indexMapping[i] = indexOfRemappedAllele == -1 ? indexOfGenericAlt : indexOfRemappedAllele;
|
||||
}
|
||||
|
||||
return indexMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new AD array by adding zeros for missing alleles given the set of indexes of the Genotype's current
|
||||
* alleles from the original AD.
|
||||
*
|
||||
* @param originalAD the original AD to extend
|
||||
* @param indexesOfRelevantAlleles the indexes of the original alleles corresponding to the new alleles
|
||||
* @return non-null array of new AD values
|
||||
*/
|
||||
protected static int[] generateAD(final int[] originalAD, final int[] indexesOfRelevantAlleles) {
|
||||
if ( originalAD == null || indexesOfRelevantAlleles == null ) throw new IllegalArgumentException("The list of input AD values and alleles must not be null");
|
||||
|
||||
final int numADs = indexesOfRelevantAlleles.length;
|
||||
final int[] newAD = new int[numADs];
|
||||
|
||||
for ( int i = 0; i < numADs; i++ ) {
|
||||
final int oldIndex = indexesOfRelevantAlleles[i];
|
||||
if ( oldIndex >= originalAD.length )
|
||||
newAD[i] = 0;
|
||||
else
|
||||
newAD[i] = originalAD[oldIndex];
|
||||
}
|
||||
|
||||
return newAD;
|
||||
}
|
||||
}
|
||||
|
|
@ -47,13 +47,14 @@ package org.broadinstitute.gatk.tools.walkers.genotyper;
|
|||
|
||||
import htsjdk.variant.variantcontext.Allele;
|
||||
import htsjdk.variant.variantcontext.GenotypeLikelihoods;
|
||||
import org.broadinstitute.gatk.engine.GenomeAnalysisEngine;
|
||||
import org.broadinstitute.gatk.utils.MathUtils;
|
||||
import org.broadinstitute.gatk.utils.genotyper.ReadLikelihoods;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Tests {@link org.broadinstitute.gatk.tools.walkers.genotyper.GenotypeLikelihoodCalculators} and {@link org.broadinstitute.gatk.tools.walkers.genotyper.GenotypeLikelihoodCalculator}.
|
||||
|
|
@ -118,7 +119,48 @@ public class GenotypeLikelihoodCalculatorUnitTest {
|
|||
Assert.assertEquals(genotypeLikelihoodsDoubles[i], genotypeLikelihood, 0.0001);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "ploidyAndMaximumAlleleAndNewMaximumAlleleData")
|
||||
public void testGenotypeIndexMap(final int ploidy, final int oldAlleleCount, final int newAlleleCount) {
|
||||
final Random rnd = GenomeAnalysisEngine.getRandomGenerator();
|
||||
final int maxAlleleCount = Math.max(oldAlleleCount,newAlleleCount);
|
||||
final int[] alleleMap = new int[newAlleleCount];
|
||||
final Map<Integer,Set<Integer>> reverseMap = new HashMap<>(oldAlleleCount);
|
||||
for (int i = 0; i < alleleMap.length; i++) {
|
||||
alleleMap[i] = rnd.nextInt(oldAlleleCount);
|
||||
if (reverseMap.get(alleleMap[i]) == null) reverseMap.put(alleleMap[i],new HashSet<Integer>(6));
|
||||
reverseMap.get(alleleMap[i]).add(i);
|
||||
}
|
||||
final GenotypeLikelihoodCalculator calculator = GenotypeLikelihoodCalculators.getInstance(ploidy,maxAlleleCount);
|
||||
|
||||
final int[] genotypeIndexMap = calculator.genotypeIndexMap(alleleMap);
|
||||
Assert.assertNotNull(genotypeIndexMap);
|
||||
Assert.assertEquals(genotypeIndexMap.length,GenotypeLikelihoodCalculators.genotypeCount(ploidy,newAlleleCount));
|
||||
|
||||
final GenotypeLikelihoodCalculator oldCalculator = GenotypeLikelihoodCalculators.getInstance(ploidy,oldAlleleCount);
|
||||
final GenotypeLikelihoodCalculator newCalculator = GenotypeLikelihoodCalculators.getInstance(ploidy,newAlleleCount);
|
||||
|
||||
for (int i = 0; i < genotypeIndexMap.length; i++) {
|
||||
final GenotypeAlleleCounts oldCounts = oldCalculator.genotypeAlleleCountsAt(genotypeIndexMap[i]);
|
||||
final GenotypeAlleleCounts newCounts = newCalculator.genotypeAlleleCountsAt(i);
|
||||
final int[] reverseCounts = new int[oldAlleleCount];
|
||||
for (int j = 0; j < newCounts.distinctAlleleCount(); j++) {
|
||||
final int newIndex = newCounts.alleleIndexAt(j);
|
||||
final int newRepeats = newCounts.alleleCountAt(j);
|
||||
final int expectedOldIndex = alleleMap[newIndex];
|
||||
final int oldIndexRank = oldCounts.alleleRankFor(expectedOldIndex);
|
||||
Assert.assertNotEquals(oldIndexRank, -1);
|
||||
final int oldIndex = oldCounts.alleleIndexAt(oldIndexRank);
|
||||
final int oldRepeats = oldCounts.alleleCountAt(oldIndexRank);
|
||||
Assert.assertEquals(oldIndex, expectedOldIndex);
|
||||
// not necessarily the same count if two or more new alleles map the same old allele.
|
||||
Assert.assertTrue(oldRepeats >= newRepeats);
|
||||
reverseCounts[oldIndex] += newRepeats;
|
||||
}
|
||||
for (int j = 0; j < oldAlleleCount; j++)
|
||||
Assert.assertEquals(oldCounts.alleleCountFor(j),reverseCounts[j]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -169,4 +211,14 @@ public class GenotypeLikelihoodCalculatorUnitTest {
|
|||
result[index++] = new Object[] { i, j };
|
||||
return result;
|
||||
}
|
||||
|
||||
@DataProvider(name="ploidyAndMaximumAlleleAndNewMaximumAlleleData")
|
||||
public Object[][] ploidyAndMaximumAlleleAndNewMaximumAlleleData() {
|
||||
final List<Object[]> result = new ArrayList<>(PLOIDY.length * MAXIMUM_ALLELE.length * 20);
|
||||
for (final int i : PLOIDY)
|
||||
for (final int j : MAXIMUM_ALLELE)
|
||||
for (int k = 0; k < (i < 10? j * 2 : j + 1); k++)
|
||||
result.add(new Object[] { i, j, k });
|
||||
return result.toArray(new Object[result.size()][]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,6 +87,18 @@ public class CombineGVCFsIntegrationTest extends WalkerTest {
|
|||
Assert.assertTrue(second.getGenotype("NA2").isNoCall());
|
||||
}
|
||||
|
||||
@Test(enabled = true)
|
||||
public void testTetraploidRun() {
|
||||
WalkerTestSpec spec = new WalkerTestSpec(
|
||||
baseTestString(" -V:sample1 " + privateTestDir + "tetraploid-gvcf-1.vcf" +
|
||||
" -V:sample2 " + privateTestDir + "tetraploid-gvcf-2.vcf" +
|
||||
" -V:sample3 " + privateTestDir + "tetraploid-gvcf-3.vcf" +
|
||||
" -L " + privateTestDir + "tetraploid-gvcfs.intervals"),
|
||||
1,
|
||||
Arrays.asList("41de0808e029ebefd8b28d31ce10109c"));
|
||||
executeTest("combineSingleSamplePipelineGVCF", spec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoSpansManyBlocksInOne() throws Exception {
|
||||
final String cmd = baseTestString(" -L 1:69512-69634");
|
||||
|
|
|
|||
|
|
@ -82,6 +82,18 @@ public class GenotypeGVCFsIntegrationTest extends WalkerTest {
|
|||
executeTest("combineSingleSamplePipelineGVCF", spec);
|
||||
}
|
||||
|
||||
@Test(enabled = true)
|
||||
public void testTetraploidRun() {
|
||||
WalkerTestSpec spec = new WalkerTestSpec(
|
||||
baseTestString(" -ploidy 4 -V:sample1 " + privateTestDir + "tetraploid-gvcf-1.vcf" +
|
||||
" -V:sample2 " + privateTestDir + "tetraploid-gvcf-2.vcf" +
|
||||
" -V:sample3 " + privateTestDir + "tetraploid-gvcf-3.vcf" +
|
||||
" -L " + privateTestDir + "tetraploid-gvcfs.intervals", b37KGReference),
|
||||
1,
|
||||
Arrays.asList("a2e482cddbc987b0ba004e13044f6e81"));
|
||||
executeTest("combineSingleSamplePipelineGVCF", spec);
|
||||
}
|
||||
|
||||
@Test(enabled = true)
|
||||
public void combineSingleSamplePipelineGVCF_includeNonVariants() {
|
||||
WalkerTestSpec spec = new WalkerTestSpec(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,273 @@
|
|||
/*
|
||||
* 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.utils.variant;
|
||||
|
||||
import htsjdk.variant.variantcontext.*;
|
||||
import org.broadinstitute.gatk.utils.*;
|
||||
import org.broadinstitute.gatk.utils.exceptions.UserException;
|
||||
import org.broadinstitute.gatk.utils.fasta.CachingIndexedFastaSequenceFile;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Tests {@link org.broadinstitute.gatk.utils.variant.ReferenceConfidenceVariantContextMerger}.
|
||||
*
|
||||
* @author Valentin Ruano-Rubio <valentin@broadinstitute.org>
|
||||
*/
|
||||
public class VariantContextMergerUnitTest extends BaseTest {
|
||||
Allele Aref, T, C, G, Cref, ATC, ATCATC;
|
||||
Allele ATCATCT;
|
||||
Allele ATref;
|
||||
Allele Anoref;
|
||||
Allele GT;
|
||||
|
||||
private GenomeLocParser genomeLocParser;
|
||||
|
||||
@BeforeSuite
|
||||
public void setup() throws IOException {
|
||||
// alleles
|
||||
Aref = Allele.create("A", true);
|
||||
Cref = Allele.create("C", true);
|
||||
T = Allele.create("T");
|
||||
C = Allele.create("C");
|
||||
G = Allele.create("G");
|
||||
ATC = Allele.create("ATC");
|
||||
ATCATC = Allele.create("ATCATC");
|
||||
ATCATCT = Allele.create("ATCATCT");
|
||||
ATref = Allele.create("AT",true);
|
||||
Anoref = Allele.create("A",false);
|
||||
GT = Allele.create("GT",false);
|
||||
genomeLocParser = new GenomeLocParser(new CachingIndexedFastaSequenceFile(new File(hg18Reference)));
|
||||
}
|
||||
|
||||
@Test(dataProvider = "referenceConfidenceMergeData")
|
||||
public void testReferenceConfidenceMerge(final String testID, final List<VariantContext> toMerge, final GenomeLoc loc, final boolean returnSiteEvenIfMonomorphic, final VariantContext expectedResult) {
|
||||
final VariantContext result = ReferenceConfidenceVariantContextMerger.merge(toMerge, loc, returnSiteEvenIfMonomorphic ? (byte) 'A' : null, true);
|
||||
if ( result == null ) {
|
||||
Assert.assertTrue(expectedResult == null);
|
||||
return;
|
||||
}
|
||||
Assert.assertEquals(result.getAlleles(), expectedResult.getAlleles(),testID);
|
||||
Assert.assertEquals(result.getNSamples(), expectedResult.getNSamples(),testID);
|
||||
for ( final Genotype expectedGenotype : expectedResult.getGenotypes() ) {
|
||||
Assert.assertTrue(result.hasGenotype(expectedGenotype.getSampleName()), "Missing " + expectedGenotype.getSampleName());
|
||||
// use string comparisons to test equality for now
|
||||
Assert.assertEquals(result.getGenotype(expectedGenotype.getSampleName()).toString(), expectedGenotype.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateADWithNewAlleles() {
|
||||
|
||||
final int[] originalAD = new int[] {1,2,0};
|
||||
final int[] indexesOfRelevantAlleles = new int[] {0,1,2,2};
|
||||
|
||||
final int[] newAD = ReferenceConfidenceVariantContextMerger.generateAD(originalAD, indexesOfRelevantAlleles);
|
||||
Assert.assertEquals(newAD, new int[]{1,2,0,0});
|
||||
}
|
||||
|
||||
|
||||
@Test(expectedExceptions = UserException.class)
|
||||
public void testGetIndexesOfRelevantAllelesWithNoALT() {
|
||||
|
||||
final List<Allele> alleles1 = new ArrayList<>(1);
|
||||
alleles1.add(Allele.create("A", true));
|
||||
final List<Allele> alleles2 = new ArrayList<>(1);
|
||||
alleles2.add(Allele.create("A", true));
|
||||
ReferenceConfidenceVariantContextMerger.getIndexesOfRelevantAlleles(alleles1, alleles2, -1);
|
||||
Assert.fail("We should have thrown an exception because the <ALT> allele was not present");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "getIndexesOfRelevantAllelesData")
|
||||
public void testGetIndexesOfRelevantAlleles(final int allelesIndex, final List<Allele> allAlleles) {
|
||||
final List<Allele> myAlleles = new ArrayList<>(3);
|
||||
|
||||
// always add the reference and <ALT> alleles
|
||||
myAlleles.add(allAlleles.get(0));
|
||||
myAlleles.add(GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
// optionally add another alternate allele
|
||||
if ( allelesIndex > 0 )
|
||||
myAlleles.add(allAlleles.get(allelesIndex));
|
||||
|
||||
final int[] indexes = ReferenceConfidenceVariantContextMerger.getIndexesOfRelevantAlleles(myAlleles, allAlleles, -1);
|
||||
|
||||
Assert.assertEquals(indexes.length, allAlleles.size());
|
||||
|
||||
for ( int i = 0; i < allAlleles.size(); i++ ) {
|
||||
if ( i == 0 )
|
||||
Assert.assertEquals(indexes[i], 0); // ref should always match
|
||||
else if ( i == allelesIndex )
|
||||
Assert.assertEquals(indexes[i], 2); // allele
|
||||
else
|
||||
Assert.assertEquals(indexes[i], 1); // <ALT>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@DataProvider(name = "referenceConfidenceMergeData")
|
||||
public Object[][] makeReferenceConfidenceMergeData() {
|
||||
final List<Object[]> tests = new ArrayList<>();
|
||||
final int start = 10;
|
||||
final GenomeLoc loc = new UnvalidatingGenomeLoc("20", 0, start, start);
|
||||
final VariantContext VCbase = new VariantContextBuilder("test", "20", start, start, Arrays.asList(Aref)).make();
|
||||
final VariantContext VCprevBase = new VariantContextBuilder("test", "20", start-1, start-1, Arrays.asList(Aref)).make();
|
||||
|
||||
final int[] standardPLs = new int[]{30, 20, 10, 71, 72, 73};
|
||||
final int[] reorderedSecondAllelePLs = new int[]{30, 71, 73, 20, 72, 10};
|
||||
|
||||
final List<Allele> noCalls = new ArrayList<>(2);
|
||||
noCalls.add(Allele.NO_CALL);
|
||||
noCalls.add(Allele.NO_CALL);
|
||||
|
||||
final List<Allele> A_ALT = Arrays.asList(Aref, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
final Genotype gA_ALT = new GenotypeBuilder("A").PL(new int[]{0, 100, 1000}).alleles(noCalls).make();
|
||||
final VariantContext vcA_ALT = new VariantContextBuilder(VCbase).alleles(A_ALT).genotypes(gA_ALT).make();
|
||||
final Allele AAref = Allele.create("AA", true);
|
||||
final List<Allele> AA_ALT = Arrays.asList(AAref, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
final Genotype gAA_ALT = new GenotypeBuilder("AA").PL(new int[]{0, 80, 800}).alleles(noCalls).make();
|
||||
final VariantContext vcAA_ALT = new VariantContextBuilder(VCprevBase).alleles(AA_ALT).genotypes(gAA_ALT).make();
|
||||
final List<Allele> A_C = Arrays.asList(Aref, C);
|
||||
final Genotype gA_C = new GenotypeBuilder("A_C").PL(new int[]{30, 20, 10}).alleles(noCalls).make();
|
||||
final List<Allele> A_C_ALT = Arrays.asList(Aref, C, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
final Genotype gA_C_ALT = new GenotypeBuilder("A_C").PL(standardPLs).alleles(noCalls).make();
|
||||
final VariantContext vcA_C_ALT = new VariantContextBuilder(VCbase).alleles(A_C_ALT).genotypes(gA_C_ALT).make();
|
||||
final List<Allele> A_G_ALT = Arrays.asList(Aref, G, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
final Genotype gA_G_ALT = new GenotypeBuilder("A_G").PL(standardPLs).alleles(noCalls).make();
|
||||
final VariantContext vcA_G_ALT = new VariantContextBuilder(VCbase).alleles(A_G_ALT).genotypes(gA_G_ALT).make();
|
||||
final List<Allele> A_C_G = Arrays.asList(Aref, C, G);
|
||||
final Genotype gA_C_G = new GenotypeBuilder("A_C_G").PL(new int[]{40, 20, 30, 20, 10, 30}).alleles(noCalls).make();
|
||||
final List<Allele> A_C_G_ALT = Arrays.asList(Aref, C, G, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
final Genotype gA_C_G_ALT = new GenotypeBuilder("A_C_G").PL(new int[]{40, 20, 30, 20, 10, 30, 71, 72, 73, 74}).alleles(noCalls).make();
|
||||
final VariantContext vcA_C_G_ALT = new VariantContextBuilder(VCbase).alleles(A_C_G_ALT).genotypes(gA_C_G_ALT).make();
|
||||
final List<Allele> A_ATC_ALT = Arrays.asList(Aref, ATC, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
final Genotype gA_ATC_ALT = new GenotypeBuilder("A_ATC").PL(standardPLs).alleles(noCalls).make();
|
||||
final VariantContext vcA_ATC_ALT = new VariantContextBuilder(VCbase).alleles(A_ATC_ALT).genotypes(gA_ATC_ALT).make();
|
||||
final Allele A = Allele.create("A", false);
|
||||
final List<Allele> AA_A_ALT = Arrays.asList(AAref, A, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
final Genotype gAA_A_ALT = new GenotypeBuilder("AA_A").PL(standardPLs).alleles(noCalls).make();
|
||||
final VariantContext vcAA_A_ALT = new VariantContextBuilder(VCprevBase).alleles(AA_A_ALT).genotypes(gAA_A_ALT).make();
|
||||
|
||||
// first test the case of a single record
|
||||
tests.add(new Object[]{"test00",Arrays.asList(vcA_C_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(A_C).genotypes(gA_C).make()});
|
||||
|
||||
// now, test pairs:
|
||||
// a SNP with another SNP
|
||||
tests.add(new Object[]{"test01",Arrays.asList(vcA_C_ALT, vcA_G_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(A_C_G).genotypes(gA_C_ALT, new GenotypeBuilder("A_G").PL(reorderedSecondAllelePLs).alleles(noCalls).make()).make()});
|
||||
// a SNP with an indel
|
||||
tests.add(new Object[]{"test02",Arrays.asList(vcA_C_ALT, vcA_ATC_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(Arrays.asList(Aref, C, ATC)).genotypes(gA_C_ALT, new GenotypeBuilder("A_ATC").PL(reorderedSecondAllelePLs).alleles(noCalls).make()).make()});
|
||||
// a SNP with 2 SNPs
|
||||
tests.add(new Object[]{"test03",Arrays.asList(vcA_C_ALT, vcA_C_G_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(A_C_G).genotypes(gA_C_ALT, gA_C_G).make()});
|
||||
// a SNP with a ref record
|
||||
tests.add(new Object[]{"test04",Arrays.asList(vcA_C_ALT, vcA_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(A_C).genotypes(gA_C, gA_ALT).make()});
|
||||
|
||||
// spanning records:
|
||||
// a SNP with a spanning ref record
|
||||
tests.add(new Object[]{"test05",Arrays.asList(vcA_C_ALT, vcAA_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(A_C).genotypes(gA_C, gAA_ALT).make()});
|
||||
// a SNP with a spanning deletion
|
||||
tests.add(new Object[]{"test06",Arrays.asList(vcA_C_ALT, vcAA_A_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(A_C).genotypes(gA_C, new GenotypeBuilder("AA_A").PL(new int[]{30, 71, 73}).alleles(noCalls).make()).make()});
|
||||
|
||||
// combination of all
|
||||
tests.add(new Object[]{"test07",Arrays.asList(vcA_C_ALT, vcA_G_ALT, vcA_ATC_ALT, vcA_C_G_ALT, vcA_ALT, vcAA_ALT, vcAA_A_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(Arrays.asList(Aref, C, G, ATC)).genotypes(new GenotypeBuilder("A_C").PL(new int[]{30, 20, 10, 71, 72, 73, 71, 72, 73, 73}).alleles(noCalls).make(),
|
||||
new GenotypeBuilder("A_G").PL(new int[]{30, 71, 73, 20, 72, 10, 71, 73, 72, 73}).alleles(noCalls).make(),
|
||||
new GenotypeBuilder("A_ATC").PL(new int[]{30, 71, 73, 71, 73, 73, 20, 72, 72, 10}).alleles(noCalls).make(),
|
||||
new GenotypeBuilder("A_C_G").PL(new int[]{40,20,30,20,10,30,71,72,73,74}).alleles(noCalls).make(),
|
||||
new GenotypeBuilder("A").PL(new int[]{0, 100, 1000, 100, 1000, 1000, 100, 1000, 1000, 1000}).alleles(noCalls).make(),
|
||||
new GenotypeBuilder("AA").PL(new int[]{0, 80, 800, 80, 800, 800, 80, 800, 800, 800}).alleles(noCalls).make(),
|
||||
new GenotypeBuilder("AA_A").PL(new int[]{30, 71, 73, 71, 73, 73, 71, 73, 73, 73}).alleles(noCalls).make()).make()});
|
||||
|
||||
// just spanning ref contexts, trying both instances where we want/do not want ref-only contexts
|
||||
tests.add(new Object[]{"test08",Arrays.asList(vcAA_ALT),
|
||||
|
||||
loc, false,
|
||||
null});
|
||||
tests.add(new Object[]{"test09", Arrays.asList(vcAA_ALT),
|
||||
loc, true,
|
||||
new VariantContextBuilder(VCbase).alleles(Arrays.asList(Allele.create("A", true))).genotypes(new GenotypeBuilder("AA").PL(new int[]{0}).alleles(noCalls).make()).make()});
|
||||
|
||||
final Object[][] result = tests.toArray(new Object[][]{});
|
||||
return result;
|
||||
}
|
||||
@DataProvider(name = "getIndexesOfRelevantAllelesData")
|
||||
public Object[][] makeGetIndexesOfRelevantAllelesData() {
|
||||
final int totalAlleles = 5;
|
||||
final List<Allele> alleles = new ArrayList<>(totalAlleles);
|
||||
alleles.add(Allele.create("A", true));
|
||||
for ( int i = 1; i < totalAlleles; i++ )
|
||||
alleles.add(Allele.create(Utils.dupString('A', i + 1), false));
|
||||
|
||||
final List<Object[]> tests = new ArrayList<>();
|
||||
|
||||
for ( int alleleIndex = 0; alleleIndex < totalAlleles; alleleIndex++ ) {
|
||||
tests.add(new Object[]{alleleIndex, alleles});
|
||||
}
|
||||
|
||||
return tests.toArray(new Object[][]{});
|
||||
}
|
||||
}
|
||||
|
|
@ -27,15 +27,14 @@ package org.broadinstitute.gatk.utils.variant;
|
|||
|
||||
import com.google.java.contract.Ensures;
|
||||
import com.google.java.contract.Requires;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import htsjdk.tribble.TribbleException;
|
||||
import htsjdk.tribble.util.popgen.HardyWeinbergCalculation;
|
||||
import org.broadinstitute.gatk.utils.*;
|
||||
import org.broadinstitute.gatk.utils.collections.Pair;
|
||||
import org.broadinstitute.gatk.utils.exceptions.UserException;
|
||||
import htsjdk.variant.variantcontext.*;
|
||||
import htsjdk.variant.vcf.VCFConstants;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.broadinstitute.gatk.utils.*;
|
||||
import org.broadinstitute.gatk.utils.collections.Pair;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
|
@ -103,6 +102,47 @@ public class GATKVariantContextUtils {
|
|||
return Collections.nCopies(ploidy,allele);
|
||||
}
|
||||
|
||||
private static boolean hasPLIncompatibleAlleles(final Collection<Allele> alleleSet1, final Collection<Allele> alleleSet2) {
|
||||
final Iterator<Allele> it1 = alleleSet1.iterator();
|
||||
final Iterator<Allele> it2 = alleleSet2.iterator();
|
||||
|
||||
while ( it1.hasNext() && it2.hasNext() ) {
|
||||
final Allele a1 = it1.next();
|
||||
final Allele a2 = it2.next();
|
||||
if ( ! a1.equals(a2) )
|
||||
return true;
|
||||
}
|
||||
|
||||
// by this point, at least one of the iterators is empty. All of the elements
|
||||
// we've compared are equal up until this point. But it's possible that the
|
||||
// sets aren't the same size, which is indicated by the test below. If they
|
||||
// are of the same size, though, the sets are compatible
|
||||
return it1.hasNext() || it2.hasNext();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the common reference allele
|
||||
*
|
||||
* @param VCs the list of VariantContexts
|
||||
* @param loc if not null, ignore records that do not begin at this start location
|
||||
* @return possibly null Allele
|
||||
*/
|
||||
protected static Allele determineReferenceAllele(final List<VariantContext> VCs, final GenomeLoc loc) {
|
||||
Allele ref = null;
|
||||
|
||||
for ( final VariantContext vc : VCs ) {
|
||||
if ( contextMatchesLoc(vc, loc) ) {
|
||||
final Allele myRef = vc.getReference();
|
||||
if ( ref == null || ref.length() < myRef.length() )
|
||||
ref = myRef;
|
||||
else if ( ref.length() == myRef.length() && ! ref.equals(myRef) )
|
||||
throw new TribbleException(String.format("The provided variant file(s) have inconsistent references for the same position(s) at %s:%d, %s vs. %s", vc.getChr(), vc.getStart(), ref, myRef));
|
||||
}
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
public enum GenotypeMergeType {
|
||||
/**
|
||||
* Make all sample genotypes unique by file. Each sample shared across RODs gets named sample.ROD.
|
||||
|
|
@ -1077,235 +1117,7 @@ public class GATKVariantContextUtils {
|
|||
return merged;
|
||||
}
|
||||
|
||||
private static Comparable combineAnnotationValues( final List<Comparable> array ) {
|
||||
return MathUtils.median(array); // right now we take the median but other options could be explored
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges VariantContexts from gVCFs into a single hybrid.
|
||||
* Assumes that none of the input records are filtered.
|
||||
*
|
||||
* @param VCs collection of unsorted genomic VCs
|
||||
* @param loc the current location
|
||||
* @param refBase the reference allele to use if all contexts in the VC are spanning (i.e. don't start at the location in loc); if null, we'll return null in this case
|
||||
* @param removeNonRefSymbolicAllele if true, remove the <NON_REF> allele from the merged VC
|
||||
* @return new VariantContext representing the merge of all VCs or null if it not relevant
|
||||
*/
|
||||
public static VariantContext referenceConfidenceMerge(final List<VariantContext> VCs, final GenomeLoc loc, final Byte refBase, final boolean removeNonRefSymbolicAllele) {
|
||||
// this can happen if e.g. you are using a dbSNP file that spans a region with no gVCFs
|
||||
if ( VCs == null || VCs.size() == 0 )
|
||||
return null;
|
||||
|
||||
// establish the baseline info (sometimes from the first VC)
|
||||
final VariantContext first = VCs.get(0);
|
||||
final String name = first.getSource();
|
||||
|
||||
// ref allele
|
||||
final Allele refAllele = determineReferenceAlleleGivenReferenceBase(VCs, loc, refBase);
|
||||
if ( refAllele == null )
|
||||
return null;
|
||||
|
||||
// FinalAlleleSet contains the alleles of the new resulting VC
|
||||
// Using linked set in order to guarantee a stable order
|
||||
final LinkedHashSet<Allele> finalAlleleSet = new LinkedHashSet<>(10);
|
||||
// Reference goes first
|
||||
finalAlleleSet.add(refAllele);
|
||||
|
||||
final Map<String, Object> attributes = new LinkedHashMap<>();
|
||||
final Set<String> rsIDs = new LinkedHashSet<>(1); // most of the time there's one id
|
||||
int depth = 0;
|
||||
final Map<String, List<Comparable>> annotationMap = new LinkedHashMap<>();
|
||||
final GenotypesContext genotypes = GenotypesContext.create();
|
||||
|
||||
final int variantContextCount = VCs.size();
|
||||
// In this list we hold the mapping of each variant context alleles.
|
||||
final List<Pair<VariantContext,List<Allele>>> vcAndNewAllelePairs = new ArrayList<>(variantContextCount);
|
||||
// cycle through and add info from the other VCs
|
||||
for ( final VariantContext vc : VCs ) {
|
||||
|
||||
// if this context doesn't start at the current location then it must be a spanning event (deletion or ref block)
|
||||
final boolean isSpanningEvent = loc.getStart() != vc.getStart();
|
||||
|
||||
vcAndNewAllelePairs.add(new Pair<>(vc,isSpanningEvent ? replaceWithNoCalls(vc.getAlleles())
|
||||
: remapAlleles(vc.getAlleles(), refAllele, finalAlleleSet)));
|
||||
}
|
||||
|
||||
// Add <NON_REF> to the end if at all required in in the output.
|
||||
if (!removeNonRefSymbolicAllele) finalAlleleSet.add(NON_REF_SYMBOLIC_ALLELE);
|
||||
|
||||
final List<Allele> allelesList = new ArrayList<>(finalAlleleSet);
|
||||
|
||||
for ( final Pair<VariantContext,List<Allele>> pair : vcAndNewAllelePairs ) {
|
||||
final VariantContext vc = pair.getFirst();
|
||||
final List<Allele> remappedAlleles = pair.getSecond();
|
||||
|
||||
mergeRefConfidenceGenotypes(genotypes, vc, remappedAlleles, allelesList);
|
||||
|
||||
// special case DP (add it up) for all events
|
||||
if ( vc.hasAttribute(VCFConstants.DEPTH_KEY) ) {
|
||||
depth += vc.getAttributeAsInt(VCFConstants.DEPTH_KEY, 0);
|
||||
} else { // handle the gVCF case from the HaplotypeCaller
|
||||
for( final Genotype gt : vc.getGenotypes() ) {
|
||||
depth += (gt.hasExtendedAttribute("MIN_DP") ? Integer.parseInt((String)gt.getAnyAttribute("MIN_DP")) : (gt.hasDP() ? gt.getDP() : 0));
|
||||
}
|
||||
}
|
||||
|
||||
if ( loc.getStart() != vc.getStart() )
|
||||
continue;
|
||||
|
||||
// special case ID (just preserve it)
|
||||
if ( vc.hasID() ) rsIDs.add(vc.getID());
|
||||
|
||||
// add attributes
|
||||
addReferenceConfidenceAttributes(vc.getAttributes(), annotationMap);
|
||||
}
|
||||
|
||||
// when combining annotations use the median value from all input VCs which had annotations provided
|
||||
for ( final Map.Entry<String, List<Comparable>> p : annotationMap.entrySet() ) {
|
||||
if ( ! p.getValue().isEmpty() ) {
|
||||
attributes.put(p.getKey(), combineAnnotationValues(p.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
if ( depth > 0 )
|
||||
attributes.put(VCFConstants.DEPTH_KEY, String.valueOf(depth));
|
||||
|
||||
// remove stale AC and AF based attributes
|
||||
removeStaleAttributesAfterMerge(attributes);
|
||||
|
||||
final String ID = rsIDs.isEmpty() ? VCFConstants.EMPTY_ID_FIELD : Utils.join(",", rsIDs);
|
||||
|
||||
final VariantContextBuilder builder = new VariantContextBuilder().source(name).id(ID).alleles(allelesList)
|
||||
.chr(loc.getContig()).start(loc.getStart()).computeEndFromAlleles(allelesList, loc.getStart(), loc.getStart())
|
||||
.genotypes(genotypes).unfiltered().attributes(new TreeMap<>(attributes)).log10PError(CommonInfo.NO_LOG10_PERROR); // we will need to re-genotype later
|
||||
|
||||
return builder.make();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the ref allele given the provided reference base at this position
|
||||
*
|
||||
* @param VCs collection of unsorted genomic VCs
|
||||
* @param loc the current location
|
||||
* @param refBase the reference allele to use if all contexts in the VC are spanning
|
||||
* @return new Allele or null if no reference allele/base is available
|
||||
*/
|
||||
private static Allele determineReferenceAlleleGivenReferenceBase(final List<VariantContext> VCs, final GenomeLoc loc, final Byte refBase) {
|
||||
final Allele refAllele = determineReferenceAllele(VCs, loc);
|
||||
if ( refAllele == null )
|
||||
return ( refBase == null ? null : Allele.create(refBase, true) );
|
||||
return refAllele;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the stale attributes from the merged set
|
||||
*
|
||||
* @param attributes the attribute map
|
||||
*/
|
||||
private static void removeStaleAttributesAfterMerge(final Map<String, Object> attributes) {
|
||||
attributes.remove(VCFConstants.ALLELE_COUNT_KEY);
|
||||
attributes.remove(VCFConstants.ALLELE_FREQUENCY_KEY);
|
||||
attributes.remove(VCFConstants.ALLELE_NUMBER_KEY);
|
||||
attributes.remove(VCFConstants.MLE_ALLELE_COUNT_KEY);
|
||||
attributes.remove(VCFConstants.MLE_ALLELE_FREQUENCY_KEY);
|
||||
attributes.remove(VCFConstants.END_KEY);
|
||||
}
|
||||
/**
|
||||
* Adds attributes to the global map from the new context in a sophisticated manner
|
||||
*
|
||||
* @param myAttributes attributes to add from
|
||||
* @param annotationMap map of annotations for combining later
|
||||
*/
|
||||
private static void addReferenceConfidenceAttributes(final Map<String, Object> myAttributes,
|
||||
final Map<String, List<Comparable>> annotationMap) {
|
||||
for ( final Map.Entry<String, Object> p : myAttributes.entrySet() ) {
|
||||
final String key = p.getKey();
|
||||
final Object value = p.getValue();
|
||||
|
||||
// add the annotation values to a list for combining later
|
||||
List<Comparable> values = annotationMap.get(key);
|
||||
if( values == null ) {
|
||||
values = new ArrayList<>();
|
||||
annotationMap.put(key, values);
|
||||
}
|
||||
try {
|
||||
final String stringValue = value.toString();
|
||||
// Branch to avoid unintentional, implicit type conversions that occur with the ? operator.
|
||||
if (stringValue.contains("."))
|
||||
values.add(Double.parseDouble(stringValue));
|
||||
else
|
||||
values.add(Integer.parseInt(stringValue));
|
||||
} catch (final NumberFormatException e) {
|
||||
// nothing to do
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasPLIncompatibleAlleles(final Collection<Allele> alleleSet1, final Collection<Allele> alleleSet2) {
|
||||
final Iterator<Allele> it1 = alleleSet1.iterator();
|
||||
final Iterator<Allele> it2 = alleleSet2.iterator();
|
||||
|
||||
while ( it1.hasNext() && it2.hasNext() ) {
|
||||
final Allele a1 = it1.next();
|
||||
final Allele a2 = it2.next();
|
||||
if ( ! a1.equals(a2) )
|
||||
return true;
|
||||
}
|
||||
|
||||
// by this point, at least one of the iterators is empty. All of the elements
|
||||
// we've compared are equal up until this point. But it's possible that the
|
||||
// sets aren't the same size, which is indicated by the test below. If they
|
||||
// are of the same size, though, the sets are compatible
|
||||
return it1.hasNext() || it2.hasNext();
|
||||
}
|
||||
|
||||
//TODO as part of a larger refactoring effort remapAlleles can be merged with createAlleleMapping.
|
||||
/**
|
||||
* This method does a couple of things:
|
||||
* <ul><li>
|
||||
* remaps the vc alleles considering the differences between the final reference allele and its own reference,</li>
|
||||
* <li>
|
||||
* collects alternative alleles present in variant context and add them to the {@code finalAlleles} set.
|
||||
* </li></ul>
|
||||
*
|
||||
* @param vcAlleles the variant context allele list.
|
||||
* @param refAllele final reference allele.
|
||||
* @param finalAlleles where to add the final set of non-ref called alleles.
|
||||
* @return never {@code null}
|
||||
*/
|
||||
private static List<Allele> remapAlleles(final List<Allele> vcAlleles, final Allele refAllele, final LinkedHashSet<Allele> finalAlleles) {
|
||||
final Allele vcRef = vcAlleles.get(0);
|
||||
if (!vcRef.isReference()) throw new IllegalStateException("the first allele of the vc allele list must be reference");
|
||||
final byte[] refBases = refAllele.getBases();
|
||||
final int extraBaseCount = refBases.length - vcRef.getBases().length;
|
||||
if (extraBaseCount < 0) throw new IllegalStateException("the wrong reference was selected");
|
||||
final List<Allele> result = new ArrayList<>(vcAlleles.size());
|
||||
|
||||
for (final Allele a : vcAlleles) {
|
||||
if (a.isReference()) {
|
||||
result.add(refAllele);
|
||||
} else if (a.isSymbolic()) {
|
||||
result.add(a);
|
||||
// we always skip <NON_REF> when adding to finalAlleles this is done outside if applies.
|
||||
if (!a.equals(NON_REF_SYMBOLIC_ALLELE))
|
||||
finalAlleles.add(a);
|
||||
} else if (a.isCalled()) {
|
||||
final Allele newAllele;
|
||||
if (extraBaseCount > 0) {
|
||||
final byte[] oldBases = a.getBases();
|
||||
final byte[] newBases = Arrays.copyOf(oldBases,oldBases.length + extraBaseCount);
|
||||
System.arraycopy(refBases,refBases.length - extraBaseCount,newBases,oldBases.length,extraBaseCount);
|
||||
newAllele = Allele.create(newBases,false);
|
||||
} else
|
||||
newAllele = a;
|
||||
result.add(newAllele);
|
||||
finalAlleles.add(newAllele);
|
||||
} else { // NO_CALL and strange miscellanea
|
||||
result.add(a);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static GenotypesContext stripPLsAndAD(final GenotypesContext genotypes) {
|
||||
final GenotypesContext newGs = GenotypesContext.create(genotypes.size());
|
||||
|
|
@ -1417,33 +1229,10 @@ public class GATKVariantContextUtils {
|
|||
return builder.make();
|
||||
}
|
||||
|
||||
static private Allele determineReferenceAllele(final List<VariantContext> VCs) {
|
||||
private static Allele determineReferenceAllele(final List<VariantContext> VCs) {
|
||||
return determineReferenceAllele(VCs, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the common reference allele
|
||||
*
|
||||
* @param VCs the list of VariantContexts
|
||||
* @param loc if not null, ignore records that do not begin at this start location
|
||||
* @return possibly null Allele
|
||||
*/
|
||||
static private Allele determineReferenceAllele(final List<VariantContext> VCs, final GenomeLoc loc) {
|
||||
Allele ref = null;
|
||||
|
||||
for ( final VariantContext vc : VCs ) {
|
||||
if ( contextMatchesLoc(vc, loc) ) {
|
||||
final Allele myRef = vc.getReference();
|
||||
if ( ref == null || ref.length() < myRef.length() )
|
||||
ref = myRef;
|
||||
else if ( ref.length() == myRef.length() && ! ref.equals(myRef) )
|
||||
throw new TribbleException(String.format("The provided variant file(s) have inconsistent references for the same position(s) at %s:%d, %s vs. %s", vc.getChr(), vc.getStart(), ref, myRef));
|
||||
}
|
||||
}
|
||||
|
||||
return ref;
|
||||
}
|
||||
|
||||
public static boolean contextMatchesLoc(final VariantContext vc, final GenomeLoc loc) {
|
||||
return loc == null || loc.getStart() == vc.getStart();
|
||||
}
|
||||
|
|
@ -1458,6 +1247,7 @@ public class GATKVariantContextUtils {
|
|||
}
|
||||
}
|
||||
|
||||
//TODO as part of a larger refactoring effort {@link #createAlleleMapping} can be merged with {@link ReferenceConfidenceVariantContextMerger#remapAlleles}.
|
||||
/**
|
||||
* Create an allele mapping for the given context where its reference allele must (potentially) be extended to the given allele
|
||||
*
|
||||
|
|
@ -1532,51 +1322,6 @@ public class GATKVariantContextUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces any alleles in the list with NO CALLS, except for the generic ALT allele
|
||||
*
|
||||
* @param alleles list of alleles to replace
|
||||
* @return non-null list of alleles
|
||||
*/
|
||||
private static List<Allele> replaceWithNoCalls(final List<Allele> alleles) {
|
||||
if ( alleles == null ) throw new IllegalArgumentException("list of alleles cannot be null");
|
||||
|
||||
final List<Allele> result = new ArrayList<>(alleles.size());
|
||||
for ( final Allele allele : alleles )
|
||||
result.add(allele.equals(NON_REF_SYMBOLIC_ALLELE) ? allele : Allele.NO_CALL);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge into the context a new genotype represented by the given VariantContext for the provided list of target alleles.
|
||||
* This method assumes that none of the alleles in the VC overlaps with any of the alleles in the set.
|
||||
*
|
||||
* @param mergedGenotypes the genotypes context to add to
|
||||
* @param VC the Variant Context for the sample
|
||||
* @param remappedAlleles the list of remapped alleles for the sample
|
||||
* @param targetAlleles the list of target alleles
|
||||
*/
|
||||
private static void mergeRefConfidenceGenotypes(final GenotypesContext mergedGenotypes,
|
||||
final VariantContext VC,
|
||||
final List<Allele> remappedAlleles,
|
||||
final List<Allele> targetAlleles) {
|
||||
for ( final Genotype g : VC.getGenotypes() ) {
|
||||
// only add if the name is new
|
||||
final String name = g.getSampleName();
|
||||
if ( !mergedGenotypes.containsSample(name) ) {
|
||||
final GenotypeBuilder genotypeBuilder = new GenotypeBuilder(g).alleles(noCallAlleles(g.getPloidy()));
|
||||
if (g.hasPL()) {
|
||||
// we need to modify it even if it already contains all of the alleles because we need to purge the <ALT> PLs out anyways
|
||||
final int[] indexesOfRelevantAlleles = getIndexesOfRelevantAlleles(remappedAlleles, targetAlleles, VC.getStart());
|
||||
final int[] PLs = generatePLs(g, indexesOfRelevantAlleles);
|
||||
final int[] AD = g.hasAD() ? generateAD(g.getAD(), indexesOfRelevantAlleles) : null;
|
||||
genotypeBuilder.PL(PLs).AD(AD).noGQ();
|
||||
}
|
||||
mergedGenotypes.add(genotypeBuilder.make());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link Allele#NO_CALL NO_CALL} allele list provided the ploidy.
|
||||
*
|
||||
|
|
@ -1598,94 +1343,6 @@ public class GATKVariantContextUtils {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the allele mapping from myAlleles to the targetAlleles, substituting the generic "<ALT>" as appropriate.
|
||||
* If the myAlleles set does not contain "<ALT>" as an allele, it throws an exception.
|
||||
*
|
||||
* @param remappedAlleles the list of alleles to evaluate
|
||||
* @param targetAlleles the target list of alleles
|
||||
* @param position position to use for error messages
|
||||
* @return non-null array of ints representing indexes
|
||||
*/
|
||||
protected static int[] getIndexesOfRelevantAlleles(final List<Allele> remappedAlleles, final List<Allele> targetAlleles, final int position) {
|
||||
|
||||
if ( remappedAlleles == null || remappedAlleles.size() == 0 ) throw new IllegalArgumentException("The list of input alleles must not be null or empty");
|
||||
if ( targetAlleles == null || targetAlleles.size() == 0 ) throw new IllegalArgumentException("The list of target alleles must not be null or empty");
|
||||
|
||||
if ( !remappedAlleles.contains(NON_REF_SYMBOLIC_ALLELE) )
|
||||
throw new UserException("The list of input alleles must contain " + NON_REF_SYMBOLIC_ALLELE + " as an allele but that is not the case at position " + position + "; please use the Haplotype Caller with gVCF output to generate appropriate records");
|
||||
final int indexOfGenericAlt = remappedAlleles.indexOf(NON_REF_SYMBOLIC_ALLELE);
|
||||
|
||||
final int[] indexMapping = new int[targetAlleles.size()];
|
||||
|
||||
// the reference alleles always match up (even if they don't appear to)
|
||||
indexMapping[0] = 0;
|
||||
|
||||
// create the index mapping, using the <ALT> allele whenever such a mapping doesn't exist
|
||||
for ( int i = 1; i < targetAlleles.size(); i++ ) {
|
||||
final int indexOfRemappedAllele = remappedAlleles.indexOf(targetAlleles.get(i));
|
||||
indexMapping[i] = indexOfRemappedAllele == -1 ? indexOfGenericAlt : indexOfRemappedAllele;
|
||||
}
|
||||
|
||||
return indexMapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates new PLs given the set of indexes of the Genotype's current alleles from the original PLs.
|
||||
* Throws an exception if the Genotype does not contain PLs.
|
||||
*
|
||||
* @param genotype the genotype from which to grab PLs
|
||||
* @param indexesOfRelevantAlleles the indexes of the original alleles corresponding to the new alleles
|
||||
* @return non-null array of new PLs
|
||||
*/
|
||||
protected static int[] generatePLs(final Genotype genotype, final int[] indexesOfRelevantAlleles) {
|
||||
if ( !genotype.hasPL() )
|
||||
throw new IllegalArgumentException("Cannot generate new PLs from a genotype without PLs");
|
||||
|
||||
final int[] originalPLs = genotype.getPL();
|
||||
|
||||
// assume diploid
|
||||
final int numLikelihoods = GenotypeLikelihoods.numLikelihoods(indexesOfRelevantAlleles.length, 2);
|
||||
final int[] newPLs = new int[numLikelihoods];
|
||||
|
||||
for ( int i = 0; i < indexesOfRelevantAlleles.length; i++ ) {
|
||||
for ( int j = i; j < indexesOfRelevantAlleles.length; j++ ) {
|
||||
final int originalPLindex = calculatePLindexFromUnorderedIndexes(indexesOfRelevantAlleles[i], indexesOfRelevantAlleles[j]);
|
||||
if ( originalPLindex >= originalPLs.length )
|
||||
throw new IllegalStateException("The original PLs do not have enough values; accessing index " + originalPLindex + " but size is " + originalPLs.length);
|
||||
|
||||
final int newPLindex = GenotypeLikelihoods.calculatePLindex(i, j);
|
||||
newPLs[newPLindex] = originalPLs[originalPLindex];
|
||||
}
|
||||
}
|
||||
|
||||
return newPLs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new AD array by adding zeros for missing alleles given the set of indexes of the Genotype's current
|
||||
* alleles from the original AD.
|
||||
*
|
||||
* @param originalAD the original AD to extend
|
||||
* @param indexesOfRelevantAlleles the indexes of the original alleles corresponding to the new alleles
|
||||
* @return non-null array of new AD values
|
||||
*/
|
||||
protected static int[] generateAD(final int[] originalAD, final int[] indexesOfRelevantAlleles) {
|
||||
if ( originalAD == null || indexesOfRelevantAlleles == null ) throw new IllegalArgumentException("The list of input AD values and alleles must not be null");
|
||||
|
||||
final int numADs = indexesOfRelevantAlleles.length;
|
||||
final int[] newAD = new int[numADs];
|
||||
|
||||
for ( int i = 0; i < numADs; i++ ) {
|
||||
final int oldIndex = indexesOfRelevantAlleles[i];
|
||||
if ( oldIndex >= originalAD.length )
|
||||
newAD[i] = 0;
|
||||
else
|
||||
newAD[i] = originalAD[oldIndex];
|
||||
}
|
||||
|
||||
return newAD;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is just a safe wrapper around GenotypeLikelihoods.calculatePLindex()
|
||||
|
|
|
|||
|
|
@ -25,13 +25,11 @@
|
|||
|
||||
package org.broadinstitute.gatk.utils.variant;
|
||||
|
||||
import org.broadinstitute.gatk.utils.BaseTest;
|
||||
import htsjdk.variant.variantcontext.*;
|
||||
import org.broadinstitute.gatk.engine.GenomeAnalysisEngine;
|
||||
import org.broadinstitute.gatk.utils.*;
|
||||
import org.broadinstitute.gatk.utils.collections.Pair;
|
||||
import org.broadinstitute.gatk.utils.exceptions.UserException;
|
||||
import org.broadinstitute.gatk.utils.fasta.CachingIndexedFastaSequenceFile;
|
||||
import htsjdk.variant.variantcontext.*;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.DataProvider;
|
||||
|
|
@ -1511,239 +1509,6 @@ public class GATKVariantContextUtilsUnitTest extends BaseTest {
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
@Test(dataProvider = "generatePLsData")
|
||||
public void testGeneratePLs(final int numOriginalAlleles, final int[] indexOrdering) {
|
||||
|
||||
final int numLikelihoods = GenotypeLikelihoods.numLikelihoods(numOriginalAlleles, 2);
|
||||
final int[] PLs = new int[numLikelihoods];
|
||||
for ( int i = 0; i < numLikelihoods; i++ )
|
||||
PLs[i] = i;
|
||||
|
||||
final List<Allele> alleles = new ArrayList<>(numOriginalAlleles);
|
||||
alleles.add(Allele.create("A", true));
|
||||
for ( int i = 1; i < numOriginalAlleles; i++ )
|
||||
alleles.add(Allele.create(Utils.dupString('A', i + 1), false));
|
||||
final Genotype genotype = new GenotypeBuilder("foo", alleles).PL(PLs).make();
|
||||
|
||||
final int[] newPLs = GATKVariantContextUtils.generatePLs(genotype, indexOrdering);
|
||||
|
||||
Assert.assertEquals(newPLs.length, numLikelihoods);
|
||||
|
||||
final int[] expectedPLs = new int[numLikelihoods];
|
||||
for ( int i = 0; i < numOriginalAlleles; i++ ) {
|
||||
for ( int j = i; j < numOriginalAlleles; j++ ) {
|
||||
final int index = GenotypeLikelihoods.calculatePLindex(i, j);
|
||||
final int value = GATKVariantContextUtils.calculatePLindexFromUnorderedIndexes(indexOrdering[i], indexOrdering[j]);
|
||||
expectedPLs[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
for ( int i = 0; i < numLikelihoods; i++ ) {
|
||||
Assert.assertEquals(newPLs[i], expectedPLs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dataProvider = "referenceConfidenceMergeData")
|
||||
public void testReferenceConfidenceMerge(final String testID, final List<VariantContext> toMerge, final GenomeLoc loc, final boolean returnSiteEvenIfMonomorphic, final VariantContext expectedResult) {
|
||||
final VariantContext result = GATKVariantContextUtils.referenceConfidenceMerge(toMerge, loc, returnSiteEvenIfMonomorphic ? (byte) 'A' : null, true);
|
||||
if ( result == null ) {
|
||||
Assert.assertTrue(expectedResult == null);
|
||||
return;
|
||||
}
|
||||
Assert.assertEquals(result.getAlleles(), expectedResult.getAlleles(),testID);
|
||||
Assert.assertEquals(result.getNSamples(), expectedResult.getNSamples(),testID);
|
||||
for ( final Genotype expectedGenotype : expectedResult.getGenotypes() ) {
|
||||
Assert.assertTrue(result.hasGenotype(expectedGenotype.getSampleName()), "Missing " + expectedGenotype.getSampleName());
|
||||
// use string comparisons to test equality for now
|
||||
Assert.assertEquals(result.getGenotype(expectedGenotype.getSampleName()).toString(), expectedGenotype.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateADWithNewAlleles() {
|
||||
|
||||
final int[] originalAD = new int[] {1,2,0};
|
||||
final int[] indexesOfRelevantAlleles = new int[] {0,1,2,2};
|
||||
|
||||
final int[] newAD = GATKVariantContextUtils.generateAD(originalAD, indexesOfRelevantAlleles);
|
||||
Assert.assertEquals(newAD, new int[]{1,2,0,0});
|
||||
}
|
||||
|
||||
|
||||
@Test(expectedExceptions = UserException.class)
|
||||
public void testGetIndexesOfRelevantAllelesWithNoALT() {
|
||||
|
||||
final List<Allele> alleles1 = new ArrayList<>(1);
|
||||
alleles1.add(Allele.create("A", true));
|
||||
final List<Allele> alleles2 = new ArrayList<>(1);
|
||||
alleles2.add(Allele.create("A", true));
|
||||
GATKVariantContextUtils.getIndexesOfRelevantAlleles(alleles1, alleles2, -1);
|
||||
Assert.fail("We should have thrown an exception because the <ALT> allele was not present");
|
||||
}
|
||||
|
||||
@Test(dataProvider = "getIndexesOfRelevantAllelesData")
|
||||
public void testGetIndexesOfRelevantAlleles(final int allelesIndex, final List<Allele> allAlleles) {
|
||||
final List<Allele> myAlleles = new ArrayList<>(3);
|
||||
|
||||
// always add the reference and <ALT> alleles
|
||||
myAlleles.add(allAlleles.get(0));
|
||||
myAlleles.add(GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
// optionally add another alternate allele
|
||||
if ( allelesIndex > 0 )
|
||||
myAlleles.add(allAlleles.get(allelesIndex));
|
||||
|
||||
final int[] indexes = GATKVariantContextUtils.getIndexesOfRelevantAlleles(myAlleles, allAlleles, -1);
|
||||
|
||||
Assert.assertEquals(indexes.length, allAlleles.size());
|
||||
|
||||
for ( int i = 0; i < allAlleles.size(); i++ ) {
|
||||
if ( i == 0 )
|
||||
Assert.assertEquals(indexes[i], 0); // ref should always match
|
||||
else if ( i == allelesIndex )
|
||||
Assert.assertEquals(indexes[i], 2); // allele
|
||||
else
|
||||
Assert.assertEquals(indexes[i], 1); // <ALT>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@DataProvider(name = "getIndexesOfRelevantAllelesData")
|
||||
public Object[][] makeGetIndexesOfRelevantAllelesData() {
|
||||
final int totalAlleles = 5;
|
||||
final List<Allele> alleles = new ArrayList<>(totalAlleles);
|
||||
alleles.add(Allele.create("A", true));
|
||||
for ( int i = 1; i < totalAlleles; i++ )
|
||||
alleles.add(Allele.create(Utils.dupString('A', i + 1), false));
|
||||
|
||||
final List<Object[]> tests = new ArrayList<>();
|
||||
|
||||
for ( int alleleIndex = 0; alleleIndex < totalAlleles; alleleIndex++ ) {
|
||||
tests.add(new Object[]{alleleIndex, alleles});
|
||||
}
|
||||
|
||||
return tests.toArray(new Object[][]{});
|
||||
}
|
||||
|
||||
@DataProvider(name = "referenceConfidenceMergeData")
|
||||
public Object[][] makeReferenceConfidenceMergeData() {
|
||||
final List<Object[]> tests = new ArrayList<>();
|
||||
final int start = 10;
|
||||
final GenomeLoc loc = new UnvalidatingGenomeLoc("20", 0, start, start);
|
||||
final VariantContext VCbase = new VariantContextBuilder("test", "20", start, start, Arrays.asList(Aref)).make();
|
||||
final VariantContext VCprevBase = new VariantContextBuilder("test", "20", start-1, start-1, Arrays.asList(Aref)).make();
|
||||
|
||||
final int[] standardPLs = new int[]{30, 20, 10, 71, 72, 73};
|
||||
final int[] reorderedSecondAllelePLs = new int[]{30, 71, 73, 20, 72, 10};
|
||||
|
||||
final List<Allele> noCalls = new ArrayList<>(2);
|
||||
noCalls.add(Allele.NO_CALL);
|
||||
noCalls.add(Allele.NO_CALL);
|
||||
|
||||
final List<Allele> A_ALT = Arrays.asList(Aref, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
final Genotype gA_ALT = new GenotypeBuilder("A").PL(new int[]{0, 100, 1000}).alleles(noCalls).make();
|
||||
final VariantContext vcA_ALT = new VariantContextBuilder(VCbase).alleles(A_ALT).genotypes(gA_ALT).make();
|
||||
final Allele AAref = Allele.create("AA", true);
|
||||
final List<Allele> AA_ALT = Arrays.asList(AAref, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
final Genotype gAA_ALT = new GenotypeBuilder("AA").PL(new int[]{0, 80, 800}).alleles(noCalls).make();
|
||||
final VariantContext vcAA_ALT = new VariantContextBuilder(VCprevBase).alleles(AA_ALT).genotypes(gAA_ALT).make();
|
||||
final List<Allele> A_C = Arrays.asList(Aref, C);
|
||||
final Genotype gA_C = new GenotypeBuilder("A_C").PL(new int[]{30, 20, 10}).alleles(noCalls).make();
|
||||
final List<Allele> A_C_ALT = Arrays.asList(Aref, C, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
final Genotype gA_C_ALT = new GenotypeBuilder("A_C").PL(standardPLs).alleles(noCalls).make();
|
||||
final VariantContext vcA_C_ALT = new VariantContextBuilder(VCbase).alleles(A_C_ALT).genotypes(gA_C_ALT).make();
|
||||
final List<Allele> A_G_ALT = Arrays.asList(Aref, G, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
final Genotype gA_G_ALT = new GenotypeBuilder("A_G").PL(standardPLs).alleles(noCalls).make();
|
||||
final VariantContext vcA_G_ALT = new VariantContextBuilder(VCbase).alleles(A_G_ALT).genotypes(gA_G_ALT).make();
|
||||
final List<Allele> A_C_G = Arrays.asList(Aref, C, G);
|
||||
final Genotype gA_C_G = new GenotypeBuilder("A_C_G").PL(new int[]{40, 20, 30, 20, 10, 30}).alleles(noCalls).make();
|
||||
final List<Allele> A_C_G_ALT = Arrays.asList(Aref, C, G, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
final Genotype gA_C_G_ALT = new GenotypeBuilder("A_C_G").PL(new int[]{40, 20, 30, 20, 10, 30, 71, 72, 73, 74}).alleles(noCalls).make();
|
||||
final VariantContext vcA_C_G_ALT = new VariantContextBuilder(VCbase).alleles(A_C_G_ALT).genotypes(gA_C_G_ALT).make();
|
||||
final List<Allele> A_ATC_ALT = Arrays.asList(Aref, ATC, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
final Genotype gA_ATC_ALT = new GenotypeBuilder("A_ATC").PL(standardPLs).alleles(noCalls).make();
|
||||
final VariantContext vcA_ATC_ALT = new VariantContextBuilder(VCbase).alleles(A_ATC_ALT).genotypes(gA_ATC_ALT).make();
|
||||
final Allele A = Allele.create("A", false);
|
||||
final List<Allele> AA_A_ALT = Arrays.asList(AAref, A, GATKVariantContextUtils.NON_REF_SYMBOLIC_ALLELE);
|
||||
final Genotype gAA_A_ALT = new GenotypeBuilder("AA_A").PL(standardPLs).alleles(noCalls).make();
|
||||
final VariantContext vcAA_A_ALT = new VariantContextBuilder(VCprevBase).alleles(AA_A_ALT).genotypes(gAA_A_ALT).make();
|
||||
|
||||
// first test the case of a single record
|
||||
tests.add(new Object[]{"test00",Arrays.asList(vcA_C_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(A_C).genotypes(gA_C).make()});
|
||||
|
||||
// now, test pairs:
|
||||
// a SNP with another SNP
|
||||
tests.add(new Object[]{"test01",Arrays.asList(vcA_C_ALT, vcA_G_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(A_C_G).genotypes(gA_C_ALT, new GenotypeBuilder("A_G").PL(reorderedSecondAllelePLs).alleles(noCalls).make()).make()});
|
||||
// a SNP with an indel
|
||||
tests.add(new Object[]{"test02",Arrays.asList(vcA_C_ALT, vcA_ATC_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(Arrays.asList(Aref, C, ATC)).genotypes(gA_C_ALT, new GenotypeBuilder("A_ATC").PL(reorderedSecondAllelePLs).alleles(noCalls).make()).make()});
|
||||
// a SNP with 2 SNPs
|
||||
tests.add(new Object[]{"test03",Arrays.asList(vcA_C_ALT, vcA_C_G_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(A_C_G).genotypes(gA_C_ALT, gA_C_G).make()});
|
||||
// a SNP with a ref record
|
||||
tests.add(new Object[]{"test04",Arrays.asList(vcA_C_ALT, vcA_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(A_C).genotypes(gA_C, gA_ALT).make()});
|
||||
|
||||
// spanning records:
|
||||
// a SNP with a spanning ref record
|
||||
tests.add(new Object[]{"test05",Arrays.asList(vcA_C_ALT, vcAA_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(A_C).genotypes(gA_C, gAA_ALT).make()});
|
||||
// a SNP with a spanning deletion
|
||||
tests.add(new Object[]{"test06",Arrays.asList(vcA_C_ALT, vcAA_A_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(A_C).genotypes(gA_C, new GenotypeBuilder("AA_A").PL(new int[]{30, 71, 73}).alleles(noCalls).make()).make()});
|
||||
|
||||
// combination of all
|
||||
tests.add(new Object[]{"test07",Arrays.asList(vcA_C_ALT, vcA_G_ALT, vcA_ATC_ALT, vcA_C_G_ALT, vcA_ALT, vcAA_ALT, vcAA_A_ALT),
|
||||
loc, false,
|
||||
new VariantContextBuilder(VCbase).alleles(Arrays.asList(Aref, C, G, ATC)).genotypes(new GenotypeBuilder("A_C").PL(new int[]{30, 20, 10, 71, 72, 73, 71, 72, 73, 73}).alleles(noCalls).make(),
|
||||
new GenotypeBuilder("A_G").PL(new int[]{30, 71, 73, 20, 72, 10, 71, 73, 72, 73}).alleles(noCalls).make(),
|
||||
new GenotypeBuilder("A_ATC").PL(new int[]{30, 71, 73, 71, 73, 73, 20, 72, 72, 10}).alleles(noCalls).make(),
|
||||
new GenotypeBuilder("A_C_G").PL(new int[]{40,20,30,20,10,30,71,72,73,74}).alleles(noCalls).make(),
|
||||
new GenotypeBuilder("A").PL(new int[]{0, 100, 1000, 100, 1000, 1000, 100, 1000, 1000, 1000}).alleles(noCalls).make(),
|
||||
new GenotypeBuilder("AA").PL(new int[]{0, 80, 800, 80, 800, 800, 80, 800, 800, 800}).alleles(noCalls).make(),
|
||||
new GenotypeBuilder("AA_A").PL(new int[]{30, 71, 73, 71, 73, 73, 71, 73, 73, 73}).alleles(noCalls).make()).make()});
|
||||
|
||||
// just spanning ref contexts, trying both instances where we want/do not want ref-only contexts
|
||||
tests.add(new Object[]{"test08",Arrays.asList(vcAA_ALT),
|
||||
|
||||
loc, false,
|
||||
null});
|
||||
tests.add(new Object[]{"test09", Arrays.asList(vcAA_ALT),
|
||||
loc, true,
|
||||
new VariantContextBuilder(VCbase).alleles(Arrays.asList(Allele.create("A", true))).genotypes(new GenotypeBuilder("AA").PL(new int[]{0}).alleles(noCalls).make()).make()});
|
||||
|
||||
final Object[][] result = tests.toArray(new Object[][]{});
|
||||
return result;
|
||||
}
|
||||
|
||||
@DataProvider(name = "generatePLsData")
|
||||
public Object[][] makeGeneratePLsData() {
|
||||
final List<Object[]> tests = new ArrayList<>();
|
||||
|
||||
for ( int originalAlleles = 2; originalAlleles <= 5; originalAlleles++ ) {
|
||||
for ( int swapPosition1 = 0; swapPosition1 < originalAlleles; swapPosition1++ ) {
|
||||
for ( int swapPosition2 = swapPosition1+1; swapPosition2 < originalAlleles; swapPosition2++ ) {
|
||||
final int[] indexes = new int[originalAlleles];
|
||||
for ( int i = 0; i < originalAlleles; i++ )
|
||||
indexes[i] = i;
|
||||
indexes[swapPosition1] = swapPosition2;
|
||||
indexes[swapPosition2] = swapPosition1;
|
||||
tests.add(new Object[]{originalAlleles, indexes});
|
||||
}
|
||||
}
|
||||
}
|
||||
return tests.toArray(new Object[][]{});
|
||||
}
|
||||
|
||||
@Test(dataProvider="overlapWithData")
|
||||
public void testOverlapsWith(final VariantContext vc, final GenomeLoc genomeLoc) {
|
||||
final boolean expected;
|
||||
|
|
|
|||
Loading…
Reference in New Issue