Pytacs: Python-implemented Topology-Aware Cell Segmentation for high-resolution spatial transcriptomics
Project description
Pytacs - Python-implemented Topology-Aware Cell Segmentation
Copyright (C) 2025 Xindong Liu
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
A tool for segmenting/integrating sub-cellular spots in high-resolution spatial transcriptomics into single-cellular spots and cell-type mapping.
Ideas are inspired by (Benjamin et al., 2024)'s work TopACT (see https://gitlab.com/kfbenjamin/topact). But Pytacs has improved it in several ways:
- The shape of predicted cells can be diverse rather than a rectangle/grid, rendering hopefully higher accuracy;
- Random-Walk-based aggregation strategy with comparative computational speed, making it more "topology-aware", and rendering hopefully higher accuracy especially at cell boundaries;
- Bootstrap downsampling strategy is adopted for generating ref scRNA-seq, making it more flexible in terms of ad-hoc cell-type mapping and novel cell-type detection.
Requirements
This package is released on PyPi now! It could be simply
installed by pip install pytacs (the package name yet might change).
For conda users,
conda create -n pytacs python=3.12 -y
conda activate pytacs
pip install pytacs
For python3 users, first make sure your python is of version 3.12, and then in your working directory,
python -m venv pytacs
source pytacs/bin/activate
python -m pip install pytacs
For developers, requirements (at develop time) are listed in
requirements.in (initial dependencies), requirements.txt (full dependencies)
and requirements.tree.txt (for a tree view).
For developers using Poetry,
the dependencies lock file is poetry.lock and the project information
including main dependencies is listed in pyproject.toml.
To use it for downstream analysis in combination with Squidpy, it is recommended to use a seperate virtual environment to install Squidpy.
Usage
In the future, there will be a well-prepared recipe module for users to use conveniently.
For detailed usage, see Basic_Usage_of_pytacs.md
>>> import pytacs as tax
# Step 1. Prepare the snRNA-seq and spRNA-seq data
>>> data_prep = tax.AnnDataPreparer(sn_adata, sp_adata)
# Step 2. Train a local classifier
>>> clf = tax.SVM()
>>> clf.fit(data_prep.sn_adata)
# Step 3. Integrate spatial spots into pseudo-single-cell-level spots
>>> agg_res = tax.rw_aggregate(
st_anndata=data_prep.sp_adata,
classifier=clf,
max_iter=20,
steps_per_iter=3,
nbhd_radius=2.4,
max_propagation_radius=10.,
mode_metric='inv_dist',
mode_embedding='pc',
mode_aggregation='unweighted',
n_pcs=50,
)
>>> ct_full = extract_celltypes_full(agg_res)
# Plot the celltypes
>>> import seaborn as sns
>>> sns.scatterplot(
x=data_prep.sp_adata.obsm['spatial'][:,0],
y=data_prep.sp_adata.obsm['spatial'][:,1],
hue=ct_full,
)
# Get refined binned pseudo-single-cell spatial transcriptomics
>>> ann_mtx = tax.SpTypeSizeAnnCntMtx(
count_matrix,
spatial_coords,
cell_types,
cell_sizes,
)
>>> ann_mtx_sc = tax.ctrbin_cellseg_parallel(
ann_mtx,
)
Demo
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytacs-2025.6.11.tar.gz.
File metadata
- Download URL: pytacs-2025.6.11.tar.gz
- Upload date:
- Size: 52.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/5.4.0-216-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eeb66d4804b8ca4c386e544ca33d084ef379abb97ebb55f2adebaf617a8b447b
|
|
| MD5 |
77e796886bf823dfb4cdad36c7fa556e
|
|
| BLAKE2b-256 |
8af19eec6498792588e838d30643c69dd3e8dda19b1742f40c254cf6c7ddc3b4
|
File details
Details for the file pytacs-2025.6.11-py3-none-any.whl.
File metadata
- Download URL: pytacs-2025.6.11-py3-none-any.whl
- Upload date:
- Size: 56.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/5.4.0-216-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb2430ba7005de12dc2f9ab7075c0070b677265f183f36f08558194a65673ac1
|
|
| MD5 |
d5c6de2e7b5e545c8debd82ba4bd25d9
|
|
| BLAKE2b-256 |
034cf1e2785f92af911996dd4a71e35de7513567d6ab177302b3e8bdb135042b
|