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

LSI-enabled BBKNN #301

Merged
merged 7 commits into from
Sep 4, 2024
Merged
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
27 changes: 11 additions & 16 deletions panpipes/python_scripts/batch_correct_bbknn.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,26 @@
# bbknn can't integrate on 2+ variables, so create a fake column with combined information
columns = [x.strip() for x in args.integration_col.split(",")]

if args.modality =="atac":
if "scaled_counts" in adata.layers.keys():
pass
else:
L.info("To run BBKNN on ATAC, PCA is needed. Computing PCA now.")
L.info("Scaling data and saving scaled counts to .layers['scaled_counts']")
sc.pp.scale(adata)
adata.layers["scaled_counts"] = adata.X.copy()
L.info("Computing PCA")
sc.tl.pca(adata, n_comps=min(50,adata.var.shape[0]-1), svd_solver='arpack', random_state=0)

if "X_pca" not in adata.obsm:
L.warning("X_pca could not be found in adata.obsm. Computing PCA with default parameters.")
if args.dimred == "PCA":
dimred = "X_pca"
elif args.dimred == "LSI":
dimred = "X_lsi"

if dimred not in adata.obsm:
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))
L.info("Scaling data")
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, n_comps=n_pcs,
svd_solver='arpack',
random_state=0)


L.info("Preparing for integration")

if len(columns) > 1:
Expand All @@ -99,6 +93,7 @@
# run bbknn
L.info("Running BBKNN")
adata = sc.external.pp.bbknn(adata,
use_rep=dimred,
batch_key=args.integration_col,
copy=True,
n_pcs = int(args.neighbors_n_pcs),
Expand Down