Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically reset PCs based on var size #76

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scanpy_scripts/lib/_pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@
"""

import scanpy as sc
import math
from ..obj_utils import write_embedding

def pca(adata, key_added=None, export_embedding=None, **kwargs):
"""
Wrapper function for sc.pp.pca, for supporting named slot
"""

# Check the number of components (use_pc) less than floor(number of genes)/2
if 'use_pc' in kwargs and kwargs['use_pc'] is not None:
kwargs['use_pc'] = min(math.floor(adata.n_vars/2), kwargs['use_pc'])

# minimum of (<value calculated above>, n_pcs_supplied)

# omit "svd_solver" to let scanpy choose automatically
if 'svd_solver' in kwargs and kwargs['svd_solver'] == 'auto':
del kwargs['svd_solver']
Expand Down