Skip to main content

Stimwrap: a Python interface for STIM

Project description

PyPI

stimwrap - a python interface for STIM

stimwrap is a Python wrapper for the spatial transcriptomics library STIM. It provides an interface for running STIM commands from python, as well as for extracting datasets and their attributes from n5 containers (backed by n5 or AnnData) that are created by STIM.

stimwrap is created and maintained by Nikos Karaiskos and Daniel León-Periñán.

Quick start

We provide an example notebook under notebooks/openst_example.ipynb, and also a Google Colab notebook

These will walk you through downloading Open-ST data, running STIM in a Python notebook (via stimwrap bindings), and seamlessly running some downstream analyses.

We provide another notebook under notebooks/visium_example.ipynb, and also a 2nd Google Colab notebook showcasing the 10x Visium adult mouse brain dataset showcased in all our tutorials.

Installation

To install the stimwrap try:

pip install stimwrap

or if you do not have sudo rights:

pip install --user stimwrap

Check if the library is successfully installed:

python -c import stimwrap as sw

If installation fails due to conflicting dependencies, create a dedicated environment with python>=3.9 and try again to install stimwrap as above.

Usage

The following assumes that the file container.n5 contains the datasets and their attributes as created by STIM:

import stimwrap as sw
pucks = sw.Container('/path/to/container.n5')

Print the names of the datasets:

print(pucks.get_dataset_names())

Focus on a specific puck and extract the relevant information:

puck_name = pucks.get_dataset_names()[0]
puck = pucks.get_dataset(puck_name)

Get the puck locations either directly from the puck:

locations = puck['locations']

or fetch them from the container:

locations = pucks.get_dataset(puck_name)['locations']

The examples above assume that the dataset is N5-backed. For AnnData-backed datasets, the key for the puck locations might be:

locations = pucks.get_dataset(puck_name)['spatial']

which will try to access the obsm/spatial variable from the dataset. Alternatively, we recommend using the official AnnData package for handling these files.

Fetch gene expression

It is possible to get the expression vector of a single gene:

hpca_vec = pucks.get_dataset(puck_name).get_gene_expression(gene='Hpca')

or the whole gene expression matrix:

dge = pucks.get_dataset(puck_name).get_gene_expression()

Fetch dataset attributes

STIM stores the dataset attributes in the n5 container. These can be directly accessed with stimwrap:

puck.get_attribute(attribute='geneList')

In N5-backed STIM, available options might also include: barcodeList and metadataList.

Fetch aligned locations

In the case where multiple consecutive sections are obtained and aligned with STIM, the aligned locations can be obtained with:

aligned_locations = puck.get_aligned_locations(transformation='model_sift')

Store aligned locations

The aligned locations can be stored in the N5 or AnnData-backed object, for seamless downstream analysis:

aligned_locations = puck.apply_save_transform(transformation='model_sift')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stimwrap-0.3.0.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

stimwrap-0.3.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file stimwrap-0.3.0.tar.gz.

File metadata

  • Download URL: stimwrap-0.3.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.10

File hashes

Hashes for stimwrap-0.3.0.tar.gz
Algorithm Hash digest
SHA256 6c79241966e7df8784b54f7dce5cf7dca1849c160ad9911a9707568976e7f422
MD5 3963de5d86e684fbb9ca600c0f816c46
BLAKE2b-256 bdbe0a6514a615751f1d5256db1beb6a45ebdeb1506808cdf6497f31c1e924ea

See more details on using hashes here.

File details

Details for the file stimwrap-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: stimwrap-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.10

File hashes

Hashes for stimwrap-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af3ff4efa0d71a97067fdafaaf8bab487fc5ad0f9ab6216c1911cf254beff891
MD5 af74586df9892c3d8770282ded227698
BLAKE2b-256 f8ae2250c89e82564cb4c5af0042f4933353e38e99ea9711de347d3f1d34f28a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page