Skip to content

Commit 19a8b06

Browse files
authored
Merge pull request #22 from devsystemslab/feat/typing
Add a few type hints, remove some unused inputs
2 parents dcb4ea0 + c6a2c94 commit 19a8b06

5 files changed

Lines changed: 39 additions & 34 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
[![PyPI][badge-pypi]][pypi]
55
[![Docs Build][badge-docs]][docs]
66
[![Downloads][badge-downloads]][downloads]
7+
[![Coverage][badge-coverage]][coverage]
78

89

910
[badge-tests]: https://github.com/devsystemslab/hnoca-tools/actions/workflows/test.yaml/badge.svg
1011
[badge-pre-commit]: https://results.pre-commit.ci/badge/github/devsystemslab/hnoca-tools/main.svg
1112
[badge-pypi]: https://img.shields.io/pypi/v/hnoca.svg
1213
[badge-docs]: https://github.com/devsystemslab/hnoca-tools/actions/workflows/build-site.yaml/badge.svg
1314
[badge-downloads]: https://static.pepy.tech/badge/hnoca
15+
[badge-coverage]: https://codecov.io/gh/devsystemslab/hnoca-tools/branch/main/graph/badge.svg
1416

1517
# Human Neural Organoid Cell Atlas Toolbox
1618
#### 🛠️ The Swiss Army Knive of the Single Cell Cartographer
@@ -129,3 +131,4 @@ de_df = stats.test_de_paired(
129131
[pypi]: https://pypi.org/project/hnoca/
130132
[docs]: https://devsystemslab.github.io/HNOCA-tools/
131133
[downloads]: https://pepy.tech/project/hnoca
134+
[coverage]: https://codecov.io/gh/devsystemslab/hnoca-tools

src/hnoca/mapping/mapper.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import anndata as ad
77
import cloudpickle
88
import numpy as np
9+
import scanpy as sc
910

1011
from hnoca.utils import check_deps
1112

@@ -93,7 +94,7 @@ def _train_scanvi(self, query_adata, retrain="partial", **kwargs):
9394

9495
self.query_model = vae_q
9596

96-
def _train_scvi(self, query_adata, retrain="partial", **kwargs):
97+
def _train_scvi(self, query_adata: sc.AnnData, retrain: str = "partial", **kwargs):
9798
"""Train a new scvi model on the query data."""
9899
unfrozen = retrain == "full"
99100
self.scvi.model.SCVI.prepare_query_anndata(query_adata, self.ref_model)
@@ -102,7 +103,7 @@ def _train_scvi(self, query_adata, retrain="partial", **kwargs):
102103

103104
self.query_model = vae_q
104105

105-
def _train_scpoli(self, query_adata, retrain="partial", labeled_indices=None, **kwargs):
106+
def _train_scpoli(self, query_adata: sc.AnnData, retrain: str = "partial", labeled_indices=None, **kwargs):
106107
"""Train a new scpoli model on the query data"""
107108
freeze = retrain != "full" # noqa F841
108109
labeled_indices = [] if labeled_indices is None else labeled_indices

src/hnoca/mapping/matching.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import anndata
22
import numpy as np
3+
import scanpy as sc
34
from scipy import sparse
45

56

67
def get_matched_transcriptome( # noqa D103
7-
adata,
8-
adata_ref,
8+
adata: sc.AnnData,
9+
adata_ref: sc.AnnData,
910
wknn,
1011
rescale_factor=1,
1112
):

src/hnoca/mapping/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import anndata as ad
22
import numpy as np
33
import pandas as pd
4+
import scanpy as sc
45
from scipy import sparse
56

67
from hnoca._logging import logger
78

89

9-
def prepare_features(query_adata, ref_model):
10+
def prepare_features(query_adata: sc.AnnData, ref_model):
1011
"""Prepare the features of the query dataset to match the reference dataset."""
1112
ref_features = ref_model.adata.var_names
1213
query_features = query_adata.var_names

src/hnoca/mapping/wknn.py

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import numpy as np
55
import pandas as pd
6+
import scanpy as sc
67
import tqdm
78
from pynndescent import NNDescent
89
from scipy import sparse
@@ -52,8 +53,6 @@ def build_nn( # noqa: D103
5253
ref,
5354
query=None,
5455
k=100,
55-
weight: Literal["unweighted", "dist", "gaussian_kernel"] = "unweighted",
56-
sigma=None,
5756
use_rapids: bool = False,
5857
):
5958
if query is None:
@@ -108,9 +107,9 @@ def random_walk_with_restart(init, transition_prob, alpha=0.5, num_rounds=100):
108107

109108

110109
def get_wknn(
111-
ref,
112-
query,
113-
ref2=None,
110+
ref: np.ndarray,
111+
query: np.ndarray,
112+
ref2: np.ndarray | None = None,
114113
k: int = 100,
115114
query2ref: bool = True,
116115
ref2query: bool = False,
@@ -123,23 +122,23 @@ def get_wknn(
123122
124123
Parameters
125124
----------
126-
ref : np.ndarray
125+
ref
127126
The reference representation to build ref-query neighbor graph
128-
query : np.ndarray
127+
query
129128
The query representation to build ref-query neighbor graph
130-
ref2 : np.ndarray
129+
ref2
131130
The reference representation to build ref-ref neighbor graph
132-
k : int
131+
k
133132
Number of neighbors per cell
134-
query2ref : bool
133+
query2ref
135134
Consider query-to-ref neighbors
136-
ref2query : bool
135+
ref2query
137136
Consider ref-to-query neighbors
138-
weighting_scheme : str
137+
weighting_scheme
139138
How to weight edges in the ref-query neighbor graph
140-
top_n : int
139+
top_n
141140
The number of top neighbors to consider
142-
return_adjs : bool
141+
return_adjs
143142
Whether to return the adjacency matrices of ref-query, query-ref, ref-ref, and ref-ref for weighting
144143
"""
145144
adj_q2r = build_nn(ref=ref, query=query, k=k)
@@ -186,26 +185,26 @@ def get_wknn(
186185
return wknn
187186

188187

189-
def estimate_presence_score( # noqa: D103
190-
ref_adata,
191-
query_adata,
188+
def estimate_presence_score(
189+
ref_adata: sc.AnnData,
190+
query_adata: sc.AnnData,
192191
wknn=None,
193-
use_rep_ref_wknn="X_latent",
194-
use_rep_query_wknn="X_latent",
195-
k_wknn=100,
196-
query2ref_wknn=True,
197-
ref2query_wknn=False,
198-
weighting_scheme_wknn="jaccard_square",
192+
use_rep_ref_wknn: str = "X_latent",
193+
use_rep_query_wknn: str = "X_latent",
194+
k_wknn: int = 100,
195+
query2ref_wknn: bool = True,
196+
ref2query_wknn: bool = False,
197+
weighting_scheme_wknn: str = "jaccard_square",
199198
ref_trans_prop=None,
200199
use_rep_ref_trans_prop=None,
201-
k_ref_trans_prop=50,
202-
symm_ref_trans_prop=True,
200+
k_ref_trans_prop: int = 50,
203201
split_by=None,
204-
do_random_walk=True,
205-
alpha_random_walk=0.1,
206-
num_rounds_random_walk=100,
202+
do_random_walk: bool = True,
203+
alpha_random_walk: float = 0.1,
204+
num_rounds_random_walk: int = 100,
207205
log=True,
208206
):
207+
"""Estimate presence score of query cells in reference dataset."""
209208
if wknn is None:
210209
ref = ref_adata.obsm[use_rep_ref_wknn]
211210
query = query_adata.obsm[use_rep_query_wknn]
@@ -271,7 +270,7 @@ def estimate_presence_score( # noqa: D103
271270
}
272271

273272

274-
def transfer_labels(ref_adata, query_adata, wknn, label_key="celltype"):
273+
def transfer_labels(ref_adata: sc.AnnData, query_adata: sc.AnnData, wknn, label_key: str = "celltype"):
275274
"""Transfer labels from reference to query data."""
276275
scores = pd.DataFrame(
277276
wknn @ pd.get_dummies(ref_adata.obs[label_key]),

0 commit comments

Comments
 (0)