Skip to content

Commit

Permalink
Fixed an error in construct_landscape of ov.space.STT
Browse files Browse the repository at this point in the history
  • Loading branch information
Starlitnightly committed Jul 25, 2024
1 parent 09e667b commit efa3e16
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
3 changes: 3 additions & 0 deletions omicverse/bulk2single/_bulk2single.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ def __init__(self,bulk_data:pd.DataFrame,single_data:anndata.AnnData,
gpu: The ID of the GPU to use. Set to -1 to use CPU. Default is 0. If set to 'mps', the MPS backend will be used.
"""
single_data.var_names_make_unique()
bulk_data=data_drop_duplicates_index(bulk_data)
self.bulk_data=bulk_data
self.single_data=single_data

if self.single_data.shape[0]>max_single_cells:
print(f"......random select {max_single_cells} single cells")
import random
Expand Down
15 changes: 15 additions & 0 deletions omicverse/externel/STT/tl/_construct_landscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,32 @@ def construct_landscape(sc_object,thresh_cal_cov = 0.3, scale_axis = 1.0, scale_
mu_hat = sc_object.uns['da_out']['mu_hat']
rho = sc_object.obsm['rho']
projection = sc_object.obsm[coord_key][:,0:2]
p_hat=adata.uns['da_out']['P_hat']


labels = np.argmax(rho,axis = 1)
K = max(labels)+1

while K<rho.shape[1]:
rho=rho[:,:-1]
mu_hat=mu_hat[:-1]
mu_hat = mu_hat / np.sum(mu_hat)
p_hat=p_hat[:-1,:-1]
p_hat=(p_hat.T/np.sum(p_hat, axis=1)).T

sc_object.obsm['rho']=rho
sc_object.uns['da_out']['mu_hat']=mu_hat
sc_object.uns['da_out']['P_hat']=p_hat



centers = []
for i in range(K):
index = labels==i
p = np.mean(projection[index], axis=0)
centers.append(p)
centers = np.array(centers)
centers = np.nan_to_num(centers, nan=0.0)

trans_coord = np.matmul(rho,centers)

Expand Down
12 changes: 10 additions & 2 deletions omicverse_guide/docs/Release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -423,5 +423,13 @@ Support Raw Windows platform

### Bulk Module

- Fiexed an key error in `ov.bulk.Matrix_ID_mapping`
- Added `enrichment_multi_concat` in `ov.bulk` to concat the result of enrichment.
- Fixed an key error in `ov.bulk.Matrix_ID_mapping`
- Added `enrichment_multi_concat` in `ov.bulk` to concat the result of enrichment.

### Bulk Module

- Added `adata.var_names_make_unique()` to avoid mat shape error if gene not unique. #100

### Space Module

- Fixed an error in `construct_landscape` of `ov.space.STT`

0 comments on commit efa3e16

Please sign in to comment.