rule multiBamSummary:
    """
    multiBamSummary computes the read coverages for genomic regions for typically two or more BAM files.
    Is part of deeptools http://deeptools.readthedocs.io/en/latest/index.html

    Required input:
        __multiBamSummary__input: list of bam files

    Required output:
        __multiBamSummary__output: npz file
    """
    input:
        __multiBamSummary__input
    params:
        bs = config['correlation']['binSize']
    log:
        __multiBamSummary__log
    output:
        __multiBamSummary__output
    threads: 4
    run:
        labels = " ".join(str(os.path.basename(label).split("_")[0]) for label in input.bam)
        shell("multiBamSummary bins --bamfiles  {input.bam} --outFileName {output}  --binSize {params.bs} -p {threads} --labels " + labels + " --ignoreDuplicates 2> {log}")

