def cutoff_w_expression(vcf_file, expression, data, name="+", filterext="",
                      extra_cmd="", limit_regions="variant_regions"):
    """Perform cutoff-based soft filtering using bcftools expressions like %QUAL < 20 || DP < 4.
    """
    base, ext = utils.splitext_plus(vcf_file)
    out_file = "{base}-filter{filterext}{ext}".format(**locals())
    if not utils.file_exists(out_file):
        with file_transaction(data, out_file) as tx_out_file:
            if vcfutils.vcf_has_variants(vcf_file):
                bcftools = config_utils.get_program("bcftools", data["config"])
                bgzip_cmd = "| bgzip -c" if out_file.endswith(".gz") else ""
                intervals = ""
                if limit_regions == "variant_regions":
                    variant_regions = dd.get_variant_regions(data)
                    if variant_regions:
                        intervals = "-T %s" % vcfutils.bgzip_and_index(variant_regions, data["config"])
                cmd = ("{bcftools} filter -O v {intervals} --soft-filter '{name}' "
                       "-e '{expression}' -m '+' {vcf_file} {extra_cmd} {bgzip_cmd} > {tx_out_file}")
                do.run(cmd.format(**locals()),
                       "Cutoff-based soft filtering %s with %s" % (vcf_file, expression), data)
            else:
                shutil.copy(vcf_file, out_file)
    if out_file.endswith(".vcf.gz"):
        out_file = vcfutils.bgzip_and_index(out_file, data["config"])
    return out_file
def cutoff_w_expression ( vcf_file , expression , data , name = "+" , filterext = "" , extra_cmd = "" , limit_regions = "variant_regions" ) : base , ext = utils . splitext_plus ( vcf_file ) out_file = "{base}-filter{filterext}{ext}" . format ( ** locals ( ) ) if not utils . file_exists ( out_file ) : with file_transaction ( data , out_file ) as tx_out_file : if vcfutils . vcf_has_variants ( vcf_file ) : bcftools = config_utils . get_program ( "bcftools" , data [ "config" ] ) bgzip_cmd = "| bgzip -c" if out_file . endswith ( ".gz" ) else "" intervals = "" if limit_regions == "variant_regions" : variant_regions = dd . get_variant_regions ( data ) if variant_regions : intervals = "-T %s" % vcfutils . bgzip_and_index ( variant_regions , data [ "config" ] ) cmd = ( "{bcftools} filter -O v {intervals} --soft-filter '{name}' " "-e '{expression}' -m '+' {vcf_file} {extra_cmd} {bgzip_cmd} > {tx_out_file}" ) do . run ( cmd . format ( ** locals ( ) ) , "Cutoff-based soft filtering %s with %s" % ( vcf_file , expression ) , data ) else : shutil . copy ( vcf_file , out_file ) if out_file . endswith ( ".vcf.gz" ) : out_file = vcfutils . bgzip_and_index ( out_file , data [ "config" ] ) return out_file
Perform cutoff-based soft filtering using bcftools expressions like %QUAL < 20 || DP < 4.