forked from scverse/scanpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make louvain optional for tests (scverse#2063)
* Make louvain dep optional for CI * Make clustering tests relying on louvain optional * Make louvain optional in test_neighbors_key_added.py * Make logreg rank_genes_groups tests not require louvain * Skip paul15 paga tests if louvain not installed * Replace louvain with leiden in pbmc3k test * Fix doc builds by updating mpl.colorbar.ColorBarBase to mpl.colorbar.ColorBar
- Loading branch information
Showing
9 changed files
with
61 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,43 @@ | ||
import pytest | ||
|
||
import numpy as np | ||
import scanpy as sc | ||
|
||
|
||
def test_rank_genes_groups_with_renamed_categories(): | ||
@pytest.mark.parametrize( | ||
"method", | ||
["t-test", "logreg"], | ||
) | ||
def test_rank_genes_groups_with_renamed_categories(method): | ||
adata = sc.datasets.blobs(n_variables=4, n_centers=3, n_observations=200) | ||
assert np.allclose(adata.X[1], [9.214668, -2.6487126, 4.2020774, 0.51076424]) | ||
|
||
sc.tl.pca(adata) | ||
sc.pp.neighbors(adata) | ||
|
||
for method in ['logreg', 't-test']: | ||
sc.tl.louvain(adata) | ||
# for method in ['logreg', 't-test']: | ||
|
||
sc.tl.rank_genes_groups(adata, 'louvain', method=method) | ||
assert adata.uns['rank_genes_groups']['names'].dtype.names == ('0', '1', '2') | ||
assert adata.uns['rank_genes_groups']['names'][0].tolist() == ('3', '1', '0') | ||
sc.tl.rank_genes_groups(adata, 'blobs', method=method) | ||
assert adata.uns['rank_genes_groups']['names'].dtype.names == ('0', '1', '2') | ||
assert adata.uns['rank_genes_groups']['names'][0].tolist() == ('1', '3', '0') | ||
|
||
adata.rename_categories('louvain', ['Zero', 'One', 'Two']) | ||
assert adata.uns['rank_genes_groups']['names'][0].tolist() == ('3', '1', '0') | ||
adata.rename_categories('blobs', ['Zero', 'One', 'Two']) | ||
assert adata.uns['rank_genes_groups']['names'][0].tolist() == ('1', '3', '0') | ||
|
||
sc.tl.rank_genes_groups(adata, 'louvain', method=method) | ||
assert adata.uns['rank_genes_groups']['names'][0].tolist() == ('3', '1', '0') | ||
sc.tl.rank_genes_groups(adata, 'blobs', method=method) | ||
assert adata.uns['rank_genes_groups']['names'][0].tolist() == ('1', '3', '0') | ||
assert adata.uns['rank_genes_groups']['names'].dtype.names == ('Zero', 'One', 'Two') | ||
|
||
|
||
def test_rank_genes_groups_with_renamed_categories_use_rep(): | ||
adata = sc.datasets.blobs(n_variables=4, n_centers=3, n_observations=200) | ||
assert np.allclose(adata.X[1], [9.214668, -2.6487126, 4.2020774, 0.51076424]) | ||
|
||
sc.tl.pca(adata) | ||
sc.pp.neighbors(adata) | ||
|
||
adata.layers["to_test"] = adata.X.copy() | ||
adata.X = adata.X[::-1, :] | ||
|
||
sc.tl.louvain(adata) | ||
sc.tl.rank_genes_groups( | ||
adata, 'louvain', method='logreg', layer="to_test", use_raw=False | ||
adata, 'blobs', method='logreg', layer="to_test", use_raw=False | ||
) | ||
assert adata.uns['rank_genes_groups']['names'].dtype.names == ('0', '1', '2') | ||
assert adata.uns['rank_genes_groups']['names'][0].tolist() == ('3', '1', '0') | ||
assert adata.uns['rank_genes_groups']['names'][0].tolist() == ('1', '3', '0') | ||
|
||
sc.tl.rank_genes_groups(adata, 'louvain', method="logreg") | ||
sc.tl.rank_genes_groups(adata, 'blobs', method="logreg") | ||
assert not adata.uns['rank_genes_groups']['names'][0].tolist() == ('3', '1', '0') |