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
This commit is contained in:
parent
302cc13735
commit
721e8cb679
|
|
@ -119,7 +119,6 @@ public class VariantsToTable extends RodWalker<Integer, Integer> {
|
|||
for ( VariantContext vc : vcs) {
|
||||
if ( (! ignoreMultiAllelic || vc.isBiallelic()) && ( showFiltered || vc.isNotFiltered() ) ) {
|
||||
List<String> vals = extractFields(vc, fieldsToTake);
|
||||
|
||||
out.println(Utils.join("\t", vals));
|
||||
}
|
||||
}
|
||||
|
|
@ -134,6 +133,10 @@ public class VariantsToTable extends RodWalker<Integer, Integer> {
|
|||
}
|
||||
}
|
||||
|
||||
private static final boolean isWildCard(String s) {
|
||||
return s.endsWith("*");
|
||||
}
|
||||
|
||||
public static List<String> extractFields(VariantContext vc, List<String> fields) {
|
||||
List<String> vals = new ArrayList<String>();
|
||||
|
||||
|
|
@ -144,6 +147,19 @@ public class VariantsToTable extends RodWalker<Integer, Integer> {
|
|||
val = getters.get(field).get(vc);
|
||||
} else if ( vc.hasAttribute(field) ) {
|
||||
val = vc.getAttributeAsString(field);
|
||||
} else if ( isWildCard(field) ) {
|
||||
Set<String> wildVals = new HashSet<String>();
|
||||
for ( Map.Entry<String,Object> elt : vc.getAttributes().entrySet()) {
|
||||
if ( elt.getKey().startsWith(field.substring(0, field.length() - 1)) ) {
|
||||
wildVals.add(elt.getValue().toString());
|
||||
}
|
||||
}
|
||||
|
||||
if ( wildVals.size() > 0 ) {
|
||||
List<String> toVal = new ArrayList<String>(wildVals);
|
||||
Collections.sort(toVal);
|
||||
val = Utils.join(",", toVal);
|
||||
}
|
||||
}
|
||||
|
||||
vals.add(val);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue