SpiceMix
SpiceMix is an unsupervised tool for analyzing data of the spatial transcriptome. SpiceMix models the observed expression of genes within a cell as a mixture of latent factors. These factors are assumed to have some spatial affinity between neighboring cells. The factors and affinities are not known a priori, but are learned by SpiceMix directly from the data, by an alternating optimization method that seeks to maximize their posterior probability given the observed gene expression. In this way, SpiceMix learns a more expressive representation of the identity of cells from their spatial transcriptome data than other available methods.
SpiceMix can be applied to any type of spatial transcriptomics data, including MERFISH, seqFISH, HDST, and Slide-seq.
Install
pip install spicemix
Usage
from pathlib import Path
import anndata as ad
import torch
from spicemix.model import SpiceMixPlus
# Load datasets
datasets = []
replicate_names = []
for fov in range(5):
dataset = ad.read_h5ad(f"./example_st_dataset_fov_{replicate}.h5ad") # Each dataset must have spatial information stored as an adjacency matrix
name = f"{fov}"
datasets.append(dataset)
replicate_names.append(name)
# Define hyperparameters
K = 20 # Number of metagenes
lambda_Sigma_x_inv = 1e-4 # Spatial affinity regularization hyperparameter
torch_context = dict(device='cuda:0', dtype=torch.float32) # Context for PyTorch tensor instantiation
# Initialize
spicemixplus_demo = SpiceMixPlus(
K=K,
datasets=datasets,
lambda_Sigma_x_inv=lambda_Sigma_x_inv,
torch_context=torch_context
)
# Train
## Initialization with NMF
for iteration in range(10):
spicemixplus_demo.estimate_parameters(update_spatial_affinities=False)
spicemixplus_demo.estimate_weights(use_neighbors=False)
## Using spatial information
num_iterations = 200
for iteration in range(num_iterations):
spicemixplus_demo.estimate_parameters()
spicemixplus_demo.estimate_weights()
# Save to disk
result_filepath = Path(f"./demo_{num_iterations}_iterations.h5ad")
spicemixplus_demo.save_results(result_filepath)
# Plot results
...
Tests
To run the provided tests and ensure that SpiceMix can run on your platform, follow the instructions below:
- Download this repo.
git clone https://github.com/alam-shahul/SpiceMixPlus.git
- Install
pytestin your environment.
pip install pytest
- Navigate to the root directory of this repo.
- Run the following command. With GPU resources, this test should execute without errors in ~2.5 minutes:
python -m pytest -s tests/test_spicemix_shared.py
Cite
Cite our paper:
@article{chidester2020spicemix,
title={SPICEMIX: Integrative single-cell spatial modeling for inferring cell identity},
author={Chidester, Benjamin and Zhou, Tianming and Ma, Jian},
journal={bioRxiv},
year={2020},
publisher={Cold Spring Harbor Laboratory}
}
Metadata
Release files for spicemix 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spicemix-0.0.1.tar.gz | 38.9 kB | Without provenance | Details for spicemix-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spicemix-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for spicemix-0.0.1-py3-none-any.whl |
Total release size: 85.5 kB
Release files / spicemix-0.0.1.tar.gz
| Download URL | spicemix-0.0.1.tar.gz |
|---|---|
| Size | 38.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5cd1f41f687b29b26ca20a597089dea34cd547a9c3a07669a477df693617438e
|
|
BLAKE2b-256 checksum How to use checksums |
02c0de17c91b344275dea2ae658fe709071c69f7cea5bab7efe10e018780d83f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.23.0
|
Release files / spicemix-0.0.1-py3-none-any.whl
| Download URL | spicemix-0.0.1-py3-none-any.whl |
|---|---|
| Size | 46.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ad8b8cd9d138d132483f1d6bda54a1d376710e5732a551cc99e0a5299d0b39d7
|
|
BLAKE2b-256 checksum How to use checksums |
cf37505becc3c9af67e42915e8e2afe6d910b109d76d505ceac778d58f486c3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.23.0
|
Security for spicemix 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.