rule mark_duplicates:
    """ 
    Mark reads duplicated. Thus, variant caller is aware of duplicated reads.

    Required input:
        __mark_duplicates__input: bam file

    Required output:
        __mark_duplicates__output: bam file

    Required configuration:
        .. code-block:: yaml

            mark_duplicates:
                remove:  # yes/no
                tmpdir:  # temporary directory
    """
    input:
        __mark_duplicates__input
    output:
        bam = __mark_duplicates__output,
        metrics = __mark_duplicates__metrics
    log:
        out = __mark_duplicates__log_std,
        err = __mark_duplicates__log_err
    params:
        remove = config["mark_duplicates"]["remove"],
        tmpdir = config["mark_duplicates"]["tmpdir"]
    threads:
        int(config["mark_duplicate"]["threads"])
    shell:
        """
        (picard MarkDuplicates I={input} O={output.bam} \
            M={output.metrics} REMOVE_DUPLICATES={params.remove} \
            TMP_DIR={params.tmpdir} && samtools index {output.bam}) \
            > {log.out} 2> {log.err}
        """
