DATAVZRD

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

datavzrd allows to render tables by providing a configuration file. Configuration templates can be dynamically customized by utilizing the rendering integration. Any files specified in the configuration file have to be also specified as additional input files in the datavzrd rule.

URL: https://github.com/datavzrd/datavzrd

Example

This wrapper can be used in the following way:

rule datavzrd:
    input:
        # the config file may be a yte template, with access to input, params and wildcards
        # analogous to Snakemake's generic template support:
        # https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#template-rendering-integration
        # For template processing, __use_yte__: true has to be stated in the config file
        config="resources/{sample}.datavzrd.yaml",
        # optional files required for rendering the given config
        table="data/{sample}.tsv",
    params:
        extra="",
    output:
        report(
            directory("results/datavzrd-report/{sample}"),
            htmlindex="index.html",
            # see https://snakemake.readthedocs.io/en/stable/snakefiles/reporting.html
            # for additional options like caption, categories and labels
        ),
        # optionally output the rendered config
        config = "resources/datavzrd/{sample}.rendered_config.yaml"
    log:
        "logs/datavzrd_report/{sample}.log",
    wrapper:
        "v5.3.0-16-g710597c/utils/datavzrd"

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

  • datavzrd=2.44.4

  • yte=1.5.4

  • numpy

  • pandas

  • polars

Authors

  • Felix Mölder

Code

__author__ = "Johannes Köster"
__copyright__ = "Copyright 2017, Johannes Köster"
__email__ = "johannes.koester@protonmail.com"
__license__ = "MIT"

import tempfile
from yte import process_yaml
from snakemake.shell import shell
import shutil

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

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

with tempfile.NamedTemporaryFile(mode="w") as processed, open(
    snakemake.input.config
) as f:
    # support templating in the config file
    process_yaml(
        f,
        outfile=processed,
        variables={
            "params": snakemake.params,
            "wildcards": snakemake.wildcards,
            "input": snakemake.input,
        },
        require_use_yte=True,
    )
    processed.flush()

    if config_out := snakemake.output.get("config"):
        shutil.copy(processed.name, config_out)
    shell("datavzrd {processed.name} {extra} --output {snakemake.output[0]} {log}")