Commit 5bfe55f2 authored by Sander Bollen's avatar Sander Bollen
Browse files

immediately return upon hitting one filter criterium by default

parent 4a45e848
Pipeline #2126 failed with stage
......@@ -25,7 +25,13 @@ from .gcoverage import *
help="Path to filter params json", required=True)
@click.option('--index-sample', type=click.STRING,
help="Name of index sample", required=True)
def filter_cli(input, output, trash, params_file, index_sample):
help="Immediately write filters to file "
"upon hitting one filter criterium. "
"Default = True")
def filter_cli(input, output, trash, params_file,
index_sample, immediate_return):
vcf = VCF(input, gts012=True)
idx = vcf.samples.index(index_sample)
......@@ -37,7 +43,7 @@ def filter_cli(input, output, trash, params_file, index_sample):
filter_params = FilterParams(params_file)
filter_it = Filterer(vcf, filter_params, idx)
filter_it = Filterer(vcf, filter_params, idx, immediate_return)
for record, fi in filter_it:
if fi is None or len(fi) == 0:
......@@ -103,10 +103,11 @@ class Filterer(object):
We assume gts012 to be set to True in the cyvcf2 readers
def __init__(self, vcf_it, filter_params, index):
def __init__(self, vcf_it, filter_params, index, immediate_return=True):
self.vcf_it = vcf_it
self.filters = filter_params
self.index = index
self.immediate_return = immediate_return
self.canonical_chroms = {"M", "X", "Y"}.union(set(map(str, range(0, 23))))
......@@ -123,28 +124,38 @@ class Filterer(object):
if chrom.startswith("chr"):
chrom = chrom.split("chr")[-1]
if chrom not in self.canonical_chroms:
if self.immediate_return:
return record, [FilterClass.NON_CANONICAL]
if self.filters.index_called:
gt = record.gt_types[self.index]
if gt == 0 or gt == 3:
if self.immediate_return:
return record, [FilterClass.INDEX_UNCALLED]
if self.filters.min_gq is not None:
gq = record.gt_quals[self.index]
if gq < self.filters.min_gq:
if self.immediate_return:
return record, [FilterClass.LOW_GQ]
if self.filters.max_gonl_af is not None:
gonl_af = get_af(record, self.filters.gonl_vcf,
if gonl_af > self.filters.max_gonl_af:
if self.immediate_return:
return record, [FilterClass.TOO_HIGH_GONL_AF]
if self.filters.max_gnomad_af is not None:
gnomad_af = get_af(record, self.filters.gnomad_vcf,
if gnomad_af > self.filters.max_gnomad_af:
if self.immediate_return:
return record, [FilterClass.TOO_HIGH_GNOMAD_AF]
return record, filters
......@@ -154,4 +165,3 @@ class Filterer(object):
def __iter__(self):
return self
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment