Skip to content

Commit

Permalink
Fixed an error of ov.pp.pca when pcs smaller than 13. #102
Browse files Browse the repository at this point in the history
  • Loading branch information
Starlitnightly committed Jul 7, 2024
1 parent 5899f85 commit 6d309c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
20 changes: 10 additions & 10 deletions omicverse/pp/_preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,23 +580,23 @@ def pca(adata, n_pcs=50, layer='scaled',inplace=True):
raise KeyError(f'Selected layer {layer} is not present. Compute it first!')

if settings.mode == 'cpu':
model = my_PCA()
model.calculate_PCA(X, n_components=n_pcs)
adata.obsm[key + '|X_pca'] = model.embs
adata.varm[key + '|pca_loadings'] = model.loads
adata.uns[key + '|pca_var_ratios'] = model.var_ratios
adata.uns[key + '|cum_sum_eigenvalues'] = np.cumsum(model.var_ratios)
if inplace:
return None
else:
return adata
sc.pp.pca(adata, layer=layer,n_comps=n_pcs)
adata.obsm[key + '|X_pca'] = adata.obsm['X_pca']
adata.varm[key + '|pca_loadings'] = adata.varm['PCs']
adata.uns[key + '|pca_var_ratios'] = adata.uns['pca']['variance_ratio']
adata.uns[key + '|cum_sum_eigenvalues'] = adata.uns['pca']['variance']

else:
import rapids_singlecell as rsc
rsc.pp.pca(adata, layer=layer,n_comps=n_pcs)
adata.obsm[key + '|X_pca'] = adata.obsm['X_pca']
adata.varm[key + '|pca_loadings'] = adata.varm['PCs']
adata.uns[key + '|pca_var_ratios'] = adata.uns['pca']['variance_ratio']
adata.uns[key + '|cum_sum_eigenvalues'] = adata.uns['pca']['variance']
if inplace:
return None
else:
return adata

def red(adata):
"""
Expand Down
3 changes: 3 additions & 0 deletions omicverse_guide/docs/Release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,3 +404,6 @@ Support Raw Windows platform
- Fixed an error of `pyTCGA.survival_analysis` when the matrix is sparse. #62, #68, #95
- Added tqdm to visualize the process of `pyTCGA.survial_analysis_all`
- Fixed an error of `data_drop_duplicates_index` with remove duplicate indexes to retain only the highest expressed genes #45

### PP Module
- Fixed an error of `ov.pp.pca` when pcs smaller than 13. #102

0 comments on commit 6d309c3

Please sign in to comment.