-
Notifications
You must be signed in to change notification settings - Fork 33
Dask Support for scrublet #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from __future__ import annotations | ||
|
||
import cupy as cp | ||
import numpy as np | ||
import pytest | ||
from cupyx.scipy import sparse as cusparse | ||
from scanpy.datasets import paul15, pbmc3k | ||
|
||
import rapids_singlecell as rsc | ||
from rapids_singlecell._testing import ( | ||
as_dense_cupy_dask_array, | ||
as_sparse_cupy_dask_array, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize("data_kind", ["sparse", "dense"]) | ||
def test_dask_scrublet(data_kind): | ||
if data_kind == "sparse": | ||
adata_1 = pbmc3k()[200:400].copy() | ||
adata_2 = pbmc3k()[200:400].copy() | ||
adata_2.X = cusparse.csr_matrix(adata_2.X.astype(np.float64)) | ||
adata_1.X = as_sparse_cupy_dask_array(adata_1.X.astype(np.float64)) | ||
elif data_kind == "dense": | ||
adata_1 = paul15()[200:400].copy() | ||
adata_2 = paul15()[200:400].copy() | ||
adata_2.X = cp.array(adata_2.X.astype(np.float64)) | ||
adata_1.X = as_dense_cupy_dask_array(adata_1.X.astype(np.float64)) | ||
else: | ||
raise ValueError(f"Unknown data_kind {data_kind}") | ||
|
||
batch = np.random.randint(0, 2, size=adata_1.shape[0]) | ||
adata_1.obs["batch"] = batch | ||
adata_2.obs["batch"] = batch | ||
rsc.pp.scrublet(adata_1, batch_key="batch", verbose=False) | ||
|
||
# sort adata_2 to compare results | ||
batch_codes = adata_2.obs["batch"].astype("category").cat.codes | ||
order = np.argsort(batch_codes) | ||
adata_2 = adata_2[order] | ||
|
||
rsc.pp.scrublet(adata_2, batch_key="batch", verbose=False) | ||
adata_2 = adata_2[np.argsort(order)] | ||
|
||
np.testing.assert_allclose( | ||
adata_1.obs["doublet_score"], adata_2.obs["doublet_score"] | ||
) | ||
np.testing.assert_array_equal( | ||
adata_1.obs["predicted_doublet"], adata_2.obs["predicted_doublet"] | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also check that both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the moment I don't return |
Uh oh!
There was an error while loading. Please reload this page.