Skip to content

Commit

Permalink
add check pca n_samples
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahOuologuem committed Sep 11, 2024
1 parent d9c421d commit 97c11ae
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
8 changes: 4 additions & 4 deletions panpipes/python_scripts/batch_correct_bbknn.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@
if "X_pca" not in adata.obsm:
L.warning("X_pca could not be found in adata.obsm. Computing PCA with default parameters.")
n_pcs = 50
if adata.var.shape[0] < n_pcs:
L.info("You have less features than number of PCs you intend to calculate")
n_pcs = adata.var.shape[0] - 1
L.info("Setting n PCS to %i" % int(n_pcs))
if adata.var.shape[0] < n_pcs or adata.obs.shape[0] < n_pcs:
L.info("You have less features/samples than number of PCs you intend to calculate")
n_pcs = min(adata.var.shape[0], adata.obs.shape[0]) - 1
L.info("Setting n PCS to %i" % int(n_pcs))
L.info("Scaling data")
sc.pp.scale(adata)
L.info("Computing PCA")
Expand Down
8 changes: 4 additions & 4 deletions panpipes/python_scripts/batch_correct_harmony.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@
L.warning("Dimred '%s' could not be found in adata.obsm. Computing PCA with default parameters." % dimred)
dimred = "X_pca"
n_pcs = 50
if adata.var.shape[0] < n_pcs:
L.info("You have less features than number of PCs you intend to calculate")
n_pcs = adata.var.shape[0] - 1
L.info("Setting n PCS to %i" % int(n_pcs))
if adata.var.shape[0] < n_pcs or adata.obs.shape[0] < n_pcs:
L.info("You have less features/samples than number of PCs you intend to calculate")
n_pcs = min(adata.var.shape[0], adata.obs.shape[0]) - 1
L.info("Setting n PCS to %i" % int(n_pcs))
L.info("Scaling data")
sc.pp.scale(adata)
L.info("Computing PCA")
Expand Down
10 changes: 8 additions & 2 deletions panpipes/python_scripts/batch_correct_none.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,19 @@


if dimred not in adata.obsm:
L.warning("Dimred '%s' could not be found in adata.obsm. Computing PCA with default parameters." % dimred)
L.warning("Dimred '%s' could not be found in adata.obsm. Computing PCA with default parameters." % dimred)
n_pcs = 50
if adata.var.shape[0] < n_pcs or adata.obs.shape[0] < n_pcs:
L.info("You have less features/samples than number of PCs you intend to calculate")
n_pcs = min(adata.var.shape[0], adata.obs.shape[0]) - 1
L.info("Setting n PCS to %i" % int(n_pcs))
L.info("Scaling data")
sc.pp.scale(adata)
L.info("Computing PCA")
sc.tl.pca(adata, svd_solver='arpack',
sc.tl.pca(adata, n_comps=n_pcs, svd_solver='arpack',
random_state=0)
pc_kwargs['use_rep'] = "X_pca"
pc_kwargs['n_pcs'] = n_pcs


L.info("Computing neighbors")
Expand Down

0 comments on commit 97c11ae

Please sign in to comment.