CNVKIT EXPORT

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

Convert copy number ratio tables (.cnr files) or segments (.cns) to another format.

URL: https://cnvkit.readthedocs.io/en/stable/importexport.html#export

Example

This wrapper can be used in the following way:

rule cnvkit_export_seg:
    input:
        ["test1.cns","test2.cns"],
    output:
        "test.cns.seg",
    log:
        "logs/test.target.log",
    params:
        extra = "" # optional
    wrapper:
        "v3.12.1-7-ge5bfa94/bio/cnvkit/export"

rule cnvkit_export_vcf:
    input:
        "test1.cns",
    output:
        "test.cns.vcf",
    log:
        "logs/test.target.log",
    params:
        extra = "-y -x female" # optional
    wrapper:
        "v3.12.1-7-ge5bfa94/bio/cnvkit/export"

rule cnvkit_export_vcf_gz:
    input:
        "test1.cns",
    output:
        "test.cns.vcf.gz",
    log:
        "logs/test.target.log",
    params:
        extra = "-y -x female" # optional
    wrapper:
        "v3.12.1-7-ge5bfa94/bio/cnvkit/export"

rule cnvkit_export_cdt:
    input:
        ["test1.cnr", "test2.cnr"]
    output:
        "test.cns.cdt",
    log:
        "logs/test.target.log",
    params:
        extra = "" # optional
    wrapper:
        "v3.12.1-7-ge5bfa94/bio/cnvkit/export"

rule cnvkit_export_jtv:
    input:
        ["test1.cnr", "test2.cnr"]
    output:
        "test.cns.jtv",
    log:
        "logs/test.target.log",
    params:
        extra = "" # optional
    wrapper:
        "v3.12.1-7-ge5bfa94/bio/cnvkit/export"

rule cnvkit_export_bed:
    input:
        bed="test1.cns",
    output:
        "test.cns.bed",
    log:
        "logs/test.target.log",
    params:
        extra = "--show all -y" # optional
    wrapper:
        "v3.12.1-7-ge5bfa94/bio/cnvkit/export"

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

  • htslib=1.20

Input/Output

Input:

  • cns: cns or cnr file(s)

Output:

  • bed/vcf/vcf.gz/cdt/seq file

Params

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

Authors

  • Patrik Smeds

Code

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

from snakemake.shell import shell
from os.path import splitext

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

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


file_name, file_extension = splitext(snakemake.output[0])

if file_extension == ".gz":
    file_extension = splitext(file_name)[1][1:]
    output = f" | bgzip > {snakemake.output}"
else:
    file_extension = file_extension[1:]
    output = f"-o {snakemake.output} "

shell(
    "(cnvkit.py export {file_extension} "
    "{snakemake.input} "
    "{extra} "
    "{output}) "
    "{log}"
)