COOLTOOLS INSULATION

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

Calculate insulation score 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_insulation:
    input:
        cooler="CN.mm9.1000kb.mcool",  ## Multiresolution cooler file
        view="mm9_view.txt",  ## File with the region names and coordinates
    output:
        "CN_{resolution,[0-9]+}.insulation.tsv",
    params:
        ## Add optional parameters
        window=[10000000, 12000000],  ## In this example, we test with two window sizes
        chunksize=20000000,  ## How many pixels are loaded in memory at once
    threads: 4  ## Number of threads to use
    log:
        "logs/CN_{resolution}_insulation.log",
    wrapper:
        "v3.8.0-49-g6f33607/bio/cooltools/insulation"

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

  • cooltools=0.6.1

Input/Output

Input:

  • a multiresolution cooler file (.mcool)

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

Output:

  • A .tsv file with insulation score and called boundaries for all window sizes. Can have a {resolution} wildcard that specifies the resolution for the analysis, then it doesn’t need to be specified as a parameter.

Params

  • window: Window size for insulation score calculation, in bp. Can be a list of multiple sizes, then all are calculated in one go

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

  • chunksize: How many pixels to process in each chunk

  • extra: Any additional arguments to pass

Authors

  • Ilya Flyamer

Code

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

import sndhdr
from snakemake.shell import shell

## Extract arguments
window = snakemake.params.get("window", "")
if isinstance(window, list):
    window = " ".join([str(w) for w in window])
else:
    window = str(window)

view = snakemake.input.get("view", "")
if view:
    view = f"--view {view}"
chunksize = snakemake.params.get("chunksize", 20000000)
extra = snakemake.params.get("extra", "")
log = snakemake.log_fmt_shell(stdout=False, stderr=True)

resolution = snakemake.params.get(
    "resolution", snakemake.wildcards.get("resolution", 0)
)
if not resolution:
    raise ValueError("Please specify resolution either as a wildcard or as a parameter")


shell(
    "(cooltools insulation"
    " {snakemake.input.cooler}::resolutions/{resolution} "
    " {window} --chunksize {chunksize} "
    " {view} "
    " -p {snakemake.threads} "
    " {extra} "
    " -o {snakemake.output}) {log}"
)