Skip to content

Commit

Permalink
filter variant tranches removes old filters by default
Browse files Browse the repository at this point in the history
  • Loading branch information
lucidtronix committed Jul 20, 2018
1 parent 0bcc3a0 commit 2e3b210
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public class FilterVariantTranches extends TwoPassVariantWalker {
@Argument(fullName = "info-key", shortName = "info-key", doc = "The key must be in the INFO field of the input VCF.")
private String infoKey = GATKVCFConstants.CNN_2D_KEY;

@Argument(fullName = "keep-old-filters", shortName = "keep-old-filters", doc = "Keeps filters already in the VCF.", optional=true)
private boolean keepOldFilters = false;

private VariantContextWriter vcfWriter;
private List<Double> snpScores = new ArrayList<>();
private List<Double> snpCutoffs = new ArrayList<>();
Expand Down Expand Up @@ -155,7 +158,9 @@ public void afterFirstPass() {
@Override
protected void secondPassApply(VariantContext variant, ReadsContext readsContext, ReferenceContext referenceContext, FeatureContext featureContext) {
final VariantContextBuilder builder = new VariantContextBuilder(variant);

if (!keepOldFilters) {
builder.unfiltered();
}
if (variant.hasAttribute(infoKey)) {
final double score = Double.parseDouble((String) variant.getAttribute(infoKey));
if (variant.isSNP() && isTrancheFiltered(score, snpCutoffs)) {
Expand Down Expand Up @@ -183,8 +188,12 @@ public void closeTool() {
private void writeVCFHeader(VariantContextWriter vcfWriter) {
// setup the header fields
final VCFHeader inputHeader = getHeaderForVariants();
final Set<VCFHeaderLine> inputHeaders = inputHeader.getMetaDataInSortedOrder();
final Set<VCFHeaderLine> hInfo = new HashSet<>(inputHeaders);
Set<VCFHeaderLine> hInfo = new LinkedHashSet<VCFHeaderLine>();
hInfo.addAll(inputHeader.getMetaDataInSortedOrder());

if (!keepOldFilters){
hInfo.removeIf(x -> x instanceof VCFFilterHeaderLine);
}

if( tranches.size() >= 2 ) {
for(int i = 0; i < tranches.size() - 1; i++) {
Expand All @@ -196,6 +205,7 @@ private void writeVCFHeader(VariantContextWriter vcfWriter) {
String filterKey = filterKeyFromTranches(infoKey, tranches.get(tranches.size()-1), 100.0);
String filterDescription = filterDescriptionFromTranches(infoKey, tranches.get(tranches.size()-1), 100.0);
hInfo.add(new VCFFilterHeaderLine(filterKey, filterDescription));

final TreeSet<String> samples = new TreeSet<>();
samples.addAll(inputHeader.getGenotypeSamples());
hInfo.addAll(getDefaultToolVCFHeaderLines());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,26 @@ public void testTrancheFilteringTranchesOrder() throws IOException {
spec.executeTest("testTrancheFilteringTranchesOrder", this);
}

@Test
public void testTrancheFilteringWithOldFilters() throws IOException {
final String trancheVCF = largeFileTestDir + "VQSR/g94982_20_1m_10m_python_2dcnn.vcf.gz";
final String indelTruthVCF = largeFileTestDir + "VQSR/ALL.wgs.indels_mills_devine_hg19_leftAligned_collapsed_double_hit.sites.20.1M-10M.vcf";
final String snpTruthVCF = largeFileTestDir + "VQSR/Omni25_sites_1525_samples.b37.20.1M-10M.vcf";

final ArgumentsBuilder argsBuilder = new ArgumentsBuilder();
argsBuilder.addArgument(StandardArgumentDefinitions.VARIANT_LONG_NAME, trancheVCF)
.addArgument(StandardArgumentDefinitions.OUTPUT_LONG_NAME, "%s")
.addArgument("resource", snpTruthVCF)
.addArgument("resource", indelTruthVCF)
.addArgument("tranche", "99.0")
.addArgument("info-key", "MIX_SMALL_2D_W_DROPOUT")
.addArgument("keep-old-filters", "true")
.addArgument(StandardArgumentDefinitions.ADD_OUTPUT_VCF_COMMANDLINE, "false");

final IntegrationTestSpec spec = new IntegrationTestSpec(argsBuilder.toString(),
Arrays.asList(largeFileTestDir + "VQSR/expected/g94982_20_1m_10m_tranched_99_with_old_filters.vcf"));
spec.executeTest("testTrancheFiltering", this);

}

}
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown

0 comments on commit 2e3b210

Please sign in to comment.