CNVKIT DIAGRAM

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

Draw copy number (either individual bins (.cnn, .cnr) or segments (.cns)) on chromosomes as an ideogram. If both the bin-level log2 ratios and segmentation calls are given, show them side-by-side on each chromosome (segments on the left side, bins on the right side).

URL: https://cnvkit.readthedocs.io/en/stable/plots.html?highlight=diagram#diagram

Example

This wrapper can be used in the following way:

rule cnvkit_diagram_cns:
    input:
        "test.cns",
    output:
        "test.cns.pdf",
    log:
        "logs/test.cns.log",
    params:
        extra = "" # optional
    wrapper:
        "v3.9.0/bio/cnvkit/diagram"

rule cnvkit_diagram_cnr:
    input:
        "test.cnr",
    output:
        "test.cnr.pdf",
    log:
        "logs/test.cnr.log",
    params:
        extra = "" # optional
    wrapper:
        "v3.9.0/bio/cnvkit/diagram"

rule cnvkit_diagram_cnn:
    input:
        "test.cnn",
    output:
        "test.cnn.pdf",
    log:
        "logs/test.cnn.log",
    params:
        extra = "" # optional
    wrapper:
        "v3.9.0/bio/cnvkit/diagram"

rule cnvkit_diagram_cnscnr:
    input:
        ["test.cns", "test.cnr"]
    output:
        "test.cnscnr.pdf",
    log:
        "logs/test.cnscnr.log",
    params:
        extra = "" # optional
    wrapper:
        "v3.9.0/bio/cnvkit/diagram"

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.

Software dependencies

  • cnvkit=0.9.11

Input/Output

Input:

  • cns file (optional, if cnr is provided)

  • cnr/cnn file (optional, if cns is provided)

Output:

  • pdf report

Params

  • extra: additional parameters that will be forwarded to cnvkit diagram

Authors

  • Patrik Smeds

Code

__author__ = "Patrik Smeds"
__copyright__ = "Copyright 2023, Patrik Smeds"
__email__ = "patrik.smeds@gmail.com"
__license__ = "MIT"

from snakemake.shell import shell

log = snakemake.log_fmt_shell(stdout=False, stderr=True)

cns_file = [f for f in snakemake.input if f.endswith(".cns")]
cnr_file = [f for f in snakemake.input if f.endswith(".cnr") or f.endswith(".cnn")]

if cns_file:
    if len(cns_file) > 1:
        raise Exception(f"Expecting only one input cns file {cns_file}")
    cns_file = f"-s {cns_file[0]}"

if cnr_file:
    if len(cnr_file) > 1:
        raise Exception(f"Expecting only one input cnr/cnn file {cnr_file}")
    cnr_file = f"{cnr_file[0]}"

extra = snakemake.params.get("extra", "")

shell(
    "(cnvkit.py diagram "
    "{cns_file} "
    "{cnr_file} "
    "-o {snakemake.output} "
    "{extra}) "
    "{log}"
)