DATAVZRD
Datavzrd allows to render tables by providing a configuration file. The configuration file can be a yte template. Inside of the template, the snakemake object is accessible (see [docs](https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#python)). 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.7.0/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.50.3
yte=1.5.7
numpy
pandas
polars
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={
"snakemake": snakemake,
# keep the ones below for backwards compatibility
"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}")