From aa5e88a393e81eb7ea0dc7328c8c47ed396c4760 Mon Sep 17 00:00:00 2001 From: Ron Levine Date: Tue, 29 Dec 2015 15:02:42 -0500 Subject: [PATCH] Fix exception when writing gVCF to stdout --- .../walkers/haplotypecaller/HaplotypeCaller.java | 12 +++++++++--- .../HaplotypeCallerIntegrationTest.java | 9 +++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCaller.java b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCaller.java index 7b4399068..7d47f27a7 100644 --- a/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCaller.java +++ b/protected/gatk-tools-protected/src/main/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCaller.java @@ -104,6 +104,7 @@ import org.broadinstitute.gatk.utils.sam.GATKSAMRecord; import org.broadinstitute.gatk.utils.sam.ReadUtils; import org.broadinstitute.gatk.utils.variant.*; +import java.io.File; import java.io.FileNotFoundException; import java.util.*; @@ -1245,10 +1246,15 @@ public class HaplotypeCaller extends ActiveRegionWalker, In /** * Is writing to an output GVCF file? * - * @return true if the VCF output file has a .g.vcf or .g.vcf.gz extension + * @return true if the VCF output file has a .g.vcf or .g.vcf.gz extension or if no output file */ private boolean isGVCF() { - String fileName = ((VariantContextWriterStub) vcfWriter).getOutputFile().getName(); - return ( fileName.endsWith("." + GATKVCFUtils.GVCF_EXT) || fileName.endsWith("." + GATKVCFUtils.GVCF_GZ_EXT) ); + final File file = ((VariantContextWriterStub) vcfWriter).getOutputFile(); + if ( file == null ){ + return true; + } else { + final String fileName = file.getName(); + return ( fileName.endsWith("." + GATKVCFUtils.GVCF_EXT) || fileName.endsWith("." + GATKVCFUtils.GVCF_GZ_EXT) ); + } } } diff --git a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerIntegrationTest.java b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerIntegrationTest.java index 4ac07e377..00d9a1090 100644 --- a/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerIntegrationTest.java +++ b/protected/gatk-tools-protected/src/test/java/org/broadinstitute/gatk/tools/walkers/haplotypecaller/HaplotypeCallerIntegrationTest.java @@ -368,6 +368,15 @@ public class HaplotypeCallerIntegrationTest extends WalkerTest { executeTest("testGraphBasedNoSuchEdgeBugFix", spec); } + @Test + public void testWriteGVCFStdout() { + final String commandLine = String.format("-T HaplotypeCaller -R %s -I %s -L %s -dontTrimActiveRegions -ERC GVCF ", + b37KGReferenceWithDecoy, privateTestDir + "graphbased_no_such_edge_bug.bam", privateTestDir + "graphbased_no_such_edge_bug.intervals.bed"); + final WalkerTestSpec spec = new WalkerTestSpec(commandLine, Arrays.asList("")); + spec.disableShadowBCF(); + executeTest("testWriteGVCFStdout", spec); + } + // This test takes longer than 15 secs ... ~ 25-35 , @Test public void testLackSensitivityDueToBadHaplotypeSelectionFix() {