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:
parent
cfb994abd2
commit
34b62fa092
|
|
@ -730,7 +730,13 @@ public class SelectVariants extends RodWalker<Integer, Integer> implements TreeR
|
||||||
if ( vc.getAlleles().size() != sub.getAlleles().size() )
|
if ( vc.getAlleles().size() != sub.getAlleles().size() )
|
||||||
newGC = VariantContextUtils.stripPLs(sub.getGenotypes());
|
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 ){
|
if ( fractionGenotypes > 0 ){
|
||||||
ArrayList<Genotype> genotypes = new ArrayList<Genotype>();
|
ArrayList<Genotype> genotypes = new ArrayList<Genotype>();
|
||||||
for ( Genotype genotype : newGC ) {
|
for ( Genotype genotype : newGC ) {
|
||||||
|
|
@ -767,17 +773,21 @@ public class SelectVariants extends RodWalker<Integer, Integer> implements TreeR
|
||||||
|
|
||||||
VariantContextUtils.calculateChromosomeCounts(builder, false);
|
VariantContextUtils.calculateChromosomeCounts(builder, false);
|
||||||
|
|
||||||
|
boolean sawDP = false;
|
||||||
int depth = 0;
|
int depth = 0;
|
||||||
for (String sample : originalVC.getSampleNames()) {
|
for (String sample : originalVC.getSampleNames()) {
|
||||||
Genotype g = originalVC.getGenotype(sample);
|
Genotype g = originalVC.getGenotype(sample);
|
||||||
|
|
||||||
if ( ! g.isFiltered() ) {
|
if ( ! g.isFiltered() ) {
|
||||||
if ( g.hasDP() )
|
if ( g.hasDP() ) {
|
||||||
depth += g.getDP();
|
depth += g.getDP();
|
||||||
|
sawDP = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.attribute("DP", depth);
|
if ( sawDP )
|
||||||
|
builder.attribute("DP", depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void randomlyAddVariant(int rank, VariantContext vc) {
|
private void randomlyAddVariant(int rank, VariantContext vc) {
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,32 @@ public class SelectVariantsIntegrationTest extends WalkerTest {
|
||||||
executeTest("testRegenotype--" + testFile, spec);
|
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
|
@Test
|
||||||
public void testMultipleRecordsAtOnePosition() {
|
public void testMultipleRecordsAtOnePosition() {
|
||||||
String testFile = privateTestDir + "selectVariants.onePosition.vcf";
|
String testFile = privateTestDir + "selectVariants.onePosition.vcf";
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue