Skip to main content

A Python package for accurate cell segmentation of spatial transcriptomics

Project description

DISSECT: Diffusion-based Cell Segmentation Integrating Spatial Transcriptomics

DISSECT (DIffusion-based cell Segmentation integrating Spatially rEsolved transCripTome) is an advanced cell segmentation algorithm developed by the Zeng Lab. It combines cytological image segmentation with transcriptome-guided fine-tuning to achieve precise spatial transcriptome reconstruction.

DISSECT leverages a pre-trained deep generative model to identify cell nuclei or membrane boundaries. By unifying the gradient fields of cytological images and transcriptomics data, it refines cell boundaries and reconstructs spatial single-cell transcriptomes.


Key Features

  • Integration of deep generative models for segmentation.
  • Combines spatial transcriptomic data with image analysis for enhanced accuracy.
  • Supports transcriptomics data from multiple platforms:
    • 10X Xenium
    • BGI Stereo-seq
    • Nanostring CosMx
  • Outputs include refined cell masks, bounding boxes, and spatial transcriptomes for downstream analyses.

Dependencies

Below are the essential libraries required to use DISSECT:

  • Python Packages:
    • numpy
    • pandas
    • torch
    • tqdm
    • scipy
    • skimage
    • shapely
    • detectron2
    • joblib

For full dependencies, refer to the environment.yml file.


Installation

Currently, DISSECT supports the following installation methods:

  • Pypi: Coming soon.
  • Conda: Coming soon.

Input Requirements

To use DISSECT, you need:

  1. Aligned Cytological Images:

    • Supported formats: .tif, .tiff, .png, .jpg.
    • Images should be pre-registered with spatial transcriptomics data.
    • Recommended libraries for loading images: tifffile, cv2, or skimage.
  2. Transcriptomics Data:

    • For platforms like 10X Xenium, BGI Stereo-seq, or Nanostring CosMx, provide the native gene matrix file.
    • For other platforms, prepare a .csv or .tsv file with the following four columns:
      • x: The x-coordinate of the transcript.
      • y: The y-coordinate of the transcript.
      • geneID: The name or identifier of the transcript.
      • MIDCount: The number of transcripts at the given location (usually 1 for imaging-based technologies).

Usage Example

import DISSECT

mask = DISSECT.segmentation(
    img_path="example_stereseq.tif",
    platform="stereoseq",
    gene_mtx_filename="example_stereoseq.gem",
    config_file="config.yaml",
    weights_file="model_weights.pth"
)

Parameters:

  • img_path: Path to the cytological image file.
  • gene_mtx_filename: Path to the gene matrix file in .csv, .tsv, or .gem format.
  • platform: The sequencing platform, options include:
    • "xenium"
    • "stereoseq"
    • "nanostring"
  • config_file: Path to an optional YAML file for model configuration parameters.
  • weights_file: Path to the pre-trained model weights file (download available https://drive.google.com/file/d/1Y9_YCJzhUPEQBDAdKVyrKplI1vpD4qiO/view?usp=sharing).

Optional Parameters:

  • output: Path to store the .npy file of segmented mask and detected bounding boxes. Default: Current working directory.
  • alpha (float): Sets the weight of the transcriptomic gradient field in refining cell boundaries. Default: 0.5.
  • expand_by (int): Number of pixels by which the bounding box is expanded outward. This ensures accurate cell boundaries without enlarging the actual cell size. Default: 5.
  • gene (bool): Whether to use transcriptomics data for fine-tuning. Default: True.
  • random_seed (int): Seed for random number generation to ensure reproducibility. Default: No predefined seed.
  • num_proposals (int): Number of bounding boxes proposed by the diffusion model. Default: 1200.
  • isslice (bool): Whether to extract a subset of the image for training. Default: False.
  • x0, y0 (int): The x and y coordinates of the upper-left corner of the extracted region when isslice is True.
  • length, width (int): The length (x-axis) and width (y-axis) of the extracted image region when isslice is True.
  • fov (int): Field of view ID to select a specific local area in the gene expression matrix, applicable when platform="nanostring".

Outputs:

  • Cell Masks: The model generates refined cell masks and saves them as a NumPy .npy file.
  • Bounding Boxes: Detected cell bounding boxes are saved in a .csv file, allowing for further custom parameter adjustments.
  • Spatial Transcriptomes: Outputs reconstructed spatial single-cell transcriptomes.

The output files are saved in the specified directory for downstream analysis.

Citation

If you use DISSECT in your research, please consider citing the following:

Zeng Lab
Dissection of Spatial Transcriptomics with Cytological Imaging Integration

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

dissect_st-0.5.0.tar.gz (61.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dissect_st-0.5.0-py3-none-any.whl (64.5 kB view details)

Uploaded Python 3

File details

Details for the file dissect_st-0.5.0.tar.gz.

File metadata

  • Download URL: dissect_st-0.5.0.tar.gz
  • Upload date:
  • Size: 61.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for dissect_st-0.5.0.tar.gz
Algorithm Hash digest
SHA256 649b351baf4ae5acfb3197c04c69616aa10a7f5d1c1cb709087a4dc6d5774c0b
MD5 afa1fcc9529dd522e100a42a5e1b113c
BLAKE2b-256 8e2c9a9fdd570c6fee047334b403722d03e8328c37d976369977bc92d62fd518

See more details on using hashes here.

File details

Details for the file dissect_st-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: dissect_st-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 64.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for dissect_st-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b7c2d161a3299b4bccb7384bb7fbd6d365f0262bba68b584d5a23c4daa7462eb
MD5 b38a856ce90cc6ee2e1870ed772e414f
BLAKE2b-256 4345d0b117e14226d6c8e85d09f3664a834de5a424d177380b9fe2959c014ba8

See more details on using hashes here.

Supported by

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