Skip to content

Commit

Permalink
fix ep.tl.umap when neighbors_key is not None (#790)
Browse files Browse the repository at this point in the history
* remove buggy extra uns checks of ep, let sc do it

* add check with ep instruction

* Update ehrapy/tools/_scanpy_tl_api.py

Co-authored-by: Lukas Heumos <[email protected]>

---------

Co-authored-by: Lukas Heumos <[email protected]>
  • Loading branch information
eroell and Zethson authored Aug 23, 2024
1 parent 4e48886 commit 423a633
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions ehrapy/tools/_scanpy_tl_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,28 @@ def umap(
**X_umap** : `adata.obsm` field UMAP coordinates of data.
"""
if adata.uns["neighbors"] is None or neighbors_key not in adata.uns:
return sc.tl.umap(
adata=adata,
min_dist=min_dist,
spread=spread,
n_components=n_components,
maxiter=maxiter,
alpha=alpha,
gamma=gamma,
negative_sample_rate=negative_sample_rate,
init_pos=init_pos,
random_state=random_state,
a=a,
b=b,
copy=copy,
method=method,
neighbors_key=neighbors_key,
)
else:
raise ValueError(f'.uns["{neighbors_key}"] or .uns["neighbors"] were not found. Run `ep.pp.neighbors` first.')

key_to_check = neighbors_key if neighbors_key is not None else "neighbors"
if key_to_check not in adata.uns:
raise ValueError(f"Did not find .uns[{key_to_check!r}]. Please run `ep.pp.neighbors` first.")

return sc.tl.umap(
adata=adata,
min_dist=min_dist,
spread=spread,
n_components=n_components,
maxiter=maxiter,
alpha=alpha,
gamma=gamma,
negative_sample_rate=negative_sample_rate,
init_pos=init_pos,
random_state=random_state,
a=a,
b=b,
copy=copy,
method=method,
neighbors_key=neighbors_key,
)


def draw_graph(
Expand Down

0 comments on commit 423a633

Please sign in to comment.