PRETEXT MAP

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

Commandline image generator for Pretext contact maps.

URL: https://github.com/wtsi-hpag/PretextSnapshot

Example

This wrapper can be used in the following way:

rule pretext_snapshot_png:
    input:
        "map.pretext",
    output:
        all=directory("all_maps/"),
        full="full_map.png",
    log:
        "logs/pretext_snapshot_png.log",
    params:
        extra="--resolution 1080",
    wrapper:
        "v3.6.0-3-gc8272d7/bio/pretext/snapshot"


rule pretext_snapshot_jpg:
    input:
        "map.pretext",
    output:
        all=directory("all_maps/"),
        full="full_map.jpg",
    log:
        "logs/pretext_snapshot_jpg.log",
    params:
        extra="--resolution 1080",
    wrapper:
        "v3.6.0-3-gc8272d7/bio/pretext/snapshot"

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

  • Outputs must all have the same format (PNG/BMP/JPG).

  • The extra param allows for additional arguments.

Software dependencies

  • pretextsnapshot=0.0.4

Input/Output

Input:

  • pretext contact map

Output:

  • full image (mandatory)

  • all images (optional)

  • specific sequences (optional)

Authors

  • Filipe G. Vieira

Code

__author__ = "Filipe G. Vieira"
__copyright__ = "Copyright 2022, Filipe G. Vieira"
__license__ = "MIT"


import tempfile
from pathlib import Path
from snakemake.shell import shell


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


out_maps = snakemake.output.keys()
sequences = "=" + ", =".join(snakemake.output.keys())


format = Path(snakemake.output.full).suffix.removeprefix(".")
if format == "jpg":
    format = "jpeg"


with tempfile.TemporaryDirectory() as tmpdir:
    shell(
        "PretextSnapshot"
        " --map {snakemake.input[0]}"
        " {extra}"
        " --sequences {sequences:q}"
        " --format {format}"
        " --folder {tmpdir}"
        " --prefix out_"
        " {log}"
    )

    if snakemake.output.get("full"):
        shell("mv {tmpdir}/out_FullMap.{format} {snakemake.output.full}")
    if snakemake.output.get("all"):
        Path(snakemake.output.all).mkdir(parents=True, exist_ok=True)
        shell("mv {tmpdir}/out_*.{format} {snakemake.output.all}/.")