Skip to content

Commit 7a47da9

Browse files
authored
Merge pull request #143 from Intron7/update-_pre
Updated pre to run faster
2 parents 2192575 + 4ebdc64 commit 7a47da9

13 files changed

+23
-20
lines changed

Diff for: decoupler/method_aucell.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from scipy.sparse import csr_matrix
99

1010
from numpy.random import default_rng
11-
from tqdm import tqdm
11+
from tqdm.auto import tqdm
1212

1313
from .pre import extract, rename_net, filt_min_n, return_data
1414

Diff for: decoupler/method_gsea.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .pre import extract, rename_net, filt_min_n, return_data
1313
from .utils import p_adjust_fdr
1414

15-
from tqdm import tqdm
15+
from tqdm.auto import tqdm
1616

1717
import numba as nb
1818

Diff for: decoupler/method_gsva.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .pre import extract, rename_net, filt_min_n, return_data
1414
from .method_gsea import std
1515

16-
from tqdm import tqdm
16+
from tqdm.auto import tqdm
1717

1818
import numba as nb
1919

Diff for: decoupler/method_mdt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from .pre import extract, match, rename_net, get_net_mat, filt_min_n, return_data
1111

12-
from tqdm import tqdm
12+
from tqdm.auto import tqdm
1313

1414

1515
def check_if_skranger():

Diff for: decoupler/method_mlm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from scipy import stats
1313

14-
from tqdm import tqdm
14+
from tqdm.auto import tqdm
1515

1616
import numba as nb
1717

Diff for: decoupler/method_ora.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from .pre import extract, rename_net, filt_min_n, return_data
1616
from .utils import p_adjust_fdr
1717

18-
from tqdm import tqdm
18+
from tqdm.auto import tqdm
1919

2020
import numba as nb
2121

Diff for: decoupler/method_udt.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
from .pre import extract, match, rename_net, get_net_mat, filt_min_n, return_data
1111

12-
from tqdm import tqdm
13-
12+
from tqdm.auto import tqdm
1413

1514
def check_if_sklearn():
1615
try:

Diff for: decoupler/method_ulm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from .pre import extract, match, rename_net, get_net_mat, filt_min_n, return_data
1313

14-
from tqdm import tqdm
14+
from tqdm.auto import tqdm
1515

1616

1717
def mat_cov(A, b):

Diff for: decoupler/method_viper.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
from .pre import extract, match, rename_net, get_net_mat, filt_min_n, return_data
1414

15-
from tqdm import tqdm
15+
from tqdm.auto import tqdm
16+
1617

1718
import numba as nb
1819

Diff for: decoupler/method_wmean.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .pre import extract, match, rename_net, get_net_mat, filt_min_n, return_data
1111
from .method_gsea import std
1212

13-
from tqdm import tqdm
13+
from tqdm.auto import tqdm
1414

1515
import numba as nb
1616

Diff for: decoupler/method_wsum.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .pre import extract, match, rename_net, get_net_mat, filt_min_n, return_data
1111
from .method_gsea import std
1212

13-
from tqdm import tqdm
13+
from tqdm.auto import tqdm
1414

1515
import numba as nb
1616

Diff for: decoupler/pre.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def check_mat(m, r, c, verbose=False):
1818

1919
# Check for empty features
2020
if type(m) is csr_matrix:
21-
msk_features = np.sum(m != 0, axis=0).A1 == 0
21+
msk_features = m.getnnz(axis=0) == 0
2222
else:
2323
msk_features = np.count_nonzero(m, axis=0) == 0
2424
n_empty_features = np.sum(msk_features)
@@ -29,16 +29,16 @@ def check_mat(m, r, c, verbose=False):
2929
m = m[:, ~msk_features]
3030

3131
# Sort features
32-
msk = np.argsort(c)
33-
m, r, c = m[:, msk], r.astype('U'), c[msk].astype('U')
32+
#msk = np.argsort(c)
33+
#m, r, c = m[:, msk], r.astype('U'), c[msk].astype('U')
3434

3535
# Check for repeated features
3636
if np.any(c[1:] == c[:-1]):
3737
raise ValueError("""mat contains repeated feature names, please make them unique.""")
3838

3939
# Check for empty samples
4040
if type(m) is csr_matrix:
41-
msk_samples = np.sum(m != 0, axis=1).A1 == 0
41+
msk_samples = m.getnnz(axis=1) == 0
4242
else:
4343
msk_samples = np.count_nonzero(m, axis=1) == 0
4444
n_empty_samples = np.sum(msk_samples)
@@ -174,9 +174,12 @@ def match(c, r, net):
174174
# Init empty regX
175175
regX = np.zeros((c.shape[0], net.shape[1]), dtype=np.float32)
176176

177-
# Match genes from mat, else are 0s
178-
idxs = np.searchsorted(c, r)
179-
regX[idxs] = net
177+
# Create an index array for rows of c corresponding to r
178+
c_dict = {gene: i for i, gene in enumerate(c)}
179+
idxs = [c_dict[gene] for gene in r if gene in c_dict]
180+
181+
# Populate regX using advanced indexing
182+
regX[idxs, :] = net[: len(idxs), :]
180183

181184
return regX
182185

Diff for: decoupler/utils_benchmark.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def format_acts_grts(res, obs, groupby, use_pval):
332332
grts = build_grts_mat(obs, exps, srcs)
333333

334334
# Match to same srcs between acts and grts
335-
grts = match(srcs, grts.columns, grts.T).T
335+
grts = match(srcs, grts.columns, grts.T.values).T
336336

337337
# Build msks tensor
338338
msks, grpbys, grps = build_msks_tensor(obs, groupby)

0 commit comments

Comments
 (0)