cellmapper 0.2.4__tar.gz → 0.2.5__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.4 → cellmapper-0.2.5}/.cruft.json +3 -3
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.github/ISSUE_TEMPLATE/bug_report.yml +1 -1
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.github/ISSUE_TEMPLATE/feature_request.yml +1 -1
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.github/copilot-instructions.md +20 -10
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.github/workflows/build.yaml +2 -4
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.github/workflows/release.yaml +2 -4
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.github/workflows/test.yaml +6 -5
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.gitignore +3 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.pre-commit-config.yaml +3 -3
- cellmapper-0.2.5/.python-version +1 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.readthedocs.yaml +2 -1
- {cellmapper-0.2.4 → cellmapper-0.2.5}/CHANGELOG.md +27 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/PKG-INFO +3 -2
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/conf.py +8 -4
- {cellmapper-0.2.4 → cellmapper-0.2.5}/pyproject.toml +6 -5
- {cellmapper-0.2.4 → cellmapper-0.2.5}/src/cellmapper/_docs.py +1 -1
- {cellmapper-0.2.4 → cellmapper-0.2.5}/src/cellmapper/check.py +19 -3
- {cellmapper-0.2.4 → cellmapper-0.2.5}/src/cellmapper/model/_knn_backend.py +45 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/src/cellmapper/model/cellmapper.py +25 -15
- {cellmapper-0.2.4 → cellmapper-0.2.5}/src/cellmapper/model/evaluate.py +47 -12
- {cellmapper-0.2.4 → cellmapper-0.2.5}/src/cellmapper/model/kernel.py +11 -6
- {cellmapper-0.2.4 → cellmapper-0.2.5}/tests/conftest.py +5 -2
- {cellmapper-0.2.4 → cellmapper-0.2.5}/tests/model/test_query_to_reference_mapping.py +1 -1
- {cellmapper-0.2.4 → cellmapper-0.2.5}/tests/model/test_self_mapping.py +21 -7
- {cellmapper-0.2.4 → cellmapper-0.2.5}/tests/test_check.py +16 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.codecov.yaml +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.editorconfig +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.vscode/extensions.json +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.vscode/launch.json +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/.vscode/settings.json +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/LICENSE +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/README.md +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/biome.jsonc +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/_static/.gitkeep +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/_static/css/custom.css +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/_static/images/cellmapper_logo_dark.svg +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/_static/images/cellmapper_logo_light.svg +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/_templates/.gitkeep +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/_templates/autosummary/class.rst +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/api.md +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/changelog.md +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/contributing.md +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/extensions/typed_returns.py +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/index.md +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/notebooks/tutorials/data_denoising.ipynb +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/notebooks/tutorials/index.rst +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/notebooks/tutorials/query_to_reference_mapping.ipynb +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/notebooks/tutorials/spatial_mapping.ipynb +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/notebooks/tutorials/spatial_smoothing.ipynb +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/references.bib +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/docs/references.md +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/src/cellmapper/__init__.py +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/src/cellmapper/constants.py +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/src/cellmapper/logging.py +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/src/cellmapper/model/embedding.py +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/src/cellmapper/model/mapping_operator.py +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/src/cellmapper/model/neighbors.py +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/src/cellmapper/utils.py +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/tests/data/precomputed_leiden.csv +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/tests/model/test_embedding.py +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/tests/model/test_evaluate.py +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/tests/model/test_kernel.py +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/tests/model/test_mapping_operator.py +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/tests/model/test_neighbors.py +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/tests/test_basic.py +0 -0
- {cellmapper-0.2.4 → cellmapper-0.2.5}/tests/test_utils.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"template": "https://github.com/scverse/cookiecutter-scverse",
|
|
3
|
-
"commit": "
|
|
4
|
-
"checkout": "v0.
|
|
3
|
+
"commit": "6ff5b92b5d44ea6d8a88e47538475718d467db95",
|
|
4
|
+
"checkout": "v0.7.0",
|
|
5
5
|
"context": {
|
|
6
6
|
"cookiecutter": {
|
|
7
7
|
"project_name": "cellmapper",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"trim_blocks": true
|
|
37
37
|
},
|
|
38
38
|
"_template": "https://github.com/scverse/cookiecutter-scverse",
|
|
39
|
-
"_commit": "
|
|
39
|
+
"_commit": "6ff5b92b5d44ea6d8a88e47538475718d467db95"
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"directory": null
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
## Important Notes
|
|
4
4
|
- Avoid drafting summary documents or endless markdown files. Just summarize in chat what you did, why, and any open questions.
|
|
5
5
|
- Don't update Jupyter notebooks - those are managed manually.
|
|
6
|
-
- When running terminal commands,
|
|
6
|
+
- When running terminal commands, use `uv run` to execute commands within the project's virtual environment (e.g., `uv run python script.py`).
|
|
7
|
+
- **Testing: ALWAYS use `hatch test`, NEVER `uv run pytest` or standalone pytest.** Hatch manages the test matrix (Python versions, dependencies) that CI uses. See "Testing Strategy" section for details.
|
|
7
8
|
- Rather than making assumptions, ask for clarification when uncertain.
|
|
8
9
|
- **GitHub workflows**: Use GitHub CLI (`gh`) when possible. For GitHub MCP server tools, ensure Docker Desktop is running first (`open -a "Docker Desktop"`).
|
|
9
10
|
|
|
@@ -44,20 +45,29 @@
|
|
|
44
45
|
|
|
45
46
|
## Development Workflow
|
|
46
47
|
|
|
47
|
-
### Environment Management (
|
|
48
|
+
### Environment Management (uv-based)
|
|
48
49
|
```bash
|
|
49
|
-
#
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
# Create/sync virtual environment
|
|
51
|
+
uv sync # install project with default dependencies
|
|
52
|
+
uv sync --extra test # include test dependencies
|
|
53
|
+
uv sync --extra doc # include documentation dependencies
|
|
54
|
+
uv sync --all-extras # include all optional dependencies
|
|
55
|
+
|
|
56
|
+
# Run commands in virtual environment
|
|
57
|
+
uv run python script.py # run any Python script
|
|
58
|
+
uv run pytest tests/ # run tests directly (alternative to hatch)
|
|
59
|
+
|
|
60
|
+
# Testing via hatch (recommended, runs test matrix, uses uv internally)
|
|
61
|
+
hatch test # test with highest Python version
|
|
62
|
+
hatch test --all # test all Python 3.11, 3.13, pre-release deps
|
|
52
63
|
|
|
53
64
|
# Documentation
|
|
54
|
-
hatch run docs:build
|
|
55
|
-
hatch run docs:open
|
|
56
|
-
hatch run docs:clean
|
|
65
|
+
hatch run docs:build # build Sphinx docs
|
|
66
|
+
hatch run docs:open # open in browser
|
|
67
|
+
hatch run docs:clean # clean build artifacts
|
|
57
68
|
|
|
58
69
|
# Environment inspection
|
|
59
|
-
hatch env show
|
|
60
|
-
hatch env find hatch-test # find test environment paths
|
|
70
|
+
hatch env show # list environments
|
|
61
71
|
```
|
|
62
72
|
|
|
63
73
|
### Testing Strategy
|
|
@@ -19,14 +19,12 @@ jobs:
|
|
|
19
19
|
package:
|
|
20
20
|
runs-on: ubuntu-latest
|
|
21
21
|
steps:
|
|
22
|
-
- uses: actions/checkout@
|
|
22
|
+
- uses: actions/checkout@v5
|
|
23
23
|
with:
|
|
24
24
|
filter: blob:none
|
|
25
25
|
fetch-depth: 0
|
|
26
26
|
- name: Install uv
|
|
27
|
-
uses: astral-sh/setup-uv@
|
|
28
|
-
with:
|
|
29
|
-
cache-dependency-glob: pyproject.toml
|
|
27
|
+
uses: astral-sh/setup-uv@v7
|
|
30
28
|
- name: Build package
|
|
31
29
|
run: uv build
|
|
32
30
|
- name: Check package
|
|
@@ -20,14 +20,12 @@ jobs:
|
|
|
20
20
|
permissions:
|
|
21
21
|
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
|
|
22
22
|
steps:
|
|
23
|
-
- uses: actions/checkout@
|
|
23
|
+
- uses: actions/checkout@v5
|
|
24
24
|
with:
|
|
25
25
|
filter: blob:none
|
|
26
26
|
fetch-depth: 0
|
|
27
27
|
- name: Install uv
|
|
28
|
-
uses: astral-sh/setup-uv@
|
|
29
|
-
with:
|
|
30
|
-
cache-dependency-glob: pyproject.toml
|
|
28
|
+
uses: astral-sh/setup-uv@v7
|
|
31
29
|
- name: Build package
|
|
32
30
|
run: uv build
|
|
33
31
|
- name: Publish package distributions to PyPI
|
|
@@ -28,12 +28,12 @@ jobs:
|
|
|
28
28
|
outputs:
|
|
29
29
|
envs: ${{ steps.get-envs.outputs.envs }}
|
|
30
30
|
steps:
|
|
31
|
-
- uses: actions/checkout@
|
|
31
|
+
- uses: actions/checkout@v5
|
|
32
32
|
with:
|
|
33
33
|
filter: blob:none
|
|
34
34
|
fetch-depth: 0
|
|
35
35
|
- name: Install uv
|
|
36
|
-
uses: astral-sh/setup-uv@
|
|
36
|
+
uses: astral-sh/setup-uv@v7
|
|
37
37
|
- name: Get test environments
|
|
38
38
|
id: get-envs
|
|
39
39
|
run: |
|
|
@@ -60,17 +60,18 @@ jobs:
|
|
|
60
60
|
|
|
61
61
|
name: ${{ matrix.env.label }}
|
|
62
62
|
runs-on: ${{ matrix.os }}
|
|
63
|
+
# Allow pre-release tests to fail without blocking the PR (dependency compatibility issues)
|
|
64
|
+
continue-on-error: ${{ contains(matrix.env.name, 'pre') }}
|
|
63
65
|
|
|
64
66
|
steps:
|
|
65
|
-
- uses: actions/checkout@
|
|
67
|
+
- uses: actions/checkout@v5
|
|
66
68
|
with:
|
|
67
69
|
filter: blob:none
|
|
68
70
|
fetch-depth: 0
|
|
69
71
|
- name: Install uv
|
|
70
|
-
uses: astral-sh/setup-uv@
|
|
72
|
+
uses: astral-sh/setup-uv@v7
|
|
71
73
|
with:
|
|
72
74
|
python-version: ${{ matrix.env.python }}
|
|
73
|
-
cache-dependency-glob: pyproject.toml
|
|
74
75
|
- name: create hatch environment
|
|
75
76
|
run: uvx hatch env create ${{ matrix.env.name }}
|
|
76
77
|
- name: run tests using hatch
|
|
@@ -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.3.10
|
|
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.11.
|
|
15
|
+
rev: v2.11.1
|
|
16
16
|
hooks:
|
|
17
17
|
- id: pyproject-fmt
|
|
18
18
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
19
|
-
rev: v0.14.
|
|
19
|
+
rev: v0.14.11
|
|
20
20
|
hooks:
|
|
21
21
|
- id: ruff-check
|
|
22
22
|
types_or: [python, pyi, jupyter]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.13
|
|
@@ -10,6 +10,33 @@ and this project adheres to [Semantic Versioning][].
|
|
|
10
10
|
|
|
11
11
|
## [Unreleased]
|
|
12
12
|
|
|
13
|
+
## [v0.2.5]
|
|
14
|
+
|
|
15
|
+
### Added
|
|
16
|
+
- Added `batch_size` parameter to `Kernel.compute_neighbors()` for backend-agnostic batching {pr}`60`
|
|
17
|
+
- Added `subset` parameter to `plot_confusion_matrix()` for filtering cells {pr}`60`
|
|
18
|
+
- Added Python 3.14 support {pr}`62`
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
- Default postfixes now include underscore: `"_pred"` and `"_conf"` instead of `"pred"` and `"conf"` {pr}`60`
|
|
22
|
+
- Switched from MathJax to KaTeX for documentation math rendering {pr}`61`
|
|
23
|
+
- Updated GitHub Actions to latest versions (checkout v5, setup-uv v7) {pr}`61`
|
|
24
|
+
- Updated test matrix to Python 3.11/3.14 {pr}`62`
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
- Fixed `PackageNotFoundError` when checking rapids availability in conda environments {pr}`60`
|
|
28
|
+
- Fixed stale k-NN state when `compute_neighbors()` fails {pr}`60`
|
|
29
|
+
- Fixed `plot_confusion_matrix()` handling of NaN values in both y_true and y_pred {pr}`60`
|
|
30
|
+
- Fixed `plot_confusion_matrix()` handling of mismatched category sets {pr}`60`
|
|
31
|
+
- Fixed `plot_confusion_matrix()` handling of float categories {pr}`60`
|
|
32
|
+
- Fixed `importlib.resources.files()` compatibility with Python 3.14 {pr}`62`
|
|
33
|
+
|
|
34
|
+
## [v0.2.4]
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
- Deprecated Python 3.10 support {pr}`55`
|
|
38
|
+
- Updated to cookiecutter-scverse template v0.6.0 {pr}`54`
|
|
39
|
+
|
|
13
40
|
## [v0.2.3]
|
|
14
41
|
|
|
15
42
|
### Changed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cellmapper
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.5
|
|
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
|
|
@@ -49,7 +49,7 @@ Provides-Extra: dev
|
|
|
49
49
|
Requires-Dist: pre-commit; extra == 'dev'
|
|
50
50
|
Requires-Dist: twine>=4.0.2; extra == 'dev'
|
|
51
51
|
Provides-Extra: doc
|
|
52
|
-
Requires-Dist: docutils!=0.18.*,!=0.19
|
|
52
|
+
Requires-Dist: docutils!=0.18.*,!=0.19.*,<0.22,>=0.8; extra == 'doc'
|
|
53
53
|
Requires-Dist: ipykernel; extra == 'doc'
|
|
54
54
|
Requires-Dist: ipython; extra == 'doc'
|
|
55
55
|
Requires-Dist: myst-nb>=1.1; extra == 'doc'
|
|
@@ -61,6 +61,7 @@ Requires-Dist: sphinx-copybutton; extra == 'doc'
|
|
|
61
61
|
Requires-Dist: sphinx-tabs; extra == 'doc'
|
|
62
62
|
Requires-Dist: sphinx>=8.1; extra == 'doc'
|
|
63
63
|
Requires-Dist: sphinxcontrib-bibtex>=1; extra == 'doc'
|
|
64
|
+
Requires-Dist: sphinxcontrib-katex; extra == 'doc'
|
|
64
65
|
Requires-Dist: sphinxext-opengraph; extra == 'doc'
|
|
65
66
|
Provides-Extra: test
|
|
66
67
|
Requires-Dist: coverage>=7.10; extra == 'test'
|
|
@@ -5,11 +5,14 @@
|
|
|
5
5
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html
|
|
6
6
|
|
|
7
7
|
# -- Path setup --------------------------------------------------------------
|
|
8
|
+
import shutil
|
|
8
9
|
import sys
|
|
9
10
|
from datetime import datetime
|
|
10
11
|
from importlib.metadata import metadata
|
|
11
12
|
from pathlib import Path
|
|
12
13
|
|
|
14
|
+
from sphinxcontrib import katex
|
|
15
|
+
|
|
13
16
|
HERE = Path(__file__).parent
|
|
14
17
|
sys.path.insert(0, str(HERE / "extensions"))
|
|
15
18
|
|
|
@@ -19,7 +22,7 @@ sys.path.insert(0, str(HERE / "extensions"))
|
|
|
19
22
|
# NOTE: If you installed your project in editable mode, this might be stale.
|
|
20
23
|
# If this is the case, reinstall it to refresh the metadata
|
|
21
24
|
info = metadata("cellmapper")
|
|
22
|
-
|
|
25
|
+
project = info["Name"]
|
|
23
26
|
author = info["Author"]
|
|
24
27
|
copyright = f"{datetime.now():%Y}, {author}."
|
|
25
28
|
version = info["Version"]
|
|
@@ -37,7 +40,7 @@ needs_sphinx = "4.0"
|
|
|
37
40
|
html_context = {
|
|
38
41
|
"display_github": True, # Integrate GitHub
|
|
39
42
|
"github_user": "quadbio",
|
|
40
|
-
"github_repo":
|
|
43
|
+
"github_repo": project,
|
|
41
44
|
"github_version": "main",
|
|
42
45
|
"conf_py_path": "/docs/",
|
|
43
46
|
}
|
|
@@ -54,9 +57,9 @@ extensions = [
|
|
|
54
57
|
"sphinx.ext.autosummary",
|
|
55
58
|
"sphinx.ext.napoleon",
|
|
56
59
|
"sphinxcontrib.bibtex",
|
|
60
|
+
"sphinxcontrib.katex",
|
|
57
61
|
"sphinx_autodoc_typehints",
|
|
58
62
|
"sphinx_tabs.tabs",
|
|
59
|
-
"sphinx.ext.mathjax",
|
|
60
63
|
"IPython.sphinxext.ipython_console_highlighting",
|
|
61
64
|
"sphinxext.opengraph",
|
|
62
65
|
*[p.stem for p in (HERE / "extensions").glob("*.py")],
|
|
@@ -121,7 +124,7 @@ html_theme = "sphinx_book_theme"
|
|
|
121
124
|
html_static_path = ["_static"]
|
|
122
125
|
html_css_files = ["css/custom.css"]
|
|
123
126
|
|
|
124
|
-
html_title =
|
|
127
|
+
html_title = project
|
|
125
128
|
|
|
126
129
|
html_theme_options = {
|
|
127
130
|
"repository_url": repository_url,
|
|
@@ -135,6 +138,7 @@ html_theme_options = {
|
|
|
135
138
|
}
|
|
136
139
|
|
|
137
140
|
pygments_style = "default"
|
|
141
|
+
katex_prerender = shutil.which(katex.NODEJS_BINARY) is not None
|
|
138
142
|
|
|
139
143
|
nitpick_ignore = [
|
|
140
144
|
# If building the documentation fails because of a missing link that is outside your control,
|
|
@@ -40,7 +40,7 @@ optional-dependencies.dev = [
|
|
|
40
40
|
"twine>=4.0.2",
|
|
41
41
|
]
|
|
42
42
|
optional-dependencies.doc = [
|
|
43
|
-
"docutils>=0.8,!=0.18.*,!=0.19
|
|
43
|
+
"docutils>=0.8,!=0.18.*,!=0.19.*,<0.22", # sphinx-tabs incompatible with 0.22, see https://github.com/executablebooks/sphinx-tabs/issues/206
|
|
44
44
|
"ipykernel",
|
|
45
45
|
"ipython",
|
|
46
46
|
"myst-nb>=1.1",
|
|
@@ -53,6 +53,7 @@ optional-dependencies.doc = [
|
|
|
53
53
|
"sphinx-copybutton",
|
|
54
54
|
"sphinx-tabs",
|
|
55
55
|
"sphinxcontrib-bibtex>=1",
|
|
56
|
+
"sphinxcontrib-katex",
|
|
56
57
|
"sphinxext-opengraph",
|
|
57
58
|
]
|
|
58
59
|
optional-dependencies.test = [
|
|
@@ -94,12 +95,12 @@ scripts.clean = "git clean -fdX -- {args:docs}"
|
|
|
94
95
|
# Test the lowest and highest supported Python versions with normal deps
|
|
95
96
|
[[tool.hatch.envs.hatch-test.matrix]]
|
|
96
97
|
deps = [ "stable" ]
|
|
97
|
-
python = [ "3.11", "3.
|
|
98
|
+
python = [ "3.11", "3.14" ]
|
|
98
99
|
|
|
99
100
|
# Test the newest supported Python version also with pre-release deps
|
|
100
101
|
[[tool.hatch.envs.hatch-test.matrix]]
|
|
101
102
|
deps = [ "pre" ]
|
|
102
|
-
python = [ "3.
|
|
103
|
+
python = [ "3.14" ]
|
|
103
104
|
|
|
104
105
|
[tool.hatch.envs.hatch-test]
|
|
105
106
|
features = [ "dev", "test" ]
|
|
@@ -151,9 +152,9 @@ lint.per-file-ignores."docs/*" = [ "I" ]
|
|
|
151
152
|
lint.per-file-ignores."tests/*" = [ "D" ]
|
|
152
153
|
lint.pydocstyle.convention = "numpy"
|
|
153
154
|
|
|
154
|
-
[tool.pytest
|
|
155
|
+
[tool.pytest]
|
|
155
156
|
testpaths = [ "tests" ]
|
|
156
|
-
|
|
157
|
+
strict = true
|
|
157
158
|
addopts = [
|
|
158
159
|
"--import-mode=importlib", # allow using test files with same name
|
|
159
160
|
]
|
|
@@ -18,7 +18,7 @@ diffusion_method
|
|
|
18
18
|
|
|
19
19
|
_prediction_postfix = """\
|
|
20
20
|
prediction_postfix
|
|
21
|
-
Postfix to
|
|
21
|
+
Postfix to append to mapped variable names (including any separator, e.g. "_pred"). Use "" for no postfix."""
|
|
22
22
|
|
|
23
23
|
_symmetrize = """\
|
|
24
24
|
symmetrize
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import importlib
|
|
4
4
|
import types
|
|
5
|
+
from importlib.metadata import PackageNotFoundError, version
|
|
5
6
|
|
|
6
7
|
from packaging.version import parse
|
|
7
8
|
|
|
8
|
-
from . import
|
|
9
|
+
from .logging import logger
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
class Checker:
|
|
@@ -42,8 +43,23 @@ class Checker:
|
|
|
42
43
|
importlib.import_module(self.name)
|
|
43
44
|
except ModuleNotFoundError as e:
|
|
44
45
|
raise RuntimeError(" ".join(filter(None, [self.vreq_hint, self.install_hint]))) from e
|
|
45
|
-
|
|
46
|
-
if
|
|
46
|
+
|
|
47
|
+
# Skip version check if no minimum version is required
|
|
48
|
+
if not self.vmin:
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
# Try to get version from package metadata (may fail for conda packages)
|
|
52
|
+
try:
|
|
53
|
+
v = parse(version(self.package_name))
|
|
54
|
+
except PackageNotFoundError:
|
|
55
|
+
logger.debug(
|
|
56
|
+
"Could not find package metadata for %s. Skipping version check. "
|
|
57
|
+
"This can happen with conda-installed packages.",
|
|
58
|
+
self.package_name,
|
|
59
|
+
)
|
|
60
|
+
return
|
|
61
|
+
|
|
62
|
+
if v < self.vmin:
|
|
47
63
|
raise RuntimeError(
|
|
48
64
|
" ".join(
|
|
49
65
|
[
|
|
@@ -110,6 +110,48 @@ class _FaissGpuBackend(_KNNBackend):
|
|
|
110
110
|
return distances, indices
|
|
111
111
|
|
|
112
112
|
|
|
113
|
+
def _batched_query(
|
|
114
|
+
backend: "_KNNBackend",
|
|
115
|
+
points: np.ndarray,
|
|
116
|
+
k: int,
|
|
117
|
+
batch_size: int | None,
|
|
118
|
+
) -> tuple[np.ndarray, np.ndarray]:
|
|
119
|
+
"""
|
|
120
|
+
Query a k-NN backend in batches to avoid memory issues.
|
|
121
|
+
|
|
122
|
+
Parameters
|
|
123
|
+
----------
|
|
124
|
+
backend
|
|
125
|
+
The k-NN backend to query.
|
|
126
|
+
points
|
|
127
|
+
Query points.
|
|
128
|
+
k
|
|
129
|
+
Number of neighbors to query.
|
|
130
|
+
batch_size
|
|
131
|
+
Number of query points per batch. If None, no batching is applied.
|
|
132
|
+
|
|
133
|
+
Returns
|
|
134
|
+
-------
|
|
135
|
+
Tuple of (distances, indices) arrays.
|
|
136
|
+
"""
|
|
137
|
+
n_points = points.shape[0]
|
|
138
|
+
|
|
139
|
+
if batch_size is None or n_points <= batch_size:
|
|
140
|
+
return backend.query(points, k)
|
|
141
|
+
|
|
142
|
+
all_distances = []
|
|
143
|
+
all_indices = []
|
|
144
|
+
|
|
145
|
+
for start in range(0, n_points, batch_size):
|
|
146
|
+
end = min(start + batch_size, n_points)
|
|
147
|
+
batch = points[start:end]
|
|
148
|
+
dist, idx = backend.query(batch, k)
|
|
149
|
+
all_distances.append(dist)
|
|
150
|
+
all_indices.append(idx)
|
|
151
|
+
|
|
152
|
+
return np.vstack(all_distances), np.vstack(all_indices)
|
|
153
|
+
|
|
154
|
+
|
|
113
155
|
class _RapidsBackend(_KNNBackend):
|
|
114
156
|
def __init__(
|
|
115
157
|
self,
|
|
@@ -143,6 +185,9 @@ class _RapidsBackend(_KNNBackend):
|
|
|
143
185
|
def query(self, points: np.ndarray, k: int) -> tuple[np.ndarray, np.ndarray]:
|
|
144
186
|
points_gpu = self.cp.asarray(points)
|
|
145
187
|
distances, indices = self._nn.kneighbors(points_gpu)
|
|
188
|
+
# Free GPU memory
|
|
189
|
+
del points_gpu
|
|
190
|
+
self.cp.get_default_memory_pool().free_all_blocks()
|
|
146
191
|
return distances, indices
|
|
147
192
|
|
|
148
193
|
|
|
@@ -209,12 +209,14 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
209
209
|
xrep = xrep[:, :n_comps]
|
|
210
210
|
yrep = yrep[:, :n_comps]
|
|
211
211
|
|
|
212
|
-
self.knn
|
|
212
|
+
# Create kernel and compute neighbors. Only assign to self.knn after
|
|
213
|
+
# successful completion to avoid stale state if neighbor computation fails.
|
|
214
|
+
knn = Kernel(
|
|
213
215
|
np.ascontiguousarray(xrep),
|
|
214
216
|
None if self._is_self_mapping else np.ascontiguousarray(yrep),
|
|
215
217
|
is_self_mapping=self._is_self_mapping,
|
|
216
218
|
)
|
|
217
|
-
|
|
219
|
+
knn.compute_neighbors(
|
|
218
220
|
n_neighbors=n_neighbors,
|
|
219
221
|
knn_method=knn_method,
|
|
220
222
|
knn_dist_metric=knn_dist_metric,
|
|
@@ -222,6 +224,7 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
222
224
|
random_state=random_state,
|
|
223
225
|
**(neighbors_kwargs or {}),
|
|
224
226
|
)
|
|
227
|
+
self.knn = knn
|
|
225
228
|
|
|
226
229
|
@d.dedent
|
|
227
230
|
def compute_mapping_matrix(
|
|
@@ -316,7 +319,7 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
316
319
|
key: str,
|
|
317
320
|
t: int | None = None,
|
|
318
321
|
diffusion_method: Literal["iterative", "spectral"] = "iterative",
|
|
319
|
-
prediction_postfix: str = "
|
|
322
|
+
prediction_postfix: str = "_pred",
|
|
320
323
|
) -> None:
|
|
321
324
|
"""
|
|
322
325
|
Map embeddings with optional multi-step diffusion.
|
|
@@ -388,7 +391,7 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
388
391
|
)
|
|
389
392
|
|
|
390
393
|
# Store the transferred embeddings in query.obsm with descriptive key
|
|
391
|
-
output_key = f"{key}
|
|
394
|
+
output_key = f"{key}{prediction_postfix}"
|
|
392
395
|
self.query.obsm[output_key] = query_data
|
|
393
396
|
logger.info("Embeddings mapped and stored in query.obsm['%s']", output_key)
|
|
394
397
|
|
|
@@ -519,6 +522,7 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
519
522
|
knn_method: Literal["sklearn", "pynndescent", "rapids"] = "sklearn",
|
|
520
523
|
knn_dist_metric: str = "euclidean",
|
|
521
524
|
only_yx: bool = False,
|
|
525
|
+
neighbors_kwargs: dict[str, Any] | None = None,
|
|
522
526
|
kernel_method: Literal[
|
|
523
527
|
"jaccard",
|
|
524
528
|
"gauss",
|
|
@@ -532,7 +536,7 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
532
536
|
| None = None,
|
|
533
537
|
symmetrize: bool | None = None,
|
|
534
538
|
self_edges: bool | None = None,
|
|
535
|
-
prediction_postfix: str = "
|
|
539
|
+
prediction_postfix: str = "_pred",
|
|
536
540
|
subset_categories: None | list[str] | str = None,
|
|
537
541
|
) -> "CellMapper":
|
|
538
542
|
"""
|
|
@@ -554,6 +558,10 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
554
558
|
%(knn_method)s
|
|
555
559
|
%(knn_dist_metric)s
|
|
556
560
|
%(only_yx)s
|
|
561
|
+
neighbors_kwargs
|
|
562
|
+
Additional keyword arguments to pass to the neighbors computation method.
|
|
563
|
+
For rapids backend, you can pass ``batch_size`` to process queries in batches
|
|
564
|
+
to avoid GPU OOM errors (e.g., ``neighbors_kwargs={"batch_size": 50000}``).
|
|
557
565
|
%(kernel_method)s
|
|
558
566
|
%(symmetrize)s
|
|
559
567
|
%(self_edges)s
|
|
@@ -567,6 +575,7 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
567
575
|
knn_method=knn_method,
|
|
568
576
|
knn_dist_metric=knn_dist_metric,
|
|
569
577
|
only_yx=only_yx,
|
|
578
|
+
neighbors_kwargs=neighbors_kwargs,
|
|
570
579
|
)
|
|
571
580
|
if self._mapping_operator is None:
|
|
572
581
|
self.compute_mapping_matrix(kernel_method=kernel_method, symmetrize=symmetrize, self_edges=self_edges)
|
|
@@ -662,8 +671,8 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
662
671
|
key: str,
|
|
663
672
|
t: int | None = None,
|
|
664
673
|
diffusion_method: Literal["iterative", "spectral"] = "iterative",
|
|
665
|
-
prediction_postfix: str = "
|
|
666
|
-
confidence_postfix: str = "
|
|
674
|
+
prediction_postfix: str = "_pred",
|
|
675
|
+
confidence_postfix: str = "_conf",
|
|
667
676
|
return_probabilities: bool = False,
|
|
668
677
|
subset_categories: None | list[str] | str = None,
|
|
669
678
|
) -> pd.DataFrame | None:
|
|
@@ -855,19 +864,19 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
855
864
|
conf_vals = np.max(ytab, axis=1).ravel()
|
|
856
865
|
conf = pd.Series(conf_vals, index=self.query.obs_names)
|
|
857
866
|
|
|
858
|
-
|
|
859
|
-
|
|
867
|
+
pred_key = f"{key}{prediction_postfix}"
|
|
868
|
+
conf_key = f"{key}{confidence_postfix}"
|
|
869
|
+
self.query.obs[pred_key] = pred
|
|
870
|
+
self.query.obs[conf_key] = conf
|
|
860
871
|
|
|
861
872
|
# Add colors if available
|
|
862
873
|
if f"{key}_colors" in self.reference.uns:
|
|
863
874
|
color_lookup = dict(
|
|
864
875
|
zip(self.reference.obs[key].cat.categories, self.reference.uns[f"{key}_colors"], strict=True)
|
|
865
876
|
)
|
|
866
|
-
self.query.uns[f"{
|
|
867
|
-
color_lookup.get(cat, "#383838") for cat in pred.cat.categories
|
|
868
|
-
]
|
|
877
|
+
self.query.uns[f"{pred_key}_colors"] = [color_lookup.get(cat, "#383838") for cat in pred.cat.categories]
|
|
869
878
|
|
|
870
|
-
logger.info("Categorical data mapped and stored in query.obs['%s'].",
|
|
879
|
+
logger.info("Categorical data mapped and stored in query.obs['%s'].", pred_key)
|
|
871
880
|
|
|
872
881
|
# Return probabilities as a sparse pandas DataFrame if requested (never densify)
|
|
873
882
|
if return_probabilities:
|
|
@@ -900,6 +909,7 @@ class CellMapper(EvaluationMixin, EmbeddingMixin):
|
|
|
900
909
|
index=self.query.obs_names,
|
|
901
910
|
)
|
|
902
911
|
|
|
903
|
-
|
|
912
|
+
pred_key = f"{key}{prediction_postfix}"
|
|
913
|
+
self.query.obs[pred_key] = pred
|
|
904
914
|
|
|
905
|
-
logger.info("Numerical data mapped and stored in query.obs['%s'].",
|
|
915
|
+
logger.info("Numerical data mapped and stored in query.obs['%s'].", pred_key)
|
|
@@ -71,7 +71,7 @@ class EvaluationMixin:
|
|
|
71
71
|
"""Mixin class for evaluation-related methods for CellMapper."""
|
|
72
72
|
|
|
73
73
|
def register_external_predictions(
|
|
74
|
-
self, label_key: str, prediction_postfix: str = "
|
|
74
|
+
self, label_key: str, prediction_postfix: str = "_pred", confidence_postfix: str = "_conf"
|
|
75
75
|
) -> None:
|
|
76
76
|
"""
|
|
77
77
|
Register externally computed predictions for evaluation.
|
|
@@ -99,8 +99,8 @@ class EvaluationMixin:
|
|
|
99
99
|
- ``confidence_postfix``: Postfix for confidence column.
|
|
100
100
|
"""
|
|
101
101
|
# Verify that the expected columns exist
|
|
102
|
-
pred_col = f"{label_key}
|
|
103
|
-
conf_col = f"{label_key}
|
|
102
|
+
pred_col = f"{label_key}{prediction_postfix}"
|
|
103
|
+
conf_col = f"{label_key}{confidence_postfix}"
|
|
104
104
|
|
|
105
105
|
if pred_col not in self.query.obs.columns:
|
|
106
106
|
raise ValueError(f"Prediction column '{pred_col}' not found in query.obs")
|
|
@@ -163,8 +163,8 @@ class EvaluationMixin:
|
|
|
163
163
|
|
|
164
164
|
# Extract ground-truth and predicted labels
|
|
165
165
|
y_true = self.query.obs[label_key].dropna()
|
|
166
|
-
y_pred = self.query.obs.loc[y_true.index, f"{label_key}
|
|
167
|
-
confidence = self.query.obs.loc[y_true.index, f"{label_key}
|
|
166
|
+
y_pred = self.query.obs.loc[y_true.index, f"{label_key}{pred_postfix}"]
|
|
167
|
+
confidence = self.query.obs.loc[y_true.index, f"{label_key}{conf_postfix}"]
|
|
168
168
|
|
|
169
169
|
# Apply confidence cutoff
|
|
170
170
|
valid_indices = confidence >= confidence_cutoff
|
|
@@ -203,32 +203,67 @@ class EvaluationMixin:
|
|
|
203
203
|
self.label_transfer_report = pd.DataFrame(report).transpose()
|
|
204
204
|
|
|
205
205
|
def plot_confusion_matrix(
|
|
206
|
-
self,
|
|
206
|
+
self,
|
|
207
|
+
label_key: str,
|
|
208
|
+
subset: np.ndarray | pd.Series | None = None,
|
|
209
|
+
figsize: tuple[int, int] = (10, 8),
|
|
210
|
+
cmap: str = "viridis",
|
|
211
|
+
save: str | Path | None = None,
|
|
212
|
+
**kwargs,
|
|
207
213
|
) -> None:
|
|
208
214
|
"""
|
|
209
215
|
Plot the confusion matrix as a heatmap using sklearn's ConfusionMatrixDisplay.
|
|
210
216
|
|
|
211
217
|
Parameters
|
|
212
218
|
----------
|
|
219
|
+
label_key
|
|
220
|
+
Key in .obs storing ground-truth cell type annotations.
|
|
221
|
+
subset
|
|
222
|
+
Boolean mask to select a subset of cells for the confusion matrix.
|
|
223
|
+
Must have the same length as query.obs or be a pandas Series indexed by obs_names.
|
|
213
224
|
figsize
|
|
214
225
|
Size of the figure (width, height). Default is (10, 8).
|
|
215
226
|
cmap
|
|
216
227
|
Colormap to use for the heatmap. Default is "viridis".
|
|
217
|
-
|
|
218
|
-
|
|
228
|
+
save
|
|
229
|
+
Path to save the figure. If None, the figure is not saved.
|
|
219
230
|
**kwargs
|
|
220
231
|
Additional keyword arguments to pass to ConfusionMatrixDisplay.
|
|
221
232
|
"""
|
|
222
233
|
if self.prediction_postfix is None or self.confidence_postfix is None:
|
|
223
234
|
raise ValueError("Label transfer has not been performed. Call map_obs() first.")
|
|
224
235
|
|
|
225
|
-
# Extract true and predicted labels
|
|
226
|
-
y_true = self.query.obs[label_key]
|
|
227
|
-
y_pred = self.query.obs
|
|
236
|
+
# Extract true and predicted labels, dropping NaNs from both
|
|
237
|
+
y_true = self.query.obs[label_key]
|
|
238
|
+
y_pred = self.query.obs[f"{label_key}{self.prediction_postfix}"]
|
|
239
|
+
valid_mask = y_true.notna() & y_pred.notna()
|
|
240
|
+
y_true = y_true[valid_mask]
|
|
241
|
+
y_pred = y_pred[valid_mask]
|
|
242
|
+
|
|
243
|
+
# Apply subset filter if provided
|
|
244
|
+
if subset is not None:
|
|
245
|
+
if isinstance(subset, pd.Series):
|
|
246
|
+
subset = subset.loc[y_true.index]
|
|
247
|
+
else:
|
|
248
|
+
# Assume boolean array aligned with query.obs, reindex to y_true
|
|
249
|
+
subset = pd.Series(subset, index=self.query.obs_names).loc[y_true.index]
|
|
250
|
+
y_true = y_true[subset]
|
|
251
|
+
y_pred = y_pred[subset]
|
|
252
|
+
|
|
253
|
+
# Get union of categories if categorical, to handle mismatched category sets
|
|
254
|
+
# Also convert to string to avoid sklearn interpreting float categories as continuous
|
|
255
|
+
labels = None
|
|
256
|
+
if hasattr(y_true, "cat") and hasattr(y_pred, "cat"):
|
|
257
|
+
all_categories = y_true.cat.categories.union(y_pred.cat.categories)
|
|
258
|
+
labels = [str(c) for c in sorted(all_categories)]
|
|
259
|
+
y_true = y_true.astype(str)
|
|
260
|
+
y_pred = y_pred.astype(str)
|
|
228
261
|
|
|
229
262
|
# Plot confusion matrix using sklearn's ConfusionMatrixDisplay
|
|
230
263
|
_, ax = plt.subplots(1, 1, figsize=figsize)
|
|
231
|
-
ConfusionMatrixDisplay.from_predictions(
|
|
264
|
+
ConfusionMatrixDisplay.from_predictions(
|
|
265
|
+
y_true, y_pred, labels=labels, cmap=cmap, xticks_rotation="vertical", ax=ax, **kwargs
|
|
266
|
+
)
|
|
232
267
|
plt.title("Confusion Matrix")
|
|
233
268
|
|
|
234
269
|
if save:
|
|
@@ -6,7 +6,7 @@ from scipy.sparse import csr_matrix
|
|
|
6
6
|
from cellmapper._docs import d
|
|
7
7
|
from cellmapper.constants import PackageConstants
|
|
8
8
|
from cellmapper.logging import logger
|
|
9
|
-
from cellmapper.model._knn_backend import get_backend
|
|
9
|
+
from cellmapper.model._knn_backend import _batched_query, get_backend
|
|
10
10
|
from cellmapper.model.neighbors import Neighbors
|
|
11
11
|
from cellmapper.utils import extract_neighbors_from_distances
|
|
12
12
|
|
|
@@ -113,6 +113,7 @@ class Kernel:
|
|
|
113
113
|
knn_dist_metric: str = "euclidean",
|
|
114
114
|
random_state: int = 0,
|
|
115
115
|
only_yx: bool = False,
|
|
116
|
+
batch_size: int | None = None,
|
|
116
117
|
**kwargs,
|
|
117
118
|
):
|
|
118
119
|
"""
|
|
@@ -127,6 +128,10 @@ class Kernel:
|
|
|
127
128
|
random_state
|
|
128
129
|
Random state for reproducibility.
|
|
129
130
|
%(only_yx)s
|
|
131
|
+
batch_size
|
|
132
|
+
Number of query points to process per batch. If None, all points are
|
|
133
|
+
processed at once. Use this to avoid out-of-memory errors on large datasets,
|
|
134
|
+
especially with GPU backends (rapids, faiss-gpu).
|
|
130
135
|
**kwargs
|
|
131
136
|
Additional keyword arguments to pass to the underlying k-NN algorithm.
|
|
132
137
|
These are method-specific and will be passed directly to the algorithm's
|
|
@@ -183,7 +188,7 @@ class Kernel:
|
|
|
183
188
|
backend_x.fit(self.xrep)
|
|
184
189
|
|
|
185
190
|
if only_yx:
|
|
186
|
-
dists, idx = backend_x
|
|
191
|
+
dists, idx = _batched_query(backend_x, self.yrep, k=n_neighbors, batch_size=batch_size)
|
|
187
192
|
self.yx = Neighbors(distances=dists, indices=idx, n_targets=self.xrep.shape[0])
|
|
188
193
|
return
|
|
189
194
|
|
|
@@ -192,10 +197,10 @@ class Kernel:
|
|
|
192
197
|
)
|
|
193
198
|
backend_y.fit(self.yrep)
|
|
194
199
|
|
|
195
|
-
x_d, x_i = backend_x
|
|
196
|
-
y_d, y_i = backend_y
|
|
197
|
-
xy_d, xy_i = backend_y
|
|
198
|
-
yx_d, yx_i = backend_x
|
|
200
|
+
x_d, x_i = _batched_query(backend_x, self.xrep, k=n_neighbors, batch_size=batch_size)
|
|
201
|
+
y_d, y_i = _batched_query(backend_y, self.yrep, k=n_neighbors, batch_size=batch_size)
|
|
202
|
+
xy_d, xy_i = _batched_query(backend_y, self.xrep, k=n_neighbors, batch_size=batch_size)
|
|
203
|
+
yx_d, yx_i = _batched_query(backend_x, self.yrep, k=n_neighbors, batch_size=batch_size)
|
|
199
204
|
|
|
200
205
|
self.xx = Neighbors(distances=x_d, indices=x_i, n_targets=None)
|
|
201
206
|
self.yy = Neighbors(distances=y_d, indices=y_i, n_targets=None)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from
|
|
1
|
+
from pathlib import Path
|
|
2
2
|
|
|
3
3
|
import numpy as np
|
|
4
4
|
import pandas as pd
|
|
@@ -7,6 +7,9 @@ import scanpy as sc
|
|
|
7
7
|
|
|
8
8
|
from cellmapper.model.cellmapper import CellMapper
|
|
9
9
|
|
|
10
|
+
# Get the tests directory path
|
|
11
|
+
TESTS_DIR = Path(__file__).parent
|
|
12
|
+
|
|
10
13
|
|
|
11
14
|
@pytest.fixture
|
|
12
15
|
def sample_distances():
|
|
@@ -31,7 +34,7 @@ def small_data():
|
|
|
31
34
|
@pytest.fixture
|
|
32
35
|
def precomputed_leiden():
|
|
33
36
|
"""Fixture to load precomputed leiden clustering."""
|
|
34
|
-
data_path =
|
|
37
|
+
data_path = TESTS_DIR / "data" / "precomputed_leiden.csv"
|
|
35
38
|
leiden_cl = pd.read_csv(str(data_path), index_col=0)["leiden"]
|
|
36
39
|
|
|
37
40
|
return leiden_cl
|
|
@@ -82,7 +82,7 @@ class TestQueryToReferenceMapping:
|
|
|
82
82
|
obs_keys="leiden",
|
|
83
83
|
use_rep="X_pca",
|
|
84
84
|
n_neighbors=1,
|
|
85
|
-
prediction_postfix="
|
|
85
|
+
prediction_postfix="_transfer",
|
|
86
86
|
# For n_neighbors=1 identity mapping, we need self-edges and no symmetrization
|
|
87
87
|
symmetrize=False,
|
|
88
88
|
self_edges=True,
|
|
@@ -51,13 +51,15 @@ class TestUMAPConnectivityValidation:
|
|
|
51
51
|
"""Test UMAP connectivity compatibility between scanpy and CellMapper implementations."""
|
|
52
52
|
|
|
53
53
|
@pytest.mark.parametrize(
|
|
54
|
-
"transformer,remove_last_neighbor",
|
|
54
|
+
"transformer,remove_last_neighbor,exact",
|
|
55
55
|
[
|
|
56
|
-
("sklearn", False),
|
|
57
|
-
|
|
56
|
+
("sklearn", False, True),
|
|
57
|
+
# pynndescent is approximate and uses SIMD, so results vary by platform
|
|
58
|
+
# We still test it but with tolerance-based comparison
|
|
59
|
+
("pynndescent", True, False),
|
|
58
60
|
],
|
|
59
61
|
)
|
|
60
|
-
def test_connectivities_from_distances(self, adata_pbmc3k, transformer, remove_last_neighbor):
|
|
62
|
+
def test_connectivities_from_distances(self, adata_pbmc3k, transformer, remove_last_neighbor, exact):
|
|
61
63
|
"""
|
|
62
64
|
Test that CellMapper can exactly reproduce scanpy's UMAP connectivities.
|
|
63
65
|
|
|
@@ -73,6 +75,8 @@ class TestUMAPConnectivityValidation:
|
|
|
73
75
|
The transformer to use ('sklearn' or 'pynndescent')
|
|
74
76
|
remove_last_neighbor
|
|
75
77
|
Whether to remove the last neighbor when loading distances
|
|
78
|
+
exact
|
|
79
|
+
Whether to require exact matrix equality (sklearn) or tolerance-based (pynndescent)
|
|
76
80
|
"""
|
|
77
81
|
# Step 1: Compute neighbors with scanpy using UMAP method
|
|
78
82
|
nbhs = Neighbors(adata_pbmc3k)
|
|
@@ -84,6 +88,7 @@ class TestUMAPConnectivityValidation:
|
|
|
84
88
|
method="umap",
|
|
85
89
|
metric="euclidean",
|
|
86
90
|
transformer=transformer,
|
|
91
|
+
random_state=42,
|
|
87
92
|
)
|
|
88
93
|
|
|
89
94
|
# Store scanpy results
|
|
@@ -100,9 +105,18 @@ class TestUMAPConnectivityValidation:
|
|
|
100
105
|
cmap.load_precomputed_distances(remove_last_neighbor=remove_last_neighbor)
|
|
101
106
|
conn_cmap = cmap.knn.yx.knn_graph_connectivities(kernel="umap", self_edges=True)
|
|
102
107
|
|
|
103
|
-
|
|
108
|
+
if exact:
|
|
109
|
+
assert (nbhs.connectivities - conn_cmap).nnz == 0, "Connectivity matrices should be identical"
|
|
110
|
+
else:
|
|
111
|
+
# For approximate methods, check correlation instead of exact equality
|
|
112
|
+
# pynndescent uses SIMD and produces different results on different platforms
|
|
113
|
+
# (macOS ARM ~0.99, Linux x86 ~0.97), so we use a relaxed threshold
|
|
114
|
+
sc_dense = nbhs.connectivities.toarray().flatten()
|
|
115
|
+
cm_dense = conn_cmap.toarray().flatten()
|
|
116
|
+
correlation = np.corrcoef(sc_dense, cm_dense)[0, 1]
|
|
117
|
+
assert correlation > 0.95, f"Connectivity matrices should be highly correlated, got {correlation:.4f}"
|
|
104
118
|
|
|
105
|
-
#
|
|
119
|
+
# Validate matrix properties
|
|
106
120
|
assert (conn_cmap - conn_cmap.T).nnz == 0, "CellMapper connectivity matrix should be symmetric"
|
|
107
121
|
assert np.allclose(conn_cmap.diagonal(), 0), "CellMapper connectivity matrix should have no self-edges"
|
|
108
122
|
|
|
@@ -186,7 +200,7 @@ class TestSelfMapping:
|
|
|
186
200
|
obs_keys=obs_key,
|
|
187
201
|
use_rep="X_pca",
|
|
188
202
|
n_neighbors=1,
|
|
189
|
-
prediction_postfix="
|
|
203
|
+
prediction_postfix="_pred",
|
|
190
204
|
# For n_neighbors=1 identity mapping, we need self-edges and no symmetrization
|
|
191
205
|
symmetrize=False,
|
|
192
206
|
self_edges=True,
|
|
@@ -32,3 +32,19 @@ class TestCheck:
|
|
|
32
32
|
check.CHECKERS["packaging"] = Checker("packaging")
|
|
33
33
|
check_deps("packaging")
|
|
34
34
|
del check.CHECKERS["packaging"]
|
|
35
|
+
|
|
36
|
+
def test_checker_missing_metadata_no_vmin(self, mocker):
|
|
37
|
+
# Should not raise when package is importable but has no metadata and no vmin
|
|
38
|
+
mocker.patch("importlib.import_module")
|
|
39
|
+
# No vmin means no version check needed
|
|
40
|
+
Checker("fake_module").check()
|
|
41
|
+
|
|
42
|
+
def test_checker_missing_metadata_with_vmin(self, mocker):
|
|
43
|
+
# Should not raise when package is importable but has no metadata (conda packages)
|
|
44
|
+
# even when vmin is specified - we skip version check in this case
|
|
45
|
+
from importlib.metadata import PackageNotFoundError
|
|
46
|
+
|
|
47
|
+
mocker.patch("importlib.import_module")
|
|
48
|
+
mocker.patch("cellmapper.check.version", side_effect=PackageNotFoundError("fake_module"))
|
|
49
|
+
# Should succeed even with vmin - version check is skipped for missing metadata
|
|
50
|
+
Checker("fake_module", vmin="1.0.0").check()
|
|
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.4 → cellmapper-0.2.5}/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
|