

shell.prefix("export PATH=../target/debug:$PATH; ")


SAMPLES = {"HG00100": "mpileup.1.bam", "HG00101": "mpileup.2.bam"}
QUERIES = {"1": "HG00100 - HG00101", "2": "HG00100"}


rule all:
    input:
        expand("calls.{query}.bcf", query="1 2".split()),


rule test_preprocess:
    input:
        "mpileup.ref.fa",
        lambda wildcards: SAMPLES[wildcards.sample],
    output:
        "{sample}.bcf",
    threads: 8
    shell:
        "alpaca preprocess -t {threads} {input} > {output}"


rule test_merge:
    input:
        fa="mpileup.ref.fa",
        bcf=expand("{sample}.bcf", sample=SAMPLES),
        csi=expand("{sample}.bcf.csi", sample=SAMPLES),
    output:
        "all.bcf",
    threads: 8
    shell:
        "alpaca merge -t {threads} {input.fa} {input.bcf} > {output}"


rule test_call:
    input:
        "all.bcf",
    output:
        "calls.{query,(1|2|3)}.bcf",
    params:
        query=lambda wildcards: QUERIES[wildcards.query]
    threads: 8
    shell:
        "alpaca call -t {threads} --fdr 0.05 '{params.query}' < {input} > {output}"


rule index_bcf:
    input:
        "{prefix}.bcf"
    output:
        "{prefix}.bcf.csi"
    shell:
        "bcftools index -f {input}"

