Skip to content

Commit

Permalink
Take advantage of CellMembrane::LogNormalizeUsingAlternateAssay
Browse files Browse the repository at this point in the history
  • Loading branch information
bbimber committed Dec 21, 2023
1 parent bdec4cd commit 9b8c91c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
11 changes: 8 additions & 3 deletions R/NimbleAppend.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#' @param targetAssayName The target assay. If this assay exists, features will be appended (and an error thrown if there are duplicates). Otherwise a new assay will be created.
#' @param renameConflictingFeatures If true, when appending to an existing assay, any conflicting feature names will be renamed, appending the value of duplicateFeatureSuffix
#' @param duplicateFeatureSuffix If renameConflictingFeatures is true, this string will be appended to duplicated feature names
#' @param normalizeData If true, Seurat::NormalizeData will be run after appending/creating the assay
#' @param normalizeData If true, data will be normalized after appending/creating the assay. This will default to CellMembrane::LogNormalizeUsingAlternateAssay; however, if assayForLibrarySize equals targetAssayName then Seurat::NormalizeData is used.
#' @param performDietSeurat If true, DietSeurat will be run, which removes existing reductions. This may or may not be required based on your usage, but the default is true out of caution.
#' @param assayForLibrarySize If normalizeData is true, then this is the assay used for librarySize when normalizing. If assayForLibrarySize equals targetAssayName, Seurat::NormalizeData is used.
#' @return A modified Seurat object.
#' @export
AppendNimbleCounts <- function(seuratObject, nimbleFile, targetAssayName, dropAmbiguousFeatures = TRUE, renameConflictingFeatures = TRUE, duplicateFeatureSuffix = ".Nimble", normalizeData = TRUE, performDietSeurat = TRUE) {
AppendNimbleCounts <- function(seuratObject, nimbleFile, targetAssayName, dropAmbiguousFeatures = TRUE, renameConflictingFeatures = TRUE, duplicateFeatureSuffix = ".Nimble", normalizeData = TRUE, performDietSeurat = TRUE, assayForLibrarySize = 'RNA') {
if (!file.exists(nimbleFile)) {
stop(paste0("Nimble file not found: ", nimbleFile))
}
Expand Down Expand Up @@ -157,7 +158,11 @@ AppendNimbleCounts <- function(seuratObject, nimbleFile, targetAssayName, dropAm
}

if (normalizeData) {
seuratObject <- Seurat::NormalizeData(seuratObject, assay = targetAssayName, verbose = FALSE)
if (targetAssayName == assayForLibrarySize) {
seuratObject <- Seurat::NormalizeData(seuratObject, assay = targetAssayName, verbose = FALSE)
} else {
seuratObject <- CellMembrane::LogNormalizeUsingAlternateAssay(seuratObject, assay = targetAssayName, assayForLibrarySize = assayForLibrarySize)
}
}

return(seuratObject)
Expand Down
7 changes: 5 additions & 2 deletions man/AppendNimbleCounts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9b8c91c

Please sign in to comment.