From b2ce07ff149af9dcd6dfbfb70264959f3207f741 Mon Sep 17 00:00:00 2001 From: tanliwei Date: Wed, 22 Nov 2023 16:16:03 +0800 Subject: [PATCH] update for CCD. --- stereo/algorithm/ccd/community_clustering_algorithm.py | 7 ++++--- stereo/algorithm/ccd/utils.py | 2 +- stereo/algorithm/community_detection.py | 4 +++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/stereo/algorithm/ccd/community_clustering_algorithm.py b/stereo/algorithm/ccd/community_clustering_algorithm.py index ef7f2a9a..809335c9 100644 --- a/stereo/algorithm/ccd/community_clustering_algorithm.py +++ b/stereo/algorithm/ccd/community_clustering_algorithm.py @@ -276,9 +276,10 @@ def calculate_cell_mixture_stats(self): stats_table = {} # calculate cell type mixtures for every cluster for label, cluster_data in cell_types_communities.groupby(clustering_labels): - cell_type_dict = {ct: 0 for ct in self.unique_cell_type} - for cell in cluster_data[self.annotation]: - cell_type_dict[cell] += 1 + # cell_type_dict = {ct: 0 for ct in self.unique_cell_type} + # for cell in cluster_data[self.annotation]: + # cell_type_dict[cell] += 1 + cell_type_dict = {ct: np.sum(cluster_data[self.annotation] == ct) for ct in self.unique_cell_type} # remove excluded cell types cell_type_dict = {k: cell_type_dict[k] for k in self.tissue.var.index.sort_values()} diff --git a/stereo/algorithm/ccd/utils.py b/stereo/algorithm/ccd/utils.py index 90b9d042..6f68466e 100644 --- a/stereo/algorithm/ccd/utils.py +++ b/stereo/algorithm/ccd/utils.py @@ -86,7 +86,7 @@ def reset_figure_params(): for key in rcParams.keys(): if key in original_rcParams: rcParams[key] = original_rcParams[key] - original_rcParams = None + # original_rcParams = None def csv_to_anndata(csv_file_path: str, annotation: str): diff --git a/stereo/algorithm/community_detection.py b/stereo/algorithm/community_detection.py index dd508cdf..23c93087 100644 --- a/stereo/algorithm/community_detection.py +++ b/stereo/algorithm/community_detection.py @@ -304,7 +304,8 @@ def cluster(self, merged_tissue): # TODO, merged_tissue da bude AnnBasedStereoE merged_tissue = AnnBasedStereoExpData(h5ad_file_path=None, based_ann_data=merged_tissue) if self.params['cluster_algo'] == 'leiden': merged_tissue._ann_data.obsm['X_pca_dummy'] = merged_tissue._ann_data.X - merged_tissue.tl.neighbors(pca_res_key='X_pca_dummy', n_neighbors=15) + merged_tissue.tl.neighbors(pca_res_key='X_pca_dummy', n_neighbors=15, + n_jobs=-1, res_key='neighbors') merged_tissue.tl.leiden(neighbors_res_key='neighbors', res_key='leiden', resolution=self.params['resolution']) merged_tissue._ann_data.obs['leiden'] = merged_tissue._ann_data.obs['leiden'].astype('int') @@ -752,6 +753,7 @@ def plot(self, function_ind: str, slice_id=0, community_id=None): finally: self.params['hide_plots'] = orig_hide_plots self.algo_list[slice_id].hide_plots = orig_hide_plots + reset_figure_params() class CommunityDetection(AlgorithmBase, _CommunityDetection):