Skip to content

Commit

Permalink
update for CCD.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanliwei-genomics-cn committed Nov 22, 2023
1 parent 996a2af commit b2ce07f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions stereo/algorithm/ccd/community_clustering_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Expand Down
2 changes: 1 addition & 1 deletion stereo/algorithm/ccd/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion stereo/algorithm/community_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit b2ce07f

Please sign in to comment.