cellmapper 0.2.6__tar.gz → 0.2.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.pre-commit-config.yaml +3 -3
- {cellmapper-0.2.6 → cellmapper-0.2.7}/CHANGELOG.md +12 -1
- {cellmapper-0.2.6 → cellmapper-0.2.7}/PKG-INFO +2 -2
- {cellmapper-0.2.6 → cellmapper-0.2.7}/pyproject.toml +34 -5
- {cellmapper-0.2.6 → cellmapper-0.2.7}/src/cellmapper/model/cellmapper.py +21 -23
- {cellmapper-0.2.6 → cellmapper-0.2.7}/src/cellmapper/model/embedding.py +9 -5
- {cellmapper-0.2.6 → cellmapper-0.2.7}/tests/model/test_query_to_reference_mapping.py +47 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.codecov.yaml +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.cruft.json +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.editorconfig +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.github/copilot-instructions.md +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.github/workflows/build.yaml +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.github/workflows/release.yaml +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.github/workflows/test.yaml +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.gitignore +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.python-version +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.readthedocs.yaml +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.vscode/extensions.json +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.vscode/launch.json +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/.vscode/settings.json +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/AGENTS.md +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/CLAUDE.md +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/LICENSE +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/README.md +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/REVIEW_GUIDE.md +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/biome.jsonc +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/_static/.gitkeep +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/_static/css/custom.css +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/_static/images/cellmapper_logo_dark.svg +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/_static/images/cellmapper_logo_light.svg +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/_templates/.gitkeep +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/_templates/autosummary/class.rst +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/api.md +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/changelog.md +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/conf.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/contributing.md +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/extensions/typed_returns.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/index.md +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/notebooks/tutorials/data_denoising.ipynb +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/notebooks/tutorials/index.rst +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/notebooks/tutorials/query_to_reference_mapping.ipynb +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/notebooks/tutorials/spatial_mapping.ipynb +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/notebooks/tutorials/spatial_smoothing.ipynb +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/references.bib +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/docs/references.md +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/src/cellmapper/__init__.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/src/cellmapper/_docs.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/src/cellmapper/check.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/src/cellmapper/constants.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/src/cellmapper/logging.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/src/cellmapper/model/_knn_backend.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/src/cellmapper/model/evaluate.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/src/cellmapper/model/kernel.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/src/cellmapper/model/mapping_operator.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/src/cellmapper/model/neighbors.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/src/cellmapper/utils.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/tests/conftest.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/tests/data/precomputed_leiden.csv +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/tests/model/test_embedding.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/tests/model/test_evaluate.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/tests/model/test_kernel.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/tests/model/test_mapping_operator.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/tests/model/test_neighbors.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/tests/model/test_self_mapping.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/tests/test_basic.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/tests/test_check.py +0 -0
- {cellmapper-0.2.6 → cellmapper-0.2.7}/tests/test_utils.py +0 -0
|
@@ -7,16 +7,16 @@ default_stages:
|
|
|
7
7
|
minimum_pre_commit_version: 2.16.0
|
|
8
8
|
repos:
|
|
9
9
|
- repo: https://github.com/biomejs/pre-commit
|
|
10
|
-
rev: v2.
|
|
10
|
+
rev: v2.5.3
|
|
11
11
|
hooks:
|
|
12
12
|
- id: biome-format
|
|
13
13
|
exclude: ^\.cruft\.json$ # inconsistent indentation with cruft - file never to be modified manually.
|
|
14
14
|
- repo: https://github.com/tox-dev/pyproject-fmt
|
|
15
|
-
rev: v2.
|
|
15
|
+
rev: v2.25.3
|
|
16
16
|
hooks:
|
|
17
17
|
- id: pyproject-fmt
|
|
18
18
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
19
|
-
rev: v0.15.
|
|
19
|
+
rev: v0.15.21
|
|
20
20
|
hooks:
|
|
21
21
|
- id: ruff-check
|
|
22
22
|
types_or: [python, pyi, jupyter]
|
|
@@ -10,12 +10,23 @@ and this project adheres to [Semantic Versioning][].
|
|
|
10
10
|
|
|
11
11
|
## [Unreleased]
|
|
12
12
|
|
|
13
|
+
## [v0.2.7]
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- uv resolves and locks the `gpcca-fast` group without compiling PETSc, through static dependency metadata {pr}`86`
|
|
17
|
+
|
|
18
|
+
### Fixed
|
|
19
|
+
- `map_obs` no longer lets missing or empty reference labels win the vote; a query cell without labelled neighbour weight gets a missing prediction with confidence 0, also with `subset_categories`, where it got the first category {pr}`94`
|
|
20
|
+
- Compatibility with scanpy 1.13, which removed the private `scanpy.get._get_obs_rep` used by `fast_cca` {pr}`94`
|
|
21
|
+
|
|
22
|
+
## [v0.2.6]
|
|
23
|
+
|
|
13
24
|
### Changed
|
|
14
25
|
- Dropped Python 3.11 support; the minimum supported version is now Python 3.12, aligning with `cellrank` (≥2.1 requires Python ≥3.12) and unpinning the `tutorials` extra from the old `cellrank` 2.0.7 {pr}`81`
|
|
15
26
|
- The `gpcca-fast` dependency group now delegates `petsc4py`/`slepc4py` to `cellrank[petsc]>=2.3.1` (mpi4py-free) instead of hardcoding them, keeping only an explicit `slepc` to work around slepc4py's missing runtime metadata {pr}`82`
|
|
16
27
|
|
|
17
28
|
### Fixed
|
|
18
|
-
- Fixed intermittent `OSError: Can't synchronously read data (filter returned failure during read)` when running the test suite under `pytest -n auto`, caused by xdist workers racing on scanpy's shared `pbmc3k_raw.h5ad` dataset cache. Each worker now uses its own cache directory.
|
|
29
|
+
- Fixed intermittent `OSError: Can't synchronously read data (filter returned failure during read)` when running the test suite under `pytest -n auto`, caused by xdist workers racing on scanpy's shared `pbmc3k_raw.h5ad` dataset cache. Each worker now uses its own cache directory. {pr}`83`
|
|
19
30
|
|
|
20
31
|
## [v0.2.5]
|
|
21
32
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: cellmapper
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: k-NN-based mapping of cells across representations
|
|
5
5
|
Project-URL: Documentation, https://cellmapper.readthedocs.io/
|
|
6
6
|
Project-URL: Homepage, https://github.com/quadbio/cellmapper
|
|
@@ -94,11 +94,27 @@ urls.Source = "https://github.com/quadbio/cellmapper"
|
|
|
94
94
|
# correctly, so petsc needs no such workaround.) Drop this once slepc4py — or
|
|
95
95
|
# cellrank's petsc extra — declares slepc.
|
|
96
96
|
#
|
|
97
|
-
#
|
|
98
|
-
#
|
|
99
|
-
#
|
|
100
|
-
#
|
|
101
|
-
#
|
|
97
|
+
# petsc4py/slepc4py compute their metadata dynamically at build time. Without help,
|
|
98
|
+
# uv would therefore compile PETSc from source just to *resolve* — breaking every
|
|
99
|
+
# bare `uv sync` / `uv run` / `uv lock`, even when this group is NOT requested. The
|
|
100
|
+
# [[tool.uv.dependency-metadata]] entries under [tool.uv] give uv that metadata
|
|
101
|
+
# statically, so resolution/locking never builds anything; PETSc/SLEPc compile only
|
|
102
|
+
# when the group is actually installed. Keep those entries in sync with this group.
|
|
103
|
+
#
|
|
104
|
+
# INSTALLING the group is the fragile part. The recommended route is pre-built
|
|
105
|
+
# conda-forge binaries (no compiler, no BLAS hunting), e.g. with pixi/mamba:
|
|
106
|
+
# mamba install -c conda-forge petsc4py slepc4py # or: pixi add petsc4py slepc4py
|
|
107
|
+
# Building from PyPI source instead needs a C compiler AND a BLAS/LAPACK. The
|
|
108
|
+
# CellRank-documented options alone (--with-fc=0 --with-mpi=0 --with-debugging=0
|
|
109
|
+
# --with-shared-libraries=1) only work on machines that already expose a system
|
|
110
|
+
# BLAS on the linker path; on others PETSc configure fails with "Could not find a
|
|
111
|
+
# functional BLAS". Adding --download-f2cblaslapack=1 gets PETSc to build but then
|
|
112
|
+
# SLEPc fails to link it (`cannot find -lf2cblas`), so for a source build point
|
|
113
|
+
# PETSc at a real shared BLAS instead, e.g.:
|
|
114
|
+
# PETSC_CONFIGURE_OPTIONS="--with-fc=0 --with-mpi=0 --with-debugging=0 \
|
|
115
|
+
# --with-shared-libraries=1 --with-blaslapack-dir=$OPENBLAS_ROOT" \
|
|
116
|
+
# uv sync --all-extras --group gpcca-fast
|
|
117
|
+
# Do NOT set SLEPC_CONFIGURE_OPTIONS — SLEPc inherits config from the built PETSc.
|
|
102
118
|
# NB: a plain `uv sync --all-extras` (without --group gpcca-fast) will UNINSTALL
|
|
103
119
|
# petsc/slepc if present — re-include the group on every refresh to keep them.
|
|
104
120
|
[dependency-groups]
|
|
@@ -133,6 +149,19 @@ envs.hatch-test.overrides.matrix.deps.env-vars = [
|
|
|
133
149
|
# jinja2==3.0.3, which conflicts with sphinx (doc extra). Override until a
|
|
134
150
|
# pygpcca release relaxes it. jinja2>=3.1 is known-safe (cellrank does the same).
|
|
135
151
|
override-dependencies = [ "jinja2>=3.1" ]
|
|
152
|
+
# Static metadata for the gpcca-fast source-only packages so uv can resolve/lock
|
|
153
|
+
# WITHOUT compiling PETSc (see the note above [dependency-groups]). These mirror
|
|
154
|
+
# the deps each package injects dynamically at build time: petsc4py -> petsc,
|
|
155
|
+
# slepc4py -> petsc4py + slepc (slepc4py's own sdist omits slepc). The `petsc`/
|
|
156
|
+
# `slepc` library packages have no Python dependencies. Version omitted -> applies
|
|
157
|
+
# to all versions; petsc & petsc4py (and slepc & slepc4py) are always co-released
|
|
158
|
+
# at matching versions, so uv resolves them in lockstep.
|
|
159
|
+
dependency-metadata = [
|
|
160
|
+
{ name = "petsc", requires-dist = [] },
|
|
161
|
+
{ name = "slepc", requires-dist = [] },
|
|
162
|
+
{ name = "petsc4py", requires-dist = [ "numpy", "petsc" ] },
|
|
163
|
+
{ name = "slepc4py", requires-dist = [ "numpy", "petsc4py", "slepc" ] },
|
|
164
|
+
]
|
|
136
165
|
|
|
137
166
|
[tool.ruff]
|
|
138
167
|
line-length = 120
|
|
@@ -681,8 +681,11 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
681
681
|
|
|
682
682
|
Automatically detects whether the data is categorical or numerical and applies
|
|
683
683
|
the appropriate mapping strategy. For categorical data, uses one-hot encoding
|
|
684
|
-
followed by matrix multiplication and argmax.
|
|
685
|
-
|
|
684
|
+
followed by matrix multiplication and argmax. Reference cells with a missing or empty
|
|
685
|
+
label don't vote; the confidence is the winning label's share of all neighbour weight,
|
|
686
|
+
unlabelled neighbours included, and a query cell without labelled neighbour weight gets
|
|
687
|
+
a missing prediction with confidence 0. For numerical data, uses direct matrix
|
|
688
|
+
multiplication.
|
|
686
689
|
|
|
687
690
|
Parameters
|
|
688
691
|
----------
|
|
@@ -816,27 +819,21 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
816
819
|
# Get the reference data
|
|
817
820
|
reference_data = self.reference.obs[key]
|
|
818
821
|
|
|
822
|
+
# Reference cells without a label (missing or empty), or with one outside subset_categories, don't vote:
|
|
823
|
+
# their one-hot rows are all zero
|
|
824
|
+
missing = reference_data.isna() | (reference_data.astype(str) == "")
|
|
825
|
+
pred_key, conf_key = f"{key}{prediction_postfix}", f"{key}{confidence_postfix}"
|
|
826
|
+
if subset_categories is None and missing.all():
|
|
827
|
+
logger.warning("No reference cell has a label in '%s'; all predictions are missing.", key)
|
|
828
|
+
self.query.obs[pred_key] = pd.Series(np.nan, index=self.query.obs_names, dtype=reference_data.dtype)
|
|
829
|
+
self.query.obs[conf_key] = 0.0
|
|
830
|
+
return pd.DataFrame(index=self.query.obs_names) if return_probabilities else None
|
|
831
|
+
onehot = OneHotEncoder(dtype=np.float32, handle_unknown="ignore")
|
|
819
832
|
if subset_categories is not None:
|
|
820
|
-
|
|
821
|
-
# Only include rows that have the desired categories
|
|
822
|
-
mask = reference_data.isin(subset_categories)
|
|
823
|
-
|
|
824
|
-
# Create a filtered DataFrame with only the subset categories
|
|
825
|
-
filtered_reference_data = reference_data.copy()
|
|
826
|
-
filtered_reference_data[~mask] = pd.NA # Set non-subset categories to missing
|
|
827
|
-
|
|
828
|
-
# Create one-hot encoding only for the subset categories
|
|
829
|
-
onehot = OneHotEncoder(dtype=np.float32, handle_unknown="ignore")
|
|
830
|
-
# Create a DataFrame with only subset categories for fitting
|
|
831
|
-
subset_df = pd.DataFrame({key: pd.Categorical(subset_categories, categories=subset_categories)})
|
|
832
|
-
onehot.fit(subset_df)
|
|
833
|
-
|
|
834
|
-
# Transform the full reference data (missing values will be ignored)
|
|
835
|
-
xtab = onehot.transform(filtered_reference_data.to_frame())
|
|
833
|
+
onehot.fit(pd.DataFrame({key: pd.Categorical(subset_categories, categories=subset_categories)}))
|
|
836
834
|
else:
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
xtab = onehot.fit_transform(self.reference.obs[[key]])
|
|
835
|
+
onehot.fit(reference_data[~missing].to_frame())
|
|
836
|
+
xtab = onehot.transform(reference_data.where(~missing).to_frame())
|
|
840
837
|
|
|
841
838
|
# Ensure CSR format for mapping operator
|
|
842
839
|
if not isinstance(xtab, csr_matrix):
|
|
@@ -856,6 +853,9 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
856
853
|
index=self.query.obs_names,
|
|
857
854
|
dtype=self.reference.obs[key].dtype,
|
|
858
855
|
)
|
|
856
|
+
# A query cell without labelled neighbour weight gets no prediction (argmax of a zero row would be 0)
|
|
857
|
+
votes = np.asarray(ytab.sum(axis=1)).ravel()
|
|
858
|
+
pred[votes == 0] = np.nan
|
|
859
859
|
|
|
860
860
|
# Confidence as max probability per row
|
|
861
861
|
if issparse(ytab):
|
|
@@ -864,8 +864,6 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
864
864
|
conf_vals = np.max(ytab, axis=1).ravel()
|
|
865
865
|
conf = pd.Series(conf_vals, index=self.query.obs_names)
|
|
866
866
|
|
|
867
|
-
pred_key = f"{key}{prediction_postfix}"
|
|
868
|
-
conf_key = f"{key}{confidence_postfix}"
|
|
869
867
|
self.query.obs[pred_key] = pred
|
|
870
868
|
self.query.obs[conf_key] = conf
|
|
871
869
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import anndata as ad
|
|
2
2
|
import numpy as np
|
|
3
3
|
import scanpy as sc
|
|
4
|
-
from scanpy.get import _check_mask, _get_obs_rep
|
|
5
4
|
from scipy.sparse import csr_matrix, issparse
|
|
6
5
|
|
|
7
6
|
from cellmapper.logging import logger
|
|
@@ -125,11 +124,16 @@ class EmbeddingMixin:
|
|
|
125
124
|
)
|
|
126
125
|
|
|
127
126
|
# Potentially subset along the features
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
if isinstance(mask_var, str):
|
|
128
|
+
mask_var = joint.var[mask_var].to_numpy(dtype=bool)
|
|
129
|
+
if mask_var is not None:
|
|
130
|
+
joint = joint[:, np.asarray(mask_var, dtype=bool)]
|
|
130
131
|
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
def rep(batch: str):
|
|
133
|
+
cells = joint[joint.obs["batch"] == batch]
|
|
134
|
+
return cells.X if layer is None else cells.layers[layer]
|
|
135
|
+
|
|
136
|
+
X_query, X_ref = rep("query"), rep("reference")
|
|
133
137
|
|
|
134
138
|
n_common_genes = X_query.shape[1]
|
|
135
139
|
logger.info(
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import numpy as np
|
|
2
|
+
import pandas as pd
|
|
2
3
|
import pytest
|
|
3
4
|
from scipy.sparse import issparse
|
|
4
5
|
from scipy.stats import pearsonr
|
|
@@ -308,6 +309,52 @@ class TestQueryToReferenceMapping:
|
|
|
308
309
|
# Verify no confidence scores for numerical data
|
|
309
310
|
assert "dpt_pseudotime_conf" not in cmap.query.obs
|
|
310
311
|
|
|
312
|
+
def test_map_obs_missing_labels_do_not_vote(self, query_reference_adata):
|
|
313
|
+
"""Unlabelled reference cells never win; they lower the confidence instead."""
|
|
314
|
+
query, reference = query_reference_adata
|
|
315
|
+
cmap = CellMapper(query=query, reference=reference)
|
|
316
|
+
cmap.compute_neighbors(n_neighbors=30, use_rep="X_pca", knn_method="sklearn")
|
|
317
|
+
cmap.compute_mapping_matrix(kernel_method="gauss")
|
|
318
|
+
cmap.map_obs(key="leiden")
|
|
319
|
+
full_conf = cmap.query.obs["leiden_conf"].copy()
|
|
320
|
+
|
|
321
|
+
labels = reference.obs["leiden"].astype(object)
|
|
322
|
+
labels.iloc[::2] = np.nan # half the reference unlabelled, as in a sparsely annotated atlas
|
|
323
|
+
labels.iloc[1::4] = ""
|
|
324
|
+
reference.obs["sparse_leiden"] = pd.Categorical(labels)
|
|
325
|
+
cmap.map_obs(key="sparse_leiden")
|
|
326
|
+
|
|
327
|
+
pred = cmap.query.obs["sparse_leiden_pred"]
|
|
328
|
+
assert pred.notna().all()
|
|
329
|
+
assert set(pred.astype(str)) <= set(reference.obs["leiden"].cat.categories) # never "" or NaN
|
|
330
|
+
assert (cmap.query.obs["sparse_leiden_conf"] < full_conf + 1e-6).all()
|
|
331
|
+
|
|
332
|
+
def test_map_obs_no_labelled_neighbours(self, query_reference_adata):
|
|
333
|
+
"""A query cell whose neighbours are all unlabelled gets no prediction, not the first category."""
|
|
334
|
+
query, reference = query_reference_adata
|
|
335
|
+
kept = reference.obs["leiden"].cat.categories[-1] # only one cluster stays labelled
|
|
336
|
+
reference.obs["one_cluster"] = reference.obs["leiden"].where(reference.obs["leiden"] == kept)
|
|
337
|
+
cmap = CellMapper(query=query, reference=reference)
|
|
338
|
+
cmap.compute_neighbors(n_neighbors=30, use_rep="X_pca", knn_method="sklearn")
|
|
339
|
+
cmap.compute_mapping_matrix(kernel_method="gauss")
|
|
340
|
+
cmap.map_obs(key="one_cluster")
|
|
341
|
+
|
|
342
|
+
pred, conf = cmap.query.obs["one_cluster_pred"], cmap.query.obs["one_cluster_conf"]
|
|
343
|
+
assert pred.isna().any() and pred.notna().any()
|
|
344
|
+
assert (pred.dropna() == kept).all()
|
|
345
|
+
assert (conf[pred.isna()] == 0).all() and (conf[pred.notna()] > 0).all()
|
|
346
|
+
|
|
347
|
+
def test_map_obs_no_labels_at_all(self, query_reference_adata):
|
|
348
|
+
"""A reference column without any label gives missing predictions, not an error."""
|
|
349
|
+
query, reference = query_reference_adata
|
|
350
|
+
reference.obs["empty"] = pd.Categorical([np.nan] * reference.n_obs)
|
|
351
|
+
cmap = CellMapper(query=query, reference=reference)
|
|
352
|
+
cmap.compute_neighbors(n_neighbors=30, use_rep="X_pca", knn_method="sklearn")
|
|
353
|
+
cmap.compute_mapping_matrix(kernel_method="gauss")
|
|
354
|
+
probs = cmap.map_obs(key="empty", return_probabilities=True)
|
|
355
|
+
assert cmap.query.obs["empty_pred"].isna().all() and (cmap.query.obs["empty_conf"] == 0).all()
|
|
356
|
+
assert probs.shape == (query.n_obs, 0)
|
|
357
|
+
|
|
311
358
|
def test_map_obs_subset_categories(self, query_reference_adata):
|
|
312
359
|
"""Test mapping with subset_categories parameter for categorical data."""
|
|
313
360
|
query, reference = query_reference_adata
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cellmapper-0.2.6 → cellmapper-0.2.7}/docs/notebooks/tutorials/query_to_reference_mapping.ipynb
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|