From 6d309c3a7d7944913ac23e841f39ae98673933ee Mon Sep 17 00:00:00 2001 From: Starlitnightly Date: Sun, 7 Jul 2024 17:24:47 +0800 Subject: [PATCH] Fixed an error of `ov.pp.pca` when pcs smaller than 13. #102 --- omicverse/pp/_preprocess.py | 20 ++++++++++---------- omicverse_guide/docs/Release_notes.md | 3 +++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/omicverse/pp/_preprocess.py b/omicverse/pp/_preprocess.py index e2f6c63b..3aadf5f5 100644 --- a/omicverse/pp/_preprocess.py +++ b/omicverse/pp/_preprocess.py @@ -580,16 +580,12 @@ 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) @@ -597,6 +593,10 @@ def pca(adata, n_pcs=50, layer='scaled',inplace=True): 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): """ diff --git a/omicverse_guide/docs/Release_notes.md b/omicverse_guide/docs/Release_notes.md index 68d6a598..9d4a04fa 100644 --- a/omicverse_guide/docs/Release_notes.md +++ b/omicverse_guide/docs/Release_notes.md @@ -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