From 9f260c0dc12cc5c0ea54df5c5eb23a480cbc4d8e Mon Sep 17 00:00:00 2001 From: Mark DePristo Date: Fri, 4 Nov 2011 09:45:20 -0400 Subject: [PATCH] Zero byte index bug fix for RandomlySplitVariants + cleanup -- vcfWriter2 was never being closed in onTraversalDone(), so the on the fly index file was being created but never actually properly written to the file. -- This bug is ultimately due to the inability of the GATK to allow multiple VCF output writers as @Output arguments, though -- Removed the unnecessary local variable iFraction, = 1000 * the input fraction argument. Now the system just uses a double random number and compares to the input fraction at all. Is there some subtle reason I don't appreciate for this programming construct? --- .../walkers/variantutils/RandomlySplitVariants.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/RandomlySplitVariants.java b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/RandomlySplitVariants.java index fa5093839..88de12f9a 100755 --- a/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/RandomlySplitVariants.java +++ b/public/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/RandomlySplitVariants.java @@ -58,15 +58,12 @@ public class RandomlySplitVariants extends RodWalker { @Argument(fullName="fractionToOut1", shortName="fraction", doc="Fraction of records to be placed in out1 (must be 0 >= fraction <= 1); all other records are placed in out2", required=false) protected double fraction = 0.5; - protected int iFraction; - /** * Set up the VCF writer, the sample expressions and regexs, and the JEXL matcher */ public void initialize() { if ( fraction < 0.0 || fraction > 1.0 ) throw new UserException.BadArgumentValue("fractionToOut1", "this value needs to be a number between 0 and 1"); - iFraction = (int)(fraction * 1000.0); // setup the header info final List inputNames = Arrays.asList(variantCollection.variants.getName()); @@ -93,8 +90,8 @@ public class RandomlySplitVariants extends RodWalker { Collection vcs = tracker.getValues(variantCollection.variants, context.getLocation()); for ( VariantContext vc : vcs ) { - int random = GenomeAnalysisEngine.getRandomGenerator().nextInt(1000); - if ( random < iFraction ) + double random = GenomeAnalysisEngine.getRandomGenerator().nextDouble(); + if ( random < fraction ) vcfWriter1.add(vc); else vcfWriter2.add(vc); @@ -107,5 +104,8 @@ public class RandomlySplitVariants extends RodWalker { public Integer reduce(Integer value, Integer sum) { return value + sum; } - public void onTraversalDone(Integer result) { logger.info(result + " records processed."); } + public void onTraversalDone(Integer result) { + logger.info(result + " records processed."); + vcfWriter2.close(); + } }