Implementation of dropped read tracking.
This commit is contained in:
parent
b873467756
commit
a8ebf21ac3
|
|
@ -88,6 +88,7 @@ import org.broadinstitute.gatk.utils.fragments.FragmentCollection;
|
|||
import org.broadinstitute.gatk.utils.fragments.FragmentUtils;
|
||||
import org.broadinstitute.gatk.utils.genotyper.*;
|
||||
import org.broadinstitute.gatk.utils.haplotype.Haplotype;
|
||||
import org.broadinstitute.gatk.utils.haplotypeBAMWriter.DroppedReadsTracker;
|
||||
import org.broadinstitute.gatk.utils.haplotypeBAMWriter.HaplotypeBAMWriter;
|
||||
import org.broadinstitute.gatk.utils.help.DocumentedGATKFeature;
|
||||
import org.broadinstitute.gatk.utils.help.HelpConstants;
|
||||
|
|
@ -561,6 +562,10 @@ public class MuTect2 extends ActiveRegionWalker<List<VariantContext>, Integer> i
|
|||
final ActiveRegion regionForGenotyping = assemblyResult.getRegionForGenotyping();
|
||||
logReadInfo(DEBUG_READ_NAME, regionForGenotyping.getReads(), "Present in region for genotyping");
|
||||
|
||||
if ( MTAC.bamWriter != null && MTAC.emitDroppedReads ) {
|
||||
haplotypeBAMWriter.addDroppedReadsFromDelta(DroppedReadsTracker.Reason.TRIMMMED, originalActiveRegion.getReads(), regionForGenotyping.getReads());
|
||||
}
|
||||
|
||||
//
|
||||
// final ActiveRegion regionForGenotyping = trimmingResult.getCallableRegion();
|
||||
|
||||
|
|
@ -572,6 +577,11 @@ public class MuTect2 extends ActiveRegionWalker<List<VariantContext>, Integer> i
|
|||
//TODO - if you move this up you might have to consider to change referenceModelForNoVariation
|
||||
//TODO - that does also filter reads.
|
||||
final Collection<GATKSAMRecord> filteredReads = filterNonPassingReads(regionForGenotyping);
|
||||
|
||||
if ( MTAC.bamWriter != null && MTAC.emitDroppedReads ) {
|
||||
haplotypeBAMWriter.addDroppedReads(DroppedReadsTracker.Reason.FILTERED, filteredReads);
|
||||
}
|
||||
|
||||
final Map<String, List<GATKSAMRecord>> perSampleFilteredReadList = splitReadsBySample(filteredReads);
|
||||
|
||||
logReadInfo(DEBUG_READ_NAME, regionForGenotyping.getReads(), "Present in region for genotyping after filtering reads");
|
||||
|
|
@ -617,6 +627,14 @@ public class MuTect2 extends ActiveRegionWalker<List<VariantContext>, Integer> i
|
|||
// Realign reads to their best haplotype.
|
||||
// KCIBUL: this is new stuff -- review it!
|
||||
final Map<GATKSAMRecord,GATKSAMRecord> readRealignments = realignReadsToTheirBestHaplotype(readLikelihoods, assemblyResult.getReferenceHaplotype(), assemblyResult.getPaddedReferenceLoc());
|
||||
|
||||
if ( MTAC.bamWriter != null && MTAC.emitDroppedReads ) {
|
||||
haplotypeBAMWriter.addDroppedReadsFromDelta(
|
||||
DroppedReadsTracker.Reason.REALIGNMENT_FAILURE,
|
||||
regionForGenotyping.getReads(),
|
||||
readRealignments.values());
|
||||
}
|
||||
|
||||
readLikelihoods.changeReads(readRealignments);
|
||||
|
||||
for (GATKSAMRecord rec : readRealignments.keySet()) {
|
||||
|
|
@ -657,6 +675,10 @@ public class MuTect2 extends ActiveRegionWalker<List<VariantContext>, Integer> i
|
|||
haplotypes,
|
||||
calledHaplotypeSet,
|
||||
readLikelihoods);
|
||||
|
||||
if ( MTAC.emitDroppedReads ) {
|
||||
haplotypeBAMWriter.writeDroppedReads();
|
||||
}
|
||||
}
|
||||
|
||||
if( MTAC.DEBUG ) { logger.info("----------------------------------------------------------------------------------"); }
|
||||
|
|
@ -1190,6 +1212,10 @@ public class MuTect2 extends ActiveRegionWalker<List<VariantContext>, Integer> i
|
|||
|
||||
final List<GATKSAMRecord> downsampledReads = DownsamplingUtils.levelCoverageByPosition(ReadUtils.sortReadsByCoordinate(readsToUse), maxReadsInRegionPerSample, minReadsPerAlignmentStart);
|
||||
|
||||
if ( MTAC.bamWriter != null && MTAC.emitDroppedReads ) {
|
||||
haplotypeBAMWriter.addDroppedReadsFromDelta(DroppedReadsTracker.Reason.DOWNSAMPLED, activeRegion.getReads(), downsampledReads);
|
||||
}
|
||||
|
||||
// handle overlapping read pairs from the same fragment
|
||||
// KC: commented out as we handle overlapping read pairs in a different way...
|
||||
//cleanOverlappingReadPairs(downsampledReads, normalSampleNames);
|
||||
|
|
|
|||
|
|
@ -90,8 +90,8 @@ public class AssemblyBasedCallerArgumentCollection extends StandardCallerArgumen
|
|||
|
||||
/**
|
||||
* The assembled haplotypes and locally realigned reads will be written as BAM to this file if requested. Really
|
||||
* for debugging purposes only. Note that the output here does not include uninformative reads so that not every
|
||||
* input read is emitted to the bam.
|
||||
* for debugging purposes only. Note that not every input read is emitted to the bam. To include trimmed, downsampled,
|
||||
* filtered and uninformative reads add the "--emitDroppedReads" argument.
|
||||
*
|
||||
* Turning on this mode may result in serious performance cost for the caller. It's really only appropriate to
|
||||
* use in specific areas where you want to better understand why the caller is making specific calls.
|
||||
|
|
@ -130,6 +130,14 @@ public class AssemblyBasedCallerArgumentCollection extends StandardCallerArgumen
|
|||
@Argument(fullName="bamWriterType", shortName="bamWriterType", doc="Which haplotypes should be written to the BAM", required = false)
|
||||
public HaplotypeBAMWriter.Type bamWriterType = HaplotypeBAMWriter.Type.CALLED_HAPLOTYPES;
|
||||
|
||||
/**
|
||||
* Determines whether dropped reads will be tracked and emitted when a bamout is specified. Use this in combination
|
||||
* with a specific interval of interest to avoid accumulating a large number of reads int eh bamout.
|
||||
*/
|
||||
@Advanced
|
||||
@Argument(fullName="emitDroppedReads", shortName="edr", doc="Emit reads that are dropped for filtering, trimming, realignment failure", required = false)
|
||||
public boolean emitDroppedReads = false;
|
||||
|
||||
/**
|
||||
* If set, certain "early exit" optimizations in HaplotypeCaller, which aim to save compute and time by skipping
|
||||
* calculations if an ActiveRegion is determined to contain no variants, will be disabled. This is most likely to be useful if
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ import org.broadinstitute.gatk.engine.filters.BadMateFilter;
|
|||
import org.broadinstitute.gatk.utils.genotyper.*;
|
||||
import org.broadinstitute.gatk.engine.iterators.ReadTransformer;
|
||||
import org.broadinstitute.gatk.engine.io.stubs.VariantContextWriterStub;
|
||||
import org.broadinstitute.gatk.utils.haplotypeBAMWriter.DroppedReadsTracker;
|
||||
import org.broadinstitute.gatk.utils.refdata.RefMetaDataTracker;
|
||||
import org.broadinstitute.gatk.engine.walkers.*;
|
||||
import org.broadinstitute.gatk.tools.walkers.annotator.VariantAnnotatorEngine;
|
||||
|
|
@ -893,12 +894,21 @@ public class HaplotypeCaller extends ActiveRegionWalker<List<VariantContext>, In
|
|||
|
||||
final ActiveRegion regionForGenotyping = assemblyResult.getRegionForGenotyping();
|
||||
|
||||
if ( HCAC.bamWriter != null && HCAC.emitDroppedReads ) {
|
||||
haplotypeBAMWriter.addDroppedReadsFromDelta(DroppedReadsTracker.Reason.TRIMMMED, originalActiveRegion.getReads(), regionForGenotyping.getReads());
|
||||
}
|
||||
|
||||
// filter out reads from genotyping which fail mapping quality based criteria
|
||||
//TODO - why don't do this before any assembly is done? Why not just once at the beginning of this method
|
||||
//TODO - on the originalActiveRegion?
|
||||
//TODO - if you move this up you might have to consider to change referenceModelForNoVariation
|
||||
//TODO - that does also filter reads.
|
||||
final Collection<GATKSAMRecord> filteredReads = filterNonPassingReads( regionForGenotyping );
|
||||
|
||||
if ( HCAC.bamWriter != null && HCAC.emitDroppedReads ) {
|
||||
haplotypeBAMWriter.addDroppedReads(DroppedReadsTracker.Reason.FILTERED, filteredReads);
|
||||
}
|
||||
|
||||
final Map<String, List<GATKSAMRecord>> perSampleFilteredReadList = splitReadsBySample( filteredReads );
|
||||
|
||||
// abort early if something is out of the acceptable range
|
||||
|
|
@ -927,6 +937,14 @@ public class HaplotypeCaller extends ActiveRegionWalker<List<VariantContext>, In
|
|||
|
||||
// Realign reads to their best haplotype.
|
||||
final Map<GATKSAMRecord,GATKSAMRecord> readRealignments = realignReadsToTheirBestHaplotype(readLikelihoods, assemblyResult.getReferenceHaplotype(), assemblyResult.getPaddedReferenceLoc());
|
||||
|
||||
if ( HCAC.bamWriter != null && HCAC.emitDroppedReads ) {
|
||||
haplotypeBAMWriter.addDroppedReadsFromDelta(
|
||||
DroppedReadsTracker.Reason.REALIGNMENT_FAILURE,
|
||||
regionForGenotyping.getReads(),
|
||||
readRealignments.values());
|
||||
}
|
||||
|
||||
readLikelihoods.changeReads(readRealignments);
|
||||
|
||||
// Note: we used to subset down at this point to only the "best" haplotypes in all samples for genotyping, but there
|
||||
|
|
@ -957,6 +975,10 @@ public class HaplotypeCaller extends ActiveRegionWalker<List<VariantContext>, In
|
|||
haplotypes,
|
||||
calledHaplotypeSet,
|
||||
readLikelihoods);
|
||||
|
||||
if ( HCAC.emitDroppedReads ) {
|
||||
haplotypeBAMWriter.writeDroppedReads();
|
||||
}
|
||||
}
|
||||
|
||||
if( HCAC.DEBUG ) { logger.info("----------------------------------------------------------------------------------"); }
|
||||
|
|
@ -1182,6 +1204,10 @@ public class HaplotypeCaller extends ActiveRegionWalker<List<VariantContext>, In
|
|||
|
||||
final List<GATKSAMRecord> downsampledReads = DownsamplingUtils.levelCoverageByPosition(ReadUtils.sortReadsByCoordinate(readsToUse), maxReadsInRegionPerSample, minReadsPerAlignmentStart);
|
||||
|
||||
if ( HCAC.bamWriter != null && HCAC.emitDroppedReads ) {
|
||||
haplotypeBAMWriter.addDroppedReadsFromDelta(DroppedReadsTracker.Reason.DOWNSAMPLED, activeRegion.getReads(), downsampledReads);
|
||||
}
|
||||
|
||||
// handle overlapping read pairs from the same fragment
|
||||
cleanOverlappingReadPairs(downsampledReads);
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,211 @@
|
|||
/*
|
||||
* 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 415 Main Street, 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 GATK3 and related documentation, if any, as they exist on the EFFECTIVE DATE and can be downloaded from http://www.broadinstitute.org/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. LICENSEE hereby automatically grants to BROAD a non-exclusive, royalty-free, irrevocable license to any LICENSEE bug fixes or modifications to the PROGRAM with unlimited rights to sublicense and/or distribute. LICENSEE agrees to provide any such modifications and bug fixes to BROAD promptly upon their creation.
|
||||
* 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. PHONE-HOME FEATURE
|
||||
* LICENSEE expressly acknowledges that the PROGRAM contains an embedded automatic reporting system (“PHONE-HOME”) which is enabled by default upon download. Unless LICENSEE requests disablement of PHONE-HOME, LICENSEE agrees that BROAD may collect limited information transmitted by PHONE-HOME regarding LICENSEE and its use of the PROGRAM. Such information shall include LICENSEE’S user identification, version number of the PROGRAM and tools being run, mode of analysis employed, and any error reports generated during run-time. Collection of such information is used by BROAD solely to monitor usage rates, fulfill reporting requirements to BROAD funding agencies, drive improvements to the PROGRAM, and facilitate adjustments to PROGRAM-related documentation.
|
||||
*
|
||||
* 4. 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-2015 Broad Institute, Inc.
|
||||
* Notice of attribution: The GATK3 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.
|
||||
*
|
||||
* 5. 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.
|
||||
*
|
||||
* 6. 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.
|
||||
*
|
||||
* 7. 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.
|
||||
*
|
||||
* 8. MISCELLANEOUS
|
||||
* 8.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.
|
||||
* 8.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.
|
||||
* 8.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.
|
||||
* 8.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.
|
||||
* 8.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.
|
||||
* 8.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.
|
||||
* 8.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.haplotypeBAMWriter;
|
||||
|
||||
import com.google.common.hash.HashFunction;
|
||||
import com.google.common.hash.Hashing;
|
||||
import htsjdk.samtools.SAMTag;
|
||||
import org.broadinstitute.gatk.utils.sam.GATKSAMRecord;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Class for tracking and emitting reads dropped by HaplotypeCaller due to filtering, trimming, etc. Reads are
|
||||
* categorized per ActiveRegion by reason, and then emitted to the HaplotypeBAMWriter's bamout read destination,
|
||||
* with an "FT" attribute with a value corresponding to the reason the reads were dropped.
|
||||
*/
|
||||
public class DroppedReadsTracker {
|
||||
|
||||
private final Map<Reason, Set<GATKSAMRecord>> droppedReads = new HashMap<>(Reason.values().length);
|
||||
private final static HashFunction murmurHasher = Hashing.murmur3_32();
|
||||
|
||||
// Enum of reasons that reads are dropped and tracked.
|
||||
public enum Reason {
|
||||
TRIMMMED {
|
||||
String reasonName() { return "Trimmed"; }
|
||||
},
|
||||
DOWNSAMPLED {
|
||||
String reasonName() { return "Downsampled"; }
|
||||
},
|
||||
REALIGNMENT_FAILURE {
|
||||
String reasonName() { return "Failed realignment"; }
|
||||
},
|
||||
FILTERED {
|
||||
String reasonName() { return "Filtered"; }
|
||||
},
|
||||
NOT_INFORMATIVE {
|
||||
String reasonName() { return "Not informative"; }
|
||||
};
|
||||
|
||||
abstract String reasonName();
|
||||
}
|
||||
|
||||
// Private wrapper for a GATKSAMRecord that provides an alternate hashCode
|
||||
// suitable for maintaining record identity across mutations that occur during
|
||||
// filtering, trimming, etc. Used by addReadsFromDelta to
|
||||
private class GATKSAMRecordHashWrapper {
|
||||
private GATKSAMRecord samRec;
|
||||
|
||||
public GATKSAMRecordHashWrapper() {
|
||||
samRec = null;
|
||||
}
|
||||
|
||||
public GATKSAMRecordHashWrapper(GATKSAMRecord rec) {
|
||||
samRec = rec;
|
||||
}
|
||||
|
||||
public GATKSAMRecordHashWrapper set(GATKSAMRecord rec) {
|
||||
samRec = rec;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof GATKSAMRecordHashWrapper)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GATKSAMRecord other = ((GATKSAMRecordHashWrapper) o).samRec;
|
||||
return samRec.getReadName().equals(other.getReadName()) && samRec.getFlags() == other.getFlags();
|
||||
}
|
||||
|
||||
// Calculate a read hash that remains invariant as reads are mutated during
|
||||
// filtering/trimming etc., but that distinguishes paired reads from their mate, secondary etc.
|
||||
public int hashCode() {
|
||||
// Use a murmur hash of the flags to distribute the values more uniformly over the full range of int
|
||||
return samRec.getReadName().hashCode() + (31 * murmurHasher.hashInt(samRec.getFlags()).asInt());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add reads that have been dropped for the specified reason to the dropped list.
|
||||
*/
|
||||
public void addReads(final Reason reason, final Collection<GATKSAMRecord> reads) {
|
||||
Set<GATKSAMRecord> readsForReason = droppedReads.get(reason);
|
||||
if (null == readsForReason) {
|
||||
readsForReason = new HashSet<>(reads.size());
|
||||
}
|
||||
for (final GATKSAMRecord rec: reads) {
|
||||
if (!previouslyDropped(rec)) {
|
||||
// tag the original read so we can track the ones we've already seen and
|
||||
// only add them to the dropped list once
|
||||
rec.setAttribute(SAMTag.FT.name(), reason.reasonName());
|
||||
readsForReason.add(rec);
|
||||
}
|
||||
}
|
||||
|
||||
droppedReads.put(reason, readsForReason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Figure out the delta between the preReads list and the postReads list by hashing on the combination of read name and
|
||||
* first_of_pair flag; any read not in the postReads list is added to the dropped list for the specified reason.
|
||||
*/
|
||||
public void addReadsFromDelta(final Reason reason, final Collection<GATKSAMRecord> preReads, final Collection<GATKSAMRecord> postReads) {
|
||||
final HashSet<GATKSAMRecordHashWrapper> postReadsSet = new HashSet<>(postReads.size());
|
||||
|
||||
for (final GATKSAMRecord postRead : postReads) {
|
||||
final GATKSAMRecordHashWrapper hashWrapper = new GATKSAMRecordHashWrapper(postRead);
|
||||
postReadsSet.add(hashWrapper);
|
||||
}
|
||||
|
||||
final int estimatedDropSize = preReads.size() - postReads.size();
|
||||
final List<GATKSAMRecord> newlyDropped = new ArrayList<>(estimatedDropSize > 0 ? estimatedDropSize : 5);
|
||||
|
||||
GATKSAMRecordHashWrapper hashWrapper = new GATKSAMRecordHashWrapper();
|
||||
for (final GATKSAMRecord preRead: preReads) {
|
||||
if (!postReadsSet.contains(hashWrapper.set(preRead))) {
|
||||
newlyDropped.add(preRead);
|
||||
}
|
||||
}
|
||||
|
||||
addReads(reason, newlyDropped);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit the accumulated dropped reads and reset/clear the cache.
|
||||
*
|
||||
* @param readDestination destination to receive the reads
|
||||
*/
|
||||
public void writeDroppedReads(final ReadDestination readDestination) {
|
||||
for (final DroppedReadsTracker.Reason reason : droppedReads.keySet()) {
|
||||
final Set<GATKSAMRecord> droppedRecords = droppedReads.get(reason);
|
||||
for (final GATKSAMRecord originalRec : droppedRecords) {
|
||||
// We want to set the vendor quality check flag on the read emitted to
|
||||
// the bamout, so clone the read before update it so we don't affect
|
||||
// subsequent filtering/trimming, etc. in the event the original read
|
||||
// gets processed again
|
||||
final GATKSAMRecord clonedRec = (GATKSAMRecord)originalRec.clone();
|
||||
clonedRec.setReadFailsVendorQualityCheckFlag(true);
|
||||
readDestination.add(clonedRec);
|
||||
}
|
||||
}
|
||||
|
||||
// clear and reset the cache
|
||||
droppedReads.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to see if the read is marked as having been previously dropped.
|
||||
*/
|
||||
private boolean previouslyDropped(GATKSAMRecord rec) {
|
||||
final String reasonDesc = rec.getStringAttribute(SAMTag.FT.name());
|
||||
for (final Reason reason : Reason.values()) {
|
||||
if (reason.reasonName().equals(reasonDesc)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -84,6 +84,8 @@ public abstract class HaplotypeBAMWriter {
|
|||
private boolean writeHaplotypesAsWell = true;
|
||||
private boolean onlyRealignInformativeReads = false;
|
||||
|
||||
protected final DroppedReadsTracker droppedReadsTracker = new DroppedReadsTracker();
|
||||
|
||||
/**
|
||||
* Possible modes for writing haplotypes to BAMs
|
||||
*/
|
||||
|
|
@ -149,6 +151,35 @@ public abstract class HaplotypeBAMWriter {
|
|||
this.output = output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Figure out the delta between the preReads list and the postReads list by hashing on the combination of read name and
|
||||
* first_of_pair flag; any read not in the postReads list is added to the dropped list for the specified reason.
|
||||
*/
|
||||
public void addDroppedReadsFromDelta(
|
||||
final DroppedReadsTracker.Reason reason,
|
||||
final Collection<GATKSAMRecord> preReads,
|
||||
final Collection<GATKSAMRecord> postReads) {
|
||||
droppedReadsTracker.addReadsFromDelta(reason, preReads, postReads);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add reads that have been dropped for the specified reason to the dropped list.
|
||||
*
|
||||
* @param reason -reason category these reads were dropped
|
||||
* @param reads - reads to write out for this reason
|
||||
*
|
||||
*/
|
||||
public void addDroppedReads(final DroppedReadsTracker.Reason reason, final Collection<GATKSAMRecord> reads) {
|
||||
droppedReadsTracker.addReads(reason, reads);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit the accumulated dropped reads and reset/clear the droppedReads cache.
|
||||
*/
|
||||
public void writeDroppedReads() {
|
||||
droppedReadsTracker.writeDroppedReads(output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write out a BAM representing for the haplotype caller at this site
|
||||
*
|
||||
|
|
|
|||
|
|
@ -84,9 +84,9 @@ public abstract class ReadDestination {
|
|||
bamHeader.setSequenceDictionary(header.getSequenceDictionary());
|
||||
bamHeader.setSortOrder(SAMFileHeader.SortOrder.coordinate);
|
||||
|
||||
// include the original read groups plus a new artificial one for the haplotypes
|
||||
final List<SAMReadGroupRecord> readGroups = new ArrayList<SAMReadGroupRecord>(header.getReadGroups());
|
||||
final SAMReadGroupRecord rg = new SAMReadGroupRecord(readGroupID);
|
||||
// include the original read groups plus an artificial one for haplotypes
|
||||
final List<SAMReadGroupRecord> readGroups = new ArrayList<>(header.getReadGroups());
|
||||
SAMReadGroupRecord rg = new SAMReadGroupRecord(readGroupID);
|
||||
rg.setSample("HC");
|
||||
rg.setSequencingCenter("BI");
|
||||
readGroups.add(rg);
|
||||
|
|
|
|||
|
|
@ -73,12 +73,14 @@ public class MuTect2IntegrationTest extends WalkerTest {
|
|||
final static String DREAM3_FP_INTERVALS_FILE = privateTestDir + "m2_dream3.fp.intervals";
|
||||
|
||||
|
||||
final String commandLine =
|
||||
"-T MuTect2 --no_cmdline_in_header -dt NONE --disableDithering -alwaysloadVectorHMM -pairHMM LOGLESS_CACHING -ip 50 -R %s --dbsnp %s --cosmic %s --normal_panel %s -I:tumor %s -I:normal %s -L %s";
|
||||
|
||||
private void M2Test(String tumorBam, String normalBam, String intervals, String args, String md5) {
|
||||
final String base = String.format(
|
||||
"-T MuTect2 --no_cmdline_in_header -dt NONE --disableDithering -alwaysloadVectorHMM -pairHMM LOGLESS_CACHING -ip 50 -R %s --dbsnp %s --cosmic %s --normal_panel %s -I:tumor %s -I:normal %s -L %s",
|
||||
REF, DBSNP, COSMIC, PON, tumorBam, normalBam, intervals) +
|
||||
" -o %s ";
|
||||
commandLine,
|
||||
REF, DBSNP, COSMIC, PON, tumorBam, normalBam, intervals) +
|
||||
" -o %s ";
|
||||
|
||||
final WalkerTestSpec spec = new WalkerTestSpec(base + " " + args, Arrays.asList(md5));
|
||||
|
||||
|
|
@ -101,6 +103,22 @@ public class MuTect2IntegrationTest extends WalkerTest {
|
|||
executeTest("testM2TumorOnly: args=" + args, spec);
|
||||
}
|
||||
|
||||
private void M2TestWithDroppedReads(String tumorBam, String normalBam, String intervals, String args, String md5Variants, String md5Bamout) {
|
||||
final String base = String.format(
|
||||
commandLine,
|
||||
REF, DBSNP, COSMIC, PON, tumorBam, normalBam, intervals) +
|
||||
" -o %s " +
|
||||
"-bamout %s --emitDroppedReads";
|
||||
|
||||
final WalkerTestSpec spec = new WalkerTestSpec(base + " " + args, Arrays.asList(md5Variants, md5Bamout));
|
||||
|
||||
// TODO: do we want to enable this and why? It explodes with
|
||||
// java.lang.RuntimeException: java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String
|
||||
// at htsjdk.variant.variantcontext.writer.BCF2FieldEncoder$StringOrCharacter.javaStringToBCF2String(BCF2FieldEncoder.java:312)
|
||||
spec.disableShadowBCF();
|
||||
executeTest("testM2Dropped: args=" + args, spec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMicroRegression() {
|
||||
M2Test(CCLE_MICRO_TUMOR_BAM, CCLE_MICRO_NORMAL_BAM, CCLE_MICRO_INTERVALS_FILE, "", "617054c6d056cad7448a463cb8d04a55");
|
||||
|
|
@ -116,6 +134,16 @@ public class MuTect2IntegrationTest extends WalkerTest {
|
|||
M2Test(DREAM3_TUMOR_BAM, DREAM3_NORMAL_BAM, DREAM3_TP_INTERVALS_FILE, "", "f856432679e43445d2939772be4326cf");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test dropped read tracking on true positives and a narrow interval range.
|
||||
*/
|
||||
@Test
|
||||
public void testTruePositivesDream3TrackedDropped() {
|
||||
M2TestWithDroppedReads(DREAM3_TUMOR_BAM, DREAM3_NORMAL_BAM, "21:10935369", "",
|
||||
"ee4786de29532ffd745048c449a9772a",
|
||||
"b536e76870326b4be01b8d6b83c1cf1c");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a number of False Positive calls from the DREAM 3 data set. Some of them are not rejected
|
||||
* (e.g. we have some FPs!) but most are rejected.
|
||||
|
|
|
|||
|
|
@ -94,6 +94,21 @@ public class HaplotypeCallerIntegrationTest extends WalkerTest {
|
|||
Assert.assertFalse(FileUtils.readFileToString(outputVCF).contains(VCFConstants.MAPPING_QUALITY_ZERO_KEY));
|
||||
}
|
||||
|
||||
private void HCTestWithBAMOut(String bam, String args, String md5Variants, String md5BAMOut) throws IOException {
|
||||
final String base = String.format("-T HaplotypeCaller -R %s -I %s ",
|
||||
REF, NA12878_BAM) +
|
||||
args +
|
||||
" --no_cmdline_in_header -o %s -bamout %s --emitDroppedReads";
|
||||
|
||||
final WalkerTestSpec spec = new WalkerTestSpec(base, Arrays.asList(md5Variants, md5BAMOut));
|
||||
executeTest("testHaplotypeCallerBamout", spec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHaplotypeBAMOutFlags() throws IOException {
|
||||
HCTestWithBAMOut(NA12878_BAM, " -L 20:10000000-10100000 ", "b49e15b4680d197db9b9f71644a5a1f9", "f84c8bc44b6af548bd3b8555a068b59e");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHaplotypeCallerMultiSample() throws IOException {
|
||||
HCTest(CEUTRIO_BAM, "", "b86311f6a0b4b5f2cfd05662f03fbe6c");
|
||||
|
|
|
|||
Loading…
Reference in New Issue