rule bamPEFragmentSize:
    """
    Bam Fragment size computing (PE mode). Is part of deeptools http://deeptools.readthedocs.io/en/latest/index.html

    Required input:
        __bamPEFragmentSize__input_bams: list of bam files

    Required output:
        __bamPEFragmentSize__output: png file
    """

    input:
        bam = __bamPEFragmentSize__input_bams #expand(DIRECTORY + "{sample}_rmdp_sorted.bam", sample=SAMPLES),
    params:
        bs = 10000
    log:
        __bamPEFragmentSize__logs
    output:
        __bamPEFragmentSize__output
    threads: 4
    run:
        labels = " ".join(str(os.path.basename(label).split("_")[0]) for label in input.bam)
        shell("bamPEFragmentSize --bamfiles  {input.bam} --histogram {output}  --binSize {params.bs} -p {threads} --samplesLabel " + labels + "  2> {log}")
