VariantsToTable now blows up by default if you ask for a field that isn't present in a record.
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@5636 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
b3cd14d10a
commit
8ed9c0f518
|
|
@ -58,8 +58,11 @@ public class VariantsToTable extends RodWalker<Integer, Integer> {
|
|||
public int MAX_RECORDS = -1;
|
||||
int nRecords = 0;
|
||||
|
||||
@Argument(fullName="ignoreMultiAllelic", shortName="IMA", doc="If provided, we will not require the site to be biallelic", required=false)
|
||||
public boolean ignoreMultiAllelic = false;
|
||||
@Argument(fullName="keepMultiAllelic", shortName="KMA", doc="If provided, we will not require the site to be biallelic", required=false)
|
||||
public boolean keepMultiAllelic = false;
|
||||
|
||||
@Argument(fullName="allowMissingData", shortName="AMD", doc="If provided, we will not require every record to contain every field", required=false)
|
||||
public boolean ALLOW_MISSING_DATA = false;
|
||||
|
||||
public void initialize() {
|
||||
out.println(Utils.join("\t", fieldsToTake));
|
||||
|
|
@ -119,8 +122,8 @@ public class VariantsToTable extends RodWalker<Integer, Integer> {
|
|||
if ( ++nRecords < MAX_RECORDS || MAX_RECORDS == -1 ) {
|
||||
Collection<VariantContext> vcs = tracker.getAllVariantContexts(ref, context.getLocation());
|
||||
for ( VariantContext vc : vcs) {
|
||||
if ( (! ignoreMultiAllelic || vc.isBiallelic()) && ( showFiltered || vc.isNotFiltered() ) ) {
|
||||
List<String> vals = extractFields(vc, fieldsToTake);
|
||||
if ( (keepMultiAllelic || vc.isBiallelic()) && ( showFiltered || vc.isNotFiltered() ) ) {
|
||||
List<String> vals = extractFields(vc, fieldsToTake, ALLOW_MISSING_DATA);
|
||||
out.println(Utils.join("\t", vals));
|
||||
}
|
||||
}
|
||||
|
|
@ -139,7 +142,7 @@ public class VariantsToTable extends RodWalker<Integer, Integer> {
|
|||
return s.endsWith("*");
|
||||
}
|
||||
|
||||
public static List<String> extractFields(VariantContext vc, List<String> fields) {
|
||||
public static List<String> extractFields(VariantContext vc, List<String> fields, boolean allowMissingData) {
|
||||
List<String> vals = new ArrayList<String>();
|
||||
|
||||
for ( String field : fields ) {
|
||||
|
|
@ -162,6 +165,8 @@ public class VariantsToTable extends RodWalker<Integer, Integer> {
|
|||
Collections.sort(toVal);
|
||||
val = Utils.join(",", toVal);
|
||||
}
|
||||
} else if ( ! allowMissingData ) {
|
||||
throw new UserException(String.format("Missing field %s in vc %s at %s", field, vc.getSource(), vc));
|
||||
}
|
||||
|
||||
vals.add(val);
|
||||
|
|
|
|||
|
|
@ -33,16 +33,24 @@ import java.util.*;
|
|||
import java.io.File;
|
||||
|
||||
public class VariantsToTableIntegrationTest extends WalkerTest {
|
||||
private String variantsToTableCmd(String moreArgs) {
|
||||
return "-R " + hg18Reference +
|
||||
" -B:eval,vcf " + validationDataLocation + "/soap_gatk_annotated.vcf" +
|
||||
" -T VariantsToTable" +
|
||||
" -F CHROM -F POS -F ID -F REF -F ALT -F QUAL -F FILTER -F TRANSITION -F DP -F SB -F set -F RankSumP -F refseq.functionalClass*" +
|
||||
" -L chr1 -KMA -o %s" + moreArgs;
|
||||
}
|
||||
|
||||
@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 -F POS -F ID -F REF -F ALT -F QUAL -F FILTER -F TRANSITION -F DP -F SB -F set -F RankSumP -F refseq.functionalClass*" +
|
||||
" -L chr1 -o %s",
|
||||
WalkerTestSpec spec = new WalkerTestSpec(variantsToTableCmd(" -AMD"),
|
||||
Arrays.asList("b2a3712c1bfad8f1383ffada8b5017ba"));
|
||||
executeTest("testComplexVariantsToTable", spec).getFirst();
|
||||
}
|
||||
|
||||
@Test(enabled = true)
|
||||
public void testComplexVariantsToTableFail() {
|
||||
WalkerTestSpec spec = new WalkerTestSpec(variantsToTableCmd(""), 1, UserException.class);
|
||||
executeTest("testComplexVariantsToTable-FAIL", spec);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue