GOLEFT INDEXCOV

https://img.shields.io/github/issues-pr/snakemake/snakemake-wrappers/bio/goleft/indexcov?label=version%20update%20pull%20requests

Quickly estimate coverage from a whole-genome bam or cram index

URL: https://github.com/brentp/goleft/tree/master/indexcov#indexcov

Example

This wrapper can be used in the following way:

rule test_goleft_indexcov:
    input:
        aln="sample.bam",
        fai="genome.fai",
    output:
        bed="regions.bed.gz",
        ped="indexcov.ped",
        roc="indexcov.roc",
        html=directory("report"),
    log:
        "indexcov.log",
    params:
        extra="-e",
    wrapper:
        "v3.10.2-10-g08bd3cd/bio/goleft/indexcov"

Note that input, output and log file paths can be chosen freely.

When running with

snakemake --use-conda

the software dependencies will be automatically deployed into an isolated environment before execution.

Notes

Coverage bed, pedigree file, and roc curves are available in the HTML report. Using bed, ped, or roc output keys alongside with html will make these results unavailable in the HTML report, but won’t break HTML content display.

Software dependencies

  • goleft=0.2.6

Input/Output

Input:

  • aln: Path to indexed BAM/CRAM file

  • fai: Path to fasta sequence index

Output:

  • html: Optional path to HTML report

  • bed: Optional path to coverage bed

  • ped: Optional path to pedigree file

  • roc: Optional path to coverage curves

Params

  • extra: Optional parameters besides -d or -r

Authors

  • Thibault Dayris

Code

# coding: utf-8

__author__ = "Thibault Dayris"
__mail__ = "thibault.dayris@gustaveroussy.fr"
__copyright__ = "Copyright 2024, Thibault Dayris"
__license__ = "MIT"

from pathlib import Path
from tempfile import TemporaryDirectory
from snakemake import shell

extra = snakemake.params.get("extra", "")
log = snakemake.log_fmt_shell(stdout=True, stderr=True, append=True)

with TemporaryDirectory() as tempdir:
    shell(
        "goleft indexcov "
        "{extra} "
        "--directory {tempdir}/out "
        "--fai {snakemake.input.fai} "
        "{snakemake.input.aln} "
        "{log} "
    )

    if snakemake.output.get("ped"):
        shell(
            "mv --verbose "
            "{tempdir}/out/out-indexcov.ped "
            "{snakemake.output.ped} "
            "{log} "
        )

    if snakemake.output.get("roc"):
        shell(
            "mv --verbose "
            "{tempdir}/out/out-indexcov.roc "
            "{snakemake.output.roc} "
            "{log} "
        )

    if snakemake.output.get("bed"):
        shell(
            "mv --verbose "
            "{tempdir}/out/out-indexcov.bed.gz "
            "{snakemake.output.bed} "
            "{log} "
        )

    # Number of files withing tempdir output
    # is defined by user command line parameters
    # and/or chromosomes present in the fasta index
    if snakemake.output.get("html"):
        # Not created automatically by Snakemake
        Path(snakemake.output.html).mkdir(parents=True, exist_ok=True)
        shell("mv --verbose {tempdir}/out/* {snakemake.output.html} {log}")