Skip to content

Commit

Permalink
* Ensure that filters are only called if they are explicitely set on …
Browse files Browse the repository at this point in the history
…the command line
  • Loading branch information
pvanheus committed Aug 6, 2023
1 parent 463245a commit 7739f9e
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/tb_variant_filter/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def filter_vcf_file(args: argparse.ArgumentParser):

variant_filters = []
for filter_class in get_filters():
variant_filters.append(filter_class(args, header))
filter = filter_class(args, header)
if filter.active:
variant_filters.append(filter)

variant_filter = UnionFilter(variant_filters)
print(variant_filter, file=sys.stderr)
Expand Down
1 change: 1 addition & 0 deletions src/tb_variant_filter/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

class Filter(object):
def __init__(self, args: argparse.Namespace, header: Header):
self.active = False
self.header = header

@abstractmethod
Expand Down
1 change: 1 addition & 0 deletions src/tb_variant_filter/filters/alt_percentage_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, args: argparse.Namespace, header: vcfpy.Header) -> "AltPercen
and args.min_percentage_alt_filter # noqa W503
and hasattr(args, "min_percentage_alt") # noqa W503
):
self.active = True
self.min_percentage = args.min_percentage_alt

@classmethod
Expand Down
1 change: 1 addition & 0 deletions src/tb_variant_filter/filters/close_to_indel_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, args: argparse.Namespace, header: Header) -> "CloseToIndelFil
super().__init__(args, header)
self.intervaltree = IntervalTree()
if hasattr(args, "close_to_indel_filter") and args.close_to_indel_filter:
self.active = True
# we need to re-open the input file because it was already read to get the header
reader = Reader(open(args.input_file.name))
dist = args.indel_window_size
Expand Down
1 change: 1 addition & 0 deletions src/tb_variant_filter/filters/min_depth_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, args: argparse.Namespace, header: vcfpy.Header) -> "MinDepthF
and args.min_depth_filter # noqa W503
and hasattr(args, "min_depth") # noqa W503
):
self.active = True
self.min_depth = args.min_depth

@classmethod
Expand Down
1 change: 1 addition & 0 deletions src/tb_variant_filter/filters/region_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(self, args: argparse.Namespace, header: Header) -> "RegionFilter":
super().__init__(args, header)
self.intervaltree = IntervalTree()
if hasattr(args, "region_filter"):
self.active = True
self.region_names = args.region_filter
for name in args.region_filter:
regions = REGIONS[name].regions
Expand Down
1 change: 1 addition & 0 deletions src/tb_variant_filter/filters/snv_only_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class SnvOnly(Filter):
def __init__(self, args: argparse.Namespace, header: vcfpy.Header) -> "SnvOnly":
super().__init__(args, header)
if hasattr(args, "snv_only_filter") and args.snv_only_filter:
self.active = True
self.snv_only = True

@classmethod
Expand Down

0 comments on commit 7739f9e

Please sign in to comment.