JQ

https://img.shields.io/badge/wrapper_version-v9.4.2-10785b https://img.shields.io/github/issues-pr/snakemake/snakemake-wrappers/utils/jq?label=version%20update%20pull%20requests&color=1cb481

Command-line JSON processor.

URL: https://github.com/jqlang/jq

Example

This wrapper can be used in the following way:

rule test_jq:
    input:
        "input/data.json",
    output:
        "out/sum.json",
    log:
        "logs/jq.log",
    params:
        expression=".array_tot = .array[0] + .array[1]",
        extra="-cr",
    threads: 1
    wrapper:
        "v9.4.2/utils/jq"

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

This tool does not support multithreading.

Software dependencies

  • jq=1.8.1

Input/Output

Input:

  • Path to JSON(L) file.

Output:

  • Path to JSON(L) file.

Params

  • expression: Expression to evaluate (by default, ‘.’).

  • extra: Optional arguments for jq command.

Authors

  • Filipe G. Vieira

Code

# coding: utf-8

"""Snakemake wrapper for jq"""

from snakemake.shell import shell

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

# jq expression should be quoted
expression = snakemake.params.get("expression", ".")

shell("jq {extra} {expression:q} {snakemake.input[0]} > {snakemake.output[0]} {log}")