rule freebayes_bcf_filter:
    """ It filters BCF file from freebayes with score, coverage depth and
    strand ratio. This rule needs atleast pysam version 0.10.

    Required input:
        __freebayes_bcf_filter__input: BCF file from freebayes

    Required output:
        __freebayes_bcf_filter__output: filtered VCF file
        __freebayes_bcf_filter__csv: CSV file

    Required parameters:
        config["freebayes_bcf_filter"]["freebayes_score"]: minimal freebayes score
        config["freebayes_bcf_filter"]["frequency"]: minimal alternative allele frequency
        config["freebayes_bcf_filter"]["depth"]: minimal coverage depth
        config["freebayes_bcf_filter"]["forward_depth"]: minimal coverage depth of
            forward strand
        config["freebayes_bcf_filter"]["reverse_depth"]: minimal coverage depth of
            reverse strand
        config["freebayes_bcf_filter"]["strand_ratio"]: minimal strand ratio [0:0.5]
    """
    input:
        bcf = __freebayes_bcf_filter__input
    output:
        vcf = __freebayes_bcf_filter__output,
        csv = __freebayes_bcf_filter__csv
    params:
        filter_dict = config['freebayes_bcf_filter']
    run:
        from easydev import TempFile
        from sequana.freebayes_bcf_filter import BCF_freebayes
        
        bcf = BCF_freebayes(input['bcf'])
        filter_bcf = bcf.filter_bcf(params['filter_dict'])
        filter_bcf.to_vcf(output['vcf'])
        filter_bcf.to_csv(output['csv'])
