From 279dff9f81bfdf996159103fad653d126916f350 Mon Sep 17 00:00:00 2001 From: Guillermo del Angel Date: Tue, 10 Jul 2012 13:59:00 -0400 Subject: [PATCH] Bug fix when specifying a JEXL expression for a field that doesn't exist: we should treat the whole expression as false, but we were rethrowing the JEXL exception in this case. Added integration test to cover this in SelectVariants --- .../utils/variantcontext/VariantJEXLContext.java | 7 ++++++- .../variantutils/SelectVariantsIntegrationTest.java | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/public/java/src/org/broadinstitute/sting/utils/variantcontext/VariantJEXLContext.java b/public/java/src/org/broadinstitute/sting/utils/variantcontext/VariantJEXLContext.java index e25599812..913615a84 100644 --- a/public/java/src/org/broadinstitute/sting/utils/variantcontext/VariantJEXLContext.java +++ b/public/java/src/org/broadinstitute/sting/utils/variantcontext/VariantJEXLContext.java @@ -268,7 +268,12 @@ class JEXLMap implements Map { // treat errors as no match jexl.put(exp, value == null ? false : value); } catch (Exception e) { - throw new UserException.CommandLineException(String.format("Invalid JEXL expression detected for %s with message %s", exp.name, e.getMessage())); + // if exception happens because variable is undefined (i.e. field in expression is not present), evaluate to FALSE + // todo - might be safer if we explicitly checked for an exception type, but Apache's API doesn't seem to have that ability + if (e.getMessage().contains("undefined variable")) + jexl.put(exp,false); + else + throw new UserException.CommandLineException(String.format("Invalid JEXL expression detected for %s with message %s", exp.name, e.getMessage())); } } diff --git a/public/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariantsIntegrationTest.java b/public/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariantsIntegrationTest.java index 59eaa177d..e25d65465 100755 --- a/public/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariantsIntegrationTest.java +++ b/public/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/SelectVariantsIntegrationTest.java @@ -70,6 +70,19 @@ public class SelectVariantsIntegrationTest extends WalkerTest { executeTest("testComplexSelection--" + testfile, spec); } + @Test + public void testNonExistingFieldSelection() { + String testfile = validationDataLocation + "test.filtered.maf_annotated.vcf"; + + WalkerTestSpec spec = new WalkerTestSpec( + baseTestString(" -env -ef -select 'foo!=0||DP>0' --variant " + testfile), + 1, + Arrays.asList("44e77cea624cfff2b8acc3a4b30485cb") // should yield empty vcf because the foo!=0 will yield complete expression false + ); + spec.disableShadowBCF(); + executeTest("testNonExistingSelection--" + testfile, spec); + } + @Test public void testSampleExclusion() { String testfile = validationDataLocation + "test.filtered.maf_annotated.vcf";