Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
6b987e6
draft for hires model & distance function prior
vitkl Nov 26, 2023
f1c3127
missing dependency
vitkl Nov 26, 2023
047f160
bug fix
vitkl Nov 26, 2023
58bffdd
bug fix
vitkl Nov 26, 2023
adba6c2
getting rid of data_transform argument
vitkl Nov 26, 2023
a99ca5e
working conv2d pooling + distance function effect
vitkl Nov 26, 2023
444cbd4
add tests and bump version
vitkl Nov 26, 2023
d13de3c
more universal quantile method
vitkl Nov 26, 2023
f769044
minor bug fixes
vitkl Nov 26, 2023
973a6c4
more bug fixes
vitkl Nov 27, 2023
2eccd8c
minor changes
vitkl Dec 5, 2023
3ac9b97
defined grid dataloader
vitkl Dec 11, 2023
f940f6b
enabling complex variable shapes (right dimensions)
vitkl Dec 11, 2023
e2e5deb
handling Dirichlet vars in obs plate using custom dim lists
vitkl Dec 11, 2023
0f49fcc
handling custom dataloader in model.train()
vitkl Dec 11, 2023
9db7e68
model for cell compartments & conv2d redistribution & bug fixes
vitkl Dec 11, 2023
527c36e
compatibility of tile and normal dataloader, registering tiles
vitkl Dec 13, 2023
4667909
multi-resolution likelihood, loading many tiles, independent c2l prior
vitkl Dec 19, 2023
a42699f
mask likelihood for non-tissue locations
vitkl Dec 19, 2023
87713ce
removing learnable weights for overdispersion
vitkl Dec 24, 2023
0fd4b05
add overdispersion scaling back
vitkl Jan 6, 2024
aa2a3e2
minor bug fixes
vitkl Mar 18, 2024
31e7885
add pyro_guide(*args, **kwargs) setup to model.train()
vitkl Mar 18, 2024
286c1fe
guide updates & draft cell comm model & tests & defaults
vitkl Apr 8, 2024
c0747ae
dealing with multi-subunit receptors + bug fixes + batch disjoint spa…
vitkl Apr 10, 2024
f9d6478
expanding tiles & overlapping tiles dataloader
vitkl Apr 11, 2024
c462b45
filtering expanded tiles + minor changes
vitkl Apr 11, 2024
5429f1f
temporary ordering bug fix
vitkl Apr 11, 2024
60aaefb
test indexing bug + minor changes + dense distance
vitkl Apr 11, 2024
0efe255
minor changes
vitkl Apr 12, 2024
85484ff
minor changes
vitkl Apr 16, 2024
a418997
cell comm downstream model draft (incl input preprocessing, simplifie…
vitkl Jun 19, 2024
41e05b1
normal likelihood + minor changes
vitkl Jun 20, 2024
4dc20c0
enable providing N_cells_per_location as array
vitkl Jun 26, 2024
ce403de
alternative N cells model (more flexible, allows N cells array input)…
vitkl Jul 6, 2024
7ddcae6
normalisation options
vitkl Jul 6, 2024
c3eec10
scaling by hierarchical annotations, correct unexpanded tiles, horses…
vitkl Jul 7, 2024
4569d79
bug fix
vitkl Jul 7, 2024
5c12379
proportion factorisation for w_sf prior, prior option for A & B inputs
vitkl Jul 13, 2024
490a2cc
use spatial receptor distribution (baseline), LR affinity with 1
vitkl Jul 13, 2024
c725e54
bug fix for non-negative model, tracking total S-R occupancy, minor c…
vitkl Jul 24, 2024
482258f
options for properly utilising segmented cell input
vitkl Jul 25, 2024
fc60db2
cell abundance proportional normalisation by N
vitkl Jul 25, 2024
fd2babc
diffusion domain function
vitkl Jul 25, 2024
92ed022
changing distance prior, option to cap distance effect to 10x of aver…
vitkl Jul 28, 2024
77666b9
minor bug fixes and changes
vitkl Aug 9, 2024
77f28d7
adding optional extra categorical + N_cells_per_location dtype bug fix
vitkl Aug 20, 2024
b1ab786
remove cell comm model from normal c2l
vitkl Aug 20, 2024
d0f5018
make dask optional
vitkl Aug 21, 2024
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
9 changes: 5 additions & 4 deletions cell2location/cell_comm/around_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def compute_weighted_average_around_target(
source_cell_type_data,
index=adata.obs_names,
columns=source_names,
)
).astype("float32")
# get normalising quantile values
source_normalisation_quantile = source_cell_type_data.quantile(normalisation_quantile, axis=0)
# compute average abundance above this quantile
Expand Down Expand Up @@ -151,7 +151,7 @@ def compute_weighted_average_around_target(
# to account for locations with no neighbours within a bin (sum == 0)
data_[np.isnan(data_)] = 0
# complete the average for a given sample
source_cell_type_data.loc[sample_ind, :] = data_
source_cell_type_data.loc[sample_ind, :] = data_.astype("float32")
# normalise data by normalising quantile (global value across distance bins)
source_cell_type_data = source_cell_type_data / source_normalisation_quantile
# account for cases of undetected signal
Expand Down Expand Up @@ -183,8 +183,9 @@ def compute_weighted_average_around_target(

weighted_avg_ = pd.Series(weighted_avg_, name=ct, index=source_names)

# hack to make self interactions less apparent
weighted_avg_[ct] = weighted_avg_[~weighted_avg_.index.isin([ct])].max() + 0.02
if genes_to_use_as_source is None:
# hack to make self interactions less apparent
weighted_avg_[ct] = (weighted_avg_[~weighted_avg_.index.isin([ct])].max() + 0.02).astype("float32")
# complete the results dataframe
weighted_avg.loc[f"target {ct}", :] = weighted_avg_

Expand Down
20 changes: 18 additions & 2 deletions cell2location/cluster_averages/cluster_averages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
from scipy.sparse import csr_matrix


def compute_cluster_averages(adata, labels, use_raw=True, layer=None):
def compute_cluster_averages(
adata,
labels,
use_raw=True,
layer=None,
use_dask=False,
):
"""
Compute average expression of each gene in each cluster

Expand Down Expand Up @@ -44,7 +50,17 @@ def compute_cluster_averages(adata, labels, use_raw=True, layer=None):
averages_mat = np.zeros((1, x.shape[1]))

for c in all_clusters:
sparse_subset = csr_matrix(x[np.isin(adata.obs[labels], c), :])
if use_dask:
from dask import config
from dask.array.core import Array

with config.set(**{"array.slicing.split_large_chunks": False}):
cur_data = x[np.isin(adata.obs[labels], c), :]
if isinstance(cur_data, Array):
cur_data = cur_data.compute()
else:
cur_data = x[np.isin(adata.obs[labels], c), :]
sparse_subset = csr_matrix(cur_data)
aver = sparse_subset.mean(0)
averages_mat = np.concatenate((averages_mat, aver))
averages_mat = averages_mat[1:, :].T
Expand Down
Empty file.
Loading