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 7, 2023
1 parent dfed0b4 commit d94bc3f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions stereo/algorithm/ccd/sliding_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import anndata as ad
import numpy as np
import pandas as pd
import scanpy as sc
# import scanpy as sc
from anndata import AnnData
from tqdm.auto import tqdm

Expand Down Expand Up @@ -70,7 +70,7 @@ def run(self):
self.calc_feature_matrix(self.win_sizes_list[0], self.sliding_steps_list[0])
else:
if self.tfile.endswith('.h5ad'):
self.tissue = sc.read(self.tfile)
self.tissue = ad.read_h5ad(self.tfile)
else:
raise AttributeError(f"File '{self.tfile}' extension is not .h5ad")

Expand Down Expand Up @@ -133,7 +133,7 @@ def calc_feature_matrix(self, win_size, sliding_step):
if window_key in ret.keys():
feature_matrix[subwindow] = {
k: feature_matrix[subwindow].get(k, 0) + ret[window_key].get(k, 0)
for k in set(feature_matrix[subwindow]).union(ret[window_key])
for k in sorted(set(feature_matrix[subwindow]).union(ret[window_key]))
}

feature_matrix = pd.DataFrame(feature_matrix).T
Expand Down Expand Up @@ -238,7 +238,7 @@ def run(self):
super().calc_feature_matrix(self.win_sizes_list[i], self.sliding_steps_list[i])
tissue_list.append(self.tissue)

self.tissue = ad.concat(tissue_list, axis=0, join='outer')
self.tissue = ad.concat(tissue_list, axis=0, join='outer', fill_value=0.0)
else:
super().run()

Expand Down
4 changes: 2 additions & 2 deletions stereo/algorithm/community_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ def cluster(self, merged_tissue): # TODO, merged_tissue da bude AnnBasedStereoE
resolution=self.params['resolution'])
merged_tissue._ann_data.obs['leiden'] = merged_tissue._ann_data.obs['leiden'].astype('int')
merged_tissue._ann_data.obs['leiden'] -= 1
merged_tissue._ann_data.obs['leiden'] = merged_tissue._ann_data.obs['leiden'].astype('U')
merged_tissue._ann_data.obs['leiden'] = merged_tissue._ann_data.obs['leiden'].astype('category')
merged_tissue._ann_data.obs['leiden'] = merged_tissue._ann_data.obs['leiden'].astype('str')
# merged_tissue._ann_data.obs['leiden'] = merged_tissue._ann_data.obs['leiden'].astype('category')
elif self.params['cluster_algo'] == 'spectral':
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)
Expand Down

0 comments on commit d94bc3f

Please sign in to comment.