Skip to content

Commit 8096b6d

Browse files
authored
Merge pull request #17 from quadbio/feat/docs
Set up docs
2 parents b362286 + 4ca964c commit 8096b6d

File tree

9 files changed

+162
-71
lines changed

9 files changed

+162
-71
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ and this project adheres to [Semantic Versioning][].
1111
## [Unreleased]
1212

1313
### Added
14-
- Included tests for the `check` module, and more tests for the main classes.
14+
- Included tests for the `check` module, and more tests for the main classes {pr}`15`.
15+
- Implemented the computation of presence scores, following HNOCA-tools {pr}`16`.
16+
- Add a `groupby` parameter to expression transfer evaluation {pr}`16`.
1517

1618
## [v0.1.1]
1719

1820
### Changed
19-
- Switched to `vcs`-based versioning.
21+
- Switched to `vcs`-based versioning {pr}`5`.
2022

2123
### Added
2224
- Added PyPI badge.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ If you don't have Python installed, we recommend installing [uv][].
2121

2222
There are two alternative options to install ``cellmapper``:
2323

24-
- **Install the latest release from [PyPI][]**:
24+
- Install the latest release from [PyPI][]:
2525

2626
```bash
2727
pip install cellmapper
2828
```
2929

30-
- **Install the latest development version**:
30+
- Install the latest development version:
3131

3232
```bash
3333
pip install git+https://github.com/quadbio/cellmapper.git@main

docs/api.md

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,25 @@
1-
# API
2-
3-
## Preprocessing
1+
# API Reference
42

53
```{eval-rst}
6-
.. module:: cellmapper.pp
7-
.. currentmodule:: cellmapper
8-
9-
.. autosummary::
10-
:toctree: generated
4+
The class :class:`~cellmapper.CellMapper` is the main class that users interact with:
115
12-
pp.basic_preproc
13-
pp.elaborate_example
14-
```
15-
16-
## Tools
17-
18-
```{eval-rst}
19-
.. module:: cellmapper.tl
6+
.. module:: cellmapper
207
.. currentmodule:: cellmapper
218
229
.. autosummary::
2310
:toctree: generated
2411
25-
tl.basic_tool
12+
CellMapper
2613
```
2714

28-
## Plotting
29-
3015
```{eval-rst}
31-
.. module:: cellmapper.pl
16+
The following classes are more technical; :class:`~cellmapper.Neighbors` is called under the hood for k-NN graph computation.
17+
18+
.. module:: cellmapper
3219
.. currentmodule:: cellmapper
3320
3421
.. autosummary::
3522
:toctree: generated
3623
37-
pl.basic_plot
38-
pl.BasicClass
24+
Neighbors
3925
```

docs/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"IPython.sphinxext.ipython_console_highlighting",
6161
"sphinxext.opengraph",
6262
*[p.stem for p in (HERE / "extensions").glob("*.py")],
63+
"sphinx.ext.extlinks",
6364
]
6465

6566
autosummary_generate = True
@@ -98,6 +99,13 @@
9899
"numpy": ("https://numpy.org/doc/stable/", None),
99100
}
100101

102+
# extlinks config
103+
extlinks = {
104+
"issue": (f"{repository_url}/issues/%s", "#%s"),
105+
"pr": (f"{repository_url}/pull/%s", "#%s"),
106+
"ghuser": ("https://github.com/%s", "@%s"),
107+
}
108+
101109
# List of patterns, relative to source directory, that match files and
102110
# directories to ignore when looking for source files.
103111
# This pattern also affects html_static_path and html_extra_path.

docs/references.bib

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,63 @@ @article{Virshup_2023
88
title = {The scverse project provides a computational ecosystem for single-cell omics data analysis},
99
journal = {Nature Biotechnology}
1010
}
11+
12+
@article{cao2022multi,
13+
title={Multi-omics single-cell data integration and regulatory inference with graph-linked embedding},
14+
author={Cao, Zhi-Jie and Gao, Ge},
15+
journal={Nature Biotechnology},
16+
volume={40},
17+
number={10},
18+
pages={1458--1466},
19+
year={2022},
20+
publisher={Nature Publishing Group US New York},
21+
url={https://www.nature.com/articles/s41587-022-01284-4},
22+
}
23+
24+
@article{van2018recovering,
25+
title={Recovering gene interactions from single-cell data using data diffusion},
26+
author={Van Dijk, David and Sharma, Roshan and Nainys, Juozas and Yim, Kristina and Kathail, Pooja and Carr, Ambrose J and Burdziak, Cassandra and Moon, Kevin R and Chaffer, Christine L and Pattabiraman, Diwakar and others},
27+
journal={Cell},
28+
volume={174},
29+
number={3},
30+
pages={716--729},
31+
year={2018},
32+
publisher={Elsevier},
33+
url={https://www.sciencedirect.com/science/article/pii/S0092867418307244?via%3Dihub},
34+
}
35+
36+
@article{lotfollahi2022mapping,
37+
title={Mapping single-cell data to reference atlases by transfer learning},
38+
author={Lotfollahi, Mohammad and Naghipourfar, Mohsen and Luecken, Malte D and Khajavi, Matin and B{\"u}ttner, Maren and Wagenstetter, Marco and Avsec, {\v{Z}}iga and Gayoso, Adam and Yosef, Nir and Interlandi, Marta and others},
39+
journal={Nature biotechnology},
40+
volume={40},
41+
number={1},
42+
pages={121--130},
43+
year={2022},
44+
publisher={Nature Publishing Group US New York},
45+
url={https://www.nature.com/articles/s41587-021-01001-7},
46+
}
47+
48+
@article{he2024integrated,
49+
title={An integrated transcriptomic cell atlas of human neural organoids},
50+
author={He, Zhisong and Dony, Leander and Fleck, Jonas Simon and Sza{\l}ata, Artur and Li, Katelyn X and Sli{\v{s}}kovi{\'c}, Irena and Lin, Hsiu-Chuan and Santel, Malgorzata and Atamian, Alexander and Quadrato, Giorgia and others},
51+
journal={Nature},
52+
volume={635},
53+
number={8039},
54+
pages={690--698},
55+
year={2024},
56+
publisher={Nature Publishing Group UK London},
57+
url={https://www.nature.com/articles/s41586-024-08172-8},
58+
}
59+
60+
@article{li2022benchmarking,
61+
title={Benchmarking spatial and single-cell transcriptomics integration methods for transcript distribution prediction and cell type deconvolution},
62+
author={Li, Bin and Zhang, Wen and Guo, Chuang and Xu, Hao and Li, Longfei and Fang, Minghao and Hu, Yinlei and Zhang, Xinye and Yao, Xinfeng and Tang, Meifang and others},
63+
journal={Nature methods},
64+
volume={19},
65+
number={6},
66+
pages={662--670},
67+
year={2022},
68+
publisher={Nature Publishing Group US New York},
69+
url={https://www.nature.com/articles/s41592-022-01480-9},
70+
}

src/cellmapper/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from importlib.metadata import version
22

33
from .cellmapper import CellMapper
4+
from .knn import Neighbors
45
from .logging import logger
56

6-
__all__ = ["logger", "CellMapper"]
7+
__all__ = ["logger", "CellMapper", "Neighbors"]
78

89
__version__ = version("cellmapper")

src/cellmapper/cellmapper.py

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,7 @@ def compute_neighbors(
186186
use_rep
187187
Data representation based on which to find nearest neighbors. If None, a joint PCA will be computed.
188188
method
189-
Method to use for computing neighbors. "sklearn" and "pynndescent" run on CPU, "rapids" and "faiss" run on GPU.
190-
Note that all but "pynndescent" perform exact neighbor search. With GPU acceleration, "faiss" is usually
191-
fastest and more memory efficient than "rapids".
189+
Method to use for computing neighbors. "sklearn" and "pynndescent" run on CPU, "rapids" and "faiss" run on GPU. Note that all but "pynndescent" perform exact neighbor search. With GPU acceleration, "faiss" is usually fastest and more memory efficient than "rapids".
192190
metric
193191
Distance metric to use for nearest neighbors.
194192
only_yx
@@ -202,13 +200,15 @@ def compute_neighbors(
202200
203201
Returns
204202
-------
205-
Nothing, but updates the following attributes:
206-
knn
207-
Nearest neighbors object.
208-
n_neighbors
209-
Number of nearest neighbors.
210-
only_yx
211-
Whether only yx neighbors were computed.
203+
None
204+
205+
Notes
206+
-----
207+
Updates the following attributes:
208+
209+
- ``knn``: Nearest neighbors object.
210+
- ``n_neighbors``: Number of nearest neighbors.
211+
- ``only_yx``: Whether only yx neighbors were computed.
212212
"""
213213
self.n_neighbors = n_neighbors
214214
self.only_yx = only_yx
@@ -237,18 +237,23 @@ def compute_mappping_matrix(
237237
----------
238238
method
239239
Method to use for computing the mapping matrix. Options include:
240-
- "jaccard": Jaccard similarity. Inspired by GLUE: Cao et al., Nature Biotechnology, 2022: https://www.nature.com/articles/s41587-022-01284-4
241-
- "gaussian": Gaussian kernel with adaptive bandwith. Loosely inspired by MAGIC: Van Dijk et al., Cell, 2018: https://www.sciencedirect.com/science/article/pii/S0092867418307244?via%3Dihub
242-
- "scarches": scArches kernel. Inspired by scArches: Lotfollahi et al., Nature Biotechnology, 2021: https://www.nature.com/articles/s41587-021-01001-7
240+
241+
- "jaccard": Jaccard similarity. Inspired by GLUE :cite:`cao2022multi`
242+
- "gaussian": Gaussian kernel with adaptive bandwidth. Loosely inspired by MAGIC :cite:`van2018recovering`
243+
- "scarches": scArches kernel. Inspired by scArches :cite:`lotfollahi2022mapping`
243244
- "inverse_distance": Inverse distance kernel.
244245
- "random": Random kernel, useful for testing.
245-
- "hnoca": HNOCA kernel. Inspired by HNOCA-tools: He et al., Nature 2024: https://www.nature.com/articles/s41586-024-08172-8
246+
- "hnoca": HNOCA kernel. Inspired by HNOCA-tools :cite:`he2024integrated`
246247
247248
Returns
248249
-------
249-
Nothing, but updates the following attributes:
250-
mapping_matrix
251-
Mapping matrix for label transfer.
250+
None
251+
252+
Notes
253+
-----
254+
Updates the following attributes:
255+
256+
- ``mapping_matrix``: Mapping matrix for label transfer.
252257
"""
253258
if self.knn is None or self.n_neighbors is None:
254259
raise ValueError("Neighbors have not been computed. Call compute_neighbors() first.")
@@ -277,24 +282,26 @@ def transfer_labels(
277282
self, obs_keys: str | list[str], prediction_postfix: str = "pred", confidence_postfix: str = "conf"
278283
) -> None:
279284
"""
280-
Transfer discrete labels from reference dataset to query dataset for one or more keys
285+
Transfer discrete labels from reference dataset to query dataset for one or more keys.
281286
282287
Parameters
283288
----------
284289
obs_keys
285290
One or more keys in ``ref.obs`` to be transferred into ``query.obs`` (must be discrete)
286291
prediction_postfix
287-
New ``query.obs`` key added for the transferred labels,
288-
by default ``{obs_key}_pred`` for each obs_key.
292+
New ``query.obs`` key added for the transferred labels, by default ``{obs_key}_pred`` for each obs_key.
289293
confidence_postfix
290-
New ``query.obs`` key added for the transferred label confidence,
291-
by default ``{obs_key}_conf`` for each obs_key.
294+
New ``query.obs`` key added for the transferred label confidence, by default ``{obs_key}_conf`` for each obs_key.
292295
293296
Returns
294297
-------
295-
Nothing, but updates the following attributes:
296-
query.obs
297-
Contains the transferred labels and their confidence scores.
298+
None
299+
300+
Notes
301+
-----
302+
Updates the following attributes:
303+
304+
- ``query.obs``: Contains the transferred labels and their confidence scores.
298305
"""
299306
if self.mapping_matrix is None:
300307
raise ValueError("Mapping matrix has not been computed. Call compute_mapping_matrix() first.")
@@ -352,9 +359,13 @@ def transfer_embeddings(self, obsm_keys: str | list[str], prediction_postfix: st
352359
353360
Returns
354361
-------
355-
Nothing, but updates the following attributes:
356-
query.obsm
357-
Contains the transferred embeddings.
362+
None
363+
364+
Notes
365+
-----
366+
Updates the following attributes:
367+
368+
- ``query.obsm``: Contains the transferred embeddings.
358369
"""
359370
if self.mapping_matrix is None:
360371
raise ValueError("Mapping matrix has not been computed. Call compute_mapping_matrix() first.")
@@ -386,7 +397,11 @@ def transfer_expression(self, layer_key: str) -> None:
386397
387398
Returns
388399
-------
389-
Nothing, but creates/updates self.query_imputed with the transferred data in .X.
400+
None
401+
402+
Notes
403+
-----
404+
Creates/updates ``self.query_imputed`` with the transferred data in .X.
390405
The new AnnData object will have the same cells as the query, but the features (genes) of the reference.
391406
"""
392407
if self.mapping_matrix is None:

src/cellmapper/evaluate.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,18 @@ def evaluate_label_transfer(
8686
Key in .obs storing ground-truth cell type annotations.
8787
confidence_cutoff
8888
Minimum confidence score required to include a cell in the evaluation.
89-
zero_divisions
90-
How to handle zero divisions in sklearn metrics comptuation.
89+
zero_division
90+
How to handle zero divisions in sklearn metrics computation.
9191
9292
Returns
9393
-------
94-
Nothing, but updates the following attributes:
95-
label_transfer_metrics
96-
Dictionary containing accuracy, precision, recall, F1 scores, and excluded fraction.
94+
None
95+
96+
Notes
97+
-----
98+
Updates the following attributes:
99+
100+
- ``label_transfer_metrics``: Dictionary containing accuracy, precision, recall, F1 scores, and excluded fraction.
97101
"""
98102
if self.prediction_postfix is None or self.confidence_postfix is None:
99103
raise ValueError("Label transfer has not been performed. Call transfer_labels() first.")
@@ -180,7 +184,7 @@ def evaluate_expression_transfer(
180184
"""
181185
Evaluate the agreement between imputed and original expression in the query dataset, optionally per group.
182186
183-
These metrics are inspired by Li et al., Nature Methods 2022 (https://www.nature.com/articles/s41592-022-01480-9).
187+
These metrics are inspired by :cite:`li2022benchmarking`.
184188
185189
Parameters
186190
----------
@@ -193,13 +197,15 @@ def evaluate_expression_transfer(
193197
194198
Returns
195199
-------
196-
Nothing, but updates the following attributes:
197-
expression_transfer_metrics
198-
Dictionary containing the average metric and number of genes used for the evaluation.
199-
query.var[f"metric_{method}"]
200-
Per-gene metric values (overall, across all cells).
201-
query.varm[f"metric_{method}"]
202-
Per-gene, per-group metric values (if groupby is provided).
200+
None
201+
202+
Notes
203+
-----
204+
Updates the following attributes:
205+
206+
- ``expression_transfer_metrics``: Dictionary containing the average metric and number of genes used for the evaluation.
207+
- ``query.var[metric_name]``: Per-gene metric values (overall, across all cells).
208+
- ``query.varm[metric_name]``: Per-gene, per-group metric values (if groupby is provided).
203209
"""
204210
imputed_x, original_x, shared_genes = self._get_aligned_expression_arrays(layer_key)
205211

@@ -329,7 +335,7 @@ def estimate_presence_score(
329335
"""
330336
Estimate raw presence scores for each reference cell based on query-to-reference connectivities.
331337
332-
Adapted from the HNOCA-tools package: https://github.com/devsystemslab/HNOCA-tools
338+
Adapted from the HNOCA-tools package :cite:`he2024integrated`.
333339
334340
Parameters
335341
----------

0 commit comments

Comments
 (0)