Two changes to SelectVariants: 1) don't add DP INFO annotation if DP wasn't used in the input VCF (it was adding DP=0 previously). 2) If MLEAC or MLEAF is present in the original VCF and the number of samples decreases, remove those annotations from the VC.

This commit is contained in:
Eric Banks 2012-08-14 12:54:31 -04:00
parent cfb994abd2
commit 34b62fa092
2 changed files with 39 additions and 3 deletions

View File

@ -730,7 +730,13 @@ public class SelectVariants extends RodWalker<Integer, Integer> implements TreeR
if ( vc.getAlleles().size() != sub.getAlleles().size() )
newGC = VariantContextUtils.stripPLs(sub.getGenotypes());
//Remove a fraction of the genotypes if needed
// if we have fewer samples in the selected VC than in the original VC, we need to strip out the MLE tags
if ( vc.getNSamples() != sub.getNSamples() ) {
builder.rmAttribute(VCFConstants.MLE_ALLELE_COUNT_KEY);
builder.rmAttribute(VCFConstants.MLE_ALLELE_FREQUENCY_KEY);
}
// Remove a fraction of the genotypes if needed
if ( fractionGenotypes > 0 ){
ArrayList<Genotype> genotypes = new ArrayList<Genotype>();
for ( Genotype genotype : newGC ) {
@ -767,17 +773,21 @@ public class SelectVariants extends RodWalker<Integer, Integer> implements TreeR
VariantContextUtils.calculateChromosomeCounts(builder, false);
boolean sawDP = false;
int depth = 0;
for (String sample : originalVC.getSampleNames()) {
Genotype g = originalVC.getGenotype(sample);
if ( ! g.isFiltered() ) {
if ( g.hasDP() )
if ( g.hasDP() ) {
depth += g.getDP();
sawDP = true;
}
}
}
builder.attribute("DP", depth);
if ( sawDP )
builder.attribute("DP", depth);
}
private void randomlyAddVariant(int rank, VariantContext vc) {

View File

@ -154,6 +154,32 @@ public class SelectVariantsIntegrationTest extends WalkerTest {
executeTest("testRegenotype--" + testFile, spec);
}
@Test
public void testRemoveMLE() {
String testFile = privateTestDir + "vcfexample.withMLE.vcf";
WalkerTestSpec spec = new WalkerTestSpec(
"-T SelectVariants -R " + b36KGReference + " -sn NA12892 --variant " + testFile + " -o %s --no_cmdline_in_header",
1,
Arrays.asList("")
);
executeTest("testRegenotype--" + testFile, spec);
}
@Test
public void testRemoveMLEAndRegenotype() {
String testFile = privateTestDir + "vcfexample.withMLE.vcf";
WalkerTestSpec spec = new WalkerTestSpec(
"-T SelectVariants -R " + b36KGReference + " -regenotype -sn NA12892 --variant " + testFile + " -o %s --no_cmdline_in_header",
1,
Arrays.asList("")
);
executeTest("testRegenotype--" + testFile, spec);
}
@Test
public void testMultipleRecordsAtOnePosition() {
String testFile = privateTestDir + "selectVariants.onePosition.vcf";