COOLTOOLS EIGS_CIS

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

Calculate cis eigenvectors for a resolution in an .mcool file

URL: https://github.com/open2c/cooltools

Example

This wrapper can be used in the following way:

rule cooltools_eigs_cis:
    input:
        cooler="CN.mm9.1000kb.mcool",  ## Multiresolution cooler file
        view="mm9_view.txt",  ## File with the region names and coordinates
        track="mm9_1000000_gc.bed",
    output:
        vecs="CN_{resolution,[0-9]+}.cis.vecs.tsv",
        lam="CN_{resolution,[0-9]+}.cis.lam.tsv",
        bigwig="CN_{resolution,[0-9]+}.cis.bw",
    params:
        ## Add optional parameters
        track_col_name="GC",
        extra="",
    log:
        "logs/CN_{resolution}_cis_eigs.log",
    wrapper:
        "v3.8.0-1-g149ef14/bio/cooltools/eigs_cis"

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

[“Output files can have a {resolution} wildcard that specifies the resolution for the analysis, then it doesn’t need to be specified as a parameter.”]

Software dependencies

  • ucsc-bedgraphtobigwig

  • cooltools=0.6.1

Input/Output

Input:

  • a multiresolution cooler file (.mcool)

  • (optional) phasing track file

  • (optional) view, a bed-style file with region coordinates and names to use for analysis

Output:

  • vecs

  • lams

  • bigwig

Params

  • resolution: Optional, can be instead specified as a wildcard in the output

  • track_col_name: Name of the column in the track file to use

  • extra: Any additional arguments to pass

Authors

  • Ilya Flyamer

Code

__author__ = "Ilya Flyamer"
__copyright__ = "Copyright 2022, Ilya Flyamer"
__email__ = "flyamer@gmail.com"
__license__ = "MIT"

from snakemake.shell import shell
import tempfile


## Extract arguments
view = snakemake.input.get("view", "")
if view:
    view = f"--view {view}"
track = snakemake.input.get("track", "")
track_col_name = snakemake.params.get("track_col_name", "")
if track and track_col_name:
    track = f"--phasing-track {track}::{track_col_name}"
elif track:
    track = f"--phasing-track {track}"

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

bigwig = snakemake.output.get("bigwig", "")
if bigwig:
    bigwig = "--bigwig"

resolution = snakemake.params.get("resolution", snakemake.wildcards.get("resolution"))
assert (
    resolution
), "Please specify resolution either as a `wildcard` or as a `parameter`"

with tempfile.TemporaryDirectory() as tmpdir:
    shell(
        "cooltools eigs-cis"
        " {snakemake.input.cooler}::resolutions/{resolution} "
        " {track}"
        " {view} "
        " {bigwig}"
        " {extra} "
        " -o {tmpdir}/out"
        " {log}"
    )

    shell("mv {tmpdir}/out.cis.vecs.tsv {snakemake.output.vecs}")
    shell("mv {tmpdir}/out.cis.lam.txt {snakemake.output.lam}")
    if bigwig:
        shell("mv {tmpdir}/out.cis.bw {snakemake.output.bigwig}")