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

add calcN parameter to CreateSeuratObject #224

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mhkowalski
Copy link
Collaborator

I'm not 100% sure that we want to do this, but I am playing around with adding a calcN parameter to CreateSeuratObject to enable disabling/enabling the calculation of nCounts and nFeatures without overriding the global option. This would be cleaner for internal functions to enable specific behavior without having to carefully set/return global options.

If we want to do this, I'll write documentation and tests for this parameter.

devtools::load_all("~/data/github/seurat-object/")
devtools::load_all("~/data/github/seurat/")

getOption("Seurat.object.assay.calcn")

#global option is set to null by default
obj <- CreateSeuratObject(pbmc_small[['RNA']]$counts, 
                          calcN=FALSE)
grep("nCount_RNA", colnames(obj[[]]))
obj <- CreateSeuratObject(pbmc_small[['RNA']]$counts, 
                          calcN=TRUE)
grep("nCount_RNA", colnames(obj[[]]))
obj <- CreateSeuratObject(pbmc_small[['RNA']]$counts)
grep("nCount_RNA", colnames(obj[[]]))

#set global default but override if set in function call
options("Seurat.object.assay.calcn" = FALSE)
obj <- CreateSeuratObject(pbmc_small[['RNA']]$counts)
grep("nCount_RNA", colnames(obj[[]]))
obj <- CreateSeuratObject(pbmc_small[['RNA']]$counts, 
                          calcN=TRUE)
grep("nCount_RNA", colnames(obj[[]]))

@mojaveazure
Copy link
Member

The options() approach was selected to allow internal functions to opt-out of running .CalcN(), while keeping it running for user-facing operations. An alternative to the op <- options(); on.exit(options(op)) would be using withr::with_options() or withr::local_options() in interal Seurat functions (withr has no dependencies and basically automates the op <- options(); on.exit(options(op)) construct), which I think would be better than exposing a calcN parameter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants