Skip to content

Commit dcf1144

Browse files
committed
Fix doc string errors.
1 parent f867e92 commit dcf1144

11 files changed

Lines changed: 95 additions & 64 deletions

File tree

docs/release_notes/1.1.5.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
~~~~~~~~~~~~~~~~~~~~~~~~~
33

44
.. rubric:: Features
5+
56
* Add Leiden clustering wrapper.
6-
* Fix documentation, refactor code in spatial.SME.
7+
* Fix documentation, refactor code in spatial.SME.

docs/release_notes/1.2.2.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
~~~~~~~~~~~~~~~~~~~~~~~~~
33

44
.. rubric:: Features
5+
56
* Added support for Python 3.11 and 3.12.
67
* Upgraded scanpy to 1.11 - clustering will be different.
78
* Added more CCI tests.
89

910
.. rubric:: Bugs
10-
* Fixed copy-paste error in louvain.py file.
11+
12+
* Fixed copy-paste error in louvain.py file.

stlearn/embedding/ica.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,22 @@ def run_ica(
2626
or 'cube'.
2727
You can also provide your own function. It should return a tuple
2828
containing the value of the function, and of its derivative, in the
29-
point. Example:
30-
def my_g(x):
31-
return x ** 3, (3 * x ** 2).mean(axis=-1)
29+
point. Example::
30+
31+
def my_g(x):
32+
return x ** 3, (3 * x ** 2).mean(axis=-1)
3233
tol
3334
Tolerance on update at each iteration.
3435
use_data
3536
if None, then using all the gene expression profile. Else, use
3637
the chosen data from adata.obsm.
3738
copy
3839
Return a copy instead of writing to adata.
40+
3941
Returns
4042
-------
4143
Depending on `copy`, returns or updates `adata` with the following fields.
4244
`X_ica` : :class:`numpy.ndarray` (`adata.obsm`)
43-
Independent Component Analysis representation of data.
4445
"""
4546

4647
adata = adata.copy() if copy else adata

stlearn/embedding/pca.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ def run_pca(
2020
) -> AnnData | None:
2121
"""\
2222
Wrap function scanpy.pp.pca
23+
2324
Principal component analysis [Pedregosa11]_.
2425
Computes PCA coordinates, loadings and variance decomposition.
2526
Uses the implementation of *scikit-learn* [Pedregosa11]_.
27+
2628
Parameters
2729
----------
2830
data
@@ -38,12 +40,12 @@ def run_pca(
3840
Passing `None` decides automatically based on sparseness of the data.
3941
svd_solver
4042
SVD solver to use:
41-
`'arpack'` (the default - deterministic)
42-
for the ARPACK wrapper in SciPy (:func:`~scipy.sparse.linalg.svds`)
43-
`'randomized'`
44-
for the randomized algorithm due to Halko (2009).
45-
`'auto'`
46-
chooses automatically depending on the size of the problem.
43+
44+
- `'arpack'` (the default - deterministic) for the ARPACK wrapper in
45+
SciPy (:func:`~scipy.sparse.linalg.svds`)
46+
- `'randomized'` for the randomized algorithm due to Halko (2009).
47+
- `'auto'` chooses automatically depending on the size of the problem.
48+
4749
random_state
4850
Change to use different initial states for the optimization.
4951
return_info
@@ -52,7 +54,7 @@ def run_pca(
5254
use_highly_variable
5355
Whether to use highly variable genes only, stored in
5456
`.var['highly_variable']`.
55-
By default uses them if they have been determined beforehand.
57+
By default, uses them if they have been determined beforehand.
5658
dtype
5759
Numpy data type string to which to convert the result.
5860
copy
@@ -65,22 +67,21 @@ def run_pca(
6567
chunk_size
6668
Number of observations to include in each chunk.
6769
Required if `chunked=True` was passed.
70+
6871
Returns
6972
-------
70-
X_pca : :class:`~scipy.sparse.spmatrix`, :class:`~numpy.ndarray`
73+
X_pca: :class:`~scipy.sparse.spmatrix`, :class:`~numpy.ndarray`
7174
If `data` is array-like and `return_info=False` was passed,
72-
this function only returns `X_pca`…
73-
adata : anndata.AnnData
74-
…otherwise if `copy=True` it returns or else adds fields to `adata`:
75-
`.obsm['X_pca']`
76-
PCA representation of data.
77-
`.varm['PCs']`
78-
The principal components containing the loadings.
79-
`.uns['pca']['variance_ratio']`
80-
Ratio of explained variance.
81-
`.uns['pca']['variance']`
82-
Explained variance, equivalent to the eigenvalues of the
83-
covariance matrix.
75+
this function only returns `X_pca`.
76+
adata: anndata.AnnData
77+
Otherwise if `copy=True` it returns or else adds fields to `adata`:
78+
79+
- `.obsm['X_pca']` - PCA representation of data.
80+
- `.varm['PCs']` - The principal components containing the loadings.
81+
- `.uns['pca']['variance_ratio']` - Ratio of explained variance.
82+
- `.uns['pca']['variance']` - Explained variance, equivalent to the
83+
eigenvalues of the covariance matrix.
84+
8485
"""
8586

8687
adata = scanpy.pp.pca(

stlearn/embedding/umap.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ def run_umap(
2626
) -> AnnData | None:
2727
"""\
2828
Wrap function scanpy.pp.umap
29+
2930
Embed the neighborhood graph using UMAP [McInnes18]_.
31+
3032
UMAP (Uniform Manifold Approximation and Projection) is a manifold learning
3133
technique suitable for visualizing high-dimensional data. Besides tending to
3234
be faster than tSNE, it optimizes the embedding such that it best reflects
@@ -37,6 +39,7 @@ def run_umap(
3739
implementation of `umap-learn <https://github.com/lmcinnes/umap>`__
3840
[McInnes18]_. For a few comparisons of UMAP with tSNE, see this `preprint
3941
<https://doi.org/10.1101/298430>`__.
42+
4043
Parameters
4144
----------
4245
adata
@@ -48,6 +51,7 @@ def run_umap(
4851
If `RandomState`, `random_state` is the random number generator;
4952
If `None`, the random number generator is the `RandomState` instance used
5053
by `np.random`.
54+
5155
Returns
5256
-------
5357
Depending on `copy`, returns or updates `adata` with the following fields.

stlearn/preprocessing/filter_genes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ def filter_genes(
1515
Wrap function scanpy.pp.filter_genes
1616
1717
Filter genes based on number of cells or counts.
18+
1819
Keep genes that have at least `min_counts` counts or are expressed in at
1920
least `min_cells` cells or have at most `max_counts` counts or are expressed
2021
in at most `max_cells` cells.
22+
2123
Only provide one of the optional parameters `min_counts`, `min_cells`,
2224
`max_counts`, `max_cells` per call.
25+
2326
Parameters
2427
----------
2528
adata
@@ -35,6 +38,7 @@ def filter_genes(
3538
Maximum number of cells expressed required for a gene to pass filtering.
3639
inplace
3740
Perform computation inplace or return result.
41+
3842
Returns
3943
-------
4044
Depending on `inplace`, returns the following arrays or directly subsets

stlearn/preprocessing/graph.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ def neighbors(
5454
the connectivity of the manifold (`method=='umap'`). If `method=='gauss'`,
5555
connectivities are computed according to [Coifman05]_, in the adaption of
5656
[Haghverdi16]_.
57+
5758
Parameters
5859
----------
59-
adata
60+
adata:
6061
Annotated data matrix.
61-
n_neighbors
62+
n_neighbors:
6263
The size of local neighborhood (in terms of number of neighboring data
6364
points) used for manifold approximation. Larger values result in more
6465
global views of the manifold, while smaller values result in more local
@@ -68,22 +69,23 @@ def neighbors(
6869
`n_neighbors` neighbor.
6970
{n_pcs}
7071
{use_rep}
71-
knn
72+
knn:
7273
If `True`, use a hard threshold to restrict the number of neighbors to
7374
`n_neighbors`, that is, consider a knn graph. Otherwise, use a Gaussian
7475
Kernel to assign low weights to neighbors more distant than the
7576
`n_neighbors` nearest neighbor.
76-
random_state
77+
random_state:
7778
A numpy random seed.
78-
method
79+
method:
7980
Use 'umap' [McInnes18]_ or 'gauss' (Gauss kernel following [Coifman05]_
8081
with adaptive width [Haghverdi16]_) for computing connectivities.
81-
metric
82+
metric:
8283
A known metric’s name or a callable that returns a distance.
83-
metric_kwds
84+
metric_kwds:
8485
Options for the metric.
85-
copy
86+
copy:
8687
Return a copy instead of writing to adata.
88+
8789
Returns
8890
-------
8991
Depending on `copy`, updates or returns `adata` with the following:

stlearn/preprocessing/log_scale.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,23 @@ def log1p(
1818
Logarithmize the data matrix.
1919
Computes :math:`X = \\log(X + 1)`,
2020
where :math:`log` denotes the natural logarithm unless a different base is given.
21+
2122
Parameters
2223
----------
23-
data
24+
data:
2425
The (annotated) data matrix of shape `n_obs` × `n_vars`.
2526
Rows correspond to cells and columns to genes.
26-
copy
27+
copy:
2728
If an :class:`~anndata.AnnData` is passed, determines whether a copy
2829
is returned.
29-
chunked
30+
chunked:
3031
Process the data matrix in chunks, which will save memory.
3132
Applies only to :class:`~anndata.AnnData`.
32-
chunk_size
33+
chunk_size:
3334
`n_obs` of the chunks to process the data in.
34-
base
35+
base:
3536
Base of the logarithm. Natural logarithm is used by default.
37+
3638
Returns
3739
-------
3840
Returns or updates `data`, depending on `copy`.
@@ -55,10 +57,12 @@ def scale(
5557
Wrap function of scanpy.pp.scale
5658
5759
Scale data to unit variance and zero mean.
60+
5861
.. note::
59-
Variables (genes) that do not display any variation (are constant across
60-
all observations) are retained and set to 0 during this operation. In
61-
the future, they might be set to NaNs.
62+
Variables (genes) that do not display any variation (are constant across
63+
all observations) are retained and set to 0 during this operation. In
64+
the future, they might be set to NaNs.
65+
6266
Parameters
6367
----------
6468
data:
@@ -72,6 +76,7 @@ def scale(
7276
copy
7377
If an :class:`~anndata.AnnData` is passed,
7478
determines whether a copy is returned.
79+
7580
Returns
7681
-------
7782
Depending on `copy` returns or updates `data` with a scaled `data.X`.

stlearn/preprocessing/normalize.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@ def normalize_total(
1313
inplace: bool = True,
1414
) -> dict[str, np.ndarray] | None:
1515
"""\
16-
Wrap function from scanpy.pp.log1p
17-
Normalize counts per cell.
16+
Wrap function from scanpy.pp.log1p - normalize counts per cell.
17+
1818
If choosing `target_sum=1e6`, this is CPM normalization.
1919
If `exclude_highly_expressed=True`, very highly expressed genes are excluded
2020
from the computation of the normalization factor (size factor) for each
2121
cell. This is meaningful as these can strongly influence the resulting
2222
normalized values for all other genes [Weinreb17]_.
2323
Similar functions are used, for example, by Seurat [Satija15]_, Cell Ranger
24-
[Zheng17]_ or SPRING [Weinreb17]_.
25-
Params
26-
------
27-
adata
24+
[Zheng17]_ or SPRING [Weinreb16]_.
25+
26+
Parameters
27+
----------
28+
adata:
2829
The annotated data matrix of shape `n_obs` × `n_vars`.
2930
Rows correspond to cells and columns to genes.
30-
target_sum
31+
target_sum:
3132
If `None`, after normalization, each observation (cell) has a total
3233
count equal to the median of total counts for observations (cells)
3334
before normalization.
@@ -37,16 +38,17 @@ def normalize_total(
3738
highly expressed, if it has more than `max_fraction` of the total counts
3839
in at least one cell. The not-excluded genes will sum up to
3940
`target_sum`.
40-
max_fraction
41+
max_fraction:
4142
If `exclude_highly_expressed=True`, consider cells as highly expressed
4243
that have more counts than `max_fraction` of the original total counts
4344
in at least one cell.
44-
key_added
45+
key_added:
4546
Name of the field in `adata.obs` where the normalization factor is
4647
stored.
47-
inplace
48+
inplace:
4849
Whether to update `adata` or return dictionary with normalized copies of
4950
`adata.X` and `adata.layers`.
51+
5052
Returns
5153
-------
5254
Returns dictionary with normalized copies of `adata.X` and `adata.layers`

stlearn/tl/clustering/leiden.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ def leiden(
2222
) -> AnnData | None:
2323
"""\
2424
Wrap function scanpy.tl.leiden
25+
2526
This requires having ran :func:`~scanpy.pp.neighbors` or
2627
:func:`~scanpy.external.pp.bbknn` first,
2728
or explicitly passing a ``adjacency`` matrix.
29+
2830
Parameters
2931
----------
3032
adata:
@@ -58,14 +60,16 @@ def leiden(
5860
`obsp` and `neighbors_key` at the same time.
5961
copy:
6062
Copy adata or modify it inplace.
63+
6164
Returns
6265
-------
63-
:obj:`None`
66+
None or AnnData
6467
By default (``copy=False``), updates ``adata`` with the following fields:
65-
``adata.obs['leiden' | key_added]`` (:class:`pandas.Series`, dtype ``category``)
66-
Array of dim (number of samples) that stores the subgroup id
67-
(``'0'``, ``'1'``, ...) for each cell.
68-
:class:`~anndata.AnnData`
68+
69+
- ``adata.obs['leiden']`` (:class:`pandas.Series`, dtype ``category``) -
70+
Array of dim (number of samples) that stores the subgroup id
71+
(``'0'``, ``'1'``, ...) for each cell.
72+
6973
When ``copy=True`` is set, a copy of ``adata`` with those fields is returned.
7074
"""
7175

0 commit comments

Comments
 (0)