MTNUCRATIOCALCULATOR

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

URL: https://github.com/apeltzer/MTNucRatioCalculator

Example

This wrapper can be used in the following way:

rule test_mtnucratio:
    input:
        "a.bam",
    output:
        txt="ratio.txt",
        json="ratio.json",
    threads: 1
    log:
        "mtnucratio.log",
    params:
        chrom="ref2",
    wrapper:
        "v5.5.2-17-g33d5b76/bio/mtnucratio"

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

No optional parameters basides chrom, the name of the mitochondrial chromosome.

Software dependencies

  • mtnucratio=0.7.1

Input/Output

Input:

  • Path to a bam file

Output:

  • json: Optional path to json-formatted results

  • txt: Optional path to text-formatted results

Params

  • chrom: Name of the mithocondrial chromosome

Authors

  • Thibault Dayris

Code

# coding: utf-8

"""Snakemake wrapper for MTNucRatioCalculator"""

from snakemake.shell import shell
from tempfile import TemporaryDirectory
from os.path import basename, realpath
from os import symlink

# Default mito chromosome name is set to 'MT'
chrom = snakemake.params.get("chrom", "MT")
log = snakemake.log_fmt_shell(
    stdout=True,
    stderr=True,
    append=True,
)
bam = str(snakemake.input)

# MTNucRatioCalculator does not let user chose
# output file names. Moving to a temporary directory:
with TemporaryDirectory() as tempdir:
    # Symlink input file to control output file names
    link_path = f"{tempdir}/{basename(bam)}"
    bam_path = realpath(bam)
    symlink(bam_path, link_path)

    # Run MTNucRatioCalculator
    shell("mtnucratio {link_path} {chrom} {log}")

    # Rename output files
    txt = snakemake.output.get("txt")
    if txt:
        shell("mv --verbose {link_path}.mtnucratio {txt} {log}")

    json = snakemake.output.get("json")
    if json:
        shell("mv --verbose {link_path}.mtnucratiomtnuc.json {json} {log}")