phe.variant_filters

Module contents

Classes and functions for working with variant filters.

Implementing Filter

The PHEFilterBase class was designed to be implemented in order to provide new filters for processing. As such it should be easy to extend PHEFilterBase to achieve this.

If you are not familiar with Python and classes please read this. It is a general introduction to the subject.

Implementation of a filter closely follows the structure for PyVCF

PHEBaseFilter adds additional infomations that is also added to the VCF header:

  • PHEFilterBase.parameter - Atrribute that allows dynmic loader to pickup the filter.This is the name used in command line arguments and configs.
  • PHEFilterBase._default_threshold - Default threshold used for the filter when non specified.
  • PHEFilterBase.short_desc() - Method for defining what the short description is dynamically.
  • PHEFilterBase.__call__() - Function that does the filtering (the same as PyVCF).

The most important of these is the __call__ function, as this is what does the filtering. It needs to return the following:

  • None if the record PASSES the filter.
  • Non None expressions are treated as failures.

Note

While it may not be obvious, but Python always returns a value. When no return statement is specified, None is returned to the calling function.

False is returned when data can not be accessed by the filter.

Once you have implemented the filter and saved it in the variant_filters directory, it should be automatically picked up by the system and available to filter on. To verify this run:

run_snp_pipeline.py --help

You filter should now be visible in the list of available filters.

Example

class MyFilter(PHEFilterBase):
    name="CoolQUAL"
    _default_threshold=40
    parameter=cool_qual

    def __init__(self, args):
        # Construct any specific details for the object

    def __call__(self, record):
        if record.QUAL < self.threshold:
            return record.QUAL

    def short_desc(self):
        return "My cool QUAL filter"
Date:24 Sep, 2015
Author:Alex Jironkin
class PHEFilterBase(args)[source]

Bases: vcf.filters.Base

Base class for VCF filters.

Attributes:
parameter

Short name of parameter being filtered.

Methods

__call__() filter a site, return not None if the site should be filtered
customize_parser(parser) hook to extend argparse parser with custom arguments
decode(filter_id) Decode name of filter.
filter_name() Create filter names by their parameter separated by magic.
get_config() This is used for reconstructing filter.
is_uncallable(record) Filter a vcf.model._Record.
short_desc() Short description of the filter (included in VCF).
call_concensus  
is_gap  
is_n  
static call_concensus(record)[source]
static decode(filter_id)[source]

Decode name of filter.

decoder_pattern = <_sre.SRE_Pattern object>
filter_name()[source]

Create filter names by their parameter separated by magic. E.g. if filter parameter is ad_ratio and threshold is 0.9 then ad_ratio:0.9 if the filter name.

get_config()[source]

This is used for reconstructing filter.

is_gap()[source]
is_n()[source]
is_uncallable(record)[source]

Filter a vcf.model._Record.

magic_sep = ':'
parameter

Short name of parameter being filtered.

short_desc()[source]

Short description of the filter (included in VCF).

available_filters()[source]

Return list of available filters.

dynamic_filter_loader()[source]

Fancy way of dynamically importing existing filters.

Returns:
dict:

Available filters dictionary. Keys are parameters that can be supplied to the filters.

make_filters(config)[source]

Create a list of filters from config.

str_to_filters(filters)[source]

Convert from filter string to array of filters. E.g. ad_ration:0.9,min_depth:5

Parameters:
filters: str

String version of filters, separated by comma.

Returns:
list:

List of phe.variant_filters.PHEFilterBase instances.