From 6b9e38c8bbf7234b8da3b373c0b9a79e34ff9301 Mon Sep 17 00:00:00 2001 From: Kristian Cibulskis Date: Wed, 16 Apr 2014 19:29:25 -0400 Subject: [PATCH] incorporated comments from review, made variables final, made AF paramater hidden, and added bounds checking to AF value --- .../simulatereads/SimulateReadsForVariants.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/simulatereads/SimulateReadsForVariants.java b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/simulatereads/SimulateReadsForVariants.java index 2ddadc683..a1f4fae49 100644 --- a/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/simulatereads/SimulateReadsForVariants.java +++ b/protected/gatk-protected/src/main/java/org/broadinstitute/sting/gatk/walkers/simulatereads/SimulateReadsForVariants.java @@ -127,6 +127,7 @@ public class SimulateReadsForVariants extends RodWalker { /** * Use this argument to simulate events at a non-50/50 allele fraction represented in the VCF by AF (used for somatic event simulation) */ + @Hidden @Argument(fullName="useAFAsAlleleFraction", shortName="AF", doc="Use AF in VCF as event allele fraction ", required=false) public boolean useAFAsAlleleFraction = false; /** @@ -296,14 +297,19 @@ public class SimulateReadsForVariants extends RodWalker { * @param ref the original reference context * @param useAFAsAlleleFraction use AF tag to indicate allele fraction */ - private void generateReadsForVariant(final VariantContext vc, final ReferenceContext ref, boolean useAFAsAlleleFraction) { + private void generateReadsForVariant(final VariantContext vc, final ReferenceContext ref, final boolean useAFAsAlleleFraction) { final int refLength = vc.getReference().getBases().length; final ArtificialHaplotype refHap = constructHaplotype(vc.getReference(), refLength, ref); final ArtificialHaplotype altHap = constructHaplotype(vc.getAlternateAllele(0), refLength, ref); + final double refAlleleFraction = (useAFAsAlleleFraction)?1-vc.getAttributeAsDouble(VCFConstants.ALLELE_FREQUENCY_KEY, 0.5):0.5; + + if (refAlleleFraction < 0.0 || refAlleleFraction > 1.0 || Double.isNaN(refAlleleFraction) || Double.isInfinite(refAlleleFraction) ) { + throw new UserException.MalformedVCF("Error in AF, must be between 0 and 1 but was " + refAlleleFraction); + } + int gi = 0; - double refAlleleFraction = (useAFAsAlleleFraction)?1-vc.getAttributeAsDouble(VCFConstants.ALLELE_FREQUENCY_KEY, 0.5):0.5f; for ( final Genotype g : vc.getGenotypes() ) { final int myDepth = sampleDepth(); for ( int d = 0; d < myDepth; d++ ) {