From 11dbfc92a70e36702d293f2d417150cd93009afe Mon Sep 17 00:00:00 2001 From: Mark DePristo Date: Fri, 22 Jun 2012 17:03:59 -0400 Subject: [PATCH] Horrible bugfix to decodeLoc() in BCF2Codec -- Just completely wrong. -- BCF2 shadowBCF now checks that the shadow bcf can be written to avoid /dev/null.bcf problem -- Added samtools ex2.bcf file for decoding to our integrationtests --- .../sting/utils/codecs/bcf2/BCF2Codec.java | 10 +-------- .../sting/utils/codecs/bcf2/BCF2Utils.java | 22 ++++++++++++++----- .../utils/codecs/vcf/VCFIntegrationTest.java | 14 +++++++++--- 3 files changed, 28 insertions(+), 18 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/utils/codecs/bcf2/BCF2Codec.java b/public/java/src/org/broadinstitute/sting/utils/codecs/bcf2/BCF2Codec.java index 91331ac13..94c24b097 100644 --- a/public/java/src/org/broadinstitute/sting/utils/codecs/bcf2/BCF2Codec.java +++ b/public/java/src/org/broadinstitute/sting/utils/codecs/bcf2/BCF2Codec.java @@ -101,15 +101,7 @@ public final class BCF2Codec implements FeatureCodec, ReferenceD @Override public Feature decodeLoc( final PositionalBufferedStream inputStream ) { - recordNo++; - final VariantContextBuilder builder = new VariantContextBuilder(); - - final int sitesBlockSize = decoder.readBlockSize(inputStream); - final int genotypeBlockSize = decoder.readBlockSize(inputStream); // necessary because it's in the stream - decoder.readNextBlock(sitesBlockSize, inputStream); - decodeSiteLoc(builder); - - return builder.fullyDecoded(true).make(); + return decode(inputStream); } @Override diff --git a/public/java/src/org/broadinstitute/sting/utils/codecs/bcf2/BCF2Utils.java b/public/java/src/org/broadinstitute/sting/utils/codecs/bcf2/BCF2Utils.java index 51fbd3a7f..21deb4158 100644 --- a/public/java/src/org/broadinstitute/sting/utils/codecs/bcf2/BCF2Utils.java +++ b/public/java/src/org/broadinstitute/sting/utils/codecs/bcf2/BCF2Utils.java @@ -32,10 +32,7 @@ import org.broadinstitute.sting.utils.codecs.vcf.VCFHeaderLine; import org.broadinstitute.sting.utils.codecs.vcf.VCFIDHeaderLine; import org.broadinstitute.sting.utils.exceptions.ReviewedStingException; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; +import java.io.*; import java.util.*; /** @@ -207,14 +204,27 @@ public final class BCF2Utils { * @return the BCF */ @Requires("vcfFile != null") - @Ensures("result != null") public static final File shadowBCF(final File vcfFile) { final String path = vcfFile.getAbsolutePath(); if ( path.contains(".vcf") ) return new File(path.replace(".vcf", ".bcf")); else { final File bcf = new File( path + ".bcf" ); - return bcf.canWrite() ? bcf : null; + if ( bcf.canRead() ) + return bcf; + else { + try { + // this is the only way to robustly decide if we could actually write to BCF + final FileOutputStream o = new FileOutputStream(bcf); + o.close(); + bcf.delete(); + return bcf; + } catch ( FileNotFoundException e ) { + return null; + } catch ( IOException e ) { + return null; + } + } } } diff --git a/public/java/test/org/broadinstitute/sting/utils/codecs/vcf/VCFIntegrationTest.java b/public/java/test/org/broadinstitute/sting/utils/codecs/vcf/VCFIntegrationTest.java index 3a5f2efe8..14b75fbc6 100644 --- a/public/java/test/org/broadinstitute/sting/utils/codecs/vcf/VCFIntegrationTest.java +++ b/public/java/test/org/broadinstitute/sting/utils/codecs/vcf/VCFIntegrationTest.java @@ -30,7 +30,6 @@ public class VCFIntegrationTest extends WalkerTest { // See https://getsatisfaction.com/gsa/topics/support_vcf_4_1_structural_variation_breakend_alleles?utm_content=topic_link&utm_medium=email&utm_source=new_topic public void testReadingAndWritingBreakpointAlleles() { String testVCF = privateTestDir + "breakpoint-example.vcf"; - //String testVCF = validationDataLocation + "multiallelic.vcf"; String baseCommand = "-R " + b37KGReference + " --no_cmdline_in_header -o %s "; @@ -51,11 +50,20 @@ public class VCFIntegrationTest extends WalkerTest { } @Test - public void testReadingAndWritingSamtoolsWExBCFExample() { + public void testWritingSamtoolsWExBCFExample() { String testVCF = privateTestDir + "ex2.vcf"; String baseCommand = "-R " + b36KGReference + " --no_cmdline_in_header -o %s "; String test1 = baseCommand + "-T SelectVariants -V " + testVCF; WalkerTestSpec spec1 = new WalkerTestSpec(test1, 1, Arrays.asList("9773d6a121cfcb18d090965bc520f120")); - executeTest("Test reading and writing samtools WEx vcf/BCF example", spec1); + executeTest("Test writing samtools WEx BCF example", spec1); + } + + @Test + public void testReadingSamtoolsWExBCFExample() { + String testVCF = privateTestDir + "ex2.bcf"; + String baseCommand = "-R " + b36KGReference + " --no_cmdline_in_header -o %s "; + String test1 = baseCommand + "-T SelectVariants -V " + testVCF; + WalkerTestSpec spec1 = new WalkerTestSpec(test1, 1, Arrays.asList("63a2e0484ae37b0680514f53e0bf0c94")); + executeTest("Test reading samtools WEx BCF example", spec1); } }