From 721e8cb67981f253442b0768ff55fceefa588c99 Mon Sep 17 00:00:00 2001 From: depristo Date: Thu, 18 Nov 2010 18:54:59 +0000 Subject: [PATCH] VariantsToTable now supports wildcard captures. -F PREFIX* now captures all fields that begin with PREFIX, output as a comma-separated list of unique values. Added integration test for VariantsToTable since I find it so useful. git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@4706 348d0f76-0448-11de-a6fe-93d51630548a --- .../walkers/variantutils/VariantsToTable.java | 18 ++++++- .../VariantToTableIntegrationTest.java | 48 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 java/test/org/broadinstitute/sting/gatk/walkers/variantutils/VariantToTableIntegrationTest.java diff --git a/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToTable.java b/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToTable.java index 40678ec58..26079d94b 100755 --- a/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToTable.java +++ b/java/src/org/broadinstitute/sting/gatk/walkers/variantutils/VariantsToTable.java @@ -119,7 +119,6 @@ public class VariantsToTable extends RodWalker { for ( VariantContext vc : vcs) { if ( (! ignoreMultiAllelic || vc.isBiallelic()) && ( showFiltered || vc.isNotFiltered() ) ) { List vals = extractFields(vc, fieldsToTake); - out.println(Utils.join("\t", vals)); } } @@ -134,6 +133,10 @@ public class VariantsToTable extends RodWalker { } } + private static final boolean isWildCard(String s) { + return s.endsWith("*"); + } + public static List extractFields(VariantContext vc, List fields) { List vals = new ArrayList(); @@ -144,6 +147,19 @@ public class VariantsToTable extends RodWalker { val = getters.get(field).get(vc); } else if ( vc.hasAttribute(field) ) { val = vc.getAttributeAsString(field); + } else if ( isWildCard(field) ) { + Set wildVals = new HashSet(); + for ( Map.Entry elt : vc.getAttributes().entrySet()) { + if ( elt.getKey().startsWith(field.substring(0, field.length() - 1)) ) { + wildVals.add(elt.getValue().toString()); + } + } + + if ( wildVals.size() > 0 ) { + List toVal = new ArrayList(wildVals); + Collections.sort(toVal); + val = Utils.join(",", toVal); + } } vals.add(val); diff --git a/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/VariantToTableIntegrationTest.java b/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/VariantToTableIntegrationTest.java new file mode 100644 index 000000000..a1efbf4a4 --- /dev/null +++ b/java/test/org/broadinstitute/sting/gatk/walkers/variantutils/VariantToTableIntegrationTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2010, The Broad Institute + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +package org.broadinstitute.sting.gatk.walkers.variantutils; + +import org.broadinstitute.sting.WalkerTest; +import org.broadinstitute.sting.utils.exceptions.UserException; +import org.testng.annotations.Test; +import org.testng.annotations.DataProvider; + +import java.util.*; +import java.io.File; + +public class VariantToTableIntegrationTest extends WalkerTest { + @Test(enabled = true) + public void testComplexVariantsToTable() { + // functional class is a wild card operator + WalkerTestSpec spec = new WalkerTestSpec( + "-R " + hg18Reference + + " -B:eval,vcf " + validationDataLocation + "/soap_gatk_annotated.vcf" + + " -T VariantsToTable" + + " -F CHROM,POS,ID,REF,ALT,QUAL,FILTER,TRANSITION,DP,SB,set,RankSumP,refseq.functionalClass*" + + " -L chr1 -o %s", + Arrays.asList("b2a3712c1bfad8f1383ffada8b5017ba")); + executeTest("testComplexVariantsToTable", spec).getFirst(); + } +} \ No newline at end of file