cc_mapping
Gaussian Mixture Model-based thresholding and cell cycle mapping for single-cell data
cc_mapping categorizes cells by fitting Gaussian Mixture Models (GMMs) to
single-cell feature measurements stored in an AnnData
object. It was developed for cell cycle analysis, and it works for any
single-cell feature you want to split into populations (for example, low and high).
Features
- Single-feature thresholding: fit a GMM to one feature and label each cell from the fitted decision boundaries
- Sequential thresholding: refine one label at a time with further features, like a gating strategy
- Manual overrides: set thresholds by hand when you need to
- Plots: histograms and strip plots with the fitted components and decision boundaries
- Feature selection: random forest selectors that find the features that best separate your labels
- Cell cycle maps: PHATE embeddings of the selected features (optional dependency)
- AnnData throughout: labels go to
adata.obs, and the fitted models and thresholds go toadata.uns
Installation
pip install cc-mapping
Optional extras:
pip install "cc-mapping[manifold]" # PHATE, for cell cycle maps
pip install "cc-mapping[persistence]" # skops, to save and load fitted feature selectors
To install from source:
git clone https://github.com/StallaertLab/cc_mapping.git
cd cc_mapping
pip install -e .
Quick start
import anndata as ad
from cc_mapping import GMMThresholding
adata = ad.read_h5ad("your_data.h5ad")
# Threshold one feature (a name in adata.var_names)
gmm = GMMThresholding(
adata=adata,
feature="PCNA",
label_obs_save_str="PCNA_category",
)
# Fit a two-component GMM and label the cells
gmm.fit(n_components=2)
gmm.categorize_samples(ordered_labels=["Low", "High"])
# Plot the histogram with the fitted components and the decision boundary
gmm.plot_hist_distribution_with_boundaries(save_path="pcna_thresholding.png")
# Get a copy of the AnnData with the labels in adata.obs["PCNA_category"]
adata = gmm.return_adata()
GMMThresholding works on a copy of your AnnData, so call return_adata()
to get the labelled result.
To set the threshold yourself, pass manual_thresholds. No fit is needed:
gmm.categorize_samples(ordered_labels=["Low", "High"], manual_thresholds=[0.05])
Sequential thresholding
SequentialGMM thresholds the whole dataset once, then refines one label at
a time using other features. Each step has a name and is recorded in adata.uns.
from cc_mapping import SequentialGMM
seq_gmm = SequentialGMM(adata=adata)
# Step 1: split every cell on DNA content
seq_gmm.threshold_entire_dataset(
feature="DNA_content",
label_obs_save_str="cell_cycle",
n_components=2,
ordered_labels=["2N", "4N"],
operation_name="DNA_threshold",
)
# Step 2: split only the 2N cells on pRB
seq_gmm.refine_labels_with_gmm(
feature="pRB",
obs_label="cell_cycle",
value_to_refine="2N",
n_components=2,
ordered_labels=["G0", "G1"],
operation_name="pRB_refinement",
)
adata = seq_gmm.return_adata()
Use refine_labels_with_manual_thresholds to refine a label with thresholds
you choose.
Combining labels
create_boolean_label_combination combines two categorical adata.obs
columns with boolean logic:
from cc_mapping import create_boolean_label_combination
adata = create_boolean_label_combination(
adata=adata,
obs_key_1="treatment",
match_values_1=["control"],
obs_key_2="cell_cycle",
match_values_2=["G0"],
operator="AND",
output_obs_key="control_G0",
true_label="control_G0",
false_label="other",
)
Feature selection and cell cycle maps
cc_mapping.feature_selection selects the features that best separate a set
of labels, and cc_mapping.manifold embeds the cells on those features with PHATE:
from cc_mapping.feature_selection import RFMinMaxSelector
from cc_mapping.manifold import run_phate
# Find the smallest feature set that keeps classification accuracy high
selector = RFMinMaxSelector(threshold=0.05, stable_iterations=5)
selector.fit_adata(adata, adata.var_names, "cell_cycle")
selector.transform_adata(adata, var_key="selected_features")
# Embed the cells with PHATE (needs the "manifold" extra)
adata = run_phate(adata, feature_set="selected_features", layer="z_score")
# coordinates are in adata.obsm["X_phate"]
run_phate reads from adata.layers, so layer must name a layer in your AnnData.
Documentation
The full documentation, tutorials and API reference are at cc-mapping.readthedocs.io.
Example notebooks are in notebooks/:
- Single thresholding
- Sequential thresholding
- CSV to AnnData
- Cell cycle maps (random forest feature selection and PHATE)
Requirements
Python 3.10 or later. pip installs the dependencies: numpy, pandas, scipy,
scikit-learn, matplotlib, anndata, pydantic, kneed, mpl-scatter-density and tqdm.
Citation
If you use cc_mapping in your research, please cite this repository:
https://github.com/StallaertLab/cc_mapping
Contributing
Contributions are welcome. Please open an issue or submit a pull request.
License
cc_mapping is released under the BSD 3-Clause License. See
LICENSE.
Support
- Bug reports and questions: GitHub Issues
- Email: dap182@pitt.edu
Metadata
Release files for cc-mapping 0.2.7
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 |
|---|---|---|---|---|
| cc_mapping-0.2.7.tar.gz | 67.0 kB | Without provenance | Details for cc_mapping-0.2.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cc_mapping-0.2.7-py3-none-any.whl | Python 3 | none | any | Details for cc_mapping-0.2.7-py3-none-any.whl |
Total release size: 144.2 kB
Release files / cc_mapping-0.2.7.tar.gz
| Download URL | cc_mapping-0.2.7.tar.gz |
|---|---|
| Size | 67.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
17d3978f767d3b92ac8dd77ed03354971dfa946390daf22ac0f0773d002dd4e9
|
|
BLAKE2b-256 checksum How to use checksums |
5d3554ec2d97459f8b4e65699d18cfb3e82bc8849338da8ce78df770a45416ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.10.9 Windows/10
|
Release files / cc_mapping-0.2.7-py3-none-any.whl
| Download URL | cc_mapping-0.2.7-py3-none-any.whl |
|---|---|
| Size | 77.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6f58f6d9ba0dbcfffe6d4ddc155e816ec2fda535c072391cc50c73a4ae8a126d
|
|
BLAKE2b-256 checksum How to use checksums |
3424fe7b58ed6190d35f6cb3ef940e7735bc29ea810958329692df734b3d2c35
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.10.9 Windows/10
|
Security for cc-mapping 0.2.7
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.