Skip to content
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

Update pre #143

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion decoupler/method_aucell.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from scipy.sparse import csr_matrix

from numpy.random import default_rng
from tqdm import tqdm
from tqdm.auto import tqdm

from .pre import extract, rename_net, filt_min_n, return_data

Expand Down
2 changes: 1 addition & 1 deletion decoupler/method_gsea.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .pre import extract, rename_net, filt_min_n, return_data
from .utils import p_adjust_fdr

from tqdm import tqdm
from tqdm.auto import tqdm

import numba as nb

Expand Down
2 changes: 1 addition & 1 deletion decoupler/method_gsva.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .pre import extract, rename_net, filt_min_n, return_data
from .method_gsea import std

from tqdm import tqdm
from tqdm.auto import tqdm

import numba as nb

Expand Down
2 changes: 1 addition & 1 deletion decoupler/method_mdt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

from tqdm import tqdm
from tqdm.auto import tqdm


def check_if_skranger():
Expand Down
2 changes: 1 addition & 1 deletion decoupler/method_mlm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from scipy import stats

from tqdm import tqdm
from tqdm.auto import tqdm

import numba as nb

Expand Down
2 changes: 1 addition & 1 deletion decoupler/method_ora.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .pre import extract, rename_net, filt_min_n, return_data
from .utils import p_adjust_fdr

from tqdm import tqdm
from tqdm.auto import tqdm

import numba as nb

Expand Down
3 changes: 1 addition & 2 deletions decoupler/method_udt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

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

from tqdm import tqdm

from tqdm.auto import tqdm

def check_if_sklearn():
try:
Expand Down
2 changes: 1 addition & 1 deletion decoupler/method_ulm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

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

from tqdm import tqdm
from tqdm.auto import tqdm


def mat_cov(A, b):
Expand Down
3 changes: 2 additions & 1 deletion decoupler/method_viper.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@

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

from tqdm import tqdm
from tqdm.auto import tqdm


import numba as nb

Expand Down
2 changes: 1 addition & 1 deletion decoupler/method_wmean.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .pre import extract, match, rename_net, get_net_mat, filt_min_n, return_data
from .method_gsea import std

from tqdm import tqdm
from tqdm.auto import tqdm

import numba as nb

Expand Down
2 changes: 1 addition & 1 deletion decoupler/method_wsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .pre import extract, match, rename_net, get_net_mat, filt_min_n, return_data
from .method_gsea import std

from tqdm import tqdm
from tqdm.auto import tqdm

import numba as nb

Expand Down
17 changes: 10 additions & 7 deletions decoupler/pre.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def check_mat(m, r, c, verbose=False):

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

# Sort features
msk = np.argsort(c)
m, r, c = m[:, msk], r.astype('U'), c[msk].astype('U')
#msk = np.argsort(c)
#m, r, c = m[:, msk], r.astype('U'), c[msk].astype('U')

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

# Check for empty samples
if type(m) is csr_matrix:
msk_samples = np.sum(m != 0, axis=1).A1 == 0
msk_samples = m.getnnz(axis=1) == 0
else:
msk_samples = np.count_nonzero(m, axis=1) == 0
n_empty_samples = np.sum(msk_samples)
Expand Down Expand Up @@ -174,9 +174,12 @@ def match(c, r, net):
# Init empty regX
regX = np.zeros((c.shape[0], net.shape[1]), dtype=np.float32)

# Match genes from mat, else are 0s
idxs = np.searchsorted(c, r)
regX[idxs] = net
# Create an index array for rows of c corresponding to r
c_dict = {gene: i for i, gene in enumerate(c)}
idxs = [c_dict[gene] for gene in r if gene in c_dict]

# Populate regX using advanced indexing
regX[idxs, :] = net[: len(idxs), :]

return regX

Expand Down
2 changes: 1 addition & 1 deletion decoupler/utils_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def format_acts_grts(res, obs, groupby, use_pval):
grts = build_grts_mat(obs, exps, srcs)

# Match to same srcs between acts and grts
grts = match(srcs, grts.columns, grts.T).T
grts = match(srcs, grts.columns, grts.T.values).T

# Build msks tensor
msks, grpbys, grps = build_msks_tensor(obs, groupby)
Expand Down
Loading