Fix for bug reported on forums: VariantsToTable does not handle lists and nested arrays correctly. Added an integration test to cover printing of PLs.
This commit is contained in:
parent
e7798ddd2a
commit
5d6aad67e2
|
|
@ -42,6 +42,7 @@ import org.broadinstitute.sting.utils.exceptions.UserException;
|
||||||
import org.broadinstitute.sting.utils.variantcontext.VariantContextUtils;
|
import org.broadinstitute.sting.utils.variantcontext.VariantContextUtils;
|
||||||
|
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -334,12 +335,12 @@ public class VariantsToTable extends RodWalker<Integer, Integer> {
|
||||||
return records;
|
return records;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addFieldValue(Object val, List<List<String>> result) {
|
private static void addFieldValue(final Object val, final List<List<String>> result) {
|
||||||
final int numResultRecords = result.size();
|
final int numResultRecords = result.size();
|
||||||
|
|
||||||
// if we're trying to create a single output record, add it
|
// if we're trying to create a single output record, add it
|
||||||
if ( numResultRecords == 1 ) {
|
if ( numResultRecords == 1 ) {
|
||||||
result.get(0).add(val.toString());
|
result.get(0).add(prettyPrintObject(val));
|
||||||
}
|
}
|
||||||
// if this field is a list of the proper size, add the appropriate entry to each record
|
// if this field is a list of the proper size, add the appropriate entry to each record
|
||||||
else if ( (val instanceof List) && ((List)val).size() == numResultRecords ) {
|
else if ( (val instanceof List) && ((List)val).size() == numResultRecords ) {
|
||||||
|
|
@ -355,6 +356,26 @@ public class VariantsToTable extends RodWalker<Integer, Integer> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String prettyPrintObject(final Object val) {
|
||||||
|
if ( val instanceof List )
|
||||||
|
return prettyPrintObject(((List)val).toArray());
|
||||||
|
|
||||||
|
if ( !val.getClass().isArray() )
|
||||||
|
return val.toString();
|
||||||
|
|
||||||
|
final int length = Array.getLength(val);
|
||||||
|
if ( length == 0 )
|
||||||
|
return "";
|
||||||
|
|
||||||
|
final StringBuilder sb = new StringBuilder(prettyPrintObject(Array.get(val, 0)));
|
||||||
|
for ( int i = 1; i < length; i++ ) {
|
||||||
|
sb.append(",");
|
||||||
|
sb.append(prettyPrintObject(Array.get(val, i)));
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static List<List<String>> extractFields(VariantContext vc, List<String> fields, boolean allowMissingData) {
|
public static List<List<String>> extractFields(VariantContext vc, List<String> fields, boolean allowMissingData) {
|
||||||
return extractFields(vc, fields, null, null, allowMissingData, false);
|
return extractFields(vc, fields, null, null, allowMissingData, false);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ public class VariantsToTableIntegrationTest extends WalkerTest {
|
||||||
@Test(enabled = true)
|
@Test(enabled = true)
|
||||||
public void testMultiAllelicOneRecord() {
|
public void testMultiAllelicOneRecord() {
|
||||||
WalkerTestSpec spec = new WalkerTestSpec(variantsToTableMultiAllelicCmd(""),
|
WalkerTestSpec spec = new WalkerTestSpec(variantsToTableMultiAllelicCmd(""),
|
||||||
Arrays.asList("13dd36c08be6c800f23988e6000d963e"));
|
Arrays.asList("0ff49c08690f61a38614606a090f23ea"));
|
||||||
executeTest("testMultiAllelicOneRecord", spec);
|
executeTest("testMultiAllelicOneRecord", spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,6 +100,19 @@ public class VariantsToTableIntegrationTest extends WalkerTest {
|
||||||
executeTest("testGenotypeFieldsWithInline", spec);
|
executeTest("testGenotypeFieldsWithInline", spec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(enabled = true)
|
||||||
|
public void testListFields() {
|
||||||
|
WalkerTest.WalkerTestSpec spec = new WalkerTest.WalkerTestSpec(
|
||||||
|
"-R " + b36KGReference +
|
||||||
|
" --variant " + privateTestDir + "vcfexample.withMLE.vcf" +
|
||||||
|
" -T VariantsToTable" +
|
||||||
|
" -GF PL" +
|
||||||
|
" -o %s",
|
||||||
|
1,
|
||||||
|
Arrays.asList("1cb2737ab0eaee0a9ae25ab2e7ac3e7e"));
|
||||||
|
executeTest("testGenotypeFields", spec);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(enabled = true)
|
@Test(enabled = true)
|
||||||
public void testMoltenOutput() {
|
public void testMoltenOutput() {
|
||||||
WalkerTest.WalkerTestSpec spec = new WalkerTest.WalkerTestSpec(
|
WalkerTest.WalkerTestSpec spec = new WalkerTest.WalkerTestSpec(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue