Skip to content

Commit

Permalink
get_pseudobulk now handles any sparse format
Browse files Browse the repository at this point in the history
  • Loading branch information
PauBadiaM committed Jul 30, 2023
1 parent 4190f6f commit 7752273
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion decoupler/tests/test_utilsanndata.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
import numpy as np
import pandas as pd
from scipy.sparse import csr_matrix
from scipy.sparse import csr_matrix, csc_matrix
from anndata import AnnData
from ..utils_anndata import get_acts, swap_layer, extract_psbulk_inputs, check_X
from ..utils_anndata import format_psbulk_inputs, psbulk_profile, compute_psbulk, get_unq_dict, get_pseudobulk
Expand Down Expand Up @@ -68,6 +68,9 @@ def test_extract_psbulk_inputs():
extract_psbulk_inputs(adata, obs=None, layer=None, use_raw=True)
with pytest.raises(ValueError):
extract_psbulk_inputs(df, obs=None, layer=None, use_raw=False)
csc_adata = adata.copy()
csc_adata.X = csc_matrix(csc_adata.X).copy()
extract_psbulk_inputs(csc_adata, obs=None, layer=None, use_raw=False)


def test_check_X():
Expand Down
9 changes: 7 additions & 2 deletions decoupler/utils_anndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"""

import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse import csr_matrix, issparse
import pandas as pd
import sys

Expand Down Expand Up @@ -115,8 +115,13 @@ def extract_psbulk_inputs(adata, obs, layer, use_raw):

# Sort genes
msk = np.argsort(var.index)
X = X[:, msk]
var = var.iloc[msk]

return X[:, msk], obs, var.iloc[msk]
if issparse(X) and not isinstance(X, csr_matrix):
X = csr_matrix(X)

return X, obs, var


def check_X(X, mode='sum', skip_checks=False):
Expand Down

0 comments on commit 7752273

Please sign in to comment.