Merge pull request #783 from broadinstitute/pd_splitsamfile
Fix NPE in SplitSamFile
This commit is contained in:
commit
bf2911d62c
|
|
@ -59,6 +59,7 @@ 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.io.DirectOutputTracker;
|
||||
import org.broadinstitute.gatk.engine.io.stubs.SAMFileWriterStub;
|
||||
import org.broadinstitute.gatk.utils.contexts.AlignmentContext;
|
||||
import org.broadinstitute.gatk.utils.contexts.AlignmentContextUtils;
|
||||
|
|
@ -1201,6 +1202,7 @@ public class HaplotypeCaller extends ActiveRegionWalker<List<VariantContext>, In
|
|||
// Capture any exception that might be thrown, and write out the assembly failure BAM if requested
|
||||
if ( captureAssemblyFailureBAM ) {
|
||||
final SAMFileWriter writer = SAMFileWriterStub.createSAMFileWriter("assemblyFailure.bam", getToolkit());
|
||||
new DirectOutputTracker().addOutput((SAMFileWriterStub) writer);
|
||||
for ( final GATKSAMRecord read : activeRegion.getReads() ) {
|
||||
writer.addAlignment(read);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ import htsjdk.samtools.SAMFileWriter;
|
|||
import htsjdk.samtools.SAMReadGroupRecord;
|
||||
import htsjdk.samtools.SAMRecord;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.broadinstitute.gatk.engine.io.DirectOutputTracker;
|
||||
import org.broadinstitute.gatk.engine.io.OutputTracker;
|
||||
import org.broadinstitute.gatk.engine.io.stubs.SAMFileWriterStub;
|
||||
import org.broadinstitute.gatk.utils.commandline.Argument;
|
||||
import org.broadinstitute.gatk.engine.CommandLineGATK;
|
||||
|
|
@ -104,6 +106,7 @@ public class SplitSamFile extends ReadWalker<SAMRecord, Map<String, SAMFileWrite
|
|||
}
|
||||
|
||||
HashMap<String, SAMFileWriter> outputs = new HashMap<>();
|
||||
final OutputTracker outputTracker = new DirectOutputTracker();
|
||||
for ( Map.Entry<String, SAMFileHeader> elt : headers.entrySet() ) {
|
||||
final String sample = elt.getKey();
|
||||
final String filename = outputRoot + sample + ".bam";
|
||||
|
|
@ -111,6 +114,7 @@ public class SplitSamFile extends ReadWalker<SAMRecord, Map<String, SAMFileWrite
|
|||
|
||||
final SAMFileWriter output = SAMFileWriterStub.createSAMFileWriter(filename, getToolkit(), elt.getValue());
|
||||
outputs.put(sample, output);
|
||||
outputTracker.addOutput( (SAMFileWriterStub) output);
|
||||
}
|
||||
|
||||
return outputs;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2012 The Broad Institute
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
|
||||
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.broadinstitute.gatk.tools.walkers.readutils;
|
||||
|
||||
import org.broadinstitute.gatk.engine.walkers.WalkerTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
|
||||
public class SplitSamFileIntegrationTest extends WalkerTest {
|
||||
|
||||
@Test
|
||||
public void testSplitSamFile() {
|
||||
final String prefix = "splitsam";
|
||||
WalkerTestSpec spec = new WalkerTestSpec(
|
||||
"-T SplitSamFile" +
|
||||
" -R " + b37KGReference +
|
||||
" -I " + privateTestDir+"/CEUTrio.HiSeq.b37.MT.1_50.bam" +
|
||||
" --outputRoot " + prefix,
|
||||
Collections.<String>emptyList()
|
||||
);
|
||||
addSplitOutput(spec, prefix, "NA12878", "b1a57327a3f0bdbe167dbc7d547f1247");
|
||||
addSplitOutput(spec, prefix, "NA12891", "3bb331fd468fc91c548f38857473f399");
|
||||
addSplitOutput(spec, prefix, "NA12892", "ac61ae9cd168ac15e3a03fe7ab51fb22");
|
||||
executeTest("testSplitSamFile", spec);
|
||||
}
|
||||
|
||||
private void addSplitOutput(final WalkerTestSpec spec, final String outputPrefix, final String sample, final String md5) {
|
||||
final File outputFile = new File(outputPrefix + sample + ".bam");
|
||||
spec.addAuxFile(md5, outputFile);
|
||||
|
||||
//The AuxFile mechanism will ensure the bam is deleted, but it doesn't know about indices
|
||||
new File(outputFile.getAbsolutePath() + ".bai").deleteOnExit();
|
||||
new File(outputFile.getAbsolutePath().replaceAll("bam$", ".bai")).deleteOnExit();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue