From 46c7ffd5163a8effca1735814b1b624c6c7eebd5 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Tue, 17 Sep 2019 18:16:45 -0400 Subject: [PATCH 01/83] Initial additions to component objects Add new 'global' slot for DimReduc objects Add new 'assay.orig' slot for Assay objects Add new 'assay.used' slot for Graph and SeuratCommand objects Add new UpdateSlots function to rebuild objects with updated slots --- NAMESPACE | 6 ++ R/objects.R | 118 +++++++++++++++++++++++++++++++++++- man/CreateDimReducObject.Rd | 6 +- man/DefaultAssay.Rd | 9 +++ 4 files changed, 135 insertions(+), 4 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 671813cce..29f9453fb 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,7 +4,9 @@ S3method("$",JackStrawData) S3method("$",Seurat) S3method("$",SeuratCommand) S3method("$<-",Seurat) +S3method("DefaultAssay<-",Assay) S3method("DefaultAssay<-",DimReduc) +S3method("DefaultAssay<-",Graph) S3method("DefaultAssay<-",Seurat) S3method("Idents<-",Seurat) S3method("JS<-",DimReduc) @@ -34,8 +36,11 @@ S3method(AddMetaData,Seurat) S3method(Cells,DimReduc) S3method(Cells,default) S3method(Command,Seurat) +S3method(DefaultAssay,Assay) S3method(DefaultAssay,DimReduc) +S3method(DefaultAssay,Graph) S3method(DefaultAssay,Seurat) +S3method(DefaultAssay,SeuratCommand) S3method(Embeddings,DimReduc) S3method(Embeddings,Seurat) S3method(FindClusters,Seurat) @@ -126,6 +131,7 @@ S3method(as.Seurat,loom) S3method(as.SingleCellExperiment,Seurat) S3method(as.data.frame,Matrix) S3method(as.list,SeuratCommand) +S3method(as.logical,DimReduc) S3method(as.logical,JackStrawData) S3method(as.loom,Seurat) S3method(as.sparse,H5Group) diff --git a/R/objects.R b/R/objects.R index 690761e68..67cf7dc1b 100644 --- a/R/objects.R +++ b/R/objects.R @@ -77,6 +77,7 @@ Assay <- setClass( data = 'AnyMatrix', scale.data = 'matrix', key = 'character', + assay.orig = 'character', var.features = 'vector', meta.features = 'data.frame', misc = 'ANY' @@ -133,6 +134,7 @@ DimReduc <- setClass( feature.loadings = 'matrix', feature.loadings.projected = 'matrix', assay.used = 'character', + global = 'logical', stdev = 'numeric', key = 'character', jackstraw = 'JackStrawData', @@ -152,7 +154,10 @@ DimReduc <- setClass( #' Graph <- setClass( Class = 'Graph', - contains = "dgCMatrix" + contains = "dgCMatrix", + slots = list( + assay.used = 'character' + ) ) #' The IntegrationData Class @@ -203,6 +208,7 @@ SeuratCommand <- setClass( slots = c( name = 'character', time.stamp = 'POSIXct', + assay.used = 'character', call.string = 'character', params = 'ANY' ) @@ -539,6 +545,7 @@ CreateAssayObject <- function( #' @param stdev Standard deviation (if applicable) for the dimensional reduction #' @param key A character string to facilitate looking up features from a #' specific DimReduc +#' @param global Specify this as a global reduction (useful for visualizations) #' @param jackstraw Results from the JackStraw function #' @param misc list for the user to store any additional information associated #' with the dimensional reduction @@ -565,6 +572,7 @@ CreateDimReducObject <- function( assay = NULL, stdev = numeric(), key = NULL, + global = FALSE, jackstraw = NULL, misc = list() ) { @@ -643,6 +651,7 @@ CreateDimReducObject <- function( feature.loadings = loadings, feature.loadings.projected = projected, assay.used = assay, + global = global, stdev = stdev, key = key, jackstraw = jackstraw, @@ -1369,6 +1378,16 @@ UpdateSeuratObject <- function(object) { if (package_version(x = slot(object = object, name = 'version')) >= package_version(x = "3.0.0")) { # Run validation message("Validating object structure") + # Update object slots + message("Updating object slots") + for (obj in FilterObjects(object = object, classes.keep = c('Assay', 'DimReduc', 'Graph'))) { + object[[obj]] <- UpdateSlots(object = object[[obj]]) + } + for (cmd in Command(object = object)) { + slot(object = object, name = 'commands')[[cmd]] <- UpdateSlots( + object = Command(object = object, command = cmd) + ) + } # Validate object keys message("Ensuring keys are in the proper strucutre") for (ko in FilterObjects(object = object)) { @@ -2522,6 +2541,19 @@ Command.Seurat <- function(object, command = NULL, value = NULL, ...) { return(params[[value]]) } +#' @rdname DefaultAssay +#' @export +#' @method DefaultAssay Assay +#' +DefaultAssay.Assay <- function(object, ...) { + return(tryCatch( + expr = slot(object = object, name = 'assay.orig'), + error = function(...) { + return(character(length = 0L)) + } + )) +} + #' @rdname DefaultAssay #' @export #' @method DefaultAssay DimReduc @@ -2531,6 +2563,19 @@ DefaultAssay.DimReduc <- function(object, ...) { return(slot(object = object, name = 'assay.used')) } +#' @rdname DefaultAssay +#' @export +#' @method DefaultAssay Graph +#' +DefaultAssay.Graph <- function(object, ...) { + return(tryCatch( + expr = slot(object = object, name = 'assay.used'), + error = function(...) { + return(character(length = 0L)) + } + )) +} + #' @rdname DefaultAssay #' @export #' @method DefaultAssay Seurat @@ -2544,6 +2589,28 @@ DefaultAssay.Seurat <- function(object, ...) { return(slot(object = object, name = 'active.assay')) } +#' @rdname DefaultAssay +#' @export +#' @method DefaultAssay SeuratCommand +#' +DefaultAssay.SeuratCommand <- function(object, ...) { + return(tryCatch( + expr = slot(object = object, name = 'assay.used'), + error = function(...) { + return(character(length = 0L)) + } + )) +} + +#' @export +#' @method DefaultAssay<- Assay +#' +"DefaultAssay<-.Assay" <- function(object, ..., value) { + object <- UpdateSlots(object = object) + slot(object = object, name = 'assay.orig') <- value + return(object) +} + #' @export #' @method DefaultAssay<- DimReduc #' @@ -2553,6 +2620,15 @@ DefaultAssay.Seurat <- function(object, ...) { return(object) } +#' @export +#' @method DefaultAssay<- Graph +#' +"DefaultAssay<-.Graph" <- function(object, ..., value) { + object <- UpdateSlots(object = object) + slot(object = object, name = 'assay.used') <- value + return(object) +} + #' @rdname DefaultAssay #' @export #' @method DefaultAssay<- Seurat @@ -5222,6 +5298,18 @@ as.list.SeuratCommand <- function(x, complete = FALSE, ...) { return(cmd) } +#' @export +#' @method as.logical DimReduc +#' +as.logical.DimReduc <- function(x, ...) { + return(tryCatch( + expr = slot(object = x, name = 'global'), + error = function(...) { + return(FALSE) + } + )) +} + #' @export #' @method as.logical JackStrawData #' @@ -6505,7 +6593,8 @@ CellsByIdentities <- function(object, cells = NULL) { FilterObjects <- function(object, classes.keep = c('Assay', 'DimReduc')) { slots <- na.omit(object = Filter( f = function(x) { - return(class(x = slot(object = object, name = x)) == 'list') + sobj <- slot(object = object, name = x) + return(is.list(x = sobj) && !is.data.frame(x = sobj) && !is.package_version(x = sobj)) }, x = slotNames(x = object) )) @@ -6726,6 +6815,31 @@ UpdateKey <- function(key) { } } +# Update slots in an object +# +# @param object An object to update +# +# @return \code{object} with the latest slot definitions +# +UpdateSlots <- function(object) { + object.list <- sapply( + X = slotNames(x = object), + FUN = function(x) { + return(tryCatch( + expr = slot(object = object, name = x), + error = function(...) { + return(NULL) + } + )) + }, + simplify = FALSE, + USE.NAMES = TRUE + ) + object.list <- Filter(f = Negate(f = is.null), x = object.list) + object.list <- c('Class' = class(x = object)[1], object.list) + return(do.call(what = 'new', args = object.list)) +} + # Pulls the proper data matrix for merging assay data. If the slot is empty, will return an empty # matrix with the proper dimensions from one of the remaining data slots. # diff --git a/man/CreateDimReducObject.Rd b/man/CreateDimReducObject.Rd index aea2540ea..7defda9f9 100644 --- a/man/CreateDimReducObject.Rd +++ b/man/CreateDimReducObject.Rd @@ -7,8 +7,8 @@ \usage{ CreateDimReducObject(embeddings = new(Class = "matrix"), loadings = new(Class = "matrix"), projected = new(Class = "matrix"), - assay = NULL, stdev = numeric(), key = NULL, jackstraw = NULL, - misc = list()) + assay = NULL, stdev = numeric(), key = NULL, global = FALSE, + jackstraw = NULL, misc = list()) } \arguments{ \item{embeddings}{A matrix with the cell embeddings} @@ -24,6 +24,8 @@ CreateDimReducObject(embeddings = new(Class = "matrix"), \item{key}{A character string to facilitate looking up features from a specific DimReduc} +\item{global}{Specify this as a global reduction (useful for visualizations)} + \item{jackstraw}{Results from the JackStraw function} \item{misc}{list for the user to store any additional information associated diff --git a/man/DefaultAssay.Rd b/man/DefaultAssay.Rd index 26be724bd..5b0e755c8 100644 --- a/man/DefaultAssay.Rd +++ b/man/DefaultAssay.Rd @@ -3,8 +3,11 @@ \name{DefaultAssay} \alias{DefaultAssay} \alias{DefaultAssay<-} +\alias{DefaultAssay.Assay} \alias{DefaultAssay.DimReduc} +\alias{DefaultAssay.Graph} \alias{DefaultAssay.Seurat} +\alias{DefaultAssay.SeuratCommand} \alias{DefaultAssay<-.Seurat} \title{Get and set the default assay} \usage{ @@ -12,10 +15,16 @@ DefaultAssay(object, ...) DefaultAssay(object, ...) <- value +\method{DefaultAssay}{Assay}(object, ...) + \method{DefaultAssay}{DimReduc}(object, ...) +\method{DefaultAssay}{Graph}(object, ...) + \method{DefaultAssay}{Seurat}(object, ...) +\method{DefaultAssay}{SeuratCommand}(object, ...) + \method{DefaultAssay}{Seurat}(object, ...) <- value } \arguments{ From f65270fa6edac00a258e214b75ab16f1b578e562 Mon Sep 17 00:00:00 2001 From: TomKellyGenetics Date: Fri, 4 Oct 2019 15:38:36 +0900 Subject: [PATCH 02/83] implement method input for FindClusters.Seurat satijalab#1645 satijalab#2168 --- R/clustering.R | 14 +++++++++++++- man/FindClusters.Rd | 8 ++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/R/clustering.R b/R/clustering.R index 40560795e..be63a92bd 100644 --- a/R/clustering.R +++ b/R/clustering.R @@ -13,6 +13,9 @@ NULL #' @importFrom pbapply pblapply #' @importFrom future.apply future_lapply #' @importFrom future nbrOfWorkers +#' @importFrom igraph graph_from_adjacency_matrix +#' @importFrom methods as +#' @importClassesFrom Matrix dgCMatrix #' #' @param modularity.fxn Modularity function (1 = standard; 2 = alternative). #' @param initial.membership,weights,node.sizes Parameters to pass to the Python leidenalg function. @@ -82,6 +85,13 @@ FindClusters.default <- function( edge.file.name = edge.file.name ) } else if (algorithm == 4) { + if (method == "matrix" || method == "igraph"){ + if (method == "igraph"){ + object <- graph_from_adjacency_matrix(object) + } + } else { + stop("method must be 'matrix' or 'igraph'") + } ids <- RunLeiden( object = object, method = method, @@ -158,6 +168,7 @@ FindClusters.Seurat <- function( weights = NULL, node.sizes = NULL, resolution = 0.8, + method = "matrix", algorithm = 1, n.start = 10, n.iter = 10, @@ -183,6 +194,7 @@ FindClusters.Seurat <- function( weights = weights, node.sizes = node.sizes, resolution = resolution, + method = method, algorithm = algorithm, n.start = n.start, n.iter = n.iter, @@ -711,7 +723,7 @@ RunLeiden <- function( "matrix" = input <- as(object, "matrix"), #run as igraph object (passes to reticulate) "igraph" = switch( - EXPR = is(object), + EXPR = is(object)[1], #generate igraph if needed (will handle updated snn class) "Graph" = input <- graph_from_adjacency_matrix(adjmatrix = object), "dgCMatrix" = input <- graph_from_adjacency_matrix(adjmatrix = object), diff --git a/man/FindClusters.Rd b/man/FindClusters.Rd index 02edfdb1f..215109b4d 100644 --- a/man/FindClusters.Rd +++ b/man/FindClusters.Rd @@ -17,10 +17,10 @@ FindClusters(object, ...) \method{FindClusters}{Seurat}(object, graph.name = NULL, modularity.fxn = 1, initial.membership = NULL, weights = NULL, - node.sizes = NULL, resolution = 0.8, algorithm = 1, n.start = 10, - n.iter = 10, random.seed = 0, group.singletons = TRUE, - temp.file.location = NULL, edge.file.name = NULL, verbose = TRUE, - ...) + node.sizes = NULL, resolution = 0.8, method = "matrix", + algorithm = 1, n.start = 10, n.iter = 10, random.seed = 0, + group.singletons = TRUE, temp.file.location = NULL, + edge.file.name = NULL, verbose = TRUE, ...) } \arguments{ \item{object}{An object} From 76f5b5b3145dae4ce4df94fb78535e46fd6c6e89 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Fri, 4 Oct 2019 10:39:04 -0400 Subject: [PATCH 03/83] move adding spline to SingleCorPlot to handle names (#2151) --- R/visualization.R | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/R/visualization.R b/R/visualization.R index ef84ea18c..566ff6dea 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -1440,15 +1440,9 @@ FeatureScatter <- function( cols = cols, pt.size = pt.size, smooth = smooth, - legend.title = 'Identity' + legend.title = 'Identity', + span = span ) - if (!is.null(x = span)) { - plot <- plot + geom_smooth( - mapping = aes_string(x = feature1, y = feature2), - method = 'loess', - span = span - ) - } return(plot) } @@ -4182,7 +4176,8 @@ SingleCorPlot <- function( smooth = FALSE, rows.highlight = NULL, legend.title = NULL, - na.value = 'grey50' + na.value = 'grey50', + span = NULL ) { pt.size <- pt.size <- pt.size %||% AutoPointSize(data = data) orig.names <- colnames(x = data) @@ -4279,6 +4274,13 @@ SingleCorPlot <- function( } } plot <- plot + theme_cowplot() + theme(plot.title = element_text(hjust = 0.5)) + if (!is.null(x = span)) { + plot <- plot + geom_smooth( + mapping = aes_string(x = names.plot[1], y = names.plot[2]), + method = 'loess', + span = span + ) + } return(plot) } From 0489f47237662559cd4d8bc2c5a356e3e198c01a Mon Sep 17 00:00:00 2001 From: yuejiang Date: Mon, 7 Oct 2019 15:28:51 -0700 Subject: [PATCH 04/83] I think you need to transpose this so that each row is an observation, each column is a feature --- R/dimensional_reduction.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/dimensional_reduction.R b/R/dimensional_reduction.R index 657822ed9..941e42fa1 100644 --- a/R/dimensional_reduction.R +++ b/R/dimensional_reduction.R @@ -1109,7 +1109,7 @@ RunTSNE.Seurat <- function( ) } else if (!is.null(x = features)) { RunTSNE( - object = as.matrix(x = GetAssayData(object = object)[features, cells]), + object = t(as.matrix(x = GetAssayData(object = object)[features, cells])), assay = DefaultAssay(object = object), seed.use = seed.use, tsne.method = tsne.method, From 02099de223d393bfec74f1fa2628f26179803bed Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Tue, 8 Oct 2019 14:47:35 -0400 Subject: [PATCH 05/83] Bump develop version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3b59306e3..594fe57d3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: Seurat -Version: 3.1.1 +Version: 3.1.1.9000 Date: 2019-09-23 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. From 6afbfd369aa7fa5ca93cf8164c861fc62be6d7ce Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Wed, 9 Oct 2019 15:12:24 -0400 Subject: [PATCH 06/83] don't store corrected UMIs in misc slot --- R/preprocessing.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/preprocessing.R b/R/preprocessing.R index f8cbd5acb..b37be893a 100644 --- a/R/preprocessing.R +++ b/R/preprocessing.R @@ -1305,6 +1305,7 @@ SCTransform <- function( message('Place corrected count matrix in counts slot') } assay.out <- CreateAssayObject(counts = vst.out$umi_corrected) + vst.out$umi_corrected <- NULL } else { assay.out <- CreateAssayObject(counts = umi) } From 9820eb5de8c2218313987d8107e25113a34bdd58 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Wed, 9 Oct 2019 15:54:06 -0400 Subject: [PATCH 07/83] bump develop version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 594fe57d3..ef28f9ebb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9000 -Date: 2019-09-23 +Version: 3.1.1.9001 +Date: 2019-10-09 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( From f8026cf9b5b12f136d0e4e9720eab319b7cd2a0b Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Wed, 9 Oct 2019 17:11:42 -0400 Subject: [PATCH 08/83] rename cells where necessary in Misc slot for SCT assays --- R/objects.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/objects.R b/R/objects.R index 690761e68..3e3d891c0 100644 --- a/R/objects.R +++ b/R/objects.R @@ -3843,6 +3843,10 @@ RenameCells.Assay <- function(object, new.names = NULL, ...) { } colnames(x = slot(object = object, name = data.slot)) <- new.names } + if (IsSCT(assay = object)) { + suppressWarnings(Misc(object, slot = "vst.out")$cells_step1 <- new.names) + suppressWarnings(rownames(x = Misc(object, slot = "vst.out")$cell_attr) <- new.names) + } return(object) } From f3f9d77ace170dc77ab271476d7b8278259b2973 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Wed, 9 Oct 2019 17:54:10 -0400 Subject: [PATCH 09/83] use function to check if SCT assay --- R/preprocessing.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/preprocessing.R b/R/preprocessing.R index b37be893a..751395c63 100644 --- a/R/preprocessing.R +++ b/R/preprocessing.R @@ -456,7 +456,7 @@ GetResidual <- function( replace.value = FALSE, verbose = TRUE ) { - if (is.null(x = Misc(object = object[[assay]], slot = 'vst.out')) & is.null(x = Misc(object = object[[assay]], slot = 'vst.set'))) { + if (!IsSCT(assay = object[[assay]])) { stop(assay, " assay was not generated by SCTransform") } if (replace.value) { From fd17e37e4450f8847bdab186123d5fa3d60a5d0a Mon Sep 17 00:00:00 2001 From: yuhanH Date: Thu, 10 Oct 2019 11:21:26 -0400 Subject: [PATCH 10/83] rename vst.list --- R/objects.R | 24 ++++++++++++++++++++---- R/utilities.R | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/R/objects.R b/R/objects.R index 3e3d891c0..7f8dff99e 100644 --- a/R/objects.R +++ b/R/objects.R @@ -3836,6 +3836,22 @@ ReorderIdent.Seurat <- function( #' RenameCells.Assay <- function(object, new.names = NULL, ...) { CheckDots(...) + + if (IsSCT(assay = object)) { + if(is.null(x = Misc(object = object, slot = 'vst.set'))){ + suppressWarnings(Misc(object, slot = "vst.out")$cells_step1 <- new.names) + suppressWarnings(rownames(x = Misc(object, slot = "vst.out")$cell_attr) <- new.names) + } else{ + suppressWarnings( + Misc(object, slot = "vst.set") <- lapply(Misc(object, slot = "vst.set"), function(x) { + new.names.vst <- new.names[ which(x$cells_step1 %in% Cells(object)) ] + x$cells_step1 <- new.names.vst + (rownames(x$cell_attr) <- new.names.vst) + return(x) + } ) ) + } + } + for (data.slot in c("counts", "data", "scale.data")) { old.data <- GetAssayData(object = object, slot = data.slot) if (ncol(x = old.data) <= 1) { @@ -3843,10 +3859,10 @@ RenameCells.Assay <- function(object, new.names = NULL, ...) { } colnames(x = slot(object = object, name = data.slot)) <- new.names } - if (IsSCT(assay = object)) { - suppressWarnings(Misc(object, slot = "vst.out")$cells_step1 <- new.names) - suppressWarnings(rownames(x = Misc(object, slot = "vst.out")$cell_attr) <- new.names) - } + + + + return(object) } diff --git a/R/utilities.R b/R/utilities.R index 6b1499345..7ee32da49 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -1571,7 +1571,7 @@ IsSCT <- function(assay) { }) return(unlist(x = sct.check)) } - return(!is.null(x = Misc(assay, slot = 'vst.out'))) + return( !is.null(x = Misc(assay, slot = 'vst.out')) | !is.null(x = Misc(assay, slot = 'vst.set')) ) } # Check the length of components of a list From 0a716e8dbc4f05726a56d7d65b875f99407ec643 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Thu, 10 Oct 2019 14:44:51 -0400 Subject: [PATCH 11/83] minor formatting fixes, bump develop version --- DESCRIPTION | 4 ++-- R/objects.R | 28 +++++++++++++--------------- R/utilities.R | 2 +- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ef28f9ebb..6b8d3216c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9001 -Date: 2019-10-09 +Version: 3.1.1.9002 +Date: 2019-10-10 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( diff --git a/R/objects.R b/R/objects.R index 7f8dff99e..57239b962 100644 --- a/R/objects.R +++ b/R/objects.R @@ -3836,22 +3836,24 @@ ReorderIdent.Seurat <- function( #' RenameCells.Assay <- function(object, new.names = NULL, ...) { CheckDots(...) - if (IsSCT(assay = object)) { - if(is.null(x = Misc(object = object, slot = 'vst.set'))){ - suppressWarnings(Misc(object, slot = "vst.out")$cells_step1 <- new.names) - suppressWarnings(rownames(x = Misc(object, slot = "vst.out")$cell_attr) <- new.names) + if (is.null(x = Misc(object = object, slot = 'vst.set'))) { + suppressWarnings(Misc(object = object, slot = "vst.out")$cells_step1 <- new.names) + suppressWarnings(rownames(x = Misc(object = object, slot = "vst.out")$cell_attr) <- new.names) } else{ suppressWarnings( - Misc(object, slot = "vst.set") <- lapply(Misc(object, slot = "vst.set"), function(x) { - new.names.vst <- new.names[ which(x$cells_step1 %in% Cells(object)) ] - x$cells_step1 <- new.names.vst - (rownames(x$cell_attr) <- new.names.vst) - return(x) - } ) ) + Misc(object, slot = "vst.set") <- lapply( + X = Misc(object = object, slot = "vst.set"), + FUN = function(x) { + new.names.vst <- new.names[which(x = x$cells_step1 %in% Cells(x = object))] + x$cells_step1 <- new.names.vst + rownames(x = x$cell_attr) <- new.names.vst + return(x) + } + ) + ) } } - for (data.slot in c("counts", "data", "scale.data")) { old.data <- GetAssayData(object = object, slot = data.slot) if (ncol(x = old.data) <= 1) { @@ -3859,10 +3861,6 @@ RenameCells.Assay <- function(object, new.names = NULL, ...) { } colnames(x = slot(object = object, name = data.slot)) <- new.names } - - - - return(object) } diff --git a/R/utilities.R b/R/utilities.R index 7ee32da49..145c368c7 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -1571,7 +1571,7 @@ IsSCT <- function(assay) { }) return(unlist(x = sct.check)) } - return( !is.null(x = Misc(assay, slot = 'vst.out')) | !is.null(x = Misc(assay, slot = 'vst.set')) ) + return(!is.null(x = Misc(object = assay, slot = 'vst.out')) | !is.null(x = Misc(object = assay, slot = 'vst.set'))) } # Check the length of components of a list From 74dda50941dc875d6b28c945af864f60ae9575a9 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Mon, 14 Oct 2019 14:45:23 -0400 Subject: [PATCH 12/83] Minor style adjustments --- R/clustering.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/clustering.R b/R/clustering.R index be63a92bd..f8abd5444 100644 --- a/R/clustering.R +++ b/R/clustering.R @@ -85,9 +85,9 @@ FindClusters.default <- function( edge.file.name = edge.file.name ) } else if (algorithm == 4) { - if (method == "matrix" || method == "igraph"){ - if (method == "igraph"){ - object <- graph_from_adjacency_matrix(object) + if (method == "matrix" || method == "igraph") { + if (method == "igraph") { + object <- graph_from_adjacency_matrix(adjmatrix = object) } } else { stop("method must be 'matrix' or 'igraph'") From 316ce7766b79e0da9392a39cdacc8cd5ed1e303d Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Tue, 15 Oct 2019 12:13:40 -0400 Subject: [PATCH 13/83] Better support for Assay subclasses --- R/objects.R | 146 ++++++++++++++++++++++++++-------------------------- 1 file changed, 72 insertions(+), 74 deletions(-) diff --git a/R/objects.R b/R/objects.R index 57239b962..2ef48e113 100644 --- a/R/objects.R +++ b/R/objects.R @@ -890,38 +890,36 @@ FetchData <- function(object, vars, cells = NULL, slot = 'data') { FUN = function(x) { vars.use <- vars[keyed.vars[[x]]] key.use <- object.keys[x] - data.return <- switch( - EXPR = class(x = object[[x]]), - 'DimReduc' = { - vars.use <- grep( - pattern = paste0('^', key.use, '[[:digit:]]+$'), - x = vars.use, - value = TRUE - ) - if (length(x = vars.use) > 0) { - tryCatch( - expr = object[[x]][[cells, vars.use, drop = FALSE]], - error = function(e) NULL - ) - } else { - NULL - } - }, - 'Assay' = { - vars.use <- gsub(pattern = paste0('^', key.use), replacement = '', x = vars.use) - data.assay <- GetAssayData( - object = object, - slot = slot, - assay = x + data.return <- if (inherits(x = object[[x]], what = 'DimReduc')) { + vars.use <- grep( + pattern = paste0('^', key.use, '[[:digit:]]+$'), + x = vars.use, + value = TRUE + ) + if (length(x = vars.use) > 0) { + tryCatch( + expr = object[[x]][[cells, vars.use, drop = FALSE]], + error = function(...) { + return(NULL) + } ) - vars.use <- vars.use[vars.use %in% rownames(x = data.assay)] - data.vars <- t(x = as.matrix(data.assay[vars.use, cells, drop = FALSE])) - if (ncol(data.vars) > 0) { - colnames(x = data.vars) <- paste0(key.use, vars.use) - } - data.vars + } else { + NULL } - ) + } else if (inherits(x = object[[x]], what = 'Assay')) { + vars.use <- gsub(pattern = paste0('^', key.use), replacement = '', x = vars.use) + data.assay <- GetAssayData( + object = object, + slot = slot, + assay = x + ) + vars.use <- vars.use[vars.use %in% rownames(x = data.assay)] + data.vars <- t(x = as.matrix(data.assay[vars.use, cells, drop = FALSE])) + if (ncol(data.vars) > 0) { + colnames(x = data.vars) <- paste0(key.use, vars.use) + } + data.vars + } data.return <- as.list(x = as.data.frame(x = data.return)) return(data.return) } @@ -3843,8 +3841,8 @@ RenameCells.Assay <- function(object, new.names = NULL, ...) { } else{ suppressWarnings( Misc(object, slot = "vst.set") <- lapply( - X = Misc(object = object, slot = "vst.set"), - FUN = function(x) { + X = Misc(object = object, slot = "vst.set"), + FUN = function(x) { new.names.vst <- new.names[which(x = x$cells_step1 %in% Cells(x = object))] x$cells_step1 <- new.names.vst rownames(x = x$cell_attr) <- new.names.vst @@ -5952,49 +5950,49 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes } } # Figure out where to store data - slot.use <- switch( - EXPR = as.character(x = class(x = value))[1], - 'Assay' = { - # Ensure we have the same number of cells - if (ncol(x = value) != ncol(x = x)) { - stop( - "Cannot add a different number of cells than already present", - call. = FALSE - ) - } - # Ensure cell order stays the same - if (all(Cells(x = value) %in% Cells(x = x)) && !all(Cells(x = value) == Cells(x = x))) { - for (slot in c('counts', 'data', 'scale.data')) { - assay.data <- GetAssayData(object = value, slot = slot) - if (!IsMatrixEmpty(x = assay.data)) { - assay.data <- assay.data[, Cells(x = x), drop = FALSE] - } - # Use slot because SetAssayData is being weird - slot(object = value, name = slot) <- assay.data + slot.use <- if (inherits(x = value, what = 'Assay')) { + # Ensure we have the same number of cells + if (ncol(x = value) != ncol(x = x)) { + stop( + "Cannot add a different number of cells than already present", + call. = FALSE + ) + } + # Ensure cell order stays the same + if (all(Cells(x = value) %in% Cells(x = x)) && !all(Cells(x = value) == Cells(x = x))) { + for (slot in c('counts', 'data', 'scale.data')) { + assay.data <- GetAssayData(object = value, slot = slot) + if (!IsMatrixEmpty(x = assay.data)) { + assay.data <- assay.data[, Cells(x = x), drop = FALSE] } + # Use slot because SetAssayData is being weird + slot(object = value, name = slot) <- assay.data } - 'assays' - }, - 'Graph' = 'graphs', - 'DimReduc' = { - # All DimReducs must be associated with an Assay - if (is.null(x = DefaultAssay(object = value))) { - stop("Cannot add a DimReduc without an assay associated with it", call. = FALSE) - } - # Ensure Assay that DimReduc is associated with is present in the Seurat object - if (!DefaultAssay(object = value) %in% FilterObjects(object = x, classes.keep = 'Assay')) { - stop("Cannot find assay '", DefaultAssay(object = value), "' in this Seurat object", call. = FALSE) - } - # Ensure DimReduc object is in order - if (all(Cells(x = value) %in% Cells(x = x)) && !all(Cells(x = value) == Cells(x = x))) { - slot(object = value, name = 'cell.embeddings') <- value[[Cells(x = x), ]] - } - 'reductions' - }, - 'SeuratCommand' = 'commands', - 'NULL' = slot.use, + } + 'assays' + } else if (inherits(x = value, what = 'Graph')) { + 'graphs' + } else if (inherits(x = value, what = 'DimReduc')) { + # All DimReducs must be associated with an Assay + if (is.null(x = DefaultAssay(object = value))) { + stop("Cannot add a DimReduc without an assay associated with it", call. = FALSE) + } + # Ensure Assay that DimReduc is associated with is present in the Seurat object + if (!DefaultAssay(object = value) %in% FilterObjects(object = x, classes.keep = 'Assay')) { + stop("Cannot find assay '", DefaultAssay(object = value), "' in this Seurat object", call. = FALSE) + } + # Ensure DimReduc object is in order + if (all(Cells(x = value) %in% Cells(x = x)) && !all(Cells(x = value) == Cells(x = x))) { + slot(object = value, name = 'cell.embeddings') <- value[[Cells(x = x), ]] + } + 'reductions' + } else if (inherits(x = value, what = 'SeuratCommand')) { + 'commands' + } else if (is.null(x = value)) { + slot.use + } else { 'meta.data' - ) + } if (slot.use == 'meta.data') { # Add data to object metadata meta.data <- x[[]] @@ -6541,10 +6539,10 @@ FilterObjects <- function(object, classes.keep = c('Assay', 'DimReduc')) { object.classes <- sapply( X = slots.objects, FUN = function(i) { - return(class(x = object[[i]])) + return(inherits(x = object[[i]], what = classes.keep)) } ) - object.classes <- object.classes[object.classes %in% classes.keep] + object.classes <- which(x = object.classes, useNames = TRUE) return(names(x = object.classes)) } From 0c0706470c53cbba7b51eac5a46fb262fa05605e Mon Sep 17 00:00:00 2001 From: TomKellyGenetics Date: Wed, 16 Oct 2019 17:56:18 +0900 Subject: [PATCH 14/83] resolve implementing methods for Leiden satijilab#2169 satijialab#1645 --- R/clustering.R | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/R/clustering.R b/R/clustering.R index be63a92bd..2ea7a9c53 100644 --- a/R/clustering.R +++ b/R/clustering.R @@ -13,9 +13,6 @@ NULL #' @importFrom pbapply pblapply #' @importFrom future.apply future_lapply #' @importFrom future nbrOfWorkers -#' @importFrom igraph graph_from_adjacency_matrix -#' @importFrom methods as -#' @importClassesFrom Matrix dgCMatrix #' #' @param modularity.fxn Modularity function (1 = standard; 2 = alternative). #' @param initial.membership,weights,node.sizes Parameters to pass to the Python leidenalg function. @@ -85,13 +82,6 @@ FindClusters.default <- function( edge.file.name = edge.file.name ) } else if (algorithm == 4) { - if (method == "matrix" || method == "igraph"){ - if (method == "igraph"){ - object <- graph_from_adjacency_matrix(object) - } - } else { - stop("method must be 'matrix' or 'igraph'") - } ids <- RunLeiden( object = object, method = method, @@ -717,23 +707,25 @@ RunLeiden <- function( if (!py_module_available(module = 'leidenalg')) { stop("Cannot find Leiden algorithm, please install through pip (e.g. pip install leidenalg).") } - switch( - EXPR = method, - #cast to dense (supported by reticulate for numpy.array) - "matrix" = input <- as(object, "matrix"), - #run as igraph object (passes to reticulate) - "igraph" = switch( - EXPR = is(object)[1], - #generate igraph if needed (will handle updated snn class) - "Graph" = input <- graph_from_adjacency_matrix(adjmatrix = object), - "dgCMatrix" = input <- graph_from_adjacency_matrix(adjmatrix = object), - "igraph" = input <- object, - "matrix" = input <- graph_from_adjacency_matrix(adjmatrix = object), - "list" = input <- graph_from_adj_list(adjlist = object), - stop("SNN object must be a compatible input for igraph") - ), - stop("method for leiden must be 'matrix' or 'igraph'") - ) + + if (method %in% c("matrix", "igraph")){ + if (method == "igraph"){ + object <- graph_from_adjacency_matrix(object) + } + } else { + warning("method for Leiden recommended as 'matrix' or 'igraph'") + } + + input <- if (inherits(x = object, what = 'list')) { + graph_from_adj_list(adjlist = object) + } else if (inherits(x = object, what = c('dgCMatrix', 'matrix', "Matrix"))) { + graph_from_adjacency_matrix(adjmatrix = object) + } else if (inherits(x = object, what = 'igraph')) { + object + } else { + stop(paste("method for Leiden not found for class", class(object))) + } + #run leiden from CRAN package (calls python with reticulate) partition <- leiden( object = input, From d75df3e446ef02b2f3a3c06ffe5f2aa6ed435add Mon Sep 17 00:00:00 2001 From: Tim Stuart <4591688+timoast@users.noreply.github.com> Date: Fri, 18 Oct 2019 16:21:07 -0400 Subject: [PATCH 15/83] Update ExpMean and LogVMR Now applies over matrix rows if matrix supplied, or over single vector. Also added the dots parameter to allow passing additional arguments that are used in other functions, which is needed when used in FindVariableFeatures. Addresses #2189 --- R/utilities.R | 18 ++++++++++++++---- man/ExpMean.Rd | 4 +++- man/LogVMR.Rd | 4 +++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/R/utilities.R b/R/utilities.R index 145c368c7..b776fd30d 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -560,6 +560,7 @@ CustomDistance <- function(my.mat, my.function, ...) { #' Calculate mean of logged values in non-log space (return answer in log-space) #' #' @param x A vector of values +#' @param ... Other arguments (not used) #' #' @return Returns the mean in log-space #' @@ -568,8 +569,12 @@ CustomDistance <- function(my.mat, my.function, ...) { #' @examples #' ExpMean(x = c(1, 2, 3)) #' -ExpMean <- function(x) { - return(log(x = mean(x = exp(x = x) - 1) + 1)) +ExpMean <- function(x, ...) { + if (inherits(x = x, what = 'AnyMatrix')) { + return(apply(X = x, FUN = function(i) {log(x = mean(x = exp(x = i) - 1) + 1)}, MARGIN = 1)) + } else { + return(log(x = mean(x = exp(x = x) - 1) + 1)) + } } #' Export Seurat object for UCSC cell browser @@ -976,6 +981,7 @@ GeneSymbolThesarus <- function( #' log-space) #' #' @param x A vector of values +#' @param ... Other arguments (not used) #' #' @return Returns the VMR in log-space #' @@ -986,8 +992,12 @@ GeneSymbolThesarus <- function( #' @examples #' LogVMR(x = c(1, 2, 3)) #' -LogVMR <- function(x) { - return(log(x = var(x = exp(x = x) - 1) / mean(x = exp(x = x) - 1))) +LogVMR <- function(x, ...) { + if (inherits(x = x, what = 'AnyMatrix')) { + return(apply(X = x, FUN = function(i) {log(x = var(x = exp(x = i) - 1) / mean(x = exp(x = i) - 1))}, MARGIN = 1)) + } else { + return(log(x = var(x = exp(x = x) - 1) / mean(x = exp(x = x) - 1))) + } } #' Aggregate expression of multiple features into a single feature diff --git a/man/ExpMean.Rd b/man/ExpMean.Rd index 48ba2683c..6e0896df4 100644 --- a/man/ExpMean.Rd +++ b/man/ExpMean.Rd @@ -4,10 +4,12 @@ \alias{ExpMean} \title{Calculate the mean of logged values} \usage{ -ExpMean(x) +ExpMean(x, ...) } \arguments{ \item{x}{A vector of values} + +\item{...}{Other arguments (not used)} } \value{ Returns the mean in log-space diff --git a/man/LogVMR.Rd b/man/LogVMR.Rd index 210132c05..53d6998c6 100644 --- a/man/LogVMR.Rd +++ b/man/LogVMR.Rd @@ -4,10 +4,12 @@ \alias{LogVMR} \title{Calculate the variance to mean ratio of logged values} \usage{ -LogVMR(x) +LogVMR(x, ...) } \arguments{ \item{x}{A vector of values} + +\item{...}{Other arguments (not used)} } \value{ Returns the VMR in log-space From 85b417430609adc812eeda91cdff693db39864b7 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Tue, 22 Oct 2019 11:28:43 -0400 Subject: [PATCH 16/83] bump develop version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6b8d3216c..1d53591ea 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9002 -Date: 2019-10-10 +Version: 3.1.1.9003 +Date: 2019-10-22 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( From 9cf5aaa48c0dcca6335dc6d890c20f43f751c06f Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Tue, 22 Oct 2019 15:37:01 -0400 Subject: [PATCH 17/83] bump develop version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1d53591ea..2a8d3a6f7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: Seurat -Version: 3.1.1.9003 +Version: 3.1.1.9004 Date: 2019-10-22 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. From 12516d30492aa4fdaa7357d2cb914df1025a4e96 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Thu, 24 Oct 2019 15:17:25 -0400 Subject: [PATCH 18/83] Allow updating and populating of vector slots Simpler handling of unpopulated slots in getter functions Add IsGlobal for DimReduc objects --- R/generics.R | 25 +++++++++++++++++---- R/objects.R | 63 +++++++++++++++++++++++++++------------------------- 2 files changed, 54 insertions(+), 34 deletions(-) diff --git a/R/generics.R b/R/generics.R index 58f18c98f..639b908d0 100644 --- a/R/generics.R +++ b/R/generics.R @@ -413,6 +413,23 @@ Idents <- function(object, ... ) { UseMethod(generic = 'Idents<-', object = object) } +#' Is an object global or persistent? +#' +#' @param object An object +#' @param ... Arguments passed to other methods +#' +#' @return \code{TRUE} if the object is global or persistent otherwise \code{FALSE} +#' +#' @rdname IsGlobal +#' @export IsGlobal +#' +#' @examples +#' IsGlobal(pbmc_small[['pca']]) +#' +IsGlobal <- function(object, ...) { + UseMethod(generic = 'IsGlobal', object = object) +} + #' Get JackStraw information #' #' @param object An object @@ -784,9 +801,9 @@ RunICA <- function(object, ...) { #' #' For details about stored LSI calculation parameters, see #' \code{PrintLSIParams}. -#' -#' @note RunLSI is being moved to Signac. Equivalent functionality can be -#' achieved via the Signac::RunTFIDF and Signac::RunSVD functions; +#' +#' @note RunLSI is being moved to Signac. Equivalent functionality can be +#' achieved via the Signac::RunTFIDF and Signac::RunSVD functions; #' for more information on Signac, please see #' \url{https://github.com/timoast/Signac} #' @@ -800,7 +817,7 @@ RunLSI <- function(object, ...) { .Deprecated( new = 'Signac::RunTFIDF', msg = paste( - "RunLSI is being moved to Signac. Equivalent functionality can be", + "RunLSI is being moved to Signac. Equivalent functionality can be", "achieved via the Signac::RunTFIDF and Signac::RunSVD functions; for", "more information on Signac, please see https://github.com/timoast/Signac" ) diff --git a/R/objects.R b/R/objects.R index bf0aa8d32..1013bd69f 100644 --- a/R/objects.R +++ b/R/objects.R @@ -13,7 +13,8 @@ NULL #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% setOldClass(Classes = 'package_version') -setClassUnion(name = 'AnyMatrix', c("matrix", "dgCMatrix")) +setClassUnion(name = 'AnyMatrix', members = c("matrix", "dgCMatrix")) +setClassUnion(name = 'OptionalCharacter', members = c('NULL', 'character')) #' The AnchorSet Class #' @@ -77,7 +78,7 @@ Assay <- setClass( data = 'AnyMatrix', scale.data = 'matrix', key = 'character', - assay.orig = 'character', + assay.orig = 'OptionalCharacter', var.features = 'vector', meta.features = 'data.frame', misc = 'ANY' @@ -156,7 +157,7 @@ Graph <- setClass( Class = 'Graph', contains = "dgCMatrix", slots = list( - assay.used = 'character' + assay.used = 'OptionalCharacter' ) ) @@ -208,7 +209,7 @@ SeuratCommand <- setClass( slots = c( name = 'character', time.stamp = 'POSIXct', - assay.used = 'character', + assay.used = 'OptionalCharacter', call.string = 'character', params = 'ANY' ) @@ -2544,12 +2545,8 @@ Command.Seurat <- function(object, command = NULL, value = NULL, ...) { #' @method DefaultAssay Assay #' DefaultAssay.Assay <- function(object, ...) { - return(tryCatch( - expr = slot(object = object, name = 'assay.orig'), - error = function(...) { - return(character(length = 0L)) - } - )) + object <- UpdateSlots(object = object) + return(slot(object = object, name = 'assay.orig')) } #' @rdname DefaultAssay @@ -2566,12 +2563,8 @@ DefaultAssay.DimReduc <- function(object, ...) { #' @method DefaultAssay Graph #' DefaultAssay.Graph <- function(object, ...) { - return(tryCatch( - expr = slot(object = object, name = 'assay.used'), - error = function(...) { - return(character(length = 0L)) - } - )) + object <- UpdateSlots(object = object) + return(slot(object = object, name = 'assay.used')) } #' @rdname DefaultAssay @@ -2592,18 +2585,16 @@ DefaultAssay.Seurat <- function(object, ...) { #' @method DefaultAssay SeuratCommand #' DefaultAssay.SeuratCommand <- function(object, ...) { - return(tryCatch( - expr = slot(object = object, name = 'assay.used'), - error = function(...) { - return(character(length = 0L)) - } - )) + object <- UpdateSlots(object = object) + return(slot(object = object, name = 'assay.used')) } #' @export #' @method DefaultAssay<- Assay #' "DefaultAssay<-.Assay" <- function(object, ..., value) { + object <- UpdateSlots(object = object) + return(slot(object = object, name = 'assay.used')) object <- UpdateSlots(object = object) slot(object = object, name = 'assay.orig') <- value return(object) @@ -2905,6 +2896,15 @@ Idents.Seurat <- function(object, ...) { return(object) } +#' @rdname IsGlobal +#' @export +#' @method IsGlobal DimReduc +#' +IsGlobal.DimReduc <- function(object, ...) { + object <- UpdateSlots(object = object) + return(slot(object = object, name = 'global')) +} + #' @param slot Name of slot to store JackStraw scores to #' Can shorten to 'empirical', 'fake', 'full', or 'overall' #' @@ -5314,16 +5314,12 @@ as.list.SeuratCommand <- function(x, complete = FALSE, ...) { return(cmd) } +#' @rdname IsGlobal #' @export #' @method as.logical DimReduc #' as.logical.DimReduc <- function(x, ...) { - return(tryCatch( - expr = slot(object = x, name = 'global'), - error = function(...) { - return(FALSE) - } - )) + return(IsGlobal(object = x)) } #' @export @@ -6730,7 +6726,7 @@ UpdateAssay <- function(old.assay, assay){ # @param old.dr Seurat2 dimension reduction slot # @param assay.used Name of assay used to compute dimension reduction # -UpdateDimReduction <- function(old.dr, assay){ +UpdateDimReduction <- function(old.dr, assay) { new.dr <- list() for (i in names(x = old.dr)) { cell.embeddings <- old.dr[[i]]@cell.embeddings %||% new(Class = 'matrix') @@ -6853,7 +6849,14 @@ UpdateSlots <- function(object) { ) object.list <- Filter(f = Negate(f = is.null), x = object.list) object.list <- c('Class' = class(x = object)[1], object.list) - return(do.call(what = 'new', args = object.list)) + object <- do.call(what = 'new', args = object.list) + for (x in slotNames(x = object)) { + xobj <- slot(object = object, name = x) + if (is.vector(x = xobj) && !is.list(x = xobj) && length(x = xobj) == 0) { + slot(object = object, name = x) <- vector(mode = class(x = xobj), length = 1L) + } + } + return(object) } # Pulls the proper data matrix for merging assay data. If the slot is empty, will return an empty From d5e5f333584985f14e0821a8d9920b214e3f544b Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Thu, 24 Oct 2019 15:24:36 -0400 Subject: [PATCH 19/83] Fix failing tests --- R/objects.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/objects.R b/R/objects.R index 1013bd69f..970c2e332 100644 --- a/R/objects.R +++ b/R/objects.R @@ -3043,6 +3043,7 @@ Key.Seurat <- function(object, ...) { #' "Key<-.DimReduc" <- function(object, ..., value) { CheckDots(...) + object <- UpdateSlots(object = object) old.key <- Key(object = object) slots <- Filter( f = function(x) { From 9ec7eb6b08c2488120fe61cb380767900d39cad4 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Thu, 24 Oct 2019 15:25:33 -0400 Subject: [PATCH 20/83] Add docs for IsGlobal --- NAMESPACE | 2 ++ man/IsGlobal.Rd | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 man/IsGlobal.Rd diff --git a/NAMESPACE b/NAMESPACE index 29f9453fb..b03f83d16 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -60,6 +60,7 @@ S3method(GetAssayData,Seurat) S3method(HVFInfo,Assay) S3method(HVFInfo,Seurat) S3method(Idents,Seurat) +S3method(IsGlobal,DimReduc) S3method(JS,DimReduc) S3method(JS,JackStrawData) S3method(Key,Assay) @@ -229,6 +230,7 @@ export(HVFInfo) export(HoverLocator) export(Idents) export(IntegrateData) +export(IsGlobal) export(JS) export(JackStraw) export(JackStrawPlot) diff --git a/man/IsGlobal.Rd b/man/IsGlobal.Rd new file mode 100644 index 000000000..5ec848dcb --- /dev/null +++ b/man/IsGlobal.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/generics.R, R/objects.R +\name{IsGlobal} +\alias{IsGlobal} +\alias{IsGlobal.DimReduc} +\alias{as.logical.DimReduc} +\title{Is an object global or persistent?} +\usage{ +IsGlobal(object, ...) + +\method{IsGlobal}{DimReduc}(object, ...) + +\method{as.logical}{DimReduc}(x, ...) +} +\arguments{ +\item{object}{An object} + +\item{...}{Arguments passed to other methods} +} +\value{ +\code{TRUE} if the object is global or persistent otherwise \code{FALSE} +} +\description{ +Is an object global or persistent? +} +\examples{ +IsGlobal(pbmc_small[['pca']]) + +} From 5537458cf4f235f1d8d655c4a8e5f1e73b286bd0 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Thu, 24 Oct 2019 17:15:42 -0400 Subject: [PATCH 21/83] Update UpdateSeuratObject to handle new slots and fill with sensible defaults --- R/objects.R | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/R/objects.R b/R/objects.R index 970c2e332..5662aeb73 100644 --- a/R/objects.R +++ b/R/objects.R @@ -1454,9 +1454,53 @@ UpdateSeuratObject <- function(object) { } object[[reduc.name]] <- reduc } - message("Object representation is consistent with the most current Seurat version") - return(object) } + if (package_version(x = slot(object = object, name = 'version')) <= package_version(x = '3.1.1')) { + # Update Assays, DimReducs, and Graphs + for (x in names(x = object)) { + message("Updating slots in ", x) + xobj <- object[[x]] + xobj <- UpdateSlots(object = xobj) + if (inherits(x = xobj, what = 'DimReduc')) { + if (any(sapply(X = c('tsne', 'umap'), FUN = grepl, x = tolower(x = x)))) { + message("Setting ", x, " DimReduc to global") + slot(object = xobj, name = 'global') <- TRUE + } + } else if (inherits(x = xobj, what = 'Graph')) { + graph.assay <- unlist(x = strsplit(x = x, split = '_'))[1] + if (graph.assay %in% Assays(object = object)) { + message("Setting default assay of ", x, " to ", graph.assay) + DefaultAssay(object = xobj) <- graph.assay + } + } + object[[x]] <- xobj + } + # Update SeuratCommands + for (cmd in Command(object = object)) { + cobj <- Command(object = object, command = cmd) + cobj <- UpdateSlots(object = cobj) + cmd.assay <- unlist(x = strsplit(x = cmd, split = '\\.')) + cmd.assay <- cmd.assay[length(x = cmd.assay)] + cmd.assay <- if (cmd.assay %in% Assays(object = object)) { + cmd.assay + } else if (cmd.assay %in% Reductions(object = object)) { + DefaultAssay(object = object[[cmd.assay]]) + } else { + NULL + } + if (is.null(x = cmd.assay)) { + message("No assay information could be found for ", cmd) + } else { + message("Setting assay used for ", cmd, " to ", cmd.assay) + } + slot(object = cobj, name = 'assay.used') <- cmd.assay + object[[cmd]] <- cobj + } + # Update object version + slot(object = object, name = 'version') <- packageVersion(pkg = 'Seurat') + } + message("Object representation is consistent with the most current Seurat version") + return(object) } stop( "We are unable to convert Seurat objects less than version 2.X to version 3.X\n", From f614ef349f7e84d16bbd3ae436ab3fc9772e6d8a Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Thu, 24 Oct 2019 19:02:42 -0400 Subject: [PATCH 22/83] Add assay information to logged commands When removing an assay, removed associated Graphs, DimReducs, and SeuratCommands Preliminary support for multi-assay graphs and dimreducs --- R/objects.R | 70 +++++++++++++++++---- tests/testthat/test_dimensional_reduction.R | 38 +++++++---- 2 files changed, 82 insertions(+), 26 deletions(-) diff --git a/R/objects.R b/R/objects.R index 5662aeb73..e827c4684 100644 --- a/R/objects.R +++ b/R/objects.R @@ -1134,8 +1134,14 @@ LogSeuratCommand <- function(object, return.command = FALSE) { # check if function works on the Assay and/or the DimReduc Level assay <- params[["assay"]] reduction <- params[["reduction"]] - if (class(x = reduction) == 'DimReduc') { - reduction = 'DimReduc' + # Get assay used for command + cmd.assay <- assay %||% (reduction %iff% if (inherits(x = reduction, what = 'DimReduc')) { + DefaultAssay(object = reduction) + } else if (reduction %in% Reductions(object = object)) { + DefaultAssay(object = object[[reduction]]) + }) + if (inherits(x = reduction, what = 'DimReduc')) { + reduction <- 'DimReduc' } # rename function name to include Assay/DimReduc info if (length(x = assay) == 1) { @@ -1149,7 +1155,8 @@ LogSeuratCommand <- function(object, return.command = FALSE) { name = command.name, params = params, time.stamp = time.stamp, - call.string = call.string + call.string = call.string, + assay.used = cmd.assay ) if (return.command) { return(seurat.command) @@ -1380,7 +1387,7 @@ UpdateSeuratObject <- function(object) { # Update object slots message("Updating object slots") for (obj in FilterObjects(object = object, classes.keep = c('Assay', 'DimReduc', 'Graph'))) { - object[[obj]] <- UpdateSlots(object = object[[obj]]) + suppressWarnings(expr = object[[obj]] <- UpdateSlots(object = object[[obj]])) } for (cmd in Command(object = object)) { slot(object = object, name = 'commands')[[cmd]] <- UpdateSlots( @@ -2940,6 +2947,14 @@ Idents.Seurat <- function(object, ...) { return(object) } +#' @rdname IsGlobal +#' @export +#' @method IsGlobal default +#' +IsGlobal.default <- function(object, ...) { + return(FALSE) +} + #' @rdname IsGlobal #' @export #' @method IsGlobal DimReduc @@ -6100,6 +6115,20 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes } 'assays' } else if (inherits(x = value, what = 'Graph')) { + # Ensure Assay that Graph is associated with is present in the Seurat object + if (is.null(x = DefaultAssay(object = value))) { + warning( + "Adding a Graph without an assay associated with it", + call. = FALSE, + immediate. = TRUE + ) + } else if (!any(DefaultAssay(object = value) %in% Assays(object = x))) { + stop("Cannot find assay '", DefaultAssay(object = value), "' in this Seurat object", call. = FALSE) + } + # Ensure Graph object is in order + if (all(Cells(x = value) %in% Cells(x = x)) && !all(Cells(x = value) == Cells(x = x))) { + value <- value[Cells(x = x), Cells(x = x)] + } 'graphs' } else if (inherits(x = value, what = 'DimReduc')) { # All DimReducs must be associated with an Assay @@ -6107,7 +6136,9 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes stop("Cannot add a DimReduc without an assay associated with it", call. = FALSE) } # Ensure Assay that DimReduc is associated with is present in the Seurat object - if (!DefaultAssay(object = value) %in% FilterObjects(object = x, classes.keep = 'Assay')) { + if (IsGlobal(object = value)) { + message("Adding global dimensional reduction information") + } else if (!any(DefaultAssay(object = value) %in% Assays(object = x))) { stop("Cannot find assay '", DefaultAssay(object = value), "' in this Seurat object", call. = FALSE) } # Ensure DimReduc object is in order @@ -6116,6 +6147,16 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes } 'reductions' } else if (inherits(x = value, what = 'SeuratCommand')) { + # Ensure Assay that SeuratCommand is associated with is present in the Seurat object + if (is.null(x = DefaultAssay(object = value))) { + warning( + "Adding a command log without an assay associated with it", + call. = FALSE, + immediate. = TRUE + ) + } else if (!any(DefaultAssay(object = value) %in% Assays(object = x))) { + stop("Cannot find assay '", DefaultAssay(object = value), "' in this Seurat object", call. = FALSE) + } 'commands' } else if (is.null(x = value)) { slot.use @@ -6245,17 +6286,20 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes x[[names(x = n.calc)]] <- n.calc } } - # When removing an Assay, clear out associated DimReducs + # When removing an Assay, clear out associated DimReducs, Graphs, and SeuratCommands if (is.null(x = value) && inherits(x = x[[i]], what = 'Assay')) { - reducs.assay <- FilterObjects(object = x, classes.keep = 'DimReduc') - reducs.assay <- Filter( - f = function(dr) { - return(DefaultAssay(object = x[[dr]]) == i) + objs.assay <- FilterObjects( + object = x, + classes.keep = c('DimReduc', 'SeuratCommand', 'Graph') + ) + objs.assay <- Filter( + f = function(o) { + return(all(DefaultAssay(object = x[[o]]) == i) && !IsGlobal(object = x[[o]])) }, - x = reducs.assay + x = objs.assay ) - for (dr in reducs.assay) { - x[[dr]] <- NULL + for (o in objs.assay) { + x[[o]] <- NULL } } # If adding a command, ensure it gets put at the end of the command list diff --git a/tests/testthat/test_dimensional_reduction.R b/tests/testthat/test_dimensional_reduction.R index 0df845568..9fadd6ea6 100644 --- a/tests/testthat/test_dimensional_reduction.R +++ b/tests/testthat/test_dimensional_reduction.R @@ -3,30 +3,38 @@ context("test-dimensional_reduction") test_that("different ways of passing distance matrix", { # Generate dummy data exp matrix set.seed(1) - dummyexpMat <- matrix(data = sample(x = c(1:50), size = 1e4, replace = TRUE), + dummyexpMat <- matrix(data = sample(x = c(1:50), size = 1e4, replace = TRUE), ncol = 100, nrow = 100) colnames(dummyexpMat) <- paste0("cell", seq(ncol(dummyexpMat))) row.names(dummyexpMat) <- paste0("gene", seq(nrow(dummyexpMat))) - + # Create Seurat object for testing obj <- CreateSeuratObject(counts = dummyexpMat) - + # Manually make a distance object to test distMat <- dist(t(dummyexpMat)) - - expect_equivalent(RunTSNE(obj, distance.matrix = distMat), - RunTSNE(obj, distance.matrix = as.matrix(distMat))) - expect_equivalent(RunTSNE(obj, distance.matrix = distMat)@reductions$tsne, - RunTSNE(distMat, assay = "RNA")) - expect_equivalent(RunTSNE(obj, distance.matrix = distMat)@reductions$tsne, - RunTSNE(as.matrix(distMat), assay = "RNA", is_distance = TRUE)) + + expect_equivalent( + suppressWarnings(expr = RunTSNE(obj, distance.matrix = distMat)), + suppressWarnings(expr = RunTSNE(obj, distance.matrix = as.matrix(distMat))) + ) + expect_equivalent( + suppressWarnings(expr = RunTSNE(obj, distance.matrix = distMat)@reductions$tsne), + suppressWarnings(expr = RunTSNE(distMat, assay = "RNA")) + ) + expect_equivalent( + suppressWarnings(expr = RunTSNE(obj, distance.matrix = distMat)@reductions$tsne), + suppressWarnings(expr = RunTSNE(as.matrix(distMat), assay = "RNA", is_distance = TRUE)) + ) }) test_that("pca returns total variance (see #982)", { # Generate dummy data exp matrix set.seed(seed = 1) - dummyexpMat <- matrix(data = sample(x = c(1:50), size = 1e4, replace = TRUE), - ncol = 100, nrow = 100) + dummyexpMat <- matrix( + data = sample(x = c(1:50), size = 1e4, replace = TRUE), + ncol = 100, nrow = 100 + ) colnames(x = dummyexpMat) <- paste0("cell", seq(ncol(x = dummyexpMat))) row.names(x = dummyexpMat) <- paste0("gene", seq(nrow(x = dummyexpMat))) @@ -35,7 +43,11 @@ test_that("pca returns total variance (see #982)", { # Scale and compute PCA, using RunPCA obj <- ScaleData(object = obj, verbose = FALSE) - pca_result <- suppressWarnings(expr = RunPCA(object = obj, features = rownames(x = obj), verbose = FALSE)) + pca_result <- suppressWarnings(expr = RunPCA( + object = obj, + features = rownames(x = obj), + verbose = FALSE + )) # Using stats::prcomp scaled_data <- Seurat::GetAssayData(object = obj, slot = "scale.data") From d435c98da1332912af0b176ffd70d47bbafd2492 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Thu, 24 Oct 2019 19:04:44 -0400 Subject: [PATCH 23/83] FindNeighbors: use assay of DimReduc as default assay FindClusters: use assay of Graph as default assay --- R/clustering.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/clustering.R b/R/clustering.R index 40560795e..cd34d6ed7 100644 --- a/R/clustering.R +++ b/R/clustering.R @@ -208,7 +208,9 @@ FindClusters.Seurat <- function( ) Idents(object = object) <- factor(x = Idents(object = object), levels = sort(x = levels)) object[['seurat_clusters']] <- Idents(object = object) - object <- LogSeuratCommand(object) + cmd <- LogSeuratCommand(object = object, return.command = TRUE) + slot(object = cmd, name = 'assay.used') <- DefaultAssay(object = object[[graph.name]]) + object[[slot(object = cmd, name = 'name')]] <- cmd return(object) } @@ -419,7 +421,8 @@ FindNeighbors.Seurat <- function( ) { CheckDots(...) if (!is.null(x = dims)) { - assay <- assay %||% DefaultAssay(object = object) + # assay <- assay %||% DefaultAssay(object = object) + assay <- DefaultAssay(object = object[[reduction]]) data.use <- Embeddings(object = object[[reduction]]) if (max(dims) > ncol(x = data.use)) { stop("More dimensions specified in dims than have been computed") @@ -456,6 +459,7 @@ FindNeighbors.Seurat <- function( } graph.name <- graph.name %||% paste0(assay, "_", names(x = neighbor.graphs)) for (ii in 1:length(x = graph.name)) { + DefaultAssay(object = neighbor.graphs[[ii]]) <- assay object[[graph.name[[ii]]]] <- neighbor.graphs[[ii]] } if (do.plot) { From 3ea5b0332c570e1bcb2ab44f4cb131075788b4ba Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Thu, 24 Oct 2019 19:06:11 -0400 Subject: [PATCH 24/83] Set UMAP and tSNE as global DimReducs --- R/dimensional_reduction.R | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/R/dimensional_reduction.R b/R/dimensional_reduction.R index 657822ed9..4f1ecdff4 100644 --- a/R/dimensional_reduction.R +++ b/R/dimensional_reduction.R @@ -1000,7 +1000,8 @@ RunTSNE.matrix <- function( tsne.reduction <- CreateDimReducObject( embeddings = tsne.data, key = reduction.key, - assay = assay + assay = assay, + global = TRUE ) return(tsne.reduction) } @@ -1247,7 +1248,8 @@ RunUMAP.default <- function( umap.reduction <- CreateDimReducObject( embeddings = umap.output, key = reduction.key, - assay = assay + assay = assay, + global = TRUE ) return(umap.reduction) } @@ -1331,7 +1333,12 @@ RunUMAP.Graph <- function( colnames(x = embeddings) <- paste0("UMAP_", 1:n.components) # center the embeddings on zero embeddings <- scale(x = embeddings, scale = FALSE) - umap <- CreateDimReducObject(embeddings = embeddings, key = reduction.key, assay = assay) + umap <- CreateDimReducObject( + embeddings = embeddings, + key = reduction.key, + assay = assay, + global = TRUE + ) return(umap) } From 2877837f29668c224ca454f060cf610fa2c7615b Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Fri, 25 Oct 2019 15:38:44 -0400 Subject: [PATCH 25/83] fix issue when meta.data column name was also a feature name --- R/objects.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/objects.R b/R/objects.R index 2ef48e113..b95576e9f 100644 --- a/R/objects.R +++ b/R/objects.R @@ -926,10 +926,10 @@ FetchData <- function(object, vars, cells = NULL, slot = 'data') { ) data.fetched <- unlist(x = data.fetched, recursive = FALSE) # Pull vars from object metadata - meta.vars <- vars[vars %in% colnames(x = object[[]])] + meta.vars <- vars[vars %in% colnames(x = object[[]]) & ! vars %in% names(x = data.fetched)] data.fetched <- c(data.fetched, object[[meta.vars]][cells, , drop = FALSE]) # Pull vars from the default assay - default.vars <- vars[vars %in% rownames(x = GetAssayData(object = object, slot = slot))] + default.vars <- vars[vars %in% rownames(x = GetAssayData(object = object, slot = slot)) & ! vars %in% names(x = data.fetched)] data.fetched <- c( data.fetched, tryCatch( From c5d70b017da2d84ff91ad98a9ac81e8b41cea31f Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Fri, 25 Oct 2019 16:08:14 -0400 Subject: [PATCH 26/83] Minor style fixes Clean up imports --- NAMESPACE | 1 - R/clustering.R | 28 +++++++++++++++++----------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 671813cce..df2e83124 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -481,7 +481,6 @@ importFrom(reticulate,import) importFrom(reticulate,np_array) importFrom(reticulate,py_module_available) importFrom(reticulate,py_set_seed) -importFrom(reticulate,r_to_py) importFrom(reticulate,tuple) importFrom(rlang,"!!") importFrom(rsvd,rsvd) diff --git a/R/clustering.R b/R/clustering.R index 2ea7a9c53..14dae7955 100644 --- a/R/clustering.R +++ b/R/clustering.R @@ -677,8 +677,7 @@ NNHelper <- function(data, query = data, k, method, ...) { # @keywords graph network igraph mvtnorm simulation # #' @importFrom leiden leiden -#' @importFrom methods as is -#' @importFrom reticulate py_module_available import r_to_py +#' @importFrom reticulate py_module_available #' @importFrom igraph graph_from_adjacency_matrix graph_from_adj_list # # @author Tom Kelly @@ -705,17 +704,22 @@ RunLeiden <- function( n.iter = 10 ) { if (!py_module_available(module = 'leidenalg')) { - stop("Cannot find Leiden algorithm, please install through pip (e.g. pip install leidenalg).") + stop( + "Cannot find Leiden algorithm, please install through pip (e.g. pip install leidenalg).", + call. = FALSE + ) } - - if (method %in% c("matrix", "igraph")){ - if (method == "igraph"){ - object <- graph_from_adjacency_matrix(object) + if (method %in% c("matrix", "igraph")) { + if (method == "igraph") { + object <- graph_from_adjacency_matrix(adjmatrix = object) } } else { - warning("method for Leiden recommended as 'matrix' or 'igraph'") + warning( + "method for Leiden recommended as 'matrix' or 'igraph'", + call. = FALSE, + immediate. = TRUE + ) } - input <- if (inherits(x = object, what = 'list')) { graph_from_adj_list(adjlist = object) } else if (inherits(x = object, what = c('dgCMatrix', 'matrix', "Matrix"))) { @@ -723,9 +727,11 @@ RunLeiden <- function( } else if (inherits(x = object, what = 'igraph')) { object } else { - stop(paste("method for Leiden not found for class", class(object))) + stop( + paste("method for Leiden not found for class", class(x = object)), + call. = FALSE + ) } - #run leiden from CRAN package (calls python with reticulate) partition <- leiden( object = input, From a9490cc34b533f10fda052a50dc096a367f972c2 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Fri, 25 Oct 2019 16:51:11 -0400 Subject: [PATCH 27/83] Bump develop version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2a8d3a6f7..6aa37811c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9004 -Date: 2019-10-22 +Version: 3.1.1.9005 +Date: 2019-10-25 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( From 9ec175acfb9430647909f2ff4c769f00d705ec16 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Fri, 25 Oct 2019 17:36:47 -0400 Subject: [PATCH 28/83] Update docs --- NAMESPACE | 2 +- R/generics.R | 9 +++++++-- R/objects.R | 28 ++++++++++++++-------------- man/Assay-class.Rd | 3 +++ man/DimReduc-class.Rd | 14 +++++++++----- man/Graph-class.Rd | 8 +++++++- man/IsGlobal.Rd | 15 +++++++++------ man/SeuratCommand-class.Rd | 2 ++ 8 files changed, 52 insertions(+), 29 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index b03f83d16..696c33665 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -61,6 +61,7 @@ S3method(HVFInfo,Assay) S3method(HVFInfo,Seurat) S3method(Idents,Seurat) S3method(IsGlobal,DimReduc) +S3method(IsGlobal,default) S3method(JS,DimReduc) S3method(JS,JackStrawData) S3method(Key,Assay) @@ -132,7 +133,6 @@ S3method(as.Seurat,loom) S3method(as.SingleCellExperiment,Seurat) S3method(as.data.frame,Matrix) S3method(as.list,SeuratCommand) -S3method(as.logical,DimReduc) S3method(as.logical,JackStrawData) S3method(as.loom,Seurat) S3method(as.sparse,H5Group) diff --git a/R/generics.R b/R/generics.R index 639b908d0..ea923447f 100644 --- a/R/generics.R +++ b/R/generics.R @@ -413,12 +413,17 @@ Idents <- function(object, ... ) { UseMethod(generic = 'Idents<-', object = object) } -#' Is an object global or persistent? +#' Is an object global/persistent? +#' +#' Typically, when removing \code{Assay} objects from an \code{Seurat} object, +#' all associated objects (eg. \code{DimReduc}, \code{Graph}, and \code{SeuratCommand} objects) +#' are removed as well. If an associated object is marked as global/persistent, +#' the associated object will remain even if its original assay was deleted #' #' @param object An object #' @param ... Arguments passed to other methods #' -#' @return \code{TRUE} if the object is global or persistent otherwise \code{FALSE} +#' @return \code{TRUE} if the object is global/persistent otherwise \code{FALSE} #' #' @rdname IsGlobal #' @export IsGlobal diff --git a/R/objects.R b/R/objects.R index e827c4684..4c2f16aa2 100644 --- a/R/objects.R +++ b/R/objects.R @@ -63,6 +63,8 @@ AnchorSet <- setClass( #' @slot data Normalized expression data #' @slot scale.data Scaled expression data #' @slot key Key for the Assay +#' @slot assay.orig Original assay that this assay is based off of. Used to track +#' assay provenence #' @slot var.features Vector of features exhibiting high variance across single cells #' @slot meta.features Feature-level metadata #' @slot misc Utility slot for storing additional data associated with the assay @@ -117,12 +119,15 @@ JackStrawData <- setClass( #' @slot cell.embeddings Cell embeddings matrix (required) #' @slot feature.loadings Feature loadings matrix (optional) #' @slot feature.loadings.projected Projected feature loadings matrix (optional) -#' @slot assay.used Name of assay used to generate DimReduc object +#' @slot assay.used Name of assay used to generate \code{DimReduc} object +#' @slot global Is this \code{DimReduc} global/persistent? If so, it will not be +#' removed when removing its associated assay #' @slot stdev A vector of standard deviations -#' @slot key Key for the DimReduc, must be alphanumerics followed by an underscore -#' @slot jackstraw A \code{\link{JackStrawData-class}} object associated with this DimReduc -#' @slot misc Utility slot for storing additional data associated with the DimReduc -#' (e.g. the total variance of the PCA) +#' @slot key Key for the \code{DimReduc}, must be alphanumerics followed by an underscore +#' @slot jackstraw A \code{\link{JackStrawData-class}} object associated with +#' this \code{DimReduc} +#' @slot misc Utility slot for storing additional data associated with the +#' \code{DimReduc} (e.g. the total variance of the PCA) #' #' @name DimReduc-class #' @rdname DimReduc-class @@ -145,7 +150,9 @@ DimReduc <- setClass( #' The Graph Class #' -#' The Graph class simply inherits from dgCMatrix. We do this to enable future expandability of graphs. +#' The Graph class inherits from dgCMatrix. We do this to enable future expandability of graphs. +#' +#' @slot assay.used Optional name of assay used to generate \code{Graph} object #' #' @name Graph-class #' @rdname Graph-class @@ -197,6 +204,7 @@ IntegrationData <- setClass( #' #' @slot name Command name #' @slot time.stamp Timestamp of when command was tun +#' @slot assay.used Optional name of assay used to generate \code{SeuratCommand} object #' @slot call.string String of the command call #' @slot params List of parameters used in the command call #' @@ -5374,14 +5382,6 @@ as.list.SeuratCommand <- function(x, complete = FALSE, ...) { return(cmd) } -#' @rdname IsGlobal -#' @export -#' @method as.logical DimReduc -#' -as.logical.DimReduc <- function(x, ...) { - return(IsGlobal(object = x)) -} - #' @export #' @method as.logical JackStrawData #' diff --git a/man/Assay-class.Rd b/man/Assay-class.Rd index 38e780b50..709bc55d8 100644 --- a/man/Assay-class.Rd +++ b/man/Assay-class.Rd @@ -22,6 +22,9 @@ data. \item{\code{key}}{Key for the Assay} +\item{\code{assay.orig}}{Original assay that this assay is based off of. Used to track +assay provenence} + \item{\code{var.features}}{Vector of features exhibiting high variance across single cells} \item{\code{meta.features}}{Feature-level metadata} diff --git a/man/DimReduc-class.Rd b/man/DimReduc-class.Rd index 5d0346074..06af61f34 100644 --- a/man/DimReduc-class.Rd +++ b/man/DimReduc-class.Rd @@ -19,15 +19,19 @@ loadings matrix. \item{\code{feature.loadings.projected}}{Projected feature loadings matrix (optional)} -\item{\code{assay.used}}{Name of assay used to generate DimReduc object} +\item{\code{assay.used}}{Name of assay used to generate \code{DimReduc} object} + +\item{\code{global}}{Is this \code{DimReduc} global/persistent? If so, it will not be +removed when removing its associated assay} \item{\code{stdev}}{A vector of standard deviations} -\item{\code{key}}{Key for the DimReduc, must be alphanumerics followed by an underscore} +\item{\code{key}}{Key for the \code{DimReduc}, must be alphanumerics followed by an underscore} -\item{\code{jackstraw}}{A \code{\link{JackStrawData-class}} object associated with this DimReduc} +\item{\code{jackstraw}}{A \code{\link{JackStrawData-class}} object associated with +this \code{DimReduc}} -\item{\code{misc}}{Utility slot for storing additional data associated with the DimReduc -(e.g. the total variance of the PCA)} +\item{\code{misc}}{Utility slot for storing additional data associated with the +\code{DimReduc} (e.g. the total variance of the PCA)} }} diff --git a/man/Graph-class.Rd b/man/Graph-class.Rd index 2e1b88754..b4935e729 100644 --- a/man/Graph-class.Rd +++ b/man/Graph-class.Rd @@ -6,8 +6,14 @@ \alias{Graph} \title{The Graph Class} \description{ -The Graph class simply inherits from dgCMatrix. We do this to enable future expandability of graphs. +The Graph class inherits from dgCMatrix. We do this to enable future expandability of graphs. } +\section{Slots}{ + +\describe{ +\item{\code{assay.used}}{Optional name of assay used to generate \code{Graph} object} +}} + \seealso{ \code{\link[Matrix]{dgCMatrix-class}} } diff --git a/man/IsGlobal.Rd b/man/IsGlobal.Rd index 5ec848dcb..6850a4bde 100644 --- a/man/IsGlobal.Rd +++ b/man/IsGlobal.Rd @@ -2,15 +2,15 @@ % Please edit documentation in R/generics.R, R/objects.R \name{IsGlobal} \alias{IsGlobal} +\alias{IsGlobal.default} \alias{IsGlobal.DimReduc} -\alias{as.logical.DimReduc} -\title{Is an object global or persistent?} +\title{Is an object global/persistent?} \usage{ IsGlobal(object, ...) -\method{IsGlobal}{DimReduc}(object, ...) +\method{IsGlobal}{default}(object, ...) -\method{as.logical}{DimReduc}(x, ...) +\method{IsGlobal}{DimReduc}(object, ...) } \arguments{ \item{object}{An object} @@ -18,10 +18,13 @@ IsGlobal(object, ...) \item{...}{Arguments passed to other methods} } \value{ -\code{TRUE} if the object is global or persistent otherwise \code{FALSE} +\code{TRUE} if the object is global/persistent otherwise \code{FALSE} } \description{ -Is an object global or persistent? +Typically, when removing \code{Assay} objects from an \code{Seurat} object, +all associated objects (eg. \code{DimReduc}, \code{Graph}, and \code{SeuratCommand} objects) +are removed as well. If an associated object is marked as global/persistent, +the associated object will remain even if its original assay was deleted } \examples{ IsGlobal(pbmc_small[['pca']]) diff --git a/man/SeuratCommand-class.Rd b/man/SeuratCommand-class.Rd index 5e38cef52..457aa305a 100644 --- a/man/SeuratCommand-class.Rd +++ b/man/SeuratCommand-class.Rd @@ -15,6 +15,8 @@ The SeuratCommand is used for logging commands that are run on a SeuratObject. I \item{\code{time.stamp}}{Timestamp of when command was tun} +\item{\code{assay.used}}{Optional name of assay used to generate \code{SeuratCommand} object} + \item{\code{call.string}}{String of the command call} \item{\code{params}}{List of parameters used in the command call} From 10307db883364b2d5e46c02eef75fcc47457fc03 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Fri, 25 Oct 2019 17:44:23 -0400 Subject: [PATCH 29/83] Remove message when adding global DimReducs --- R/objects.R | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/R/objects.R b/R/objects.R index 4c2f16aa2..ac9d5618d 100644 --- a/R/objects.R +++ b/R/objects.R @@ -6136,9 +6136,7 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes stop("Cannot add a DimReduc without an assay associated with it", call. = FALSE) } # Ensure Assay that DimReduc is associated with is present in the Seurat object - if (IsGlobal(object = value)) { - message("Adding global dimensional reduction information") - } else if (!any(DefaultAssay(object = value) %in% Assays(object = x))) { + if (!IsGlobal(object = value) && !any(DefaultAssay(object = value) %in% Assays(object = x))) { stop("Cannot find assay '", DefaultAssay(object = value), "' in this Seurat object", call. = FALSE) } # Ensure DimReduc object is in order From 52086dcef3c46c1eab87abbf533a4bcfd6f80cd2 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Fri, 25 Oct 2019 17:50:12 -0400 Subject: [PATCH 30/83] devtools::document updated this --- man/RunLSI.Rd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/RunLSI.Rd b/man/RunLSI.Rd index 8e0d69630..391a59bc4 100644 --- a/man/RunLSI.Rd +++ b/man/RunLSI.Rd @@ -47,8 +47,8 @@ For details about stored LSI calculation parameters, see \code{PrintLSIParams}. } \note{ -RunLSI is being moved to Signac. Equivalent functionality can be -achieved via the Signac::RunTFIDF and Signac::RunSVD functions; +RunLSI is being moved to Signac. Equivalent functionality can be +achieved via the Signac::RunTFIDF and Signac::RunSVD functions; for more information on Signac, please see \url{https://github.com/timoast/Signac} } From 379c727218bb94060bc0d041be7ee04b5e34b0cb Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Fri, 25 Oct 2019 18:39:00 -0400 Subject: [PATCH 31/83] bump develop version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6aa37811c..ed987105d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: Seurat -Version: 3.1.1.9005 +Version: 3.1.1.9006 Date: 2019-10-25 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. From f56659560cd1f8fb77489e2c133005d98ef60ba2 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Mon, 28 Oct 2019 17:51:23 -0400 Subject: [PATCH 32/83] only fill with 1L vector for new slots --- R/objects.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/objects.R b/R/objects.R index ac9d5618d..10c51dcdd 100644 --- a/R/objects.R +++ b/R/objects.R @@ -6937,7 +6937,7 @@ UpdateSlots <- function(object) { object.list <- Filter(f = Negate(f = is.null), x = object.list) object.list <- c('Class' = class(x = object)[1], object.list) object <- do.call(what = 'new', args = object.list) - for (x in slotNames(x = object)) { + for (x in setdiff(x = slotNames(x = object), y = names(x = object.list))) { xobj <- slot(object = object, name = x) if (is.vector(x = xobj) && !is.list(x = xobj) && length(x = xobj) == 0) { slot(object = object, name = x) <- vector(mode = class(x = xobj), length = 1L) From 915dcf40e8cac2c04e2924f6e44a397c3b1e1254 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Mon, 28 Oct 2019 18:07:41 -0400 Subject: [PATCH 33/83] bump develop version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ed987105d..55105ee39 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9006 -Date: 2019-10-25 +Version: 3.1.1.9007 +Date: 2019-10-28 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( From 4c4a7c24504f61d9dc3045e0e9f246062b8ef29c Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Wed, 30 Oct 2019 13:55:48 -0400 Subject: [PATCH 34/83] bump develop version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 55105ee39..d4ec847ef 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9007 -Date: 2019-10-28 +Version: 3.1.1.9008 +Date: 2019-10-30 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( From 79a9f53a5d6f64e22411af438eef8b31b1ec18ee Mon Sep 17 00:00:00 2001 From: Alan O'Callaghan Date: Thu, 31 Oct 2019 12:59:14 +0000 Subject: [PATCH 35/83] Resolve #2267 --- R/visualization.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/visualization.R b/R/visualization.R index ef84ea18c..ce925b233 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -4490,7 +4490,7 @@ SingleExIPlot <- function( } else{ data[, feature] <- data[, feature] + noise } - axis.label <- ifelse(test = log, yes = 'Log Expression Level', no = 'Expression Level') + axis.label <- 'Expression Level' y.max <- y.max %||% max(data[, feature]) if (is.null(x = split) || type != 'violin') { vln.geom <- geom_violin From 931a1361783441c93d503214a0fa019fed940bc4 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Thu, 31 Oct 2019 15:43:08 -0400 Subject: [PATCH 36/83] bump develop version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d4ec847ef..4c2759960 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9008 -Date: 2019-10-30 +Version: 3.1.1.9009 +Date: 2019-10-31 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( From fa601b45395fe4ee0cee6728bc29eb1fd27860c9 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Fri, 1 Nov 2019 11:50:41 -0400 Subject: [PATCH 37/83] Fix issue where ggplot2 wasn't recognizing colons in feature names Addresses satijalab/seurat-private#218 --- R/visualization.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/R/visualization.R b/R/visualization.R index 44369150f..7feaf0ae2 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -4187,6 +4187,12 @@ SingleCorPlot <- function( x = colnames(x = data), fixed = TRUE ) + names.plot <- colnames(x = data) <- gsub( + pattern = ':', + replacement = '.', + x = colnames(x = data), + fixed = TRUE + ) if (ncol(x = data) < 2) { msg <- "Too few variables passed" if (ncol(x = data) == 1) { From c6ee4f9ae9280725c7a66fabd057892b04936554 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Fri, 1 Nov 2019 12:23:26 -0400 Subject: [PATCH 38/83] Fix total variance calculation for exact PCA --- R/dimensional_reduction.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/dimensional_reduction.R b/R/dimensional_reduction.R index 4f1ecdff4..3080f341d 100644 --- a/R/dimensional_reduction.R +++ b/R/dimensional_reduction.R @@ -811,10 +811,10 @@ RunPCA.default <- function( cell.embeddings <- pca.results$v } else { + total.variance <- sum(RowVar(x = object)) if (approx) { npcs <- min(npcs, nrow(x = object) - 1) pca.results <- irlba(A = t(x = object), nv = npcs, ...) - total.variance <- sum(RowVar(x = object)) feature.loadings <- pca.results$v sdev <- pca.results$d/sqrt(max(1, ncol(object) - 1)) if (weight.by.var) { @@ -827,7 +827,6 @@ RunPCA.default <- function( pca.results <- prcomp(x = t(object), rank. = npcs, ...) feature.loadings <- pca.results$rotation sdev <- pca.results$sdev - total.variance <- sum(sdev) if (weight.by.var) { cell.embeddings <- pca.results$x %*% diag(pca.results$sdev[1:npcs]^2) } else { From 26e1cf5703c97a5e31f747121d49657d145566db Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Fri, 1 Nov 2019 12:25:42 -0400 Subject: [PATCH 39/83] Bump develop version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4c2759960..af9ea0f4e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9009 -Date: 2019-10-31 +Version: 3.1.1.9010 +Date: 2019-11-01 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( From e0f77adb4ceee08d09471c9c9d245e36226b697d Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Fri, 1 Nov 2019 16:29:26 -0400 Subject: [PATCH 40/83] Don't recompute CalcN if counts doesn't change --- R/objects.R | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/R/objects.R b/R/objects.R index b043f455e..d0bdb90fd 100644 --- a/R/objects.R +++ b/R/objects.R @@ -6278,10 +6278,15 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes } # For Assays, run CalcN if (inherits(x = value, what = 'Assay')) { - n.calc <- CalcN(object = value) - if (!is.null(x = n.calc)) { - names(x = n.calc) <- paste(names(x = n.calc), i, sep = '_') - x[[names(x = n.calc)]] <- n.calc + if (i %in% Assays(object = x) && ! identical( + x = GetAssayData(object = x, assay = i, slot = "counts"), + y = GetAssayData(object = value, slot = "counts")) + ) { + n.calc <- CalcN(object = value) + if (!is.null(x = n.calc)) { + names(x = n.calc) <- paste(names(x = n.calc), i, sep = '_') + x[[names(x = n.calc)]] <- n.calc + } } } # When removing an Assay, clear out associated DimReducs, Graphs, and SeuratCommands From c77831eab7700fdbf32a78336b7ddbdd91d7feac Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Fri, 1 Nov 2019 16:50:35 -0400 Subject: [PATCH 41/83] bump develop version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index af9ea0f4e..42cdffa31 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: Seurat -Version: 3.1.1.9010 +Version: 3.1.1.9011 Date: 2019-11-01 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. From 82a08a1a7405c400105987725e4f32046ff295f3 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Tue, 5 Nov 2019 16:54:17 -0500 Subject: [PATCH 42/83] update Seurat object slots before trying to update other classes --- R/objects.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/objects.R b/R/objects.R index b043f455e..5464176ad 100644 --- a/R/objects.R +++ b/R/objects.R @@ -1394,6 +1394,7 @@ UpdateSeuratObject <- function(object) { message("Validating object structure") # Update object slots message("Updating object slots") + object <- UpdateSlots(object = object) for (obj in FilterObjects(object = object, classes.keep = c('Assay', 'DimReduc', 'Graph'))) { suppressWarnings(expr = object[[obj]] <- UpdateSlots(object = object[[obj]])) } From 2cfcdbf428a4d632189fe44a4462589c53a1493a Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Tue, 5 Nov 2019 17:07:40 -0500 Subject: [PATCH 43/83] Update DESCRIPTION --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 42cdffa31..b83c9e398 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9011 -Date: 2019-11-01 +Version: 3.1.1.9012 +Date: 2019-11-05 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( From 3f881a3d8d3f7e5bff93f42596c17219882ad69a Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Tue, 5 Nov 2019 17:33:34 -0500 Subject: [PATCH 44/83] Bump develop version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index b83c9e398..fe53c2aff 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: Seurat -Version: 3.1.1.9012 +Version: 3.1.1.9013 Date: 2019-11-05 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. From aa96b057450fc0e7af38ddbbf38af1364e4e4eb0 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Thu, 7 Nov 2019 11:36:15 -0500 Subject: [PATCH 45/83] Add check for matching cell names in the query and weight.reduction --- R/integration.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/integration.R b/R/integration.R index 020ee197a..0eef9155d 100644 --- a/R/integration.R +++ b/R/integration.R @@ -2619,6 +2619,9 @@ RunIntegration <- function( dr.weights <- merged.obj[['pca']] } else { dr <- weight.reduction[[2]] + if (!all(cells2 %in% rownames(x = dr))) { + stop("Query cells not present in supplied DimReduc object. Set weight.reduction to a DimReduc object containing the query cells.") + } if (inherits(x = dr, what = "DimReduc")) { dr.weights <- dr } else { From fd7b948f58d7ce47a5a6df601a35763d48ea36ec Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Thu, 7 Nov 2019 11:44:40 -0500 Subject: [PATCH 46/83] bump develop version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fe53c2aff..6fba0e642 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9013 -Date: 2019-11-05 +Version: 3.1.1.9014 +Date: 2019-11-07 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( From c329f9a7256feda2ab776c0eb397037740021c8d Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Thu, 7 Nov 2019 14:49:55 -0500 Subject: [PATCH 47/83] Disallow non-alphanumeric names for [[<- --- R/objects.R | 38 ++++++++++++-------------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/R/objects.R b/R/objects.R index 7463d9f25..ac9656203 100644 --- a/R/objects.R +++ b/R/objects.R @@ -6094,6 +6094,12 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes stop("Cannot delete the default assay", call. = FALSE) } } + # remove disallowed characters from object name + newi <- make.names(names = i) + if (i != newi) { + warning("Invalid name supplied, making object name syntactically valid. New object name is ", newi) + i <- newi + } # Figure out where to store data slot.use <- if (inherits(x = value, what = 'Assay')) { # Ensure we have the same number of cells @@ -6225,29 +6231,8 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes if (class(x = value) %in% c('Assay', 'DimReduc')) { if (length(x = Key(object = value)) == 0) { Key(object = value) <- paste0(tolower(x = i), '_') - } else if (!grepl(pattern = '^[[:alnum:]]+_$', x = Key(object = value))) { - non.alnum <- gsub( - pattern = '[[:alnum:]]', - replacement = '', - x = Key(object = value) - ) - non.alnum <- unlist(x = strsplit(x = non.alnum, split = '')) - non.alnum <- paste(non.alnum, collapse = '|') - new.key <- gsub( - pattern = non.alnum, - replacement = '', - x = Key(object = value) - ) - new.key <- paste0(new.key, '_') - warning( - "All object keys must be alphanumeric characters, followed by an underscore ('_'), setting key to '", - new.key, - "'", - call. = FALSE, - immediate. = TRUE - ) - Key(object = value) <- new.key } + Key(object = value) <- UpdateKey(key = Key(object = value)) # Check for duplicate keys object.keys <- sapply( X = FilterObjects(object = x), @@ -6899,12 +6884,13 @@ UpdateKey <- function(key) { if (grepl(pattern = '^[[:alnum:]]+_', x = key)) { return(key) } else { - new.key <- regmatches( + new.key <- gsub( + pattern = "[[:^alnum:]]", + replacement = "", x = key, - m = regexec(pattern = '[[:alnum:]]+', text = key) + perl = TRUE ) - new.key <- unlist(x = new.key, use.names = FALSE) - new.key <- paste0(paste(new.key, collapse = ''), '_') + new.key <- paste0(new.key, '_') if (new.key == '_') { new.key <- paste0(RandomName(length = 3), '_') } From 220b056df35cd68493d1594e089525844c61707f Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Wed, 13 Nov 2019 11:48:43 -0500 Subject: [PATCH 48/83] run CalcN for Assays being added --- R/objects.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/objects.R b/R/objects.R index 7463d9f25..79df4d54b 100644 --- a/R/objects.R +++ b/R/objects.R @@ -6279,10 +6279,11 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes } # For Assays, run CalcN if (inherits(x = value, what = 'Assay')) { - if (i %in% Assays(object = x) && ! identical( - x = GetAssayData(object = x, assay = i, slot = "counts"), - y = GetAssayData(object = value, slot = "counts")) - ) { + if ((!i %in% Assays(object = x)) | + (i %in% Assays(object = x) && ! identical( + x = GetAssayData(object = x, assay = i, slot = "counts"), + y = GetAssayData(object = value, slot = "counts")) + )) { n.calc <- CalcN(object = value) if (!is.null(x = n.calc)) { names(x = n.calc) <- paste(names(x = n.calc), i, sep = '_') From 0f85399dc230121af31ed8c0456250ead5ea2f28 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Wed, 13 Nov 2019 13:15:29 -0500 Subject: [PATCH 49/83] Add options to prevent setting random seed --- R/dimensional_reduction.R | 16 ++++++++++++---- R/objects.R | 6 ++++-- R/preprocessing.R | 6 ++++-- R/utilities.R | 6 ++++-- R/visualization.R | 9 +++++++-- 5 files changed, 31 insertions(+), 12 deletions(-) diff --git a/R/dimensional_reduction.R b/R/dimensional_reduction.R index 3080f341d..d7221779e 100644 --- a/R/dimensional_reduction.R +++ b/R/dimensional_reduction.R @@ -314,6 +314,7 @@ ProjectDim <- function( #' @param standardize Standardize matrices - scales columns to have unit variance #' and mean 0 #' @param num.cc Number of canonical vectors to calculate +#' @param seed.use Random seed to set. If NULL, does not set a seed #' @param verbose Show progress messages #' #' @importFrom irlba irlba @@ -326,10 +327,13 @@ RunCCA.default <- function( object2, standardize = TRUE, num.cc = 20, + seed.use = 42, verbose = FALSE, ... ) { - set.seed(seed = 42) + if (!is.null(x = seed.use)) { + set.seed(seed = seed.use) + } cells1 <- colnames(x = object1) cells2 <- colnames(x = object2) if (standardize) { @@ -942,7 +946,7 @@ RunPCA.Seurat <- function( } #' @param assay Name of assay that that t-SNE is being run on -#' @param seed.use Random seed for the t-SNE +#' @param seed.use Random seed for the t-SNE. If NULL, does not set the seed #' @param tsne.method Select the method to use to compute the tSNE. Available #' methods are: #' \itemize{ @@ -975,7 +979,9 @@ RunTSNE.matrix <- function( reduction.key = "tSNE_", ... ) { - set.seed(seed = seed.use) + if (!is.null(x = seed.use)) { + set.seed(seed = seed.use) + } tsne.data <- switch( EXPR = tsne.method, 'Rtsne' = Rtsne( @@ -1849,7 +1855,9 @@ JackRandom <- function( weight.by.var = weight.by.var, maxit = 1000 ) { - set.seed(seed = seed.use) + if (!is.null(x = seed.use)) { + set.seed(seed = seed.use) + } rand.genes <- sample( x = rownames(x = scaled.data), size = nrow(x = scaled.data) * prop.use diff --git a/R/objects.R b/R/objects.R index 7463d9f25..4d4232e52 100644 --- a/R/objects.R +++ b/R/objects.R @@ -4687,7 +4687,7 @@ WhichCells.Assay <- function( #' @param downsample Maximum number of cells per identity class, default is \code{Inf}; #' downsampling will happen after all other operations, including inverting the #' cell selection -#' @param seed Random seed for downsampling +#' @param seed Random seed for downsampling. If NULL, does not set a seed #' #' @importFrom stats na.omit #' @@ -4713,7 +4713,9 @@ WhichCells.Seurat <- function( } cell.order <- cells if (!is.null(x = idents)) { - set.seed(seed = seed) + if (!is.null(x = seed)) { + set.seed(seed = seed) + } if (any(!idents %in% levels(x = Idents(object = object)))) { stop( "Cannot find the following identities in the object: ", diff --git a/R/preprocessing.R b/R/preprocessing.R index 751395c63..b97c87d44 100644 --- a/R/preprocessing.R +++ b/R/preprocessing.R @@ -262,7 +262,7 @@ CreateGeneActivityMatrix <- function( #' @param kfunc Clustering function for initial hashtag grouping. Default is "clara" for fast k-medoids clustering on large applications, also support "kmeans" for kmeans clustering #' @param nsamples Number of samples to be drawn from the dataset used for clustering, for kfunc = "clara" #' @param nstarts nstarts value for k-means clustering (for kfunc = "kmeans"). 100 by default -#' @param seed Sets the random seed +#' @param seed Sets the random seed. If NULL, seed is not set #' @param verbose Prints the output #' #' @return The Seurat object with the following demultiplexed information stored in the meta data: @@ -300,7 +300,9 @@ HTODemux <- function( seed = 42, verbose = TRUE ) { - set.seed(seed = seed) + if (!is.null(x = seed)) { + set.seed(seed = seed) + } #initial clustering assay <- assay %||% DefaultAssay(object = object) data <- GetAssayData(object = object, assay = assay) diff --git a/R/utilities.R b/R/utilities.R index b776fd30d..3a2d94969 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -21,7 +21,7 @@ NULL #' @param k Use feature clusters returned from DoKMeans #' @param assay Name of assay to use #' @param name Name for the expression programs -#' @param seed Set a random seed +#' @param seed Set a random seed. If NULL, seed is not set. #' @param search Search for symbol synonyms for features in \code{features} that #' don't match features in \code{object}? Searches the HGNC's gene names database; #' see \code{\link{UpdateSymbolList}} for more details @@ -77,7 +77,9 @@ AddModuleScore <- function( search = FALSE, ... ) { - set.seed(seed = seed) + if (!is.null(x = seed)) { + set.seed(seed = seed) + } assay.old <- DefaultAssay(object = object) assay <- assay %||% assay.old DefaultAssay(object = object) <- assay diff --git a/R/visualization.R b/R/visualization.R index 7feaf0ae2..8efafc893 100644 --- a/R/visualization.R +++ b/R/visualization.R @@ -3606,7 +3606,8 @@ ExIPlot <- function( adjust = adjust, cols = cols, pt.size = pt.size, - log = log + log = log, + ... )) } ) @@ -4445,6 +4446,7 @@ SingleDimPlot <- function( # @param adjust Adjust parameter for geom_violin # @param cols Colors to use for plotting # @param log plot Y axis on log scale +# @param seed.use Random seed to use. If NULL, don't set a seed # # @return A ggplot-based Expression-by-Identity plot # @@ -4466,9 +4468,12 @@ SingleExIPlot <- function( adjust = 1, pt.size = 0, cols = NULL, + seed.use = 42, log = FALSE ) { - set.seed(seed = 42) + if (!is.null(x = seed.use)) { + set.seed(seed = seed.use) + } if (!is.data.frame(x = data) || ncol(x = data) != 1) { stop("'SingleExIPlot requires a data frame with 1 column") } From 3905a770e1b0ecdc525a6d72b3014e01d51033bb Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Wed, 13 Nov 2019 13:21:06 -0500 Subject: [PATCH 50/83] Bump develop version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6fba0e642..5f03c69bb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9014 -Date: 2019-11-07 +Version: 3.1.1.9015 +Date: 2019-11-13 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( From 255399c3f60e55775fab9539822f949caf01805c Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Wed, 13 Nov 2019 13:39:55 -0500 Subject: [PATCH 51/83] Bump develop version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 5f03c69bb..845353c35 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: Seurat -Version: 3.1.1.9015 +Version: 3.1.1.9016 Date: 2019-11-13 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. From a892d0147b0b6e0e31c2419dad4b7c5694049669 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Wed, 13 Nov 2019 18:17:56 -0500 Subject: [PATCH 52/83] remove roxygen docs for non-exported functions, move to internal section of file --- R/integration.R | 816 +++++++++++++++--------------- man/MapQuery.Rd | 61 --- man/PairwiseIntegrateReference.Rd | 67 --- 3 files changed, 408 insertions(+), 536 deletions(-) delete mode 100644 man/MapQuery.Rd delete mode 100644 man/PairwiseIntegrateReference.Rd diff --git a/R/integration.R b/R/integration.R index 0eef9155d..5e5a095fc 100644 --- a/R/integration.R +++ b/R/integration.R @@ -871,113 +871,6 @@ LocalStruct <- function( return(local.struct) } -#' Map queries to reference -#' -#' Map query objects onto assembled reference dataset -#' -#' @param anchorset Anchorset found by FindIntegrationAnchors -#' @param reference Pre-integrated reference dataset to map query datasets to -#' @param new.assay.name Name for the new assay containing the integrated data -#' @param normalization.method Name of normalization method used: LogNormalize -#' or SCT -#' @param features Vector of features to use when computing the PCA to determine the weights. Only set -#' if you want a different set from those used in the anchor finding process -#' @param features.to.integrate Vector of features to integrate. By default, will use the features -#' used in anchor finding. -#' @param dims Number of PCs to use in the weighting procedure -#' @param k.weight Number of neighbors to consider when weighting -#' @param weight.reduction Dimension reduction to use when calculating anchor weights. -#' This can be either: -#' \itemize{ -#' \item{A string, specifying the name of a dimension reduction present in all objects to be integrated} -#' \item{A vector of strings, specifying the name of a dimension reduction to use for each object to be integrated} -#' \item{NULL, in which case a new PCA will be calculated and used to calculate anchor weights} -#' } -#' Note that, if specified, the requested dimension reduction will only be used for calculating anchor weights in the -#' first merge between reference and query, as the merged object will subsequently contain more cells than was in -#' query, and weights will need to be calculated for all cells in the object. -#' @param sd.weight Controls the bandwidth of the Gaussian kernel for weighting -#' @param sample.tree Specify the order of integration. If NULL, will compute automatically. -#' @param preserve.order Do not reorder objects based on size for each pairwise integration. -#' @param do.cpp Run cpp code where applicable -#' @param eps Error bound on the neighbor finding algorithm (from \code{\link{RANN}}) -#' @param verbose Print progress bars and output -#' -#' @return Returns an integrated matrix -#' -MapQuery <- function( - anchorset, - reference, - new.assay.name = "integrated", - normalization.method = c("LogNormalize", "SCT"), - features = NULL, - features.to.integrate = NULL, - dims = 1:30, - k.weight = 100, - weight.reduction = NULL, - sd.weight = 1, - sample.tree = NULL, - preserve.order = FALSE, - do.cpp = TRUE, - eps = 0, - verbose = TRUE -) { - normalization.method <- match.arg(arg = normalization.method) - reference.datasets <- slot(object = anchorset, name = 'reference.objects') - object.list <- slot(object = anchorset, name = 'object.list') - anchors <- slot(object = anchorset, name = 'anchors') - features <- features %||% slot(object = anchorset, name = "anchor.features") - features.to.integrate <- features.to.integrate %||% features - cellnames.list <- list() - for (ii in 1:length(x = object.list)) { - cellnames.list[[ii]] <- colnames(x = object.list[[ii]]) - } - if (length(x = reference.datasets) == length(x = object.list)) { - query.datasets <- NULL - } else { - query.datasets <- setdiff(x = seq_along(along.with = object.list), y = reference.datasets) - } - my.lapply <- ifelse( - test = verbose && nbrOfWorkers() == 1, - yes = pblapply, - no = future_lapply - ) - query.corrected <- my.lapply( - X = query.datasets, - FUN = function(dataset1) { - if (verbose) { - message("Integrating dataset ", dataset1, " with reference dataset") - } - filtered.anchors <- anchors[anchors$dataset1 %in% reference.datasets & anchors$dataset2 == dataset1, ] - integrated <- RunIntegration( - filtered.anchors = filtered.anchors, - reference = reference, - query = object.list[[dataset1]], - new.assay.name = new.assay.name, - normalization.method = normalization.method, - cellnames.list = cellnames.list, - features.to.integrate = features.to.integrate, - weight.reduction = weight.reduction, - features = features, - dims = dims, - do.cpp = do.cpp, - k.weight = k.weight, - sd.weight = sd.weight, - eps = eps, - verbose = verbose - ) - return(integrated) - } - ) - reference.integrated <- GetAssayData( - object = reference, - slot = 'data' - )[features.to.integrate, ] - query.corrected[[length(x = query.corrected) + 1]] <- reference.integrated - all.integrated <- do.call(cbind, query.corrected) - return(all.integrated) -} - #' Calculates a mixing metric #' #' Here we compute a measure of how well mixed a composite dataset is. To @@ -1045,319 +938,93 @@ MixingMetric <- function( return(mixing) } -#' Pairwise dataset integration -#' -#' Used for reference construction +#' Prepare an object list that has been run through SCTransform for integration #' -#' @param anchorset Results from FindIntegrationAnchors -#' @param new.assay.name Name for the new assay containing the integrated data -#' @param normalization.method Name of normalization method used: LogNormalize -#' or SCT -#' @param features Vector of features to use when computing the PCA to determine -#' the weights. Only set if you want a different set from those used in the -#' anchor finding process -#' @param features.to.integrate Vector of features to integrate. By default, -#' will use the features used in anchor finding. -#' @param dims Number of PCs to use in the weighting procedure -#' @param k.weight Number of neighbors to consider when weighting -#' @param weight.reduction Dimension reduction to use when calculating anchor -#' weights. This can be either: +#' @param object.list A list of objects to prep for integration +#' @param assay Name or vector of assay names (one for each object) that correspond +#' to the assay that SCTransform has been run on. If NULL, the current default +#' assay for each object is used. +#' @param anchor.features Can be either: #' \itemize{ -#' \item{A string, specifying the name of a dimension reduction present in -#' all objects to be integrated} -#' \item{A vector of strings, specifying the name of a dimension reduction to -#' use for each object to be integrated} -#' \item{NULL, in which case a new PCA will be calculated and used to -#' calculate anchor weights} +#' \item{A numeric value. This will call \code{\link{SelectIntegrationFeatures}} +#' to select the provided number of features to be used in anchor finding} +#' \item{A vector of features to be used as input to the anchor finding +#' process} #' } -#' Note that, if specified, the requested dimension reduction will only be used -#' for calculating anchor weights in the first merge between reference and -#' query, as the merged object will subsequently contain more cells than was in -#' query, and weights will need to be calculated for all cells in the object. -#' @param sd.weight Controls the bandwidth of the Gaussian kernel for weighting -#' @param sample.tree Specify the order of integration. If NULL, will compute -#' automatically. -#' @param preserve.order Do not reorder objects based on size for each pairwise -#' integration. -#' @param do.cpp Run cpp code where applicable -#' @param eps Error bound on the neighbor finding algorithm (from -#' \code{\link{RANN}}) -#' @param verbose Print progress bars and output +#' @param sct.clip.range Numeric of length two specifying the min and max values +#' the Pearson residual will be clipped to +#' @param verbose Display output/messages #' -#' @return Returns a Seurat object with a new integrated Assay +#' @return An object list with the \code{scale.data} slots set to the anchor +#' features #' -PairwiseIntegrateReference <- function( - anchorset, - new.assay.name = "integrated", - normalization.method = c("LogNormalize", "SCT"), - features = NULL, - features.to.integrate = NULL, - dims = 1:30, - k.weight = 100, - weight.reduction = NULL, - sd.weight = 1, - sample.tree = NULL, - preserve.order = FALSE, - do.cpp = TRUE, - eps = 0, +#' @importFrom pbapply pblapply +#' @importFrom methods slot slot<- +#' @importFrom future nbrOfWorkers +#' @importFrom future.apply future_lapply +#' +#' @export +#' +PrepSCTIntegration <- function( + object.list, + assay = NULL, + anchor.features = 2000, + sct.clip.range = NULL, verbose = TRUE ) { - object.list <- slot(object = anchorset, name = "object.list") - reference.objects <- slot(object = anchorset, name = "reference.objects") - features <- features %||% slot(object = anchorset, name = "anchor.features") - features.to.integrate <- features.to.integrate %||% features - if (length(x = reference.objects) == 1) { - ref.obj <- object.list[[reference.objects]] - ref.obj[[new.assay.name]] <- CreateAssayObject( - data = GetAssayData(ref.obj, slot = 'data')[features.to.integrate, ] - ) - DefaultAssay(object = ref.obj) <- new.assay.name - return(ref.obj) - } - anchors <- slot(object = anchorset, name = "anchors") - offsets <- slot(object = anchorset, name = "offsets") - objects.ncell <- sapply(X = object.list, FUN = ncol) - if (!is.null(x = weight.reduction)) { - if (length(x = weight.reduction) == 1 | inherits(x = weight.reduction, what = "DimReduc")) { - if (length(x = object.list) == 2) { - weight.reduction <- list(NULL, weight.reduction) - } else if (inherits(x = weight.reduction, what = "character")) { - weight.reduction <- rep(x = weight.reduction, times = length(x = object.list)) - } else { - stop("Invalid input for weight.reduction. Please specify either the names of the dimension", - "reduction for each object in the list or provide DimReduc objects.") - } - } - if (length(x = weight.reduction) != length(x = object.list)) { - stop("Please specify a dimension reduction for each object, or one dimension reduction to be used for all objects") + my.lapply <- ifelse( + test = verbose && nbrOfWorkers() == 1, + yes = pblapply, + no = future_lapply + ) + assay <- assay %||% sapply(X = object.list, FUN = DefaultAssay) + assay <- rep_len(x = assay, length.out = length(x = object.list)) + objects.names <- names(x = object.list) + object.list <- lapply( + X = 1:length(x = object.list), + FUN = function(i) { + DefaultAssay(object = object.list[[i]]) <- assay[i] + return(object.list[[i]]) } - available.reductions <- lapply(X = object.list, FUN = FilterObjects, classes.keep = 'DimReduc') - for (ii in 1:length(x = weight.reduction)) { - if (ii == 1 & is.null(x = weight.reduction[[ii]])) next - if (!inherits(x = weight.reduction[[ii]], what = "DimReduc")) { - if (!weight.reduction[[ii]] %in% available.reductions[[ii]]) { - stop("Requested dimension reduction (", weight.reduction[[ii]], ") is not present in object ", ii) + ) + sct.check <- vapply( + X = 1:length(x = object.list), + FUN = function(i) { + sct.check <- IsSCT(assay = object.list[[i]][[assay[i]]]) + if (!sct.check) { + if ("FindIntegrationAnchors" %in% Command(object = object.list[[i]]) && + Command(object = object.list[[i]], command = "FindIntegrationAnchors", value = "normalization.method") == "SCT") { + sct.check <- TRUE } - weight.reduction[[ii]] <- object.list[[ii]][[weight.reduction[[ii]]]] } - } - } - if (is.null(x = sample.tree)) { - similarity.matrix <- CountAnchors( - anchor.df = anchors, - offsets = offsets, - obj.lengths = objects.ncell + return(sct.check) + }, + FUN.VALUE = logical(length = 1L), + USE.NAMES = FALSE + ) + if (!all(sct.check)) { + stop( + "The following assays have not been processed with SCTransform:\n", + paste( + ' object:', + which(x = !sct.check, useNames = FALSE), + '- assay:', + assay[!sct.check], + collapse = '\n' + ), + call. = FALSE ) - similarity.matrix <- similarity.matrix[reference.objects, reference.objects] - sample.tree <- BuildSampleTree(similarity.matrix = similarity.matrix) - sample.tree <- AdjustSampleTree(x = sample.tree, reference.objects = reference.objects) - } - cellnames.list <- list() - for (ii in 1:length(x = object.list)) { - cellnames.list[[ii]] <- colnames(x = object.list[[ii]]) } - unintegrated <- merge( - x = object.list[[reference.objects[[1]]]], - y = object.list[reference.objects[2:length(x = reference.objects)]] - ) - names(x = object.list) <- as.character(-(1:length(x = object.list))) - if (verbose & (length(x = reference.objects) != length(x = object.list))) { - message("Building integrated reference") - } - for (ii in 1:nrow(x = sample.tree)) { - merge.pair <- as.character(x = sample.tree[ii, ]) - length1 <- ncol(x = object.list[[merge.pair[1]]]) - length2 <- ncol(x = object.list[[merge.pair[2]]]) - if (!(preserve.order) & (length2 > length1)) { - merge.pair <- rev(x = merge.pair) - sample.tree[ii, ] <- as.numeric(merge.pair) - } - object.1 <- DietSeurat( - object = object.list[[merge.pair[1]]], - assays = DefaultAssay(object = object.list[[merge.pair[1]]]), - counts = FALSE - ) - object.2 <- DietSeurat( - object = object.list[[merge.pair[2]]], - assays = DefaultAssay(object = object.list[[merge.pair[2]]]), - counts = FALSE - ) - # suppress key duplication warning - suppressWarnings(object.1[["ToIntegrate"]] <- object.1[[DefaultAssay(object = object.1)]]) - DefaultAssay(object = object.1) <- "ToIntegrate" - object.1 <- DietSeurat(object = object.1, assays = "ToIntegrate") - suppressWarnings(object.2[["ToIntegrate"]] <- object.2[[DefaultAssay(object = object.2)]]) - DefaultAssay(object = object.2) <- "ToIntegrate" - object.2 <- DietSeurat(object = object.2, assays = "ToIntegrate") - datasets <- ParseMergePair(sample.tree, ii) - if (verbose) { - message( - "Merging dataset ", - paste(datasets$object2, collapse = " "), - " into ", - paste(datasets$object1, collapse = " ") - ) - } - merged.obj <- merge(x = object.1, y = object.2, merge.data = TRUE) - if (verbose) { - message("Extracting anchors for merged samples") - } - filtered.anchors <- anchors[anchors$dataset1 %in% datasets$object1 & anchors$dataset2 %in% datasets$object2, ] - integrated.matrix <- RunIntegration( - filtered.anchors = filtered.anchors, - normalization.method = normalization.method, - reference = object.1, - query = object.2, - cellnames.list = cellnames.list, - new.assay.name = new.assay.name, - features.to.integrate = features.to.integrate, - features = features, - dims = dims, - weight.reduction = weight.reduction, - do.cpp = do.cpp, - k.weight = k.weight, - sd.weight = sd.weight, - eps = eps, - verbose = verbose - ) - integrated.matrix <- cbind(integrated.matrix, GetAssayData(object = object.1, slot = 'data')[features.to.integrate, ]) - merged.obj[[new.assay.name]] <- CreateAssayObject(data = integrated.matrix) - DefaultAssay(object = merged.obj) <- new.assay.name - object.list[[as.character(x = ii)]] <- merged.obj - object.list[[merge.pair[[1]]]] <- NULL - object.list[[merge.pair[[2]]]] <- NULL - invisible(x = CheckGC()) - } - integrated.data <- GetAssayData( - object = object.list[[as.character(x = ii)]], - assay = new.assay.name, - slot = 'data' - ) - integrated.data <- integrated.data[, colnames(x = unintegrated)] - new.assay <- new( - Class = 'Assay', - counts = new(Class = "dgCMatrix"), - data = integrated.data, - scale.data = matrix(), - var.features = vector(), - meta.features = data.frame(row.names = rownames(x = integrated.data)), - misc = NULL - ) - unintegrated[[new.assay.name]] <- new.assay - # "unintegrated" now contains the integrated assay - DefaultAssay(object = unintegrated) <- new.assay.name - VariableFeatures(object = unintegrated) <- features - if (normalization.method == "SCT"){ - unintegrated[[new.assay.name]] <- SetAssayData( - object = unintegrated[[new.assay.name]], - slot = "scale.data", - new.data = as.matrix(x = GetAssayData(object = unintegrated[[new.assay.name]], slot = "data")) - ) - } - unintegrated <- SetIntegrationData( - object = unintegrated, - integration.name = "Integration", - slot = "anchors", - new.data = anchors - ) - unintegrated <- SetIntegrationData( - object = unintegrated, - integration.name = "Integration", - slot = "sample.tree", - new.data = sample.tree - ) - unintegrated[["FindIntegrationAnchors"]] <- slot(object = anchorset, name = "command") - unintegrated <- LogSeuratCommand(object = unintegrated) - return(unintegrated) -} - -#' Prepare an object list that has been run through SCTransform for integration -#' -#' @param object.list A list of objects to prep for integration -#' @param assay Name or vector of assay names (one for each object) that correspond -#' to the assay that SCTransform has been run on. If NULL, the current default -#' assay for each object is used. -#' @param anchor.features Can be either: -#' \itemize{ -#' \item{A numeric value. This will call \code{\link{SelectIntegrationFeatures}} -#' to select the provided number of features to be used in anchor finding} -#' \item{A vector of features to be used as input to the anchor finding -#' process} -#' } -#' @param sct.clip.range Numeric of length two specifying the min and max values -#' the Pearson residual will be clipped to -#' @param verbose Display output/messages -#' -#' @return An object list with the \code{scale.data} slots set to the anchor -#' features -#' -#' @importFrom pbapply pblapply -#' @importFrom methods slot slot<- -#' @importFrom future nbrOfWorkers -#' @importFrom future.apply future_lapply -#' -#' @export -#' -PrepSCTIntegration <- function( - object.list, - assay = NULL, - anchor.features = 2000, - sct.clip.range = NULL, - verbose = TRUE -) { - my.lapply <- ifelse( - test = verbose && nbrOfWorkers() == 1, - yes = pblapply, - no = future_lapply - ) - assay <- assay %||% sapply(X = object.list, FUN = DefaultAssay) - assay <- rep_len(x = assay, length.out = length(x = object.list)) - objects.names <- names(x = object.list) - object.list <- lapply( - X = 1:length(x = object.list), - FUN = function(i) { - DefaultAssay(object = object.list[[i]]) <- assay[i] - return(object.list[[i]]) - } - ) - sct.check <- vapply( - X = 1:length(x = object.list), - FUN = function(i) { - sct.check <- IsSCT(assay = object.list[[i]][[assay[i]]]) - if (!sct.check) { - if ("FindIntegrationAnchors" %in% Command(object = object.list[[i]]) && - Command(object = object.list[[i]], command = "FindIntegrationAnchors", value = "normalization.method") == "SCT") { - sct.check <- TRUE - } - } - return(sct.check) - }, - FUN.VALUE = logical(length = 1L), - USE.NAMES = FALSE - ) - if (!all(sct.check)) { - stop( - "The following assays have not been processed with SCTransform:\n", - paste( - ' object:', - which(x = !sct.check, useNames = FALSE), - '- assay:', - assay[!sct.check], - collapse = '\n' - ), - call. = FALSE - ) - } - - object.list <- lapply( - X = 1:length(x = object.list), - FUN = function(i) { - vst_out <- Misc(object = object.list[[i]][[assay[i]]], slot = "vst.out") - vst_out$cell_attr <- vst_out$cell_attr[Cells(x = object.list[[i]]), ] - vst_out$cells_step1 <- intersect(x = vst_out$cells_step1, y = Cells(x = object.list[[i]])) - suppressWarnings(expr = Misc(object = object.list[[i]][[assay[i]]], slot = "vst.out") <- vst_out) - return(object.list[[i]]) - } + + object.list <- lapply( + X = 1:length(x = object.list), + FUN = function(i) { + vst_out <- Misc(object = object.list[[i]][[assay[i]]], slot = "vst.out") + vst_out$cell_attr <- vst_out$cell_attr[Cells(x = object.list[[i]]), ] + vst_out$cells_step1 <- intersect(x = vst_out$cells_step1, y = Cells(x = object.list[[i]])) + suppressWarnings(expr = Misc(object = object.list[[i]][[assay[i]]], slot = "vst.out") <- vst_out) + return(object.list[[i]]) + } ) if (is.numeric(x = anchor.features)) { @@ -2360,6 +2027,113 @@ GetCellOffsets <- function(anchors, dataset, cell, cellnames.list, cellnames) { return(cell.offset) } +# Map queries to reference +# +# Map query objects onto assembled reference dataset +# +# @param anchorset Anchorset found by FindIntegrationAnchors +# @param reference Pre-integrated reference dataset to map query datasets to +# @param new.assay.name Name for the new assay containing the integrated data +# @param normalization.method Name of normalization method used: LogNormalize +# or SCT +# @param features Vector of features to use when computing the PCA to determine the weights. Only set +# if you want a different set from those used in the anchor finding process +# @param features.to.integrate Vector of features to integrate. By default, will use the features +# used in anchor finding. +# @param dims Number of PCs to use in the weighting procedure +# @param k.weight Number of neighbors to consider when weighting +# @param weight.reduction Dimension reduction to use when calculating anchor weights. +# This can be either: +# \itemize{ +# \item{A string, specifying the name of a dimension reduction present in all objects to be integrated} +# \item{A vector of strings, specifying the name of a dimension reduction to use for each object to be integrated} +# \item{NULL, in which case a new PCA will be calculated and used to calculate anchor weights} +# } +# Note that, if specified, the requested dimension reduction will only be used for calculating anchor weights in the +# first merge between reference and query, as the merged object will subsequently contain more cells than was in +# query, and weights will need to be calculated for all cells in the object. +# @param sd.weight Controls the bandwidth of the Gaussian kernel for weighting +# @param sample.tree Specify the order of integration. If NULL, will compute automatically. +# @param preserve.order Do not reorder objects based on size for each pairwise integration. +# @param do.cpp Run cpp code where applicable +# @param eps Error bound on the neighbor finding algorithm (from \code{\link{RANN}}) +# @param verbose Print progress bars and output +# +# @return Returns an integrated matrix +# +MapQuery <- function( + anchorset, + reference, + new.assay.name = "integrated", + normalization.method = c("LogNormalize", "SCT"), + features = NULL, + features.to.integrate = NULL, + dims = 1:30, + k.weight = 100, + weight.reduction = NULL, + sd.weight = 1, + sample.tree = NULL, + preserve.order = FALSE, + do.cpp = TRUE, + eps = 0, + verbose = TRUE +) { + normalization.method <- match.arg(arg = normalization.method) + reference.datasets <- slot(object = anchorset, name = 'reference.objects') + object.list <- slot(object = anchorset, name = 'object.list') + anchors <- slot(object = anchorset, name = 'anchors') + features <- features %||% slot(object = anchorset, name = "anchor.features") + features.to.integrate <- features.to.integrate %||% features + cellnames.list <- list() + for (ii in 1:length(x = object.list)) { + cellnames.list[[ii]] <- colnames(x = object.list[[ii]]) + } + if (length(x = reference.datasets) == length(x = object.list)) { + query.datasets <- NULL + } else { + query.datasets <- setdiff(x = seq_along(along.with = object.list), y = reference.datasets) + } + my.lapply <- ifelse( + test = verbose && nbrOfWorkers() == 1, + yes = pblapply, + no = future_lapply + ) + query.corrected <- my.lapply( + X = query.datasets, + FUN = function(dataset1) { + if (verbose) { + message("Integrating dataset ", dataset1, " with reference dataset") + } + filtered.anchors <- anchors[anchors$dataset1 %in% reference.datasets & anchors$dataset2 == dataset1, ] + integrated <- RunIntegration( + filtered.anchors = filtered.anchors, + reference = reference, + query = object.list[[dataset1]], + new.assay.name = new.assay.name, + normalization.method = normalization.method, + cellnames.list = cellnames.list, + features.to.integrate = features.to.integrate, + weight.reduction = weight.reduction, + features = features, + dims = dims, + do.cpp = do.cpp, + k.weight = k.weight, + sd.weight = sd.weight, + eps = eps, + verbose = verbose + ) + return(integrated) + } + ) + reference.integrated <- GetAssayData( + object = reference, + slot = 'data' + )[features.to.integrate, ] + query.corrected[[length(x = query.corrected) + 1]] <- reference.integrated + all.integrated <- do.call(cbind, query.corrected) + return(all.integrated) +} + # Convert nearest neighbor information to a sparse matrix # # @param idx Nearest neighbor index @@ -2389,6 +2163,232 @@ NNtoMatrix <- function(idx, distance, k) { return(nn.matrix) } +# Pairwise dataset integration +# +# Used for reference construction +# +# @param anchorset Results from FindIntegrationAnchors +# @param new.assay.name Name for the new assay containing the integrated data +# @param normalization.method Name of normalization method used: LogNormalize +# or SCT +# @param features Vector of features to use when computing the PCA to determine +# the weights. Only set if you want a different set from those used in the +# anchor finding process +# @param features.to.integrate Vector of features to integrate. By default, +# will use the features used in anchor finding. +# @param dims Number of PCs to use in the weighting procedure +# @param k.weight Number of neighbors to consider when weighting +# @param weight.reduction Dimension reduction to use when calculating anchor +# weights. This can be either: +# \itemize{ +# \item{A string, specifying the name of a dimension reduction present in +# all objects to be integrated} +# \item{A vector of strings, specifying the name of a dimension reduction to +# use for each object to be integrated} +# \item{NULL, in which case a new PCA will be calculated and used to +# calculate anchor weights} +# } +# Note that, if specified, the requested dimension reduction will only be used +# for calculating anchor weights in the first merge between reference and +# query, as the merged object will subsequently contain more cells than was in +# query, and weights will need to be calculated for all cells in the object. +# @param sd.weight Controls the bandwidth of the Gaussian kernel for weighting +# @param sample.tree Specify the order of integration. If NULL, will compute +# automatically. +# @param preserve.order Do not reorder objects based on size for each pairwise +# integration. +# @param do.cpp Run cpp code where applicable +# @param eps Error bound on the neighbor finding algorithm (from +# \code{\link{RANN}}) +# @param verbose Print progress bars and output +# +# @return Returns a Seurat object with a new integrated Assay +# +PairwiseIntegrateReference <- function( + anchorset, + new.assay.name = "integrated", + normalization.method = c("LogNormalize", "SCT"), + features = NULL, + features.to.integrate = NULL, + dims = 1:30, + k.weight = 100, + weight.reduction = NULL, + sd.weight = 1, + sample.tree = NULL, + preserve.order = FALSE, + do.cpp = TRUE, + eps = 0, + verbose = TRUE +) { + object.list <- slot(object = anchorset, name = "object.list") + reference.objects <- slot(object = anchorset, name = "reference.objects") + features <- features %||% slot(object = anchorset, name = "anchor.features") + features.to.integrate <- features.to.integrate %||% features + if (length(x = reference.objects) == 1) { + ref.obj <- object.list[[reference.objects]] + ref.obj[[new.assay.name]] <- CreateAssayObject( + data = GetAssayData(ref.obj, slot = 'data')[features.to.integrate, ] + ) + DefaultAssay(object = ref.obj) <- new.assay.name + return(ref.obj) + } + anchors <- slot(object = anchorset, name = "anchors") + offsets <- slot(object = anchorset, name = "offsets") + objects.ncell <- sapply(X = object.list, FUN = ncol) + if (!is.null(x = weight.reduction)) { + if (length(x = weight.reduction) == 1 | inherits(x = weight.reduction, what = "DimReduc")) { + if (length(x = object.list) == 2) { + weight.reduction <- list(NULL, weight.reduction) + } else if (inherits(x = weight.reduction, what = "character")) { + weight.reduction <- rep(x = weight.reduction, times = length(x = object.list)) + } else { + stop("Invalid input for weight.reduction. Please specify either the names of the dimension", + "reduction for each object in the list or provide DimReduc objects.") + } + } + if (length(x = weight.reduction) != length(x = object.list)) { + stop("Please specify a dimension reduction for each object, or one dimension reduction to be used for all objects") + } + available.reductions <- lapply(X = object.list, FUN = FilterObjects, classes.keep = 'DimReduc') + for (ii in 1:length(x = weight.reduction)) { + if (ii == 1 & is.null(x = weight.reduction[[ii]])) next + if (!inherits(x = weight.reduction[[ii]], what = "DimReduc")) { + if (!weight.reduction[[ii]] %in% available.reductions[[ii]]) { + stop("Requested dimension reduction (", weight.reduction[[ii]], ") is not present in object ", ii) + } + weight.reduction[[ii]] <- object.list[[ii]][[weight.reduction[[ii]]]] + } + } + } + if (is.null(x = sample.tree)) { + similarity.matrix <- CountAnchors( + anchor.df = anchors, + offsets = offsets, + obj.lengths = objects.ncell + ) + similarity.matrix <- similarity.matrix[reference.objects, reference.objects] + sample.tree <- BuildSampleTree(similarity.matrix = similarity.matrix) + sample.tree <- AdjustSampleTree(x = sample.tree, reference.objects = reference.objects) + } + cellnames.list <- list() + for (ii in 1:length(x = object.list)) { + cellnames.list[[ii]] <- colnames(x = object.list[[ii]]) + } + unintegrated <- merge( + x = object.list[[reference.objects[[1]]]], + y = object.list[reference.objects[2:length(x = reference.objects)]] + ) + names(x = object.list) <- as.character(-(1:length(x = object.list))) + if (verbose & (length(x = reference.objects) != length(x = object.list))) { + message("Building integrated reference") + } + for (ii in 1:nrow(x = sample.tree)) { + merge.pair <- as.character(x = sample.tree[ii, ]) + length1 <- ncol(x = object.list[[merge.pair[1]]]) + length2 <- ncol(x = object.list[[merge.pair[2]]]) + if (!(preserve.order) & (length2 > length1)) { + merge.pair <- rev(x = merge.pair) + sample.tree[ii, ] <- as.numeric(merge.pair) + } + object.1 <- DietSeurat( + object = object.list[[merge.pair[1]]], + assays = DefaultAssay(object = object.list[[merge.pair[1]]]), + counts = FALSE + ) + object.2 <- DietSeurat( + object = object.list[[merge.pair[2]]], + assays = DefaultAssay(object = object.list[[merge.pair[2]]]), + counts = FALSE + ) + # suppress key duplication warning + suppressWarnings(object.1[["ToIntegrate"]] <- object.1[[DefaultAssay(object = object.1)]]) + DefaultAssay(object = object.1) <- "ToIntegrate" + object.1 <- DietSeurat(object = object.1, assays = "ToIntegrate") + suppressWarnings(object.2[["ToIntegrate"]] <- object.2[[DefaultAssay(object = object.2)]]) + DefaultAssay(object = object.2) <- "ToIntegrate" + object.2 <- DietSeurat(object = object.2, assays = "ToIntegrate") + datasets <- ParseMergePair(sample.tree, ii) + if (verbose) { + message( + "Merging dataset ", + paste(datasets$object2, collapse = " "), + " into ", + paste(datasets$object1, collapse = " ") + ) + } + merged.obj <- merge(x = object.1, y = object.2, merge.data = TRUE) + if (verbose) { + message("Extracting anchors for merged samples") + } + filtered.anchors <- anchors[anchors$dataset1 %in% datasets$object1 & anchors$dataset2 %in% datasets$object2, ] + integrated.matrix <- RunIntegration( + filtered.anchors = filtered.anchors, + normalization.method = normalization.method, + reference = object.1, + query = object.2, + cellnames.list = cellnames.list, + new.assay.name = new.assay.name, + features.to.integrate = features.to.integrate, + features = features, + dims = dims, + weight.reduction = weight.reduction, + do.cpp = do.cpp, + k.weight = k.weight, + sd.weight = sd.weight, + eps = eps, + verbose = verbose + ) + integrated.matrix <- cbind(integrated.matrix, GetAssayData(object = object.1, slot = 'data')[features.to.integrate, ]) + merged.obj[[new.assay.name]] <- CreateAssayObject(data = integrated.matrix) + DefaultAssay(object = merged.obj) <- new.assay.name + object.list[[as.character(x = ii)]] <- merged.obj + object.list[[merge.pair[[1]]]] <- NULL + object.list[[merge.pair[[2]]]] <- NULL + invisible(x = CheckGC()) + } + integrated.data <- GetAssayData( + object = object.list[[as.character(x = ii)]], + assay = new.assay.name, + slot = 'data' + ) + integrated.data <- integrated.data[, colnames(x = unintegrated)] + new.assay <- new( + Class = 'Assay', + counts = new(Class = "dgCMatrix"), + data = integrated.data, + scale.data = matrix(), + var.features = vector(), + meta.features = data.frame(row.names = rownames(x = integrated.data)), + misc = NULL + ) + unintegrated[[new.assay.name]] <- new.assay + # "unintegrated" now contains the integrated assay + DefaultAssay(object = unintegrated) <- new.assay.name + VariableFeatures(object = unintegrated) <- features + if (normalization.method == "SCT"){ + unintegrated[[new.assay.name]] <- SetAssayData( + object = unintegrated[[new.assay.name]], + slot = "scale.data", + new.data = as.matrix(x = GetAssayData(object = unintegrated[[new.assay.name]], slot = "data")) + ) + } + unintegrated <- SetIntegrationData( + object = unintegrated, + integration.name = "Integration", + slot = "anchors", + new.data = anchors + ) + unintegrated <- SetIntegrationData( + object = unintegrated, + integration.name = "Integration", + slot = "sample.tree", + new.data = sample.tree + ) + unintegrated[["FindIntegrationAnchors"]] <- slot(object = anchorset, name = "command") + unintegrated <- LogSeuratCommand(object = unintegrated) + return(unintegrated) +} + # Parse merge information from dataset clustering # # @param clustering clustering dataframe from hclust ($merge). diff --git a/man/MapQuery.Rd b/man/MapQuery.Rd deleted file mode 100644 index b16de4e06..000000000 --- a/man/MapQuery.Rd +++ /dev/null @@ -1,61 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/integration.R -\name{MapQuery} -\alias{MapQuery} -\title{Map queries to reference} -\usage{ -MapQuery(anchorset, reference, new.assay.name = "integrated", - normalization.method = c("LogNormalize", "SCT"), features = NULL, - features.to.integrate = NULL, dims = 1:30, k.weight = 100, - weight.reduction = NULL, sd.weight = 1, sample.tree = NULL, - preserve.order = FALSE, do.cpp = TRUE, eps = 0, verbose = TRUE) -} -\arguments{ -\item{anchorset}{Anchorset found by FindIntegrationAnchors} - -\item{reference}{Pre-integrated reference dataset to map query datasets to} - -\item{new.assay.name}{Name for the new assay containing the integrated data} - -\item{normalization.method}{Name of normalization method used: LogNormalize -or SCT} - -\item{features}{Vector of features to use when computing the PCA to determine the weights. Only set -if you want a different set from those used in the anchor finding process} - -\item{features.to.integrate}{Vector of features to integrate. By default, will use the features -used in anchor finding.} - -\item{dims}{Number of PCs to use in the weighting procedure} - -\item{k.weight}{Number of neighbors to consider when weighting} - -\item{weight.reduction}{Dimension reduction to use when calculating anchor weights. -This can be either: -\itemize{ - \item{A string, specifying the name of a dimension reduction present in all objects to be integrated} - \item{A vector of strings, specifying the name of a dimension reduction to use for each object to be integrated} - \item{NULL, in which case a new PCA will be calculated and used to calculate anchor weights} -} -Note that, if specified, the requested dimension reduction will only be used for calculating anchor weights in the -first merge between reference and query, as the merged object will subsequently contain more cells than was in -query, and weights will need to be calculated for all cells in the object.} - -\item{sd.weight}{Controls the bandwidth of the Gaussian kernel for weighting} - -\item{sample.tree}{Specify the order of integration. If NULL, will compute automatically.} - -\item{preserve.order}{Do not reorder objects based on size for each pairwise integration.} - -\item{do.cpp}{Run cpp code where applicable} - -\item{eps}{Error bound on the neighbor finding algorithm (from \code{\link{RANN}})} - -\item{verbose}{Print progress bars and output} -} -\value{ -Returns an integrated matrix -} -\description{ -Map query objects onto assembled reference dataset -} diff --git a/man/PairwiseIntegrateReference.Rd b/man/PairwiseIntegrateReference.Rd deleted file mode 100644 index 2308be8c1..000000000 --- a/man/PairwiseIntegrateReference.Rd +++ /dev/null @@ -1,67 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/integration.R -\name{PairwiseIntegrateReference} -\alias{PairwiseIntegrateReference} -\title{Pairwise dataset integration} -\usage{ -PairwiseIntegrateReference(anchorset, new.assay.name = "integrated", - normalization.method = c("LogNormalize", "SCT"), features = NULL, - features.to.integrate = NULL, dims = 1:30, k.weight = 100, - weight.reduction = NULL, sd.weight = 1, sample.tree = NULL, - preserve.order = FALSE, do.cpp = TRUE, eps = 0, verbose = TRUE) -} -\arguments{ -\item{anchorset}{Results from FindIntegrationAnchors} - -\item{new.assay.name}{Name for the new assay containing the integrated data} - -\item{normalization.method}{Name of normalization method used: LogNormalize -or SCT} - -\item{features}{Vector of features to use when computing the PCA to determine -the weights. Only set if you want a different set from those used in the -anchor finding process} - -\item{features.to.integrate}{Vector of features to integrate. By default, -will use the features used in anchor finding.} - -\item{dims}{Number of PCs to use in the weighting procedure} - -\item{k.weight}{Number of neighbors to consider when weighting} - -\item{weight.reduction}{Dimension reduction to use when calculating anchor -weights. This can be either: -\itemize{ - \item{A string, specifying the name of a dimension reduction present in - all objects to be integrated} - \item{A vector of strings, specifying the name of a dimension reduction to - use for each object to be integrated} - \item{NULL, in which case a new PCA will be calculated and used to - calculate anchor weights} -} -Note that, if specified, the requested dimension reduction will only be used -for calculating anchor weights in the first merge between reference and -query, as the merged object will subsequently contain more cells than was in -query, and weights will need to be calculated for all cells in the object.} - -\item{sd.weight}{Controls the bandwidth of the Gaussian kernel for weighting} - -\item{sample.tree}{Specify the order of integration. If NULL, will compute -automatically.} - -\item{preserve.order}{Do not reorder objects based on size for each pairwise -integration.} - -\item{do.cpp}{Run cpp code where applicable} - -\item{eps}{Error bound on the neighbor finding algorithm (from -\code{\link{RANN}})} - -\item{verbose}{Print progress bars and output} -} -\value{ -Returns a Seurat object with a new integrated Assay -} -\description{ -Used for reference construction -} From b87b115cc3fc268bc28f91252abde1ddb67d2151 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Thu, 14 Nov 2019 12:33:31 -0500 Subject: [PATCH 53/83] Bump develop version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 845353c35..8473bd007 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9016 -Date: 2019-11-13 +Version: 3.1.1.9017 +Date: 2019-11-14 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( From 6e4ec8a9088dbe5720b2d912bd8ea05ad3c1f79e Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Thu, 14 Nov 2019 14:26:43 -0500 Subject: [PATCH 54/83] Pass dots to SetAssayData.Assay --- R/objects.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/objects.R b/R/objects.R index 1ed09d72d..f0c225fdd 100644 --- a/R/objects.R +++ b/R/objects.R @@ -4260,7 +4260,7 @@ SetAssayData.Seurat <- function( ) { CheckDots(...) assay <- assay %||% DefaultAssay(object = object) - object[[assay]] <- SetAssayData(object = object[[assay]], slot = slot, new.data = new.data) + object[[assay]] <- SetAssayData(object = object[[assay]], slot = slot, new.data = new.data, ...) return(object) } From fd5ce0c2976d4b4b7fa293527e7fbcde85eee309 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Fri, 15 Nov 2019 11:08:23 -0500 Subject: [PATCH 55/83] improve RunPCA docs, update .Rd files for seed changes --- R/dimensional_reduction.R | 3 ++- man/AddModuleScore.Rd | 2 +- man/HTODemux.Rd | 2 +- man/RunCCA.Rd | 4 +++- man/RunPCA.Rd | 3 ++- man/RunTSNE.Rd | 2 +- man/WhichCells.Rd | 2 +- 7 files changed, 11 insertions(+), 7 deletions(-) diff --git a/R/dimensional_reduction.R b/R/dimensional_reduction.R index d7221779e..6c9d88196 100644 --- a/R/dimensional_reduction.R +++ b/R/dimensional_reduction.R @@ -861,7 +861,8 @@ RunPCA.default <- function( return(reduction.data) } -#' @param features Features to compute PCA on +#' @param features Features to compute PCA on. If features=NULL, PCA will be run +#' using the variable features for the Assay. #' #' @rdname RunPCA #' @export diff --git a/man/AddModuleScore.Rd b/man/AddModuleScore.Rd index a4d6b35ca..05324f657 100644 --- a/man/AddModuleScore.Rd +++ b/man/AddModuleScore.Rd @@ -25,7 +25,7 @@ AddModuleScore(object, features, pool = NULL, nbin = 24, ctrl = 100, \item{name}{Name for the expression programs} -\item{seed}{Set a random seed} +\item{seed}{Set a random seed. If NULL, seed is not set.} \item{search}{Search for symbol synonyms for features in \code{features} that don't match features in \code{object}? Searches the HGNC's gene names database; diff --git a/man/HTODemux.Rd b/man/HTODemux.Rd index 65a4d5f89..69a097a99 100644 --- a/man/HTODemux.Rd +++ b/man/HTODemux.Rd @@ -23,7 +23,7 @@ HTODemux(object, assay = "HTO", positive.quantile = 0.99, \item{nsamples}{Number of samples to be drawn from the dataset used for clustering, for kfunc = "clara"} -\item{seed}{Sets the random seed} +\item{seed}{Sets the random seed. If NULL, seed is not set} \item{verbose}{Prints the output} } diff --git a/man/RunCCA.Rd b/man/RunCCA.Rd index 9825ceffa..ead5c6842 100644 --- a/man/RunCCA.Rd +++ b/man/RunCCA.Rd @@ -9,7 +9,7 @@ RunCCA(object1, object2, ...) \method{RunCCA}{default}(object1, object2, standardize = TRUE, - num.cc = 20, verbose = FALSE, ...) + num.cc = 20, seed.use = 42, verbose = FALSE, ...) \method{RunCCA}{Seurat}(object1, object2, assay1 = NULL, assay2 = NULL, num.cc = 20, features = NULL, renormalize = FALSE, @@ -30,6 +30,8 @@ and mean 0} \item{num.cc}{Number of canonical vectors to calculate} +\item{seed.use}{Random seed to set. If NULL, does not set a seed} + \item{verbose}{Show progress messages} \item{assay1, assay2}{Assays to pull from in the first and second objects, respectively} diff --git a/man/RunPCA.Rd b/man/RunPCA.Rd index b56e17a71..d0a20d149 100644 --- a/man/RunPCA.Rd +++ b/man/RunPCA.Rd @@ -54,7 +54,8 @@ NULL will not set a seed.} \item{approx}{Use truncated singular value decomposition to approximate PCA} -\item{features}{Features to compute PCA on} +\item{features}{Features to compute PCA on. If features=NULL, PCA will be run +using the variable features for the Assay.} \item{reduction.name}{dimensional reduction name, pca by default} } diff --git a/man/RunTSNE.Rd b/man/RunTSNE.Rd index c6040aa7b..8da749669 100644 --- a/man/RunTSNE.Rd +++ b/man/RunTSNE.Rd @@ -34,7 +34,7 @@ RunTSNE(object, ...) \item{assay}{Name of assay that that t-SNE is being run on} -\item{seed.use}{Random seed for the t-SNE} +\item{seed.use}{Random seed for the t-SNE. If NULL, does not set the seed} \item{tsne.method}{Select the method to use to compute the tSNE. Available methods are: diff --git a/man/WhichCells.Rd b/man/WhichCells.Rd index 8d62c7779..bd5508239 100644 --- a/man/WhichCells.Rd +++ b/man/WhichCells.Rd @@ -37,7 +37,7 @@ are present in the feature name} downsampling will happen after all other operations, including inverting the cell selection} -\item{seed}{Random seed for downsampling} +\item{seed}{Random seed for downsampling. If NULL, does not set a seed} } \value{ A vector of cell names From 550af4227bec5f096cfb43cb6566b0015fdc086b Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Fri, 15 Nov 2019 11:43:45 -0500 Subject: [PATCH 56/83] minor style fix, bump develop version --- DESCRIPTION | 4 ++-- R/dimensional_reduction.R | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8473bd007..2c83618e9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9017 -Date: 2019-11-14 +Version: 3.1.1.9018 +Date: 2019-11-15 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( diff --git a/R/dimensional_reduction.R b/R/dimensional_reduction.R index 3f6b59c06..e80023368 100644 --- a/R/dimensional_reduction.R +++ b/R/dimensional_reduction.R @@ -1115,7 +1115,7 @@ RunTSNE.Seurat <- function( ) } else if (!is.null(x = features)) { RunTSNE( - object = t(as.matrix(x = GetAssayData(object = object)[features, cells])), + object = t(x = as.matrix(x = GetAssayData(object = object)[features, cells])), assay = DefaultAssay(object = object), seed.use = seed.use, tsne.method = tsne.method, From 877852213a8f07e52fc9209b5837a742a429d228 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Fri, 15 Nov 2019 12:36:10 -0500 Subject: [PATCH 57/83] Bump develop version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2c83618e9..c089167b3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: Seurat -Version: 3.1.1.9018 +Version: 3.1.1.9019 Date: 2019-11-15 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. From 3b74463147ae4d18b3f2cbf18ab88c858e82d464 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Fri, 15 Nov 2019 12:43:24 -0500 Subject: [PATCH 58/83] Bump develop version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index c089167b3..096df3b19 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: Seurat -Version: 3.1.1.9019 +Version: 3.1.1.9020 Date: 2019-11-15 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. From 991061e31ac5ba60ab20053a2a8d7294a4c87981 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Fri, 15 Nov 2019 13:02:38 -0500 Subject: [PATCH 59/83] Add reference to make.names --- R/objects.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/objects.R b/R/objects.R index 6f9573f0c..d768a8f78 100644 --- a/R/objects.R +++ b/R/objects.R @@ -6099,7 +6099,13 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes # remove disallowed characters from object name newi <- make.names(names = i) if (i != newi) { - warning("Invalid name supplied, making object name syntactically valid. New object name is ", newi) + warning( + "Invalid name supplied, making object name syntactically valid. New object name is ", + newi, + "; see ?make.names for more details on syntax validity", + call. = FALSE, + immediate. = TRUE + ) i <- newi } # Figure out where to store data From 29a929029b144491490b84779bce9b3644489aa9 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Tue, 19 Nov 2019 18:19:28 -0500 Subject: [PATCH 60/83] make sure proper assay is being used --- R/utilities.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utilities.R b/R/utilities.R index 3a2d94969..1f36e1a60 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -1109,7 +1109,7 @@ PercentageFeatureSet <- function( warning("Both pattern and features provided. Pattern is being ignored.") } features <- features %||% grep(pattern = pattern, x = rownames(x = object[[assay]]), value = TRUE) - percent.featureset <- colSums(x = GetAssayData(object = object, slot = "counts")[features, , drop = FALSE])/ + percent.featureset <- colSums(x = GetAssayData(object = object, assay = assay, slot = "counts")[features, , drop = FALSE])/ object[[paste0("nCount_", assay)]] * 100 if (!is.null(x = col.name)) { object <- AddMetaData(object = object, metadata = percent.featureset, col.name = col.name) From dea922c7048d295e21fad176f5d9b0039017f696 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Tue, 19 Nov 2019 18:26:26 -0500 Subject: [PATCH 61/83] bump develop version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 096df3b19..b31ed982c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9020 -Date: 2019-11-15 +Version: 3.1.1.9021 +Date: 2019-11-19 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( From 4ed00c48269a49ca982c35bfa60a930505556ea8 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Wed, 27 Nov 2019 10:44:42 -0500 Subject: [PATCH 62/83] Fix docs for ScaleData --- R/preprocessing.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/preprocessing.R b/R/preprocessing.R index b97c87d44..229fb5314 100644 --- a/R/preprocessing.R +++ b/R/preprocessing.R @@ -2113,7 +2113,7 @@ RunALRA.Seurat <- function( #' @importFrom future nbrOfWorkers #' -#' @param features Vector of features names to scale/center. Default is all features +#' @param features Vector of features names to scale/center. Default is variable features. #' @param vars.to.regress Variables to regress out (previously latent.vars in #' RegressOut). For example, nUMI, or percent.mito. #' @param latent.data Extra data to regress out, should be cells x latent data From e79ce45cb6fb10dde33fb228003bdf0458a6a356 Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Wed, 27 Nov 2019 12:29:07 -0500 Subject: [PATCH 63/83] run docs, bump develop version --- DESCRIPTION | 4 ++-- man/ScaleData.Rd | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b31ed982c..0f05c2ee9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9021 -Date: 2019-11-19 +Version: 3.1.1.9022 +Date: 2019-11-27 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( diff --git a/man/ScaleData.Rd b/man/ScaleData.Rd index 1ba86be6c..8b311d755 100644 --- a/man/ScaleData.Rd +++ b/man/ScaleData.Rd @@ -32,7 +32,7 @@ ScaleData(object, ...) \item{...}{Arguments passed to other methods} -\item{features}{Vector of features names to scale/center. Default is all features} +\item{features}{Vector of features names to scale/center. Default is variable features.} \item{vars.to.regress}{Variables to regress out (previously latent.vars in RegressOut). For example, nUMI, or percent.mito.} From 288686aba629805f18fa97b2dc25ed1b187dea96 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Wed, 4 Dec 2019 11:51:02 -0500 Subject: [PATCH 64/83] Change object class testing to use inherits or is.* instead of class In R 4.X, matrices are now arrays This means that class(matrix()) will be a two-length vector instead of one-length if doesn't like two-length vectors, so using class becomes dangerous Instead, we're using inherits or is.* functions to test object class --- R/differential_expression.R | 6 +++--- R/objects.R | 8 ++++---- R/preprocessing.R | 33 ++++++++++++++++----------------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/R/differential_expression.R b/R/differential_expression.R index e58da661a..6b627d485 100644 --- a/R/differential_expression.R +++ b/R/differential_expression.R @@ -136,7 +136,7 @@ FindAllMarkers <- function( return(cond$message) } ) - if (class(x = genes.de[[i]]) == "character") { + if (is.character(x = genes.de[[i]])) { messages[[i]] <- genes.de[[i]] genes.de[[i]] <- NULL } @@ -233,7 +233,7 @@ FindConservedMarkers <- function( verbose = TRUE, ... ) { - if (class(x = meta.method) != "function") { + if (!is.function(x = meta.method)) { stop("meta.method should be a function from the metap package. Please see https://cran.r-project.org/web/packages/metap/metap.pdf for a detailed description of the available functions.") } object.var <- FetchData(object = object, vars = grouping.var) @@ -1412,7 +1412,7 @@ NBModelComparison <- function(y, theta, latent.data, com.fac, grp.fac) { ), silent = TRUE ) - if (class(x = fit2)[1] == 'numeric' | class(x = fit4)[1] == 'numeric') { + if (is.numeric(x = fit2) || is.numeric(x = fit4)) { message('One of the glm.nb calls failed') return(c(rep(x = NA, 5), freqs)) } diff --git a/R/objects.R b/R/objects.R index f0c225fdd..a32128669 100644 --- a/R/objects.R +++ b/R/objects.R @@ -722,7 +722,7 @@ CreateSeuratObject <- function( warning("Some cells in meta.data not present in provided counts matrix.") meta.data <- meta.data[intersect(x = rownames(x = meta.data), y = colnames(x = counts)), ] } - if (class(x = meta.data) == "data.frame") { + if (is.data.frame(x = meta.data)) { new.meta.data <- data.frame(row.names = colnames(x = counts)) for (ii in 1:ncol(x = meta.data)) { new.meta.data[rownames(x = meta.data), colnames(x = meta.data)[ii]] <- meta.data[, ii, drop = FALSE] @@ -6224,7 +6224,7 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes ) } # Check keyed objects - if (class(x = value) %in% c('Assay', 'DimReduc')) { + if (inherits(x = value, what = c('Assay', 'DimReduc'))) { if (length(x = Key(object = value)) == 0) { Key(object = value) <- paste0(tolower(x = i), '_') } else if (!grepl(pattern = '^[[:alnum:]]+_$', x = Key(object = value))) { @@ -6281,9 +6281,9 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes } # For Assays, run CalcN if (inherits(x = value, what = 'Assay')) { - if ((!i %in% Assays(object = x)) | + if ((!i %in% Assays(object = x)) | (i %in% Assays(object = x) && ! identical( - x = GetAssayData(object = x, assay = i, slot = "counts"), + x = GetAssayData(object = x, assay = i, slot = "counts"), y = GetAssayData(object = value, slot = "counts")) )) { n.calc <- CalcN(object = value) diff --git a/R/preprocessing.R b/R/preprocessing.R index 229fb5314..766e7f061 100644 --- a/R/preprocessing.R +++ b/R/preprocessing.R @@ -109,9 +109,9 @@ CalculateBarcodeInflections <- function( } )$x ## workaround for aggregate behavior noted above - if (class(x = whichmin_list) == 'list') { # uneven lengths + if (is.list(x = whichmin_list)) { # uneven lengths is_inflection <- unlist(x = whichmin_list) - } else if (class(x = whichmin_list) == 'matrix') { # even lengths + } else if (is.matrix(x = whichmin_list)) { # even lengths is_inflection <- as.vector(x = t(x = whichmin_list)) } tmp <- cbind(barcode_dist_sub, is_inflection) @@ -191,15 +191,15 @@ CreateGeneActivityMatrix <- function( peak.df <- as.data.frame(x = peak.df) colnames(x = peak.df) <- c("chromosome", 'start', 'end') peaks.gr <- GenomicRanges::makeGRangesFromDataFrame(df = peak.df) - + # if any peaks start at 0, change to 1 - # otherwise GenomicRanges::distanceToNearest will not work + # otherwise GenomicRanges::distanceToNearest will not work BiocGenerics::start(peaks.gr[BiocGenerics::start(peaks.gr) == 0, ]) <- 1 # get annotation file, select genes gtf <- rtracklayer::import(con = annotation.file) gtf <- GenomeInfoDb::keepSeqlevels(x = gtf, value = seq.levels, pruning.mode = 'coarse') - + # change seqlevelsStyle if not the same if (!any(GenomeInfoDb::seqlevelsStyle(x = gtf) == GenomeInfoDb::seqlevelsStyle(x = peaks.gr))) { GenomeInfoDb::seqlevelsStyle(gtf) <- GenomeInfoDb::seqlevelsStyle(peaks.gr) @@ -216,11 +216,11 @@ CreateGeneActivityMatrix <- function( keep.overlaps <- gene.distances[rtracklayer::mcols(x = gene.distances)$distance == 0] peak.ids <- peaks.gr[S4Vectors::queryHits(x = keep.overlaps)] gene.ids <- gtf.genes[S4Vectors::subjectHits(x = keep.overlaps)] - + # Some GTF rows will not have gene_name attribute # Replace it by gene_id attribute gene.ids$gene_name[is.na(gene.ids$gene_name)] <- gene.ids$gene_id[is.na(gene.ids$gene_name)] - + peak.ids$gene.name <- gene.ids$gene_name peak.ids <- as.data.frame(x = peak.ids) peak.ids$peak <- rownames(peak.matrix)[S4Vectors::queryHits(x = keep.overlaps)] @@ -582,10 +582,10 @@ GetResidual <- function( #' mat_norm #' LogNormalize <- function(data, scale.factor = 1e4, verbose = TRUE) { - if (class(x = data) == "data.frame") { + if (is.data.frame(x = data)) { data <- as.matrix(x = data) } - if (class(x = data) != "dgCMatrix") { + if (!inherits(x = data, what = 'dgCMatrix')) { data <- as(object = data, Class = "dgCMatrix") } # call Rcpp function to normalize @@ -1066,10 +1066,10 @@ Read10X_h5 <- function(filename, use.names = TRUE, unique.features = TRUE) { #' mat_norm #' RelativeCounts <- function(data, scale.factor = 1, verbose = TRUE) { - if (class(x = data) == "data.frame") { + if (is.data.frame(x = data)) { data <- as.matrix(x = data) } - if (class(x = data) != "dgCMatrix") { + if (!inherits(x = data, what = 'dgCMatrix')) { data <- as(object = data, Class = "dgCMatrix") } if (verbose) { @@ -1419,10 +1419,10 @@ SubsetByBarcodeInflections <- function(object) { #' mat_norm <- TF.IDF(data = mat) #' TF.IDF <- function(data, verbose = TRUE) { - if (class(x = data) == "data.frame") { + if (is.data.frame(x = data)) { data <- as.matrix(x = data) } - if (class(x = data) != "dgCMatrix") { + if (!inherits(x = data, what = 'dgCMatrix')) { data <- as(object = data, Class = "dgCMatrix") } if (verbose) { @@ -2502,7 +2502,6 @@ ClassifyCells <- function(data, q) { message("No threshold found for ", colnames(x = data)[i], "...") } ) - # if (class(x = model) == "character") { if (is.character(x = model)) { next } @@ -2569,10 +2568,10 @@ ClassifyCells <- function(data, q) { # @import Matrix # CustomNormalize <- function(data, custom_function, margin, verbose = TRUE) { - if (class(x = data) == "data.frame") { + if (is.data.frame(x = data)) { data <- as.matrix(x = data) } - if (class(x = data) != "dgCMatrix") { + if (!inherits(x = data, what = 'dgCMatrix')) { data <- as(object = data, Class = "dgCMatrix") } myapply <- ifelse(test = verbose, yes = pbapply, no = apply) @@ -2782,7 +2781,7 @@ NBResiduals <- function(fmla, regression.mat, gene, return.mode = FALSE) { data = regression.mat ), silent = TRUE) - if (class(fit)[1] == 'numeric') { + if (is.numeric(x = fit)) { message(sprintf('glm.nb failed for gene %s; falling back to scale(log(y+1))', gene)) resid <- scale(x = log(x = regression.mat[, 'GENE'] + 1))[, 1] mode <- 'scale' From 08c1ab105afc258d74842208fcc5cf657b0a76be Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Wed, 4 Dec 2019 14:17:18 -0500 Subject: [PATCH 65/83] trigger rebuild From 2c5c05ff13de6420bd17a5ed6c794a652ce88272 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Wed, 4 Dec 2019 14:37:17 -0500 Subject: [PATCH 66/83] Bump develop version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0f05c2ee9..929917ea0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9022 -Date: 2019-11-27 +Version: 3.1.1.9023 +Date: 2019-12-04 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( From 26e0796f4c10f49ba21edfe7cc8c087df0aebabb Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Thu, 5 Dec 2019 09:51:56 -0500 Subject: [PATCH 67/83] update docs for patch release - new roxygen2 version --- DESCRIPTION | 6 +- man/AddMetaData.Rd | 1 - man/AddModuleScore.Rd | 16 +++- man/AverageExpression.Rd | 15 +++- man/BuildClusterTree.Rd | 14 +++- man/CalculateBarcodeInflections.Rd | 10 ++- man/CellCycleScoring.Rd | 3 +- man/CellScatter.Rd | 12 ++- man/CollapseEmbeddingOutliers.Rd | 10 ++- man/CollapseSpeciesExpressionMatrix.Rd | 8 +- man/ColorDimSplit.Rd | 53 +++++++------ man/CreateDimReducObject.Rd | 15 +++- man/CreateGeneActivityMatrix.Rd | 12 ++- man/CreateSeuratObject.Rd | 13 ++- man/DietSeurat.Rd | 12 ++- man/DimHeatmap.Rd | 21 ++++- man/DimPlot.Rd | 28 +++++-- man/DoHeatmap.Rd | 27 +++++-- man/DotPlot.Rd | 19 ++++- man/ExportToCellbrowser.Rd | 19 +++-- man/FeaturePlot.Rd | 34 ++++++-- man/FeatureScatter.Rd | 16 +++- man/FindAllMarkers.Rd | 27 +++++-- man/FindClusters.Rd | 51 +++++++++--- man/FindConservedMarkers.Rd | 14 +++- man/FindIntegrationAnchors.Rd | 24 ++++-- man/FindMarkers.Rd | 63 +++++++++++---- man/FindNeighbors.Rd | 78 +++++++++++++----- man/FindTransferAnchors.Rd | 26 ++++-- man/FindVariableFeatures.Rd | 63 ++++++++++----- man/GetResidual.Rd | 11 ++- man/HTODemux.Rd | 14 +++- man/HTOHeatmap.Rd | 13 ++- man/HVFInfo.Rd | 3 +- man/Idents.Rd | 15 ++-- man/IntegrateData.Rd | 21 +++-- man/JackStraw.Rd | 13 ++- man/JackStrawPlot.Rd | 3 +- man/LabelClusters.Rd | 11 ++- man/LabelPoints.Rd | 11 ++- man/Loadings.Rd | 3 +- man/LocalStruct.Rd | 13 ++- man/MULTIseqDemux.Rd | 12 ++- man/MetaFeature.Rd | 10 ++- man/MixingMetric.Rd | 12 ++- man/NormalizeData.Rd | 35 ++++++--- man/OldWhichCells.Rd | 30 +++++-- man/PCASigGenes.Rd | 9 ++- man/PercentageFeatureSet.Rd | 9 ++- man/PolyDimPlot.Rd | 9 ++- man/PolyFeaturePlot.Rd | 14 +++- man/PrepSCTIntegration.Rd | 9 ++- man/ProjectDim.Rd | 13 ++- man/RenameCells.Rd | 9 ++- man/RidgePlot.Rd | 19 ++++- man/RunALRA.Rd | 36 +++++++-- man/RunCCA.Rd | 30 +++++-- man/RunICA.Rd | 60 ++++++++++---- man/RunLSI.Rd | 39 +++++++-- man/RunPCA.Rd | 59 ++++++++++---- man/RunTSNE.Rd | 65 +++++++++++---- man/RunUMAP.Rd | 105 ++++++++++++++++++------- man/SCTransform.Rd | 26 ++++-- man/ScaleData.Rd | 67 ++++++++++++---- man/ScoreJackStraw.Rd | 20 +++-- man/SelectIntegrationFeatures.Rd | 10 ++- man/SetAssayData.Rd | 3 +- man/SeuratTheme.Rd | 10 ++- man/SubsetData.Rd | 30 +++++-- man/TopFeatures.Rd | 10 ++- man/TransferData.Rd | 16 +++- man/UpdateSymbolList.Rd | 18 ++++- man/VariableFeaturePlot.Rd | 10 ++- man/VariableFeatures.Rd | 3 +- man/VizDimLoadings.Rd | 14 +++- man/VlnPlot.Rd | 23 +++++- man/WhichCells.Rd | 17 ++-- man/as.Seurat.Rd | 27 +++++-- man/as.loom.Rd | 26 +++--- man/as.sparse.Rd | 13 ++- man/h5ad.Rd | 17 ++-- man/merge.Seurat.Rd | 13 ++- man/print.DimReduc.Rd | 3 +- man/subset.Seurat.Rd | 3 +- 84 files changed, 1343 insertions(+), 461 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 929917ea0..c132dab29 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9023 -Date: 2019-12-04 +Version: 3.1.2 +Date: 2019-12-08 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( @@ -81,7 +81,7 @@ Collate: 'tree.R' 'utilities.R' 'zzz.R' -RoxygenNote: 6.1.1 +RoxygenNote: 7.0.2 Encoding: UTF-8 Suggests: loomR, diff --git a/man/AddMetaData.Rd b/man/AddMetaData.Rd index 58f337942..4cd1823b8 100644 --- a/man/AddMetaData.Rd +++ b/man/AddMetaData.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/generics.R, R/objects.R -\docType{methods} \name{AddMetaData} \alias{AddMetaData} \alias{SeuratAccess} diff --git a/man/AddModuleScore.Rd b/man/AddModuleScore.Rd index 05324f657..0ca38567b 100644 --- a/man/AddModuleScore.Rd +++ b/man/AddModuleScore.Rd @@ -4,9 +4,19 @@ \alias{AddModuleScore} \title{Calculate module scores for feature expression programs in single cells} \usage{ -AddModuleScore(object, features, pool = NULL, nbin = 24, ctrl = 100, - k = FALSE, assay = NULL, name = "Cluster", seed = 1, - search = FALSE, ...) +AddModuleScore( + object, + features, + pool = NULL, + nbin = 24, + ctrl = 100, + k = FALSE, + assay = NULL, + name = "Cluster", + seed = 1, + search = FALSE, + ... +) } \arguments{ \item{object}{Seurat object} diff --git a/man/AverageExpression.Rd b/man/AverageExpression.Rd index aa279a5bc..668ddb269 100644 --- a/man/AverageExpression.Rd +++ b/man/AverageExpression.Rd @@ -4,9 +4,18 @@ \alias{AverageExpression} \title{Averaged feature expression by identity class} \usage{ -AverageExpression(object, assays = NULL, features = NULL, - return.seurat = FALSE, add.ident = NULL, slot = "data", - use.scale = FALSE, use.counts = FALSE, verbose = TRUE, ...) +AverageExpression( + object, + assays = NULL, + features = NULL, + return.seurat = FALSE, + add.ident = NULL, + slot = "data", + use.scale = FALSE, + use.counts = FALSE, + verbose = TRUE, + ... +) } \arguments{ \item{object}{Seurat object} diff --git a/man/BuildClusterTree.Rd b/man/BuildClusterTree.Rd index 0ebde224b..e43fa9ed6 100644 --- a/man/BuildClusterTree.Rd +++ b/man/BuildClusterTree.Rd @@ -4,9 +4,17 @@ \alias{BuildClusterTree} \title{Phylogenetic Analysis of Identity Classes} \usage{ -BuildClusterTree(object, assay = NULL, features = NULL, dims = NULL, - graph = NULL, slot = "data", reorder = FALSE, - reorder.numeric = FALSE, verbose = TRUE) +BuildClusterTree( + object, + assay = NULL, + features = NULL, + dims = NULL, + graph = NULL, + slot = "data", + reorder = FALSE, + reorder.numeric = FALSE, + verbose = TRUE +) } \arguments{ \item{object}{Seurat object} diff --git a/man/CalculateBarcodeInflections.Rd b/man/CalculateBarcodeInflections.Rd index d386ad7da..878cbdc38 100644 --- a/man/CalculateBarcodeInflections.Rd +++ b/man/CalculateBarcodeInflections.Rd @@ -4,9 +4,13 @@ \alias{CalculateBarcodeInflections} \title{Calculate the Barcode Distribution Inflection} \usage{ -CalculateBarcodeInflections(object, barcode.column = "nCount_RNA", - group.column = "orig.ident", threshold.low = NULL, - threshold.high = NULL) +CalculateBarcodeInflections( + object, + barcode.column = "nCount_RNA", + group.column = "orig.ident", + threshold.low = NULL, + threshold.high = NULL +) } \arguments{ \item{object}{Seurat object} diff --git a/man/CellCycleScoring.Rd b/man/CellCycleScoring.Rd index 9bdf6cdeb..4cbef5feb 100644 --- a/man/CellCycleScoring.Rd +++ b/man/CellCycleScoring.Rd @@ -4,8 +4,7 @@ \alias{CellCycleScoring} \title{Score cell cycle phases} \usage{ -CellCycleScoring(object, s.features, g2m.features, set.ident = FALSE, - ...) +CellCycleScoring(object, s.features, g2m.features, set.ident = FALSE, ...) } \arguments{ \item{object}{A Seurat object} diff --git a/man/CellScatter.Rd b/man/CellScatter.Rd index dfa6ff14d..de0383621 100644 --- a/man/CellScatter.Rd +++ b/man/CellScatter.Rd @@ -5,8 +5,16 @@ \alias{CellPlot} \title{Cell-cell scatter plot} \usage{ -CellScatter(object, cell1, cell2, features = NULL, highlight = NULL, - cols = NULL, pt.size = 1, smooth = FALSE) +CellScatter( + object, + cell1, + cell2, + features = NULL, + highlight = NULL, + cols = NULL, + pt.size = 1, + smooth = FALSE +) } \arguments{ \item{object}{Seurat object} diff --git a/man/CollapseEmbeddingOutliers.Rd b/man/CollapseEmbeddingOutliers.Rd index e80e74355..68610f432 100644 --- a/man/CollapseEmbeddingOutliers.Rd +++ b/man/CollapseEmbeddingOutliers.Rd @@ -4,8 +4,14 @@ \alias{CollapseEmbeddingOutliers} \title{Move outliers towards center on dimension reduction plot} \usage{ -CollapseEmbeddingOutliers(object, reduction = "umap", dims = 1:2, - group.by = "ident", outlier.sd = 2, reduction.key = "UMAP_") +CollapseEmbeddingOutliers( + object, + reduction = "umap", + dims = 1:2, + group.by = "ident", + outlier.sd = 2, + reduction.key = "UMAP_" +) } \arguments{ \item{object}{Seurat object} diff --git a/man/CollapseSpeciesExpressionMatrix.Rd b/man/CollapseSpeciesExpressionMatrix.Rd index 013671e87..53c2b8811 100644 --- a/man/CollapseSpeciesExpressionMatrix.Rd +++ b/man/CollapseSpeciesExpressionMatrix.Rd @@ -4,8 +4,12 @@ \alias{CollapseSpeciesExpressionMatrix} \title{Slim down a multi-species expression matrix, when only one species is primarily of interenst.} \usage{ -CollapseSpeciesExpressionMatrix(object, prefix = "HUMAN_", - controls = "MOUSE_", ncontrols = 100) +CollapseSpeciesExpressionMatrix( + object, + prefix = "HUMAN_", + controls = "MOUSE_", + ncontrols = 100 +) } \arguments{ \item{object}{A UMI count matrix. Should contain rownames that start with diff --git a/man/ColorDimSplit.Rd b/man/ColorDimSplit.Rd index c69611570..a2a85b4bc 100644 --- a/man/ColorDimSplit.Rd +++ b/man/ColorDimSplit.Rd @@ -4,8 +4,14 @@ \alias{ColorDimSplit} \title{Color dimensional reduction plot by tree split} \usage{ -ColorDimSplit(object, node, left.color = "red", right.color = "blue", - other.color = "grey50", ...) +ColorDimSplit( + object, + node, + left.color = "red", + right.color = "blue", + other.color = "grey50", + ... +) } \arguments{ \item{object}{Seurat object} @@ -18,41 +24,42 @@ ColorDimSplit(object, node, left.color = "red", right.color = "blue", \item{other.color}{Color for all other cells} -\item{...}{Arguments passed on to \code{DimPlot} -\describe{ - \item{dims}{Dimensions to plot, must be a two-length numeric vector specifying x- and y-dimensions} - \item{cells}{Vector of cells to plot (default is all cells)} - \item{cols}{Vector of colors, each color corresponds to an identity class. This may also be a single character +\item{...}{ + Arguments passed on to \code{\link[=DimPlot]{DimPlot}} + \describe{ + \item{\code{dims}}{Dimensions to plot, must be a two-length numeric vector specifying x- and y-dimensions} + \item{\code{cells}}{Vector of cells to plot (default is all cells)} + \item{\code{cols}}{Vector of colors, each color corresponds to an identity class. This may also be a single character or numeric value corresponding to a palette as specified by \code{\link[RColorBrewer]{brewer.pal.info}}. By default, ggplot2 assigns colors} - \item{pt.size}{Adjust point size for plotting} - \item{reduction}{Which dimensionality reduction to use. If not specified, first searches for umap, then tsne, then pca} - \item{group.by}{Name of one or more metadata columns to group (color) cells by + \item{\code{pt.size}}{Adjust point size for plotting} + \item{\code{reduction}}{Which dimensionality reduction to use. If not specified, first searches for umap, then tsne, then pca} + \item{\code{group.by}}{Name of one or more metadata columns to group (color) cells by (for example, orig.ident); pass 'ident' to group by identity class} - \item{split.by}{Name of a metadata column to split plot by; + \item{\code{split.by}}{Name of a metadata column to split plot by; see \code{\link{FetchData}} for more details} - \item{shape.by}{If NULL, all points are circles (default). You can specify any + \item{\code{shape.by}}{If NULL, all points are circles (default). You can specify any cell attribute (that can be pulled with FetchData) allowing for both different colors and different shapes on cells} - \item{order}{Specify the order of plotting for the idents. This can be + \item{\code{order}}{Specify the order of plotting for the idents. This can be useful for crowded plots if points of interest are being buried. Provide either a full list of valid idents or a subset to be plotted last (on top)} - \item{label}{Whether to label the clusters} - \item{label.size}{Sets size of labels} - \item{repel}{Repel labels} - \item{cells.highlight}{A list of character or numeric vectors of cells to + \item{\code{label}}{Whether to label the clusters} + \item{\code{label.size}}{Sets size of labels} + \item{\code{repel}}{Repel labels} + \item{\code{cells.highlight}}{A list of character or numeric vectors of cells to highlight. If only one group of cells desired, can simply pass a vector instead of a list. If set, colors selected cells to the color(s) in \code{cols.highlight} and other cells black (white if dark.theme = TRUE); will also resize to the size(s) passed to \code{sizes.highlight}} - \item{cols.highlight}{A vector of colors to highlight the cells as; will + \item{\code{cols.highlight}}{A vector of colors to highlight the cells as; will repeat to the length groups in cells.highlight} - \item{sizes.highlight}{Size of highlighted cells; will repeat to the length + \item{\code{sizes.highlight}}{Size of highlighted cells; will repeat to the length groups in cells.highlight} - \item{na.value}{Color value for NA points when using custom scale} - \item{combine}{Combine plots into a single gg object; note that if TRUE; themeing will not work when plotting multiple features} - \item{ncol}{Number of columns for display when combining plots} -}} + \item{\code{na.value}}{Color value for NA points when using custom scale} + \item{\code{combine}}{Combine plots into a single gg object; note that if TRUE; themeing will not work when plotting multiple features} + \item{\code{ncol}}{Number of columns for display when combining plots} + }} } \value{ Returns a DimPlot diff --git a/man/CreateDimReducObject.Rd b/man/CreateDimReducObject.Rd index 7defda9f9..7abd130b9 100644 --- a/man/CreateDimReducObject.Rd +++ b/man/CreateDimReducObject.Rd @@ -5,10 +5,17 @@ \alias{SetDimReduction} \title{Create a DimReduc object} \usage{ -CreateDimReducObject(embeddings = new(Class = "matrix"), - loadings = new(Class = "matrix"), projected = new(Class = "matrix"), - assay = NULL, stdev = numeric(), key = NULL, global = FALSE, - jackstraw = NULL, misc = list()) +CreateDimReducObject( + embeddings = new(Class = "matrix"), + loadings = new(Class = "matrix"), + projected = new(Class = "matrix"), + assay = NULL, + stdev = numeric(), + key = NULL, + global = FALSE, + jackstraw = NULL, + misc = list() +) } \arguments{ \item{embeddings}{A matrix with the cell embeddings} diff --git a/man/CreateGeneActivityMatrix.Rd b/man/CreateGeneActivityMatrix.Rd index 1b4b89b06..d69bc808f 100644 --- a/man/CreateGeneActivityMatrix.Rd +++ b/man/CreateGeneActivityMatrix.Rd @@ -4,9 +4,15 @@ \alias{CreateGeneActivityMatrix} \title{Convert a peak matrix to a gene activity matrix} \usage{ -CreateGeneActivityMatrix(peak.matrix, annotation.file, - seq.levels = c(1:22, "X", "Y"), include.body = TRUE, - upstream = 2000, downstream = 0, verbose = TRUE) +CreateGeneActivityMatrix( + peak.matrix, + annotation.file, + seq.levels = c(1:22, "X", "Y"), + include.body = TRUE, + upstream = 2000, + downstream = 0, + verbose = TRUE +) } \arguments{ \item{peak.matrix}{Matrix of peak counts} diff --git a/man/CreateSeuratObject.Rd b/man/CreateSeuratObject.Rd index 1c3e81e7d..a464b8dc7 100644 --- a/man/CreateSeuratObject.Rd +++ b/man/CreateSeuratObject.Rd @@ -4,9 +4,16 @@ \alias{CreateSeuratObject} \title{Create a Seurat object} \usage{ -CreateSeuratObject(counts, project = "SeuratProject", assay = "RNA", - min.cells = 0, min.features = 0, names.field = 1, - names.delim = "_", meta.data = NULL) +CreateSeuratObject( + counts, + project = "SeuratProject", + assay = "RNA", + min.cells = 0, + min.features = 0, + names.field = 1, + names.delim = "_", + meta.data = NULL +) } \arguments{ \item{counts}{Unnormalized data such as raw counts or TPMs} diff --git a/man/DietSeurat.Rd b/man/DietSeurat.Rd index 558e05d7c..2e6dfb66c 100644 --- a/man/DietSeurat.Rd +++ b/man/DietSeurat.Rd @@ -4,8 +4,16 @@ \alias{DietSeurat} \title{Slim down a Seurat object} \usage{ -DietSeurat(object, counts = TRUE, data = TRUE, scale.data = FALSE, - features = NULL, assays = NULL, dimreducs = NULL, graphs = NULL) +DietSeurat( + object, + counts = TRUE, + data = TRUE, + scale.data = FALSE, + features = NULL, + assays = NULL, + dimreducs = NULL, + graphs = NULL +) } \arguments{ \item{object}{Seurat object} diff --git a/man/DimHeatmap.Rd b/man/DimHeatmap.Rd index 018da2835..c7429b1e7 100644 --- a/man/DimHeatmap.Rd +++ b/man/DimHeatmap.Rd @@ -5,10 +5,23 @@ \alias{PCHeatmap} \title{Dimensional reduction heatmap} \usage{ -DimHeatmap(object, dims = 1, nfeatures = 30, cells = NULL, - reduction = "pca", disp.min = -2.5, disp.max = NULL, - balanced = TRUE, projected = FALSE, ncol = NULL, combine = TRUE, - fast = TRUE, raster = TRUE, slot = "scale.data", assays = NULL) +DimHeatmap( + object, + dims = 1, + nfeatures = 30, + cells = NULL, + reduction = "pca", + disp.min = -2.5, + disp.max = NULL, + balanced = TRUE, + projected = FALSE, + ncol = NULL, + combine = TRUE, + fast = TRUE, + raster = TRUE, + slot = "scale.data", + assays = NULL +) PCHeatmap(object, ...) } diff --git a/man/DimPlot.Rd b/man/DimPlot.Rd index 1bd3889ea..29c9fed17 100644 --- a/man/DimPlot.Rd +++ b/man/DimPlot.Rd @@ -8,12 +8,28 @@ \alias{UMAPPlot} \title{Dimensional reduction plot} \usage{ -DimPlot(object, dims = c(1, 2), cells = NULL, cols = NULL, - pt.size = NULL, reduction = NULL, group.by = NULL, - split.by = NULL, shape.by = NULL, order = NULL, label = FALSE, - label.size = 4, repel = FALSE, cells.highlight = NULL, - cols.highlight = "#DE2D26", sizes.highlight = 1, - na.value = "grey50", combine = TRUE, ncol = NULL, ...) +DimPlot( + object, + dims = c(1, 2), + cells = NULL, + cols = NULL, + pt.size = NULL, + reduction = NULL, + group.by = NULL, + split.by = NULL, + shape.by = NULL, + order = NULL, + label = FALSE, + label.size = 4, + repel = FALSE, + cells.highlight = NULL, + cols.highlight = "#DE2D26", + sizes.highlight = 1, + na.value = "grey50", + combine = TRUE, + ncol = NULL, + ... +) PCAPlot(object, ...) diff --git a/man/DoHeatmap.Rd b/man/DoHeatmap.Rd index 4041f7582..8c5c711bd 100644 --- a/man/DoHeatmap.Rd +++ b/man/DoHeatmap.Rd @@ -4,12 +4,27 @@ \alias{DoHeatmap} \title{Feature expression heatmap} \usage{ -DoHeatmap(object, features = NULL, cells = NULL, group.by = "ident", - group.bar = TRUE, group.colors = NULL, disp.min = -2.5, - disp.max = NULL, slot = "scale.data", assay = NULL, label = TRUE, - size = 5.5, hjust = 0, angle = 45, raster = TRUE, - draw.lines = TRUE, lines.width = NULL, group.bar.height = 0.02, - combine = TRUE) +DoHeatmap( + object, + features = NULL, + cells = NULL, + group.by = "ident", + group.bar = TRUE, + group.colors = NULL, + disp.min = -2.5, + disp.max = NULL, + slot = "scale.data", + assay = NULL, + label = TRUE, + size = 5.5, + hjust = 0, + angle = 45, + raster = TRUE, + draw.lines = TRUE, + lines.width = NULL, + group.bar.height = 0.02, + combine = TRUE +) } \arguments{ \item{object}{Seurat object} diff --git a/man/DotPlot.Rd b/man/DotPlot.Rd index 3a5f10747..eec9138ad 100644 --- a/man/DotPlot.Rd +++ b/man/DotPlot.Rd @@ -5,10 +5,21 @@ \alias{SplitDotPlotGG} \title{Dot plot visualization} \usage{ -DotPlot(object, assay = NULL, features, cols = c("lightgrey", "blue"), - col.min = -2.5, col.max = 2.5, dot.min = 0, dot.scale = 6, - group.by = NULL, split.by = NULL, scale.by = "radius", - scale.min = NA, scale.max = NA) +DotPlot( + object, + assay = NULL, + features, + cols = c("lightgrey", "blue"), + col.min = -2.5, + col.max = 2.5, + dot.min = 0, + dot.scale = 6, + group.by = NULL, + split.by = NULL, + scale.by = "radius", + scale.min = NA, + scale.max = NA +) } \arguments{ \item{object}{Seurat object} diff --git a/man/ExportToCellbrowser.Rd b/man/ExportToCellbrowser.Rd index 11c3a3eff..4796ddf0d 100644 --- a/man/ExportToCellbrowser.Rd +++ b/man/ExportToCellbrowser.Rd @@ -4,11 +4,20 @@ \alias{ExportToCellbrowser} \title{Export Seurat object for UCSC cell browser} \usage{ -ExportToCellbrowser(object, dir, dataset.name = Project(object = object), - reductions = "tsne", markers.file = NULL, - cluster.field = "Cluster", cb.dir = NULL, port = NULL, - skip.expr.matrix = FALSE, skip.metadata = FALSE, - skip.reductions = FALSE, ...) +ExportToCellbrowser( + object, + dir, + dataset.name = Project(object = object), + reductions = "tsne", + markers.file = NULL, + cluster.field = "Cluster", + cb.dir = NULL, + port = NULL, + skip.expr.matrix = FALSE, + skip.metadata = FALSE, + skip.reductions = FALSE, + ... +) } \arguments{ \item{object}{Seurat object} diff --git a/man/FeaturePlot.Rd b/man/FeaturePlot.Rd index ca1eecd55..3e202b085 100644 --- a/man/FeaturePlot.Rd +++ b/man/FeaturePlot.Rd @@ -5,14 +5,32 @@ \alias{FeatureHeatmap} \title{Visualize 'features' on a dimensional reduction plot} \usage{ -FeaturePlot(object, features, dims = c(1, 2), cells = NULL, cols = if - (blend) { c("lightgrey", "#ff0000", "#00ff00") } else { - c("lightgrey", "blue") }, pt.size = NULL, order = FALSE, - min.cutoff = NA, max.cutoff = NA, reduction = NULL, - split.by = NULL, shape.by = NULL, slot = "data", blend = FALSE, - blend.threshold = 0.5, label = FALSE, label.size = 4, - repel = FALSE, ncol = NULL, combine = TRUE, coord.fixed = FALSE, - by.col = TRUE, sort.cell = FALSE) +FeaturePlot( + object, + features, + dims = c(1, 2), + cells = NULL, + cols = if (blend) { c("lightgrey", "#ff0000", "#00ff00") } else { + c("lightgrey", "blue") }, + pt.size = NULL, + order = FALSE, + min.cutoff = NA, + max.cutoff = NA, + reduction = NULL, + split.by = NULL, + shape.by = NULL, + slot = "data", + blend = FALSE, + blend.threshold = 0.5, + label = FALSE, + label.size = 4, + repel = FALSE, + ncol = NULL, + combine = TRUE, + coord.fixed = FALSE, + by.col = TRUE, + sort.cell = FALSE +) } \arguments{ \item{object}{Seurat object} diff --git a/man/FeatureScatter.Rd b/man/FeatureScatter.Rd index 300551ec2..599fcaffb 100644 --- a/man/FeatureScatter.Rd +++ b/man/FeatureScatter.Rd @@ -5,9 +5,19 @@ \alias{GenePlot} \title{Scatter plot of single cell data} \usage{ -FeatureScatter(object, feature1, feature2, cells = NULL, - group.by = NULL, cols = NULL, pt.size = 1, shape.by = NULL, - span = NULL, smooth = FALSE, slot = "data") +FeatureScatter( + object, + feature1, + feature2, + cells = NULL, + group.by = NULL, + cols = NULL, + pt.size = 1, + shape.by = NULL, + span = NULL, + smooth = FALSE, + slot = "data" +) } \arguments{ \item{object}{Seurat object} diff --git a/man/FindAllMarkers.Rd b/man/FindAllMarkers.Rd index 91d1818a7..098ade004 100644 --- a/man/FindAllMarkers.Rd +++ b/man/FindAllMarkers.Rd @@ -5,12 +5,27 @@ \alias{FindAllMarkersNode} \title{Gene expression markers for all identity classes} \usage{ -FindAllMarkers(object, assay = NULL, features = NULL, - logfc.threshold = 0.25, test.use = "wilcox", slot = "data", - min.pct = 0.1, min.diff.pct = -Inf, node = NULL, verbose = TRUE, - only.pos = FALSE, max.cells.per.ident = Inf, random.seed = 1, - latent.vars = NULL, min.cells.feature = 3, min.cells.group = 3, - pseudocount.use = 1, return.thresh = 0.01, ...) +FindAllMarkers( + object, + assay = NULL, + features = NULL, + logfc.threshold = 0.25, + test.use = "wilcox", + slot = "data", + min.pct = 0.1, + min.diff.pct = -Inf, + node = NULL, + verbose = TRUE, + only.pos = FALSE, + max.cells.per.ident = Inf, + random.seed = 1, + latent.vars = NULL, + min.cells.feature = 3, + min.cells.group = 3, + pseudocount.use = 1, + return.thresh = 0.01, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/FindClusters.Rd b/man/FindClusters.Rd index 215109b4d..83f45f22e 100644 --- a/man/FindClusters.Rd +++ b/man/FindClusters.Rd @@ -8,19 +8,44 @@ \usage{ FindClusters(object, ...) -\method{FindClusters}{default}(object, modularity.fxn = 1, - initial.membership = NULL, weights = NULL, node.sizes = NULL, - resolution = 0.8, method = "matrix", algorithm = 1, n.start = 10, - n.iter = 10, random.seed = 0, group.singletons = TRUE, - temp.file.location = NULL, edge.file.name = NULL, verbose = TRUE, - ...) - -\method{FindClusters}{Seurat}(object, graph.name = NULL, - modularity.fxn = 1, initial.membership = NULL, weights = NULL, - node.sizes = NULL, resolution = 0.8, method = "matrix", - algorithm = 1, n.start = 10, n.iter = 10, random.seed = 0, - group.singletons = TRUE, temp.file.location = NULL, - edge.file.name = NULL, verbose = TRUE, ...) +\method{FindClusters}{default}( + object, + modularity.fxn = 1, + initial.membership = NULL, + weights = NULL, + node.sizes = NULL, + resolution = 0.8, + method = "matrix", + algorithm = 1, + n.start = 10, + n.iter = 10, + random.seed = 0, + group.singletons = TRUE, + temp.file.location = NULL, + edge.file.name = NULL, + verbose = TRUE, + ... +) + +\method{FindClusters}{Seurat}( + object, + graph.name = NULL, + modularity.fxn = 1, + initial.membership = NULL, + weights = NULL, + node.sizes = NULL, + resolution = 0.8, + method = "matrix", + algorithm = 1, + n.start = 10, + n.iter = 10, + random.seed = 0, + group.singletons = TRUE, + temp.file.location = NULL, + edge.file.name = NULL, + verbose = TRUE, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/FindConservedMarkers.Rd b/man/FindConservedMarkers.Rd index d1d0798ba..2500454e6 100644 --- a/man/FindConservedMarkers.Rd +++ b/man/FindConservedMarkers.Rd @@ -4,9 +4,17 @@ \alias{FindConservedMarkers} \title{Finds markers that are conserved between the groups} \usage{ -FindConservedMarkers(object, ident.1, ident.2 = NULL, grouping.var, - assay = "RNA", slot = "data", meta.method = minimump, - verbose = TRUE, ...) +FindConservedMarkers( + object, + ident.1, + ident.2 = NULL, + grouping.var, + assay = "RNA", + slot = "data", + meta.method = minimump, + verbose = TRUE, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/FindIntegrationAnchors.Rd b/man/FindIntegrationAnchors.Rd index e6cb48ca1..1d3187985 100644 --- a/man/FindIntegrationAnchors.Rd +++ b/man/FindIntegrationAnchors.Rd @@ -4,13 +4,25 @@ \alias{FindIntegrationAnchors} \title{Find integration anchors} \usage{ -FindIntegrationAnchors(object.list = NULL, assay = NULL, - reference = NULL, anchor.features = 2000, scale = TRUE, +FindIntegrationAnchors( + object.list = NULL, + assay = NULL, + reference = NULL, + anchor.features = 2000, + scale = TRUE, normalization.method = c("LogNormalize", "SCT"), - sct.clip.range = NULL, reduction = c("cca", "rpca"), - l2.norm = TRUE, dims = 1:30, k.anchor = 5, k.filter = 200, - k.score = 30, max.features = 200, nn.method = "rann", eps = 0, - verbose = TRUE) + sct.clip.range = NULL, + reduction = c("cca", "rpca"), + l2.norm = TRUE, + dims = 1:30, + k.anchor = 5, + k.filter = 200, + k.score = 30, + max.features = 200, + nn.method = "rann", + eps = 0, + verbose = TRUE +) } \arguments{ \item{object.list}{A list of objects between which to find anchors for diff --git a/man/FindMarkers.Rd b/man/FindMarkers.Rd index acba420b9..e0b1b02e1 100644 --- a/man/FindMarkers.Rd +++ b/man/FindMarkers.Rd @@ -9,22 +9,53 @@ \usage{ FindMarkers(object, ...) -\method{FindMarkers}{default}(object, slot = "data", - counts = numeric(), cells.1 = NULL, cells.2 = NULL, - features = NULL, reduction = NULL, logfc.threshold = 0.25, - test.use = "wilcox", min.pct = 0.1, min.diff.pct = -Inf, - verbose = TRUE, only.pos = FALSE, max.cells.per.ident = Inf, - random.seed = 1, latent.vars = NULL, min.cells.feature = 3, - min.cells.group = 3, pseudocount.use = 1, ...) - -\method{FindMarkers}{Seurat}(object, ident.1 = NULL, ident.2 = NULL, - group.by = NULL, subset.ident = NULL, assay = NULL, - slot = "data", reduction = NULL, features = NULL, - logfc.threshold = 0.25, test.use = "wilcox", min.pct = 0.1, - min.diff.pct = -Inf, verbose = TRUE, only.pos = FALSE, - max.cells.per.ident = Inf, random.seed = 1, latent.vars = NULL, - min.cells.feature = 3, min.cells.group = 3, pseudocount.use = 1, - ...) +\method{FindMarkers}{default}( + object, + slot = "data", + counts = numeric(), + cells.1 = NULL, + cells.2 = NULL, + features = NULL, + reduction = NULL, + logfc.threshold = 0.25, + test.use = "wilcox", + min.pct = 0.1, + min.diff.pct = -Inf, + verbose = TRUE, + only.pos = FALSE, + max.cells.per.ident = Inf, + random.seed = 1, + latent.vars = NULL, + min.cells.feature = 3, + min.cells.group = 3, + pseudocount.use = 1, + ... +) + +\method{FindMarkers}{Seurat}( + object, + ident.1 = NULL, + ident.2 = NULL, + group.by = NULL, + subset.ident = NULL, + assay = NULL, + slot = "data", + reduction = NULL, + features = NULL, + logfc.threshold = 0.25, + test.use = "wilcox", + min.pct = 0.1, + min.diff.pct = -Inf, + verbose = TRUE, + only.pos = FALSE, + max.cells.per.ident = Inf, + random.seed = 1, + latent.vars = NULL, + min.cells.feature = 3, + min.cells.group = 3, + pseudocount.use = 1, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/FindNeighbors.Rd b/man/FindNeighbors.Rd index 5527f870c..61d15cc1e 100644 --- a/man/FindNeighbors.Rd +++ b/man/FindNeighbors.Rd @@ -10,25 +10,65 @@ \usage{ FindNeighbors(object, ...) -\method{FindNeighbors}{default}(object, distance.matrix = FALSE, - k.param = 20, compute.SNN = TRUE, prune.SNN = 1/15, - nn.method = "rann", annoy.metric = "euclidean", nn.eps = 0, - verbose = TRUE, force.recalc = FALSE, ...) - -\method{FindNeighbors}{Assay}(object, features = NULL, k.param = 20, - compute.SNN = TRUE, prune.SNN = 1/15, nn.method = "rann", - annoy.metric = "euclidean", nn.eps = 0, verbose = TRUE, - force.recalc = FALSE, ...) - -\method{FindNeighbors}{dist}(object, k.param = 20, compute.SNN = TRUE, - prune.SNN = 1/15, nn.method = "rann", annoy.metric = "euclidean", - nn.eps = 0, verbose = TRUE, force.recalc = FALSE, ...) - -\method{FindNeighbors}{Seurat}(object, reduction = "pca", dims = 1:10, - assay = NULL, features = NULL, k.param = 20, compute.SNN = TRUE, - prune.SNN = 1/15, nn.method = "rann", annoy.metric = "euclidean", - nn.eps = 0, verbose = TRUE, force.recalc = FALSE, - do.plot = FALSE, graph.name = NULL, ...) +\method{FindNeighbors}{default}( + object, + distance.matrix = FALSE, + k.param = 20, + compute.SNN = TRUE, + prune.SNN = 1/15, + nn.method = "rann", + annoy.metric = "euclidean", + nn.eps = 0, + verbose = TRUE, + force.recalc = FALSE, + ... +) + +\method{FindNeighbors}{Assay}( + object, + features = NULL, + k.param = 20, + compute.SNN = TRUE, + prune.SNN = 1/15, + nn.method = "rann", + annoy.metric = "euclidean", + nn.eps = 0, + verbose = TRUE, + force.recalc = FALSE, + ... +) + +\method{FindNeighbors}{dist}( + object, + k.param = 20, + compute.SNN = TRUE, + prune.SNN = 1/15, + nn.method = "rann", + annoy.metric = "euclidean", + nn.eps = 0, + verbose = TRUE, + force.recalc = FALSE, + ... +) + +\method{FindNeighbors}{Seurat}( + object, + reduction = "pca", + dims = 1:10, + assay = NULL, + features = NULL, + k.param = 20, + compute.SNN = TRUE, + prune.SNN = 1/15, + nn.method = "rann", + annoy.metric = "euclidean", + nn.eps = 0, + verbose = TRUE, + force.recalc = FALSE, + do.plot = FALSE, + graph.name = NULL, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/FindTransferAnchors.Rd b/man/FindTransferAnchors.Rd index fa9ce247a..7fd5c04af 100644 --- a/man/FindTransferAnchors.Rd +++ b/man/FindTransferAnchors.Rd @@ -4,13 +4,27 @@ \alias{FindTransferAnchors} \title{Find transfer anchors} \usage{ -FindTransferAnchors(reference, query, +FindTransferAnchors( + reference, + query, normalization.method = c("LogNormalize", "SCT"), - reference.assay = NULL, query.assay = NULL, - reduction = "pcaproject", project.query = FALSE, features = NULL, - npcs = 30, l2.norm = TRUE, dims = 1:30, k.anchor = 5, - k.filter = 200, k.score = 30, max.features = 200, - nn.method = "rann", eps = 0, approx.pca = TRUE, verbose = TRUE) + reference.assay = NULL, + query.assay = NULL, + reduction = "pcaproject", + project.query = FALSE, + features = NULL, + npcs = 30, + l2.norm = TRUE, + dims = 1:30, + k.anchor = 5, + k.filter = 200, + k.score = 30, + max.features = 200, + nn.method = "rann", + eps = 0, + approx.pca = TRUE, + verbose = TRUE +) } \arguments{ \item{reference}{Seurat object to use as the reference} diff --git a/man/FindVariableFeatures.Rd b/man/FindVariableFeatures.Rd index ac545ff61..0ae3a8600 100644 --- a/man/FindVariableFeatures.Rd +++ b/man/FindVariableFeatures.Rd @@ -10,24 +10,51 @@ \usage{ FindVariableFeatures(object, ...) -\method{FindVariableFeatures}{default}(object, selection.method = "vst", - loess.span = 0.3, clip.max = "auto", mean.function = FastExpMean, - dispersion.function = FastLogVMR, num.bin = 20, - binning.method = "equal_width", verbose = TRUE, ...) - -\method{FindVariableFeatures}{Assay}(object, selection.method = "vst", - loess.span = 0.3, clip.max = "auto", mean.function = FastExpMean, - dispersion.function = FastLogVMR, num.bin = 20, - binning.method = "equal_width", nfeatures = 2000, - mean.cutoff = c(0.1, 8), dispersion.cutoff = c(1, Inf), - verbose = TRUE, ...) - -\method{FindVariableFeatures}{Seurat}(object, assay = NULL, - selection.method = "vst", loess.span = 0.3, clip.max = "auto", - mean.function = FastExpMean, dispersion.function = FastLogVMR, - num.bin = 20, binning.method = "equal_width", nfeatures = 2000, - mean.cutoff = c(0.1, 8), dispersion.cutoff = c(1, Inf), - verbose = TRUE, ...) +\method{FindVariableFeatures}{default}( + object, + selection.method = "vst", + loess.span = 0.3, + clip.max = "auto", + mean.function = FastExpMean, + dispersion.function = FastLogVMR, + num.bin = 20, + binning.method = "equal_width", + verbose = TRUE, + ... +) + +\method{FindVariableFeatures}{Assay}( + object, + selection.method = "vst", + loess.span = 0.3, + clip.max = "auto", + mean.function = FastExpMean, + dispersion.function = FastLogVMR, + num.bin = 20, + binning.method = "equal_width", + nfeatures = 2000, + mean.cutoff = c(0.1, 8), + dispersion.cutoff = c(1, Inf), + verbose = TRUE, + ... +) + +\method{FindVariableFeatures}{Seurat}( + object, + assay = NULL, + selection.method = "vst", + loess.span = 0.3, + clip.max = "auto", + mean.function = FastExpMean, + dispersion.function = FastLogVMR, + num.bin = 20, + binning.method = "equal_width", + nfeatures = 2000, + mean.cutoff = c(0.1, 8), + dispersion.cutoff = c(1, Inf), + verbose = TRUE, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/GetResidual.Rd b/man/GetResidual.Rd index e8f8a3970..13ef55616 100644 --- a/man/GetResidual.Rd +++ b/man/GetResidual.Rd @@ -4,8 +4,15 @@ \alias{GetResidual} \title{Calculate pearson residuals of features not in the scale.data} \usage{ -GetResidual(object, features, assay = "SCT", umi.assay = "RNA", - clip.range = NULL, replace.value = FALSE, verbose = TRUE) +GetResidual( + object, + features, + assay = "SCT", + umi.assay = "RNA", + clip.range = NULL, + replace.value = FALSE, + verbose = TRUE +) } \arguments{ \item{object}{A seurat object} diff --git a/man/HTODemux.Rd b/man/HTODemux.Rd index 69a097a99..e8c22b7a1 100644 --- a/man/HTODemux.Rd +++ b/man/HTODemux.Rd @@ -4,9 +4,17 @@ \alias{HTODemux} \title{Demultiplex samples based on data from cell 'hashing'} \usage{ -HTODemux(object, assay = "HTO", positive.quantile = 0.99, - init = NULL, nstarts = 100, kfunc = "clara", nsamples = 100, - seed = 42, verbose = TRUE) +HTODemux( + object, + assay = "HTO", + positive.quantile = 0.99, + init = NULL, + nstarts = 100, + kfunc = "clara", + nsamples = 100, + seed = 42, + verbose = TRUE +) } \arguments{ \item{object}{Seurat object. Assumes that the hash tag oligo (HTO) data has been added and normalized.} diff --git a/man/HTOHeatmap.Rd b/man/HTOHeatmap.Rd index 0588fa917..0646ee5d2 100644 --- a/man/HTOHeatmap.Rd +++ b/man/HTOHeatmap.Rd @@ -4,10 +4,15 @@ \alias{HTOHeatmap} \title{Hashtag oligo heatmap} \usage{ -HTOHeatmap(object, assay = "HTO", classification = paste0(assay, - "_classification"), global.classification = paste0(assay, - "_classification.global"), ncells = 5000, singlet.names = NULL, - raster = TRUE) +HTOHeatmap( + object, + assay = "HTO", + classification = paste0(assay, "_classification"), + global.classification = paste0(assay, "_classification.global"), + ncells = 5000, + singlet.names = NULL, + raster = TRUE +) } \arguments{ \item{object}{Seurat object. Assumes that the hash tag oligo (HTO) data has been added and normalized, and demultiplexing has been run with HTODemux().} diff --git a/man/HVFInfo.Rd b/man/HVFInfo.Rd index 36bbda9a5..69e94318b 100644 --- a/man/HVFInfo.Rd +++ b/man/HVFInfo.Rd @@ -10,8 +10,7 @@ HVFInfo(object, ...) \method{HVFInfo}{Assay}(object, selection.method, status = FALSE, ...) -\method{HVFInfo}{Seurat}(object, selection.method = NULL, assay = NULL, - status = FALSE, ...) +\method{HVFInfo}{Seurat}(object, selection.method = NULL, assay = NULL, status = FALSE, ...) } \arguments{ \item{object}{An object} diff --git a/man/Idents.Rd b/man/Idents.Rd index edcf0ffc7..899208d92 100644 --- a/man/Idents.Rd +++ b/man/Idents.Rd @@ -32,11 +32,16 @@ StashIdent(object, save.name, ...) \method{Idents}{Seurat}(object, ...) -\method{Idents}{Seurat}(object, cells = NULL, drop = FALSE, - ...) <- value - -\method{ReorderIdent}{Seurat}(object, var, reverse = FALSE, - afxn = mean, reorder.numeric = FALSE, ...) +\method{Idents}{Seurat}(object, cells = NULL, drop = FALSE, ...) <- value + +\method{ReorderIdent}{Seurat}( + object, + var, + reverse = FALSE, + afxn = mean, + reorder.numeric = FALSE, + ... +) \method{RenameIdents}{Seurat}(object, ...) diff --git a/man/IntegrateData.Rd b/man/IntegrateData.Rd index b90c42575..f05fd4885 100644 --- a/man/IntegrateData.Rd +++ b/man/IntegrateData.Rd @@ -4,11 +4,22 @@ \alias{IntegrateData} \title{Integrate data} \usage{ -IntegrateData(anchorset, new.assay.name = "integrated", - normalization.method = c("LogNormalize", "SCT"), features = NULL, - features.to.integrate = NULL, dims = 1:30, k.weight = 100, - weight.reduction = NULL, sd.weight = 1, sample.tree = NULL, - preserve.order = FALSE, do.cpp = TRUE, eps = 0, verbose = TRUE) +IntegrateData( + anchorset, + new.assay.name = "integrated", + normalization.method = c("LogNormalize", "SCT"), + features = NULL, + features.to.integrate = NULL, + dims = 1:30, + k.weight = 100, + weight.reduction = NULL, + sd.weight = 1, + sample.tree = NULL, + preserve.order = FALSE, + do.cpp = TRUE, + eps = 0, + verbose = TRUE +) } \arguments{ \item{anchorset}{Results from FindIntegrationAnchors} diff --git a/man/JackStraw.Rd b/man/JackStraw.Rd index 2004721b5..285bcad6c 100644 --- a/man/JackStraw.Rd +++ b/man/JackStraw.Rd @@ -4,9 +4,16 @@ \alias{JackStraw} \title{Determine statistical significance of PCA scores.} \usage{ -JackStraw(object, reduction = "pca", assay = NULL, dims = 20, - num.replicate = 100, prop.freq = 0.01, verbose = TRUE, - maxit = 1000) +JackStraw( + object, + reduction = "pca", + assay = NULL, + dims = 20, + num.replicate = 100, + prop.freq = 0.01, + verbose = TRUE, + maxit = 1000 +) } \arguments{ \item{object}{Seurat object} diff --git a/man/JackStrawPlot.Rd b/man/JackStrawPlot.Rd index 0ad06c923..dce058247 100644 --- a/man/JackStrawPlot.Rd +++ b/man/JackStrawPlot.Rd @@ -4,8 +4,7 @@ \alias{JackStrawPlot} \title{JackStraw Plot} \usage{ -JackStrawPlot(object, dims = 1:5, reduction = "pca", xmax = 0.1, - ymax = 0.3) +JackStrawPlot(object, dims = 1:5, reduction = "pca", xmax = 0.1, ymax = 0.3) } \arguments{ \item{object}{Seurat object} diff --git a/man/LabelClusters.Rd b/man/LabelClusters.Rd index d78726196..ba34e2a94 100644 --- a/man/LabelClusters.Rd +++ b/man/LabelClusters.Rd @@ -4,8 +4,15 @@ \alias{LabelClusters} \title{Label clusters on a ggplot2-based scatter plot} \usage{ -LabelClusters(plot, id, clusters = NULL, labels = NULL, - split.by = NULL, repel = TRUE, ...) +LabelClusters( + plot, + id, + clusters = NULL, + labels = NULL, + split.by = NULL, + repel = TRUE, + ... +) } \arguments{ \item{plot}{A ggplot2-based scatter plot} diff --git a/man/LabelPoints.Rd b/man/LabelPoints.Rd index c09231534..7af57e7a6 100644 --- a/man/LabelPoints.Rd +++ b/man/LabelPoints.Rd @@ -5,8 +5,15 @@ \alias{Labeler} \title{Add text labels to a ggplot2 plot} \usage{ -LabelPoints(plot, points, labels = NULL, repel = FALSE, xnudge = 0.3, - ynudge = 0.05, ...) +LabelPoints( + plot, + points, + labels = NULL, + repel = FALSE, + xnudge = 0.3, + ynudge = 0.05, + ... +) } \arguments{ \item{plot}{A ggplot2 plot with a GeomPoint layer} diff --git a/man/Loadings.Rd b/man/Loadings.Rd index 721dbfea8..af4c6547c 100644 --- a/man/Loadings.Rd +++ b/man/Loadings.Rd @@ -14,8 +14,7 @@ Loadings(object, ...) <- value \method{Loadings}{DimReduc}(object, projected = FALSE, ...) -\method{Loadings}{Seurat}(object, reduction = "pca", projected = FALSE, - ...) +\method{Loadings}{Seurat}(object, reduction = "pca", projected = FALSE, ...) \method{Loadings}{DimReduc}(object, projected = TRUE, ...) <- value } diff --git a/man/LocalStruct.Rd b/man/LocalStruct.Rd index 44ffd1e2c..5ced0313b 100644 --- a/man/LocalStruct.Rd +++ b/man/LocalStruct.Rd @@ -4,9 +4,16 @@ \alias{LocalStruct} \title{Calculate the local structure preservation metric} \usage{ -LocalStruct(object, grouping.var, idents = NULL, neighbors = 100, - reduction = "pca", reduced.dims = 1:10, orig.dims = 1:10, - verbose = TRUE) +LocalStruct( + object, + grouping.var, + idents = NULL, + neighbors = 100, + reduction = "pca", + reduced.dims = 1:10, + orig.dims = 1:10, + verbose = TRUE +) } \arguments{ \item{object}{Seurat object} diff --git a/man/MULTIseqDemux.Rd b/man/MULTIseqDemux.Rd index 505cdda59..3b032e144 100644 --- a/man/MULTIseqDemux.Rd +++ b/man/MULTIseqDemux.Rd @@ -4,9 +4,15 @@ \alias{MULTIseqDemux} \title{Demultiplex samples based on classification method from MULTI-seq (McGinnis et al., bioRxiv 2018)} \usage{ -MULTIseqDemux(object, assay = "HTO", quantile = 0.7, - autoThresh = FALSE, maxiter = 5, qrange = seq(from = 0.1, to = 0.9, - by = 0.05), verbose = TRUE) +MULTIseqDemux( + object, + assay = "HTO", + quantile = 0.7, + autoThresh = FALSE, + maxiter = 5, + qrange = seq(from = 0.1, to = 0.9, by = 0.05), + verbose = TRUE +) } \arguments{ \item{object}{Seurat object. Assumes that the specified assay data has been added} diff --git a/man/MetaFeature.Rd b/man/MetaFeature.Rd index 8d7872851..82941cc4d 100644 --- a/man/MetaFeature.Rd +++ b/man/MetaFeature.Rd @@ -4,8 +4,14 @@ \alias{MetaFeature} \title{Aggregate expression of multiple features into a single feature} \usage{ -MetaFeature(object, features, meta.name = "metafeature", cells = NULL, - assay = NULL, slot = "data") +MetaFeature( + object, + features, + meta.name = "metafeature", + cells = NULL, + assay = NULL, + slot = "data" +) } \arguments{ \item{object}{A Seurat object} diff --git a/man/MixingMetric.Rd b/man/MixingMetric.Rd index f9eec617c..a4b3a90f4 100644 --- a/man/MixingMetric.Rd +++ b/man/MixingMetric.Rd @@ -4,8 +4,16 @@ \alias{MixingMetric} \title{Calculates a mixing metric} \usage{ -MixingMetric(object, grouping.var, reduction = "pca", dims = 1:2, - k = 5, max.k = 300, eps = 0, verbose = TRUE) +MixingMetric( + object, + grouping.var, + reduction = "pca", + dims = 1:2, + k = 5, + max.k = 300, + eps = 0, + verbose = TRUE +) } \arguments{ \item{object}{Seurat object} diff --git a/man/NormalizeData.Rd b/man/NormalizeData.Rd index 37d298df5..28cf1e316 100644 --- a/man/NormalizeData.Rd +++ b/man/NormalizeData.Rd @@ -9,17 +9,34 @@ \usage{ NormalizeData(object, ...) -\method{NormalizeData}{default}(object, - normalization.method = "LogNormalize", scale.factor = 10000, - margin = 1, block.size = NULL, verbose = TRUE, ...) +\method{NormalizeData}{default}( + object, + normalization.method = "LogNormalize", + scale.factor = 10000, + margin = 1, + block.size = NULL, + verbose = TRUE, + ... +) -\method{NormalizeData}{Assay}(object, - normalization.method = "LogNormalize", scale.factor = 10000, - margin = 1, verbose = TRUE, ...) +\method{NormalizeData}{Assay}( + object, + normalization.method = "LogNormalize", + scale.factor = 10000, + margin = 1, + verbose = TRUE, + ... +) -\method{NormalizeData}{Seurat}(object, assay = NULL, - normalization.method = "LogNormalize", scale.factor = 10000, - margin = 1, verbose = TRUE, ...) +\method{NormalizeData}{Seurat}( + object, + assay = NULL, + normalization.method = "LogNormalize", + scale.factor = 10000, + margin = 1, + verbose = TRUE, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/OldWhichCells.Rd b/man/OldWhichCells.Rd index 32607c37b..8968df339 100644 --- a/man/OldWhichCells.Rd +++ b/man/OldWhichCells.Rd @@ -8,14 +8,30 @@ \usage{ OldWhichCells(object, ...) -\method{OldWhichCells}{Assay}(object, cells, subset.name = NULL, - low.threshold = -Inf, high.threshold = Inf, accept.value = NULL, - ...) +\method{OldWhichCells}{Assay}( + object, + cells, + subset.name = NULL, + low.threshold = -Inf, + high.threshold = Inf, + accept.value = NULL, + ... +) -\method{OldWhichCells}{Seurat}(object, cells = NULL, - subset.name = NULL, low.threshold = -Inf, high.threshold = Inf, - accept.value = NULL, ident.keep = NULL, ident.remove = NULL, - max.cells.per.ident = Inf, random.seed = 1, assay = NULL, ...) +\method{OldWhichCells}{Seurat}( + object, + cells = NULL, + subset.name = NULL, + low.threshold = -Inf, + high.threshold = Inf, + accept.value = NULL, + ident.keep = NULL, + ident.remove = NULL, + max.cells.per.ident = Inf, + random.seed = 1, + assay = NULL, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/PCASigGenes.Rd b/man/PCASigGenes.Rd index 70ac592e0..1d6d9b459 100644 --- a/man/PCASigGenes.Rd +++ b/man/PCASigGenes.Rd @@ -4,8 +4,13 @@ \alias{PCASigGenes} \title{Significant genes from a PCA} \usage{ -PCASigGenes(object, pcs.use, pval.cut = 0.1, use.full = FALSE, - max.per.pc = NULL) +PCASigGenes( + object, + pcs.use, + pval.cut = 0.1, + use.full = FALSE, + max.per.pc = NULL +) } \arguments{ \item{object}{Seurat object} diff --git a/man/PercentageFeatureSet.Rd b/man/PercentageFeatureSet.Rd index 7fad70050..23a0352c9 100644 --- a/man/PercentageFeatureSet.Rd +++ b/man/PercentageFeatureSet.Rd @@ -4,8 +4,13 @@ \alias{PercentageFeatureSet} \title{Calculate the percentage of all counts that belong to a given set of features} \usage{ -PercentageFeatureSet(object, pattern = NULL, features = NULL, - col.name = NULL, assay = NULL) +PercentageFeatureSet( + object, + pattern = NULL, + features = NULL, + col.name = NULL, + assay = NULL +) } \arguments{ \item{object}{A Seurat object} diff --git a/man/PolyDimPlot.Rd b/man/PolyDimPlot.Rd index b6832bad1..a72c51311 100644 --- a/man/PolyDimPlot.Rd +++ b/man/PolyDimPlot.Rd @@ -4,8 +4,13 @@ \alias{PolyDimPlot} \title{Polygon DimPlot} \usage{ -PolyDimPlot(object, group.by = NULL, cells = NULL, - poly.data = "spatial", flip.coords = FALSE) +PolyDimPlot( + object, + group.by = NULL, + cells = NULL, + poly.data = "spatial", + flip.coords = FALSE +) } \arguments{ \item{object}{Seurat object} diff --git a/man/PolyFeaturePlot.Rd b/man/PolyFeaturePlot.Rd index 0e8e33b14..ba48d100a 100644 --- a/man/PolyFeaturePlot.Rd +++ b/man/PolyFeaturePlot.Rd @@ -4,9 +4,17 @@ \alias{PolyFeaturePlot} \title{Polygon FeaturePlot} \usage{ -PolyFeaturePlot(object, features, cells = NULL, poly.data = "spatial", - ncol = ceiling(x = length(x = features)/2), min.cutoff = 0, - max.cutoff = NA, common.scale = TRUE, flip.coords = FALSE) +PolyFeaturePlot( + object, + features, + cells = NULL, + poly.data = "spatial", + ncol = ceiling(x = length(x = features)/2), + min.cutoff = 0, + max.cutoff = NA, + common.scale = TRUE, + flip.coords = FALSE +) } \arguments{ \item{object}{Seurat object} diff --git a/man/PrepSCTIntegration.Rd b/man/PrepSCTIntegration.Rd index 081d6e766..a0545766a 100644 --- a/man/PrepSCTIntegration.Rd +++ b/man/PrepSCTIntegration.Rd @@ -4,8 +4,13 @@ \alias{PrepSCTIntegration} \title{Prepare an object list that has been run through SCTransform for integration} \usage{ -PrepSCTIntegration(object.list, assay = NULL, anchor.features = 2000, - sct.clip.range = NULL, verbose = TRUE) +PrepSCTIntegration( + object.list, + assay = NULL, + anchor.features = 2000, + sct.clip.range = NULL, + verbose = TRUE +) } \arguments{ \item{object.list}{A list of objects to prep for integration} diff --git a/man/ProjectDim.Rd b/man/ProjectDim.Rd index 6d1210624..5b8307341 100644 --- a/man/ProjectDim.Rd +++ b/man/ProjectDim.Rd @@ -4,9 +4,16 @@ \alias{ProjectDim} \title{Project Dimensional reduction onto full dataset} \usage{ -ProjectDim(object, reduction = "pca", assay = NULL, dims.print = 1:5, - nfeatures.print = 20, overwrite = FALSE, do.center = FALSE, - verbose = TRUE) +ProjectDim( + object, + reduction = "pca", + assay = NULL, + dims.print = 1:5, + nfeatures.print = 20, + overwrite = FALSE, + do.center = FALSE, + verbose = TRUE +) } \arguments{ \item{object}{Seurat object} diff --git a/man/RenameCells.Rd b/man/RenameCells.Rd index e3e0c3929..8a071cf75 100644 --- a/man/RenameCells.Rd +++ b/man/RenameCells.Rd @@ -13,8 +13,13 @@ RenameCells(object, ...) \method{RenameCells}{DimReduc}(object, new.names = NULL, ...) -\method{RenameCells}{Seurat}(object, add.cell.id = NULL, - new.names = NULL, for.merge = FALSE, ...) +\method{RenameCells}{Seurat}( + object, + add.cell.id = NULL, + new.names = NULL, + for.merge = FALSE, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/RidgePlot.Rd b/man/RidgePlot.Rd index 491e7929d..2bba82d6c 100644 --- a/man/RidgePlot.Rd +++ b/man/RidgePlot.Rd @@ -4,9 +4,22 @@ \alias{RidgePlot} \title{Single cell ridge plot} \usage{ -RidgePlot(object, features, cols = NULL, idents = NULL, sort = FALSE, - assay = NULL, group.by = NULL, y.max = NULL, same.y.lims = FALSE, - log = FALSE, ncol = NULL, combine = TRUE, slot = "data", ...) +RidgePlot( + object, + features, + cols = NULL, + idents = NULL, + sort = FALSE, + assay = NULL, + group.by = NULL, + y.max = NULL, + same.y.lims = FALSE, + log = FALSE, + ncol = NULL, + combine = TRUE, + slot = "data", + ... +) } \arguments{ \item{object}{Seurat object} diff --git a/man/RunALRA.Rd b/man/RunALRA.Rd index 8ad711ad0..ac7106ef8 100644 --- a/man/RunALRA.Rd +++ b/man/RunALRA.Rd @@ -8,14 +8,34 @@ \usage{ RunALRA(object, ...) -\method{RunALRA}{default}(object, k = NULL, q = 10, - quantile.prob = 0.001, use.mkl = FALSE, mkl.seed = -1, ...) - -\method{RunALRA}{Seurat}(object, k = NULL, q = 10, - quantile.prob = 0.001, use.mkl = FALSE, mkl.seed = -1, - assay = NULL, slot = "data", setDefaultAssay = TRUE, - genes.use = NULL, K = NULL, thresh = 6, noise.start = NULL, - q.k = 2, k.only = FALSE, ...) +\method{RunALRA}{default}( + object, + k = NULL, + q = 10, + quantile.prob = 0.001, + use.mkl = FALSE, + mkl.seed = -1, + ... +) + +\method{RunALRA}{Seurat}( + object, + k = NULL, + q = 10, + quantile.prob = 0.001, + use.mkl = FALSE, + mkl.seed = -1, + assay = NULL, + slot = "data", + setDefaultAssay = TRUE, + genes.use = NULL, + K = NULL, + thresh = 6, + noise.start = NULL, + q.k = 2, + k.only = FALSE, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/RunCCA.Rd b/man/RunCCA.Rd index ead5c6842..5e6cffcd3 100644 --- a/man/RunCCA.Rd +++ b/man/RunCCA.Rd @@ -8,13 +8,31 @@ \usage{ RunCCA(object1, object2, ...) -\method{RunCCA}{default}(object1, object2, standardize = TRUE, - num.cc = 20, seed.use = 42, verbose = FALSE, ...) +\method{RunCCA}{default}( + object1, + object2, + standardize = TRUE, + num.cc = 20, + seed.use = 42, + verbose = FALSE, + ... +) -\method{RunCCA}{Seurat}(object1, object2, assay1 = NULL, assay2 = NULL, - num.cc = 20, features = NULL, renormalize = FALSE, - rescale = FALSE, compute.gene.loadings = TRUE, add.cell.id1 = NULL, - add.cell.id2 = NULL, verbose = TRUE, ...) +\method{RunCCA}{Seurat}( + object1, + object2, + assay1 = NULL, + assay2 = NULL, + num.cc = 20, + features = NULL, + renormalize = FALSE, + rescale = FALSE, + compute.gene.loadings = TRUE, + add.cell.id1 = NULL, + add.cell.id2 = NULL, + verbose = TRUE, + ... +) } \arguments{ \item{object1}{First Seurat object} diff --git a/man/RunICA.Rd b/man/RunICA.Rd index 942c7834b..cb1569a4f 100644 --- a/man/RunICA.Rd +++ b/man/RunICA.Rd @@ -9,20 +9,52 @@ \usage{ RunICA(object, ...) -\method{RunICA}{default}(object, assay = NULL, nics = 50, - rev.ica = FALSE, ica.function = "icafast", verbose = TRUE, - ndims.print = 1:5, nfeatures.print = 30, reduction.name = "ica", - reduction.key = "ica_", seed.use = 42, ...) - -\method{RunICA}{Assay}(object, assay = NULL, features = NULL, - nics = 50, rev.ica = FALSE, ica.function = "icafast", - verbose = TRUE, ndims.print = 1:5, nfeatures.print = 30, - reduction.name = "ica", reduction.key = "ica_", seed.use = 42, ...) - -\method{RunICA}{Seurat}(object, assay = NULL, features = NULL, - nics = 50, rev.ica = FALSE, ica.function = "icafast", - verbose = TRUE, ndims.print = 1:5, nfeatures.print = 30, - reduction.name = "ica", reduction.key = "IC_", seed.use = 42, ...) +\method{RunICA}{default}( + object, + assay = NULL, + nics = 50, + rev.ica = FALSE, + ica.function = "icafast", + verbose = TRUE, + ndims.print = 1:5, + nfeatures.print = 30, + reduction.name = "ica", + reduction.key = "ica_", + seed.use = 42, + ... +) + +\method{RunICA}{Assay}( + object, + assay = NULL, + features = NULL, + nics = 50, + rev.ica = FALSE, + ica.function = "icafast", + verbose = TRUE, + ndims.print = 1:5, + nfeatures.print = 30, + reduction.name = "ica", + reduction.key = "ica_", + seed.use = 42, + ... +) + +\method{RunICA}{Seurat}( + object, + assay = NULL, + features = NULL, + nics = 50, + rev.ica = FALSE, + ica.function = "icafast", + verbose = TRUE, + ndims.print = 1:5, + nfeatures.print = 30, + reduction.name = "ica", + reduction.key = "IC_", + seed.use = 42, + ... +) } \arguments{ \item{object}{Seurat object} diff --git a/man/RunLSI.Rd b/man/RunLSI.Rd index 391a59bc4..61efcaf2e 100644 --- a/man/RunLSI.Rd +++ b/man/RunLSI.Rd @@ -9,16 +9,39 @@ \usage{ RunLSI(object, ...) -\method{RunLSI}{default}(object, assay = NULL, n = 50, - reduction.key = "LSI_", scale.max = NULL, seed.use = 42, - verbose = TRUE, ...) +\method{RunLSI}{default}( + object, + assay = NULL, + n = 50, + reduction.key = "LSI_", + scale.max = NULL, + seed.use = 42, + verbose = TRUE, + ... +) -\method{RunLSI}{Assay}(object, assay = NULL, features = NULL, n = 50, - reduction.key = "LSI_", scale.max = NULL, verbose = TRUE, ...) +\method{RunLSI}{Assay}( + object, + assay = NULL, + features = NULL, + n = 50, + reduction.key = "LSI_", + scale.max = NULL, + verbose = TRUE, + ... +) -\method{RunLSI}{Seurat}(object, assay = NULL, features = NULL, - n = 50, reduction.key = "LSI_", reduction.name = "lsi", - scale.max = NULL, verbose = TRUE, ...) +\method{RunLSI}{Seurat}( + object, + assay = NULL, + features = NULL, + n = 50, + reduction.key = "LSI_", + reduction.name = "lsi", + scale.max = NULL, + verbose = TRUE, + ... +) } \arguments{ \item{object}{Seurat object} diff --git a/man/RunPCA.Rd b/man/RunPCA.Rd index d0a20d149..c5aecfb52 100644 --- a/man/RunPCA.Rd +++ b/man/RunPCA.Rd @@ -9,20 +9,51 @@ \usage{ RunPCA(object, ...) -\method{RunPCA}{default}(object, assay = NULL, npcs = 50, - rev.pca = FALSE, weight.by.var = TRUE, verbose = TRUE, - ndims.print = 1:5, nfeatures.print = 30, reduction.key = "PC_", - seed.use = 42, approx = TRUE, ...) - -\method{RunPCA}{Assay}(object, assay = NULL, features = NULL, - npcs = 50, rev.pca = FALSE, weight.by.var = TRUE, verbose = TRUE, - ndims.print = 1:5, nfeatures.print = 30, reduction.key = "PC_", - seed.use = 42, ...) - -\method{RunPCA}{Seurat}(object, assay = NULL, features = NULL, - npcs = 50, rev.pca = FALSE, weight.by.var = TRUE, verbose = TRUE, - ndims.print = 1:5, nfeatures.print = 30, reduction.name = "pca", - reduction.key = "PC_", seed.use = 42, ...) +\method{RunPCA}{default}( + object, + assay = NULL, + npcs = 50, + rev.pca = FALSE, + weight.by.var = TRUE, + verbose = TRUE, + ndims.print = 1:5, + nfeatures.print = 30, + reduction.key = "PC_", + seed.use = 42, + approx = TRUE, + ... +) + +\method{RunPCA}{Assay}( + object, + assay = NULL, + features = NULL, + npcs = 50, + rev.pca = FALSE, + weight.by.var = TRUE, + verbose = TRUE, + ndims.print = 1:5, + nfeatures.print = 30, + reduction.key = "PC_", + seed.use = 42, + ... +) + +\method{RunPCA}{Seurat}( + object, + assay = NULL, + features = NULL, + npcs = 50, + rev.pca = FALSE, + weight.by.var = TRUE, + verbose = TRUE, + ndims.print = 1:5, + nfeatures.print = 30, + reduction.name = "pca", + reduction.key = "PC_", + seed.use = 42, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/RunTSNE.Rd b/man/RunTSNE.Rd index 8da749669..34136f686 100644 --- a/man/RunTSNE.Rd +++ b/man/RunTSNE.Rd @@ -10,22 +10,55 @@ \usage{ RunTSNE(object, ...) -\method{RunTSNE}{matrix}(object, assay = NULL, seed.use = 1, - tsne.method = "Rtsne", add.iter = 0, dim.embed = 2, - reduction.key = "tSNE_", ...) - -\method{RunTSNE}{DimReduc}(object, cells = NULL, dims = 1:5, - seed.use = 1, tsne.method = "Rtsne", add.iter = 0, dim.embed = 2, - reduction.key = "tSNE_", ...) - -\method{RunTSNE}{dist}(object, assay = NULL, seed.use = 1, - tsne.method = "Rtsne", add.iter = 0, dim.embed = 2, - reduction.key = "tSNE_", ...) - -\method{RunTSNE}{Seurat}(object, reduction = "pca", cells = NULL, - dims = 1:5, features = NULL, seed.use = 1, tsne.method = "Rtsne", - add.iter = 0, dim.embed = 2, distance.matrix = NULL, - reduction.name = "tsne", reduction.key = "tSNE_", ...) +\method{RunTSNE}{matrix}( + object, + assay = NULL, + seed.use = 1, + tsne.method = "Rtsne", + add.iter = 0, + dim.embed = 2, + reduction.key = "tSNE_", + ... +) + +\method{RunTSNE}{DimReduc}( + object, + cells = NULL, + dims = 1:5, + seed.use = 1, + tsne.method = "Rtsne", + add.iter = 0, + dim.embed = 2, + reduction.key = "tSNE_", + ... +) + +\method{RunTSNE}{dist}( + object, + assay = NULL, + seed.use = 1, + tsne.method = "Rtsne", + add.iter = 0, + dim.embed = 2, + reduction.key = "tSNE_", + ... +) + +\method{RunTSNE}{Seurat}( + object, + reduction = "pca", + cells = NULL, + dims = 1:5, + features = NULL, + seed.use = 1, + tsne.method = "Rtsne", + add.iter = 0, + dim.embed = 2, + distance.matrix = NULL, + reduction.name = "tsne", + reduction.key = "tSNE_", + ... +) } \arguments{ \item{object}{Seurat object} diff --git a/man/RunUMAP.Rd b/man/RunUMAP.Rd index 8014d96ad..bab8bdc64 100644 --- a/man/RunUMAP.Rd +++ b/man/RunUMAP.Rd @@ -9,33 +9,84 @@ \usage{ RunUMAP(object, ...) -\method{RunUMAP}{default}(object, assay = NULL, umap.method = "uwot", - n.neighbors = 30L, n.components = 2L, metric = "cosine", - n.epochs = NULL, learning.rate = 1, min.dist = 0.3, spread = 1, - set.op.mix.ratio = 1, local.connectivity = 1L, - repulsion.strength = 1, negative.sample.rate = 5, a = NULL, - b = NULL, uwot.sgd = FALSE, seed.use = 42, metric.kwds = NULL, - angular.rp.forest = FALSE, reduction.key = "UMAP_", verbose = TRUE, - ...) - -\method{RunUMAP}{Graph}(object, assay = NULL, - umap.method = "umap-learn", n.components = 2L, - metric = "correlation", n.epochs = 0L, learning.rate = 1, - min.dist = 0.3, spread = 1, repulsion.strength = 1, - negative.sample.rate = 5L, a = NULL, b = NULL, uwot.sgd = FALSE, - seed.use = 42L, metric.kwds = NULL, verbose = TRUE, - reduction.key = "UMAP_", ...) - -\method{RunUMAP}{Seurat}(object, dims = NULL, reduction = "pca", - features = NULL, graph = NULL, assay = "RNA", - umap.method = "uwot", n.neighbors = 30L, n.components = 2L, - metric = "cosine", n.epochs = NULL, learning.rate = 1, - min.dist = 0.3, spread = 1, set.op.mix.ratio = 1, - local.connectivity = 1L, repulsion.strength = 1, - negative.sample.rate = 5L, a = NULL, b = NULL, uwot.sgd = FALSE, - seed.use = 42L, metric.kwds = NULL, angular.rp.forest = FALSE, - verbose = TRUE, reduction.name = "umap", reduction.key = "UMAP_", - ...) +\method{RunUMAP}{default}( + object, + assay = NULL, + umap.method = "uwot", + n.neighbors = 30L, + n.components = 2L, + metric = "cosine", + n.epochs = NULL, + learning.rate = 1, + min.dist = 0.3, + spread = 1, + set.op.mix.ratio = 1, + local.connectivity = 1L, + repulsion.strength = 1, + negative.sample.rate = 5, + a = NULL, + b = NULL, + uwot.sgd = FALSE, + seed.use = 42, + metric.kwds = NULL, + angular.rp.forest = FALSE, + reduction.key = "UMAP_", + verbose = TRUE, + ... +) + +\method{RunUMAP}{Graph}( + object, + assay = NULL, + umap.method = "umap-learn", + n.components = 2L, + metric = "correlation", + n.epochs = 0L, + learning.rate = 1, + min.dist = 0.3, + spread = 1, + repulsion.strength = 1, + negative.sample.rate = 5L, + a = NULL, + b = NULL, + uwot.sgd = FALSE, + seed.use = 42L, + metric.kwds = NULL, + verbose = TRUE, + reduction.key = "UMAP_", + ... +) + +\method{RunUMAP}{Seurat}( + object, + dims = NULL, + reduction = "pca", + features = NULL, + graph = NULL, + assay = "RNA", + umap.method = "uwot", + n.neighbors = 30L, + n.components = 2L, + metric = "cosine", + n.epochs = NULL, + learning.rate = 1, + min.dist = 0.3, + spread = 1, + set.op.mix.ratio = 1, + local.connectivity = 1L, + repulsion.strength = 1, + negative.sample.rate = 5L, + a = NULL, + b = NULL, + uwot.sgd = FALSE, + seed.use = 42L, + metric.kwds = NULL, + angular.rp.forest = FALSE, + verbose = TRUE, + reduction.name = "umap", + reduction.key = "UMAP_", + ... +) } \arguments{ \item{object}{An object} diff --git a/man/SCTransform.Rd b/man/SCTransform.Rd index c06c21394..03a211e2c 100644 --- a/man/SCTransform.Rd +++ b/man/SCTransform.Rd @@ -4,13 +4,25 @@ \alias{SCTransform} \title{Use regularized negative binomial regression to normalize UMI count data} \usage{ -SCTransform(object, assay = "RNA", new.assay.name = "SCT", - do.correct.umi = TRUE, ncells = NULL, variable.features.n = 3000, - variable.features.rv.th = 1.3, vars.to.regress = NULL, - do.scale = FALSE, do.center = TRUE, clip.range = c(-sqrt(x = ncol(x - = object[[assay]])/30), sqrt(x = ncol(x = object[[assay]])/30)), - conserve.memory = FALSE, return.only.var.genes = TRUE, - seed.use = 1448145, verbose = TRUE, ...) +SCTransform( + object, + assay = "RNA", + new.assay.name = "SCT", + do.correct.umi = TRUE, + ncells = NULL, + variable.features.n = 3000, + variable.features.rv.th = 1.3, + vars.to.regress = NULL, + do.scale = FALSE, + do.center = TRUE, + clip.range = c(-sqrt(x = ncol(x = object[[assay]])/30), sqrt(x = ncol(x = + object[[assay]])/30)), + conserve.memory = FALSE, + return.only.var.genes = TRUE, + seed.use = 1448145, + verbose = TRUE, + ... +) } \arguments{ \item{object}{A seurat object} diff --git a/man/ScaleData.Rd b/man/ScaleData.Rd index 8b311d755..d39e0791c 100644 --- a/man/ScaleData.Rd +++ b/man/ScaleData.Rd @@ -9,23 +9,56 @@ \usage{ ScaleData(object, ...) -\method{ScaleData}{default}(object, features = NULL, - vars.to.regress = NULL, latent.data = NULL, split.by = NULL, - model.use = "linear", use.umi = FALSE, do.scale = TRUE, - do.center = TRUE, scale.max = 10, block.size = 1000, - min.cells.to.block = 3000, verbose = TRUE, ...) - -\method{ScaleData}{Assay}(object, features = NULL, - vars.to.regress = NULL, latent.data = NULL, split.by = NULL, - model.use = "linear", use.umi = FALSE, do.scale = TRUE, - do.center = TRUE, scale.max = 10, block.size = 1000, - min.cells.to.block = 3000, verbose = TRUE, ...) - -\method{ScaleData}{Seurat}(object, features = NULL, assay = NULL, - vars.to.regress = NULL, split.by = NULL, model.use = "linear", - use.umi = FALSE, do.scale = TRUE, do.center = TRUE, - scale.max = 10, block.size = 1000, min.cells.to.block = 3000, - verbose = TRUE, ...) +\method{ScaleData}{default}( + object, + features = NULL, + vars.to.regress = NULL, + latent.data = NULL, + split.by = NULL, + model.use = "linear", + use.umi = FALSE, + do.scale = TRUE, + do.center = TRUE, + scale.max = 10, + block.size = 1000, + min.cells.to.block = 3000, + verbose = TRUE, + ... +) + +\method{ScaleData}{Assay}( + object, + features = NULL, + vars.to.regress = NULL, + latent.data = NULL, + split.by = NULL, + model.use = "linear", + use.umi = FALSE, + do.scale = TRUE, + do.center = TRUE, + scale.max = 10, + block.size = 1000, + min.cells.to.block = 3000, + verbose = TRUE, + ... +) + +\method{ScaleData}{Seurat}( + object, + features = NULL, + assay = NULL, + vars.to.regress = NULL, + split.by = NULL, + model.use = "linear", + use.umi = FALSE, + do.scale = TRUE, + do.center = TRUE, + scale.max = 10, + block.size = 1000, + min.cells.to.block = 3000, + verbose = TRUE, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/ScoreJackStraw.Rd b/man/ScoreJackStraw.Rd index 1cf1713cf..5be895815 100644 --- a/man/ScoreJackStraw.Rd +++ b/man/ScoreJackStraw.Rd @@ -9,14 +9,18 @@ \usage{ ScoreJackStraw(object, ...) -\method{ScoreJackStraw}{JackStrawData}(object, dims = 1:5, - score.thresh = 1e-05, ...) - -\method{ScoreJackStraw}{DimReduc}(object, dims = 1:5, - score.thresh = 1e-05, ...) - -\method{ScoreJackStraw}{Seurat}(object, reduction = "pca", dims = 1:5, - score.thresh = 1e-05, do.plot = FALSE, ...) +\method{ScoreJackStraw}{JackStrawData}(object, dims = 1:5, score.thresh = 1e-05, ...) + +\method{ScoreJackStraw}{DimReduc}(object, dims = 1:5, score.thresh = 1e-05, ...) + +\method{ScoreJackStraw}{Seurat}( + object, + reduction = "pca", + dims = 1:5, + score.thresh = 1e-05, + do.plot = FALSE, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/SelectIntegrationFeatures.Rd b/man/SelectIntegrationFeatures.Rd index 6dac1227e..1ecaf2f2b 100644 --- a/man/SelectIntegrationFeatures.Rd +++ b/man/SelectIntegrationFeatures.Rd @@ -4,8 +4,14 @@ \alias{SelectIntegrationFeatures} \title{Select integration features} \usage{ -SelectIntegrationFeatures(object.list, nfeatures = 2000, assay = NULL, - verbose = TRUE, fvf.nfeatures = 2000, ...) +SelectIntegrationFeatures( + object.list, + nfeatures = 2000, + assay = NULL, + verbose = TRUE, + fvf.nfeatures = 2000, + ... +) } \arguments{ \item{object.list}{List of seurat objects} diff --git a/man/SetAssayData.Rd b/man/SetAssayData.Rd index c2d7c4a0f..cdff1a931 100644 --- a/man/SetAssayData.Rd +++ b/man/SetAssayData.Rd @@ -10,8 +10,7 @@ SetAssayData(object, ...) \method{SetAssayData}{Assay}(object, slot, new.data, ...) -\method{SetAssayData}{Seurat}(object, slot = "data", new.data, - assay = NULL, ...) +\method{SetAssayData}{Seurat}(object, slot = "data", new.data, assay = NULL, ...) } \arguments{ \item{object}{An object} diff --git a/man/SeuratTheme.Rd b/man/SeuratTheme.Rd index 5e9a62606..b4169a400 100644 --- a/man/SeuratTheme.Rd +++ b/man/SeuratTheme.Rd @@ -19,8 +19,14 @@ SeuratTheme() DarkTheme(...) -FontSize(x.text = NULL, y.text = NULL, x.title = NULL, - y.title = NULL, main = NULL, ...) +FontSize( + x.text = NULL, + y.text = NULL, + x.title = NULL, + y.title = NULL, + main = NULL, + ... +) NoAxes(..., keep.text = FALSE, keep.ticks = FALSE) diff --git a/man/SubsetData.Rd b/man/SubsetData.Rd index 10d427f89..a590bf6c8 100644 --- a/man/SubsetData.Rd +++ b/man/SubsetData.Rd @@ -8,14 +8,30 @@ \usage{ SubsetData(object, ...) -\method{SubsetData}{Assay}(object, cells = NULL, subset.name = NULL, - low.threshold = -Inf, high.threshold = Inf, accept.value = NULL, - ...) +\method{SubsetData}{Assay}( + object, + cells = NULL, + subset.name = NULL, + low.threshold = -Inf, + high.threshold = Inf, + accept.value = NULL, + ... +) -\method{SubsetData}{Seurat}(object, assay = NULL, cells = NULL, - subset.name = NULL, ident.use = NULL, ident.remove = NULL, - low.threshold = -Inf, high.threshold = Inf, accept.value = NULL, - max.cells.per.ident = Inf, random.seed = 1, ...) +\method{SubsetData}{Seurat}( + object, + assay = NULL, + cells = NULL, + subset.name = NULL, + ident.use = NULL, + ident.remove = NULL, + low.threshold = -Inf, + high.threshold = Inf, + accept.value = NULL, + max.cells.per.ident = Inf, + random.seed = 1, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/TopFeatures.Rd b/man/TopFeatures.Rd index 036bf57ef..52319b479 100644 --- a/man/TopFeatures.Rd +++ b/man/TopFeatures.Rd @@ -4,8 +4,14 @@ \alias{TopFeatures} \title{Find features with highest scores for a given dimensional reduction technique} \usage{ -TopFeatures(object, dim = 1, nfeatures = 20, projected = FALSE, - balanced = FALSE, ...) +TopFeatures( + object, + dim = 1, + nfeatures = 20, + projected = FALSE, + balanced = FALSE, + ... +) } \arguments{ \item{object}{DimReduc object} diff --git a/man/TransferData.Rd b/man/TransferData.Rd index d6b5af28e..1388696f9 100644 --- a/man/TransferData.Rd +++ b/man/TransferData.Rd @@ -4,9 +4,19 @@ \alias{TransferData} \title{Transfer Labels} \usage{ -TransferData(anchorset, refdata, weight.reduction = "pcaproject", - l2.norm = FALSE, dims = 1:30, k.weight = 50, sd.weight = 1, - eps = 0, do.cpp = TRUE, verbose = TRUE, slot = "data") +TransferData( + anchorset, + refdata, + weight.reduction = "pcaproject", + l2.norm = FALSE, + dims = 1:30, + k.weight = 50, + sd.weight = 1, + eps = 0, + do.cpp = TRUE, + verbose = TRUE, + slot = "data" +) } \arguments{ \item{anchorset}{Results from FindTransferAnchors} diff --git a/man/UpdateSymbolList.Rd b/man/UpdateSymbolList.Rd index 58d378599..aca1e2339 100644 --- a/man/UpdateSymbolList.Rd +++ b/man/UpdateSymbolList.Rd @@ -8,11 +8,21 @@ \url{https://www.genenames.org/} \url{http://rest.genenames.org/} } \usage{ -GeneSymbolThesarus(symbols, timeout = 10, several.ok = FALSE, - verbose = TRUE, ...) +GeneSymbolThesarus( + symbols, + timeout = 10, + several.ok = FALSE, + verbose = TRUE, + ... +) -UpdateSymbolList(symbols, timeout = 10, several.ok = FALSE, - verbose = TRUE, ...) +UpdateSymbolList( + symbols, + timeout = 10, + several.ok = FALSE, + verbose = TRUE, + ... +) } \arguments{ \item{symbols}{A vector of gene symbols} diff --git a/man/VariableFeaturePlot.Rd b/man/VariableFeaturePlot.Rd index fbb419045..08f15ae1a 100644 --- a/man/VariableFeaturePlot.Rd +++ b/man/VariableFeaturePlot.Rd @@ -6,8 +6,14 @@ \alias{MeanVarPlot} \title{View variable features} \usage{ -VariableFeaturePlot(object, cols = c("black", "red"), pt.size = 1, - log = NULL, selection.method = NULL, assay = NULL) +VariableFeaturePlot( + object, + cols = c("black", "red"), + pt.size = 1, + log = NULL, + selection.method = NULL, + assay = NULL +) } \arguments{ \item{object}{Seurat object} diff --git a/man/VariableFeatures.Rd b/man/VariableFeatures.Rd index f42a1da34..064e84923 100644 --- a/man/VariableFeatures.Rd +++ b/man/VariableFeatures.Rd @@ -15,8 +15,7 @@ VariableFeatures(object, ...) <- value \method{VariableFeatures}{Assay}(object, selection.method = NULL, ...) -\method{VariableFeatures}{Seurat}(object, assay = NULL, - selection.method = NULL, ...) +\method{VariableFeatures}{Seurat}(object, assay = NULL, selection.method = NULL, ...) \method{VariableFeatures}{Assay}(object, ...) <- value diff --git a/man/VizDimLoadings.Rd b/man/VizDimLoadings.Rd index b71d4a4ea..e8111c48d 100644 --- a/man/VizDimLoadings.Rd +++ b/man/VizDimLoadings.Rd @@ -4,9 +4,17 @@ \alias{VizDimLoadings} \title{Visualize Dimensional Reduction genes} \usage{ -VizDimLoadings(object, dims = 1:5, nfeatures = 30, col = "blue", - reduction = "pca", projected = FALSE, balanced = FALSE, - ncol = NULL, combine = TRUE) +VizDimLoadings( + object, + dims = 1:5, + nfeatures = 30, + col = "blue", + reduction = "pca", + projected = FALSE, + balanced = FALSE, + ncol = NULL, + combine = TRUE +) } \arguments{ \item{object}{Seurat object} diff --git a/man/VlnPlot.Rd b/man/VlnPlot.Rd index b3054f41d..4d221d21b 100644 --- a/man/VlnPlot.Rd +++ b/man/VlnPlot.Rd @@ -4,10 +4,25 @@ \alias{VlnPlot} \title{Single cell violin plot} \usage{ -VlnPlot(object, features, cols = NULL, pt.size = 1, idents = NULL, - sort = FALSE, assay = NULL, group.by = NULL, split.by = NULL, - adjust = 1, y.max = NULL, same.y.lims = FALSE, log = FALSE, - ncol = NULL, combine = TRUE, slot = "data", ...) +VlnPlot( + object, + features, + cols = NULL, + pt.size = 1, + idents = NULL, + sort = FALSE, + assay = NULL, + group.by = NULL, + split.by = NULL, + adjust = 1, + y.max = NULL, + same.y.lims = FALSE, + log = FALSE, + ncol = NULL, + combine = TRUE, + slot = "data", + ... +) } \arguments{ \item{object}{Seurat object} diff --git a/man/WhichCells.Rd b/man/WhichCells.Rd index bd5508239..1ffbde70d 100644 --- a/man/WhichCells.Rd +++ b/man/WhichCells.Rd @@ -8,12 +8,19 @@ \usage{ WhichCells(object, ...) -\method{WhichCells}{Assay}(object, cells = NULL, expression, - invert = FALSE, ...) +\method{WhichCells}{Assay}(object, cells = NULL, expression, invert = FALSE, ...) -\method{WhichCells}{Seurat}(object, cells = NULL, idents = NULL, - expression, slot = "data", invert = FALSE, downsample = Inf, - seed = 1, ...) +\method{WhichCells}{Seurat}( + object, + cells = NULL, + idents = NULL, + expression, + slot = "data", + invert = FALSE, + downsample = Inf, + seed = 1, + ... +) } \arguments{ \item{object}{An object} diff --git a/man/as.Seurat.Rd b/man/as.Seurat.Rd index 1370538e0..247bad39c 100644 --- a/man/as.Seurat.Rd +++ b/man/as.Seurat.Rd @@ -9,16 +9,27 @@ \usage{ as.Seurat(x, ...) -\method{as.Seurat}{CellDataSet}(x, slot = "counts", assay = "RNA", - verbose = TRUE, ...) +\method{as.Seurat}{CellDataSet}(x, slot = "counts", assay = "RNA", verbose = TRUE, ...) -\method{as.Seurat}{loom}(x, cells = "CellID", features = "Gene", - normalized = NULL, scaled = NULL, assay = NULL, verbose = TRUE, - ...) +\method{as.Seurat}{loom}( + x, + cells = "CellID", + features = "Gene", + normalized = NULL, + scaled = NULL, + assay = NULL, + verbose = TRUE, + ... +) -\method{as.Seurat}{SingleCellExperiment}(x, counts = "counts", - data = "logcounts", assay = "RNA", - project = "SingleCellExperiment", ...) +\method{as.Seurat}{SingleCellExperiment}( + x, + counts = "counts", + data = "logcounts", + assay = "RNA", + project = "SingleCellExperiment", + ... +) } \arguments{ \item{x}{An object to convert to class \code{Seurat}} diff --git a/man/as.loom.Rd b/man/as.loom.Rd index 717bab7bd..e4fb73445 100644 --- a/man/as.loom.Rd +++ b/man/as.loom.Rd @@ -7,30 +7,30 @@ \usage{ as.loom(x, ...) -\method{as.loom}{Seurat}(x, assay = NULL, filename = file.path(getwd(), - paste0(Project(object = x), ".loom")), max.size = "400mb", - chunk.dims = NULL, chunk.size = NULL, overwrite = FALSE, - verbose = TRUE, ...) +\method{as.loom}{Seurat}( + x, + assay = NULL, + filename = file.path(getwd(), paste0(Project(object = x), ".loom")), + max.size = "400mb", + chunk.dims = NULL, + chunk.size = NULL, + overwrite = FALSE, + verbose = TRUE, + ... +) } \arguments{ \item{x}{An object to convert to class \code{loom}} -\item{...}{Ignored for now} - \item{assay}{Assay to store in loom file} \item{filename}{The name of the new loom file} -\item{max.size}{Set maximum chunk size in terms of memory usage, unused if \code{chunk.dims} is set; -may pass a character string (eg. \code{3gb}, \code{1200mb}) or exact value in bytes} - -\item{chunk.dims}{Matrix chunk dimensions; auto-determined by default} +\item{chunk.dims}{A one- or two-length integer vector of chunksizes for \code{/matrix}, defaults to 'auto' to automatically determine chunksize} -\item{chunk.size}{Maximum number of cells read/written to disk at once; auto-determined by default} +\item{chunk.size}{How many rows of \code{data} should we stream to the loom file at any given time?} \item{overwrite}{Overwrite an already existing loom file?} - -\item{verbose}{Display a progress bar} } \description{ Convert objects to loom objects diff --git a/man/as.sparse.Rd b/man/as.sparse.Rd index 4b129a335..ec299c8af 100644 --- a/man/as.sparse.Rd +++ b/man/as.sparse.Rd @@ -19,8 +19,13 @@ as.sparse(x, ...) \method{as.sparse}{matrix}(x, ...) -\method{as.data.frame}{Matrix}(x, row.names = NULL, optional = FALSE, - ..., stringsAsFactors = default.stringsAsFactors()) +\method{as.data.frame}{Matrix}( + x, + row.names = NULL, + optional = FALSE, + ..., + stringsAsFactors = default.stringsAsFactors() +) } \arguments{ \item{x}{An object} @@ -32,10 +37,10 @@ as.sparse(x, ...) \item{optional}{logical. If \code{TRUE}, setting row names and converting column names (to syntactic names: see - \code{\link{make.names}}) is optional. Note that all of \R's + \code{\link[base]{make.names}}) is optional. Note that all of \R's \pkg{base} package \code{as.data.frame()} methods use \code{optional} only for column names treatment, basically with the - meaning of \code{\link{data.frame}(*, check.names = !optional)}. + meaning of \code{\link[base]{data.frame}(*, check.names = !optional)}. See also the \code{make.names} argument of the \code{matrix} method.} \item{stringsAsFactors}{logical: should the character vector be converted diff --git a/man/h5ad.Rd b/man/h5ad.Rd index 4b3a980ab..2194fc6f7 100644 --- a/man/h5ad.Rd +++ b/man/h5ad.Rd @@ -12,14 +12,19 @@ ReadH5AD(file, ...) WriteH5AD(object, ...) -\method{ReadH5AD}{character}(file, assay = "RNA", layers = "data", - verbose = TRUE, ...) +\method{ReadH5AD}{character}(file, assay = "RNA", layers = "data", verbose = TRUE, ...) -\method{ReadH5AD}{H5File}(file, assay = "RNA", layers = "data", - verbose = TRUE, ...) +\method{ReadH5AD}{H5File}(file, assay = "RNA", layers = "data", verbose = TRUE, ...) -\method{WriteH5AD}{Seurat}(object, file, assay = NULL, graph = NULL, - verbose = TRUE, overwrite = FALSE, ...) +\method{WriteH5AD}{Seurat}( + object, + file, + assay = NULL, + graph = NULL, + verbose = TRUE, + overwrite = FALSE, + ... +) } \arguments{ \item{file}{Name of h5ad file, or an H5File object for reading in} diff --git a/man/merge.Seurat.Rd b/man/merge.Seurat.Rd index c57d303b1..7c003b9e0 100644 --- a/man/merge.Seurat.Rd +++ b/man/merge.Seurat.Rd @@ -8,11 +8,16 @@ \alias{AddSamples} \title{Merge Seurat Objects} \usage{ -\method{merge}{Assay}(x = NULL, y = NULL, add.cell.ids = NULL, - merge.data = TRUE, ...) +\method{merge}{Assay}(x = NULL, y = NULL, add.cell.ids = NULL, merge.data = TRUE, ...) -\method{merge}{Seurat}(x = NULL, y = NULL, add.cell.ids = NULL, - merge.data = TRUE, project = "SeuratProject", ...) +\method{merge}{Seurat}( + x = NULL, + y = NULL, + add.cell.ids = NULL, + merge.data = TRUE, + project = "SeuratProject", + ... +) } \arguments{ \item{x}{Object} diff --git a/man/print.DimReduc.Rd b/man/print.DimReduc.Rd index 8f622d7f9..7415ef9c3 100644 --- a/man/print.DimReduc.Rd +++ b/man/print.DimReduc.Rd @@ -5,8 +5,7 @@ \alias{print} \title{Print the results of a dimensional reduction analysis} \usage{ -\method{print}{DimReduc}(x, dims = 1:5, nfeatures = 20, - projected = FALSE, ...) +\method{print}{DimReduc}(x, dims = 1:5, nfeatures = 20, projected = FALSE, ...) } \arguments{ \item{x}{An object} diff --git a/man/subset.Seurat.Rd b/man/subset.Seurat.Rd index bbc07badd..403ac8397 100644 --- a/man/subset.Seurat.Rd +++ b/man/subset.Seurat.Rd @@ -8,8 +8,7 @@ \usage{ \method{[}{Seurat}(x, i, j, ...) -\method{subset}{Seurat}(x, subset, cells = NULL, features = NULL, - idents = NULL, ...) +\method{subset}{Seurat}(x, subset, cells = NULL, features = NULL, idents = NULL, ...) } \arguments{ \item{x}{Seurat object to be subsetted} From 9b1cbd84464c0ad1bb85455b3406fc717fbb783f Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Thu, 5 Dec 2019 12:40:14 -0500 Subject: [PATCH 68/83] Update NEWS with additions/changes for v3.1.2 --- NEWS.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/NEWS.md b/NEWS.md index 4936c1d6d..412d35e14 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,17 @@ All notable changes to Seurat will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +## [3.1.2] - 2019-12-11 +### Added +- New silent slot updater +- New random seed options to `RunCCA`, `RunTSNE`, `WhichCells`, `HTODemux`, `AddModuleScore`, `VlnPlot`, and `RidgePlot` +- Enhancements for dealing with `Assay`-derived objects + +### Changed +- Only run `CalcN` (generates nFeatures and nCounts) when `counts` changes +- Fix issue regarding colons in feature names +- Change object class testing to use `inherits` or `is.*` for R 4.0 compatability + ## [3.1.1] - 2019-09-20 ### Added - New `RegroupIdents` function to reassign idents based on metadata column majority From a195b2287ac2863bf65826f1d57a05bcccb39818 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Thu, 5 Dec 2019 12:41:03 -0500 Subject: [PATCH 69/83] Update README version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 340161254..0e6576d59 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![CRAN Version](https://www.r-pkg.org/badges/version/Seurat)](https://cran.r-project.org/package=Seurat) [![CRAN Downloads](https://cranlogs.r-pkg.org/badges/Seurat)](https://cran.r-project.org/package=Seurat) -# Seurat v3.1.1 +# Seurat v3.1.2 Seurat is an R toolkit for single cell genomics, developed and maintained by the Satija Lab at NYGC. From 7206c1d695f11ea62d65e8d469f43fec244add32 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Thu, 5 Dec 2019 14:28:13 -0500 Subject: [PATCH 70/83] Export CellsByIdentities Also add new idents parameter to limit resulting vector --- R/objects.R | 69 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/R/objects.R b/R/objects.R index a32128669..05f3c25d1 100644 --- a/R/objects.R +++ b/R/objects.R @@ -368,6 +368,46 @@ Assays <- function(object, slot = NULL) { return(slot(object = object, name = 'assays')[[slot]]) } +#' Get cell names grouped by identity class +#' +#' @param object A Seurat object +#' @param idents A vector of identity class levels to limit resulting list to; +#' defaults to all identity class levels +#' @param cells A vector of cells to grouping to +#' +#' @return A named list where names are identity classes and values are vectors +#' of cells beloning to that class +#' +#' @export +#' +#' @examples +#' CellsByIdentities(object = pbmc_small) +#' +CellsByIdentities <- function(object, idents = NULL, cells = NULL) { + cells <- cells %||% colnames(x = object) + cells <- intersect(x = cells, y = colnames(x = object)) + if (length(x = cells) == 0) { + stop("Cannot find cells provided") + } + idents <- idents %||% levels(x = object) + idents <- intersect(x = idents, y = levels(x = object)) + if (length(x = idents) == 0) { + stop("None of the provided identity class levels were found", call. = FALSE) + } + cells.idents <- sapply( + X = idents, + FUN = function(i) { + return(cells[as.vector(x = Idents(object = object)[cells]) == i]) + }, + simplify = FALSE, + USE.NAMES = TRUE + ) + if (any(is.na(x = Idents(object = object)[cells]))) { + cells.idents["NA"] <- names(x = which(x = is.na(x = Idents(object = object)[cells]))) + } + return(cells.idents) +} + #' Create an Assay object #' #' Create an Assay object from a feature (e.g. gene) expression matrix. The @@ -6662,35 +6702,6 @@ CalcN <- function(object) { )) } -# Get cell names grouped by identity class -# -# @param object A Seurat object -# @param cells A vector of cells to grouping to -# -# @return A named list where names are identity classes and values are vectors -# of cells beloning to that class -# -CellsByIdentities <- function(object, cells = NULL) { - cells <- cells %||% colnames(x = object) - cells <- intersect(x = cells, y = colnames(x = object)) - if (length(x = cells) == 0) { - stop("Cannot find cells provided") - } - idents <- levels(x = object) - cells.idents <- sapply( - X = idents, - FUN = function(i) { - return(cells[as.vector(x = Idents(object = object)[cells]) == i]) - }, - simplify = FALSE, - USE.NAMES = TRUE - ) - if (any(is.na(x = Idents(object = object)[cells]))) { - cells.idents["NA"] <- names(x = which(x = is.na(x = Idents(object = object)[cells]))) - } - return(cells.idents) -} - # Get the names of objects within a Seurat object that are of a certain class # # @param object A Seurat object From 5b2a1ab8a6a82455d900edaedfdc4db9272cb045 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Fri, 6 Dec 2019 11:11:58 -0500 Subject: [PATCH 71/83] Export RowMergeSparseMatrices --- NAMESPACE | 1 + R/utilities.R | 23 ++++++++++++++++------- man/RowMergeSparseMatrices.Rd | 27 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 man/RowMergeSparseMatrices.Rd diff --git a/NAMESPACE b/NAMESPACE index a6585a3f6..da934d8f0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -279,6 +279,7 @@ export(ReorderIdent) export(RestoreLegend) export(RidgePlot) export(RotatedAxis) +export(RowMergeSparseMatrices) export(RunALRA) export(RunCCA) export(RunICA) diff --git a/R/utilities.R b/R/utilities.R index 1f36e1a60..69deb5f55 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -1820,13 +1820,22 @@ RandomName <- function(length = 5L, ...) { return(paste(sample(x = letters, size = length, ...), collapse = '')) } -# Internal function for merging two matrices by rowname -# -# @param mat1 First matrix -# @param mat2 Second matrix -# -# @return A merged matrix -# +#' Merge two matrices by rowname +#' +#' This function is for use on sparse matrices and +#' should not be run on a Seurat object. +#' +#' Shared matrix rows (with the same row name) will be merged, +#' and unshared rows (with different names) will be filled +#' with zeros in the matrix not containing the row. +#' +#' @param mat1 First matrix +#' @param mat2 Second matrix +#' +#' @return A merged matrix +#' @export +#' @return Returns a sparse matrix +#' #' @importFrom methods as # RowMergeSparseMatrices <- function(mat1, mat2){ diff --git a/man/RowMergeSparseMatrices.Rd b/man/RowMergeSparseMatrices.Rd new file mode 100644 index 000000000..3bab2d31f --- /dev/null +++ b/man/RowMergeSparseMatrices.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utilities.R +\name{RowMergeSparseMatrices} +\alias{RowMergeSparseMatrices} +\title{Merge two matrices by rowname} +\usage{ +RowMergeSparseMatrices(mat1, mat2) +} +\arguments{ +\item{mat1}{First matrix} + +\item{mat2}{Second matrix} +} +\value{ +A merged matrix + +Returns a sparse matrix +} +\description{ +This function is for use on sparse matrices and +should not be run on a Seurat object. +} +\details{ +Shared matrix rows (with the same row name) will be merged, +and unshared rows (with different names) will be filled +with zeros in the matrix not containing the row. +} From 038d5482a92615da7b3b7be06d8d8581f3d31182 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Fri, 6 Dec 2019 11:51:31 -0500 Subject: [PATCH 72/83] Fix code sorting --- R/utilities.R | 100 +++++++++++++++++++++++++------------------------- 1 file changed, 51 insertions(+), 49 deletions(-) diff --git a/R/utilities.R b/R/utilities.R index 69deb5f55..a52977b2e 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -1147,6 +1147,57 @@ RegroupIdents <- function(object, metadata) { return(object) } +#' Merge two matrices by rowname +#' +#' This function is for use on sparse matrices and +#' should not be run on a Seurat object. +#' +#' Shared matrix rows (with the same row name) will be merged, +#' and unshared rows (with different names) will be filled +#' with zeros in the matrix not containing the row. +#' +#' @param mat1 First matrix +#' @param mat2 Second matrix +#' +#' @return A merged matrix +#' +#' @return Returns a sparse matrix +#' +#' @importFrom methods as +# +#' @export +#' +RowMergeSparseMatrices <- function(mat1, mat2){ + if (inherits(x = mat1, what = "data.frame")) { + mat1 <- as.matrix(x = mat1) + } + if (inherits(x = mat2, what = "data.frame")) { + mat2 <- as.matrix(x = mat2) + } + mat1.names <- rownames(x = mat1) + mat2.names <- rownames(x = mat2) + if (length(x = mat1.names) == length(x = mat2.names) && all(mat1.names == mat2.names)) { + new.mat <- cbind(mat1, mat2) + } else { + mat1 <- as(object = mat1, Class = "RsparseMatrix") + mat2 <- as(object = mat2, Class = "RsparseMatrix") + all.names <- union(x = mat1.names, y = mat2.names) + new.mat <- RowMergeMatrices( + mat1 = mat1, + mat2 = mat2, + mat1_rownames = mat1.names, + mat2_rownames = mat2.names, + all_rownames = all.names + ) + rownames(x = new.mat) <- make.unique(names = all.names) + } + colnames(x = new.mat) <- make.unique(names = c( + colnames(x = mat1), + colnames(x = mat2) + )) + return(new.mat) +} + #' Stop Cellbrowser web server #' #' @importFrom reticulate py_module_available @@ -1820,55 +1871,6 @@ RandomName <- function(length = 5L, ...) { return(paste(sample(x = letters, size = length, ...), collapse = '')) } -#' Merge two matrices by rowname -#' -#' This function is for use on sparse matrices and -#' should not be run on a Seurat object. -#' -#' Shared matrix rows (with the same row name) will be merged, -#' and unshared rows (with different names) will be filled -#' with zeros in the matrix not containing the row. -#' -#' @param mat1 First matrix -#' @param mat2 Second matrix -#' -#' @return A merged matrix -#' @export -#' @return Returns a sparse matrix -#' -#' @importFrom methods as -# -RowMergeSparseMatrices <- function(mat1, mat2){ - if (inherits(x = mat1, what = "data.frame")) { - mat1 <- as.matrix(x = mat1) - } - if (inherits(x = mat2, what = "data.frame")) { - mat2 <- as.matrix(x = mat2) - } - mat1.names <- rownames(x = mat1) - mat2.names <- rownames(x = mat2) - if (length(x = mat1.names) == length(x = mat2.names) && all(mat1.names == mat2.names)) { - new.mat <- cbind(mat1, mat2) - } else { - mat1 <- as(object = mat1, Class = "RsparseMatrix") - mat2 <- as(object = mat2, Class = "RsparseMatrix") - all.names <- union(x = mat1.names, y = mat2.names) - new.mat <- RowMergeMatrices( - mat1 = mat1, - mat2 = mat2, - mat1_rownames = mat1.names, - mat2_rownames = mat2.names, - all_rownames = all.names - ) - rownames(x = new.mat) <- make.unique(names = all.names) - } - colnames(x = new.mat) <- make.unique(names = c( - colnames(x = mat1), - colnames(x = mat2) - )) - return(new.mat) -} - # Return what was passed # # @param x anything From beafbca0b12e5d25e10c771707bd83a6c50c1b0b Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Mon, 9 Dec 2019 09:59:18 -0500 Subject: [PATCH 73/83] Update docs for RunPCA --- R/dimensional_reduction.R | 4 +++- man/RunPCA.Rd | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/R/dimensional_reduction.R b/R/dimensional_reduction.R index 9a0ffad67..69de120a6 100644 --- a/R/dimensional_reduction.R +++ b/R/dimensional_reduction.R @@ -862,7 +862,9 @@ RunPCA.default <- function( } #' @param features Features to compute PCA on. If features=NULL, PCA will be run -#' using the variable features for the Assay. +#' using the variable features for the Assay. Note that the features must be present +#' the scaled data. Any requested features that are not scaled will be dropped, and +#' the PCA will be run using the remaining features. #' #' @rdname RunPCA #' @export diff --git a/man/RunPCA.Rd b/man/RunPCA.Rd index d0a20d149..912e493df 100644 --- a/man/RunPCA.Rd +++ b/man/RunPCA.Rd @@ -55,7 +55,9 @@ NULL will not set a seed.} \item{approx}{Use truncated singular value decomposition to approximate PCA} \item{features}{Features to compute PCA on. If features=NULL, PCA will be run -using the variable features for the Assay.} +using the variable features for the Assay. Note that the features must be present +the scaled data. Any requested features that are not scaled will be dropped, and +the PCA will be run using the remaining features.} \item{reduction.name}{dimensional reduction name, pca by default} } From 166ce1c626fb4f85e5e8fb43271ac5f4ee1bbc14 Mon Sep 17 00:00:00 2001 From: timoast <4591688+timoast@users.noreply.github.com> Date: Mon, 9 Dec 2019 10:42:53 -0500 Subject: [PATCH 74/83] Fix typo --- R/dimensional_reduction.R | 4 ++-- man/RunPCA.Rd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/dimensional_reduction.R b/R/dimensional_reduction.R index 69de120a6..f6c9aa043 100644 --- a/R/dimensional_reduction.R +++ b/R/dimensional_reduction.R @@ -863,8 +863,8 @@ RunPCA.default <- function( #' @param features Features to compute PCA on. If features=NULL, PCA will be run #' using the variable features for the Assay. Note that the features must be present -#' the scaled data. Any requested features that are not scaled will be dropped, and -#' the PCA will be run using the remaining features. +#' in the scaled data. Any requested features that are not scaled or have 0 variance +#' will be dropped, and the PCA will be run using the remaining features. #' #' @rdname RunPCA #' @export diff --git a/man/RunPCA.Rd b/man/RunPCA.Rd index 912e493df..f4d9bba56 100644 --- a/man/RunPCA.Rd +++ b/man/RunPCA.Rd @@ -56,8 +56,8 @@ NULL will not set a seed.} \item{features}{Features to compute PCA on. If features=NULL, PCA will be run using the variable features for the Assay. Note that the features must be present -the scaled data. Any requested features that are not scaled will be dropped, and -the PCA will be run using the remaining features.} +in the scaled data. Any requested features that are not scaled or have 0 variance +will be dropped, and the PCA will be run using the remaining features.} \item{reduction.name}{dimensional reduction name, pca by default} } From 328f5c33bea8af3c6c29cd3d1e794739e1831254 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Tue, 10 Dec 2019 11:28:39 -0500 Subject: [PATCH 75/83] Only run make.names when value != NULL --- R/objects.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/objects.R b/R/objects.R index 6a9f7e30b..0022accec 100644 --- a/R/objects.R +++ b/R/objects.R @@ -6137,7 +6137,11 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes } } # remove disallowed characters from object name - newi <- make.names(names = i) + newi <- if (is.null(x = value)) { + i + } else { + make.names(names = i) + } if (i != newi) { warning( "Invalid name supplied, making object name syntactically valid. New object name is ", From 14487740bfc8cc7d92c44045b2b67dfd059f7444 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Tue, 10 Dec 2019 11:30:57 -0500 Subject: [PATCH 76/83] Handle(ish) multiple objects being added at once --- R/objects.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/objects.R b/R/objects.R index 0022accec..4f56d70a0 100644 --- a/R/objects.R +++ b/R/objects.R @@ -6142,7 +6142,7 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes } else { make.names(names = i) } - if (i != newi) { + if (any(i != newi)) { warning( "Invalid name supplied, making object name syntactically valid. New object name is ", newi, From ae699eb129a96e2ee23ce2e545e6b4022105c371 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Tue, 10 Dec 2019 14:51:46 -0500 Subject: [PATCH 77/83] Add RenameAssays --- R/objects.R | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/R/objects.R b/R/objects.R index 4f56d70a0..a004df1e2 100644 --- a/R/objects.R +++ b/R/objects.R @@ -1246,6 +1246,73 @@ Reductions <- function(object, slot = NULL) { return(slot(object = object, name = 'reductions')[[slot]]) } +#' Rename assays in a \code{Seurat} object +#' +#' @param object A \code{Seurat} object +#' @param ... Named arguments as \code{old.assay = new.assay} +#' +#' @return \code{object} with assays renamed +#' +#' @export +#' @examples +#' RenameAssays(object = pbmc_small, RNA = 'rna') +#' +RenameAssays <- function(object, ...) { + assay.pairs <- tryCatch( + expr = as.list(x = ...), + error = function(e) { + return(list(...)) + } + ) + old.assays <- names(x = assay.pairs) + # Handle missing assays + missing.assays <- setdiff(x = old.assays, y = Assays(object = object)) + if (length(x = missing.assays) == length(x = old.assays)) { + stop("None of the assays provided are present in this object", call. = FALSE) + } else if (length(x = missing.assays)) { + warning( + "The following assays could not be found: ", + paste(missing.assays, collapse = ', '), + call. = FALSE, + immediate. = TRUE + ) + } + old.assays <- setdiff(x = old.assays, missing.assays) + assay.pairs <- assay.pairs[old.assays] + # Check to see that all old assays are named + if (is.null(x = names(x = assay.pairs)) || any(sapply(X = old.assays, FUN = nchar) < 1)) { + stop("All arguments must be named with the old assay name", call. = FALSE) + } + # Ensure each old assay is going to one new assay + if (!all(sapply(X = assay.pairs, FUN = length) == 1) || length(x = old.assays) != length(x = unique(x = old.assays))) { + stop("Can only rename assays to one new name", call. = FALSE) + } + # Ensure each new assay is coming from one old assay + if (length(x = assay.pairs) != length(x = unique(x = assay.pairs))) { + stop( + "One or more assays are set to be lost due to duplicate new assay names", + call. = FALSE + ) + } + # Rename assays + for (old in names(x = assay.pairs)) { + new <- assay.pairs[[old]] + # If we aren't actually renaming any + if (old == new) { + next + } + old.key <- Key(object = object[[old]]) + suppressWarnings(expr = object[[new]] <- object[[old]]) + if (old == DefaultAssay(object = object)) { + message("Renaming default assay from ", old, " to ", new) + DefaultAssay(object = object) <- new + } + Key(object = object[[new]]) <- old.key + object[[old]] <- NULL + } + return(object) +} + #' Set integation data #' #' @param object Seurat object @@ -1435,6 +1502,10 @@ UpdateSeuratObject <- function(object) { # Update object slots message("Updating object slots") object <- UpdateSlots(object = object) + # Rename assays + assays <- make.names(names = Assays(object = object)) + names(x = assays) <- Assays(object = object) + object <- do.call(what = RenameAssays, args = c('object' = object, assays)) for (obj in FilterObjects(object = object, classes.keep = c('Assay', 'DimReduc', 'Graph'))) { suppressWarnings(expr = object[[obj]] <- UpdateSlots(object = object[[obj]])) } From bb3fc9f26543d6488b0bbcbc2c86fd759bfdab6e Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Wed, 11 Dec 2019 14:30:18 -0500 Subject: [PATCH 78/83] bump develop version --- DESCRIPTION | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 929917ea0..6fca93610 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1.9023 -Date: 2019-12-04 +Version: 3.1.1.9024 +Date: 2019-12-11 Title: Tools for Single Cell Genomics Description: A toolkit for quality control, analysis, and exploration of single cell RNA sequencing data. 'Seurat' aims to enable users to identify and interpret sources of heterogeneity from single cell transcriptomic measurements, and to integrate diverse types of single cell data. See Satija R, Farrell J, Gennert D, et al (2015) , Macosko E, Basu A, Satija R, et al (2015) , and Butler A and Satija R (2017) for more details. Authors@R: c( From 400266a67744c764b24dd48d0c5d3083a02fee33 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Wed, 11 Dec 2019 15:10:30 -0500 Subject: [PATCH 79/83] Update documentation --- NAMESPACE | 2 ++ man/CellsByIdentities.Rd | 27 +++++++++++++++++++++++++++ man/RenameAssays.Rd | 23 +++++++++++++++++++++++ man/RowMergeSparseMatrices.Rd | 2 +- man/as.loom.Rd | 11 +++++++++-- 5 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 man/CellsByIdentities.Rd create mode 100644 man/RenameAssays.Rd diff --git a/NAMESPACE b/NAMESPACE index da934d8f0..b5b51149c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -182,6 +182,7 @@ export(CellCycleScoring) export(CellScatter) export(CellSelector) export(Cells) +export(CellsByIdentities) export(CollapseEmbeddingOutliers) export(CollapseSpeciesExpressionMatrix) export(ColorDimSplit) @@ -273,6 +274,7 @@ export(ReadH5AD) export(Reductions) export(RegroupIdents) export(RelativeCounts) +export(RenameAssays) export(RenameCells) export(RenameIdents) export(ReorderIdent) diff --git a/man/CellsByIdentities.Rd b/man/CellsByIdentities.Rd new file mode 100644 index 000000000..7dc5fa867 --- /dev/null +++ b/man/CellsByIdentities.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/objects.R +\name{CellsByIdentities} +\alias{CellsByIdentities} +\title{Get cell names grouped by identity class} +\usage{ +CellsByIdentities(object, idents = NULL, cells = NULL) +} +\arguments{ +\item{object}{A Seurat object} + +\item{idents}{A vector of identity class levels to limit resulting list to; +defaults to all identity class levels} + +\item{cells}{A vector of cells to grouping to} +} +\value{ +A named list where names are identity classes and values are vectors +of cells beloning to that class +} +\description{ +Get cell names grouped by identity class +} +\examples{ +CellsByIdentities(object = pbmc_small) + +} diff --git a/man/RenameAssays.Rd b/man/RenameAssays.Rd new file mode 100644 index 000000000..17e550096 --- /dev/null +++ b/man/RenameAssays.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/objects.R +\name{RenameAssays} +\alias{RenameAssays} +\title{Rename assays in a \code{Seurat} object} +\usage{ +RenameAssays(object, ...) +} +\arguments{ +\item{object}{A \code{Seurat} object} + +\item{...}{Named arguments as \code{old.assay = new.assay}} +} +\value{ +\code{object} with assays renamed +} +\description{ +Rename assays in a \code{Seurat} object +} +\examples{ +RenameAssays(object = pbmc_small, RNA = 'rna') + +} diff --git a/man/RowMergeSparseMatrices.Rd b/man/RowMergeSparseMatrices.Rd index 3bab2d31f..b1667a0da 100644 --- a/man/RowMergeSparseMatrices.Rd +++ b/man/RowMergeSparseMatrices.Rd @@ -17,7 +17,7 @@ A merged matrix Returns a sparse matrix } \description{ -This function is for use on sparse matrices and +This function is for use on sparse matrices and should not be run on a Seurat object. } \details{ diff --git a/man/as.loom.Rd b/man/as.loom.Rd index e4fb73445..6fe8c7b65 100644 --- a/man/as.loom.Rd +++ b/man/as.loom.Rd @@ -22,15 +22,22 @@ as.loom(x, ...) \arguments{ \item{x}{An object to convert to class \code{loom}} +\item{...}{Ignored for now} + \item{assay}{Assay to store in loom file} \item{filename}{The name of the new loom file} -\item{chunk.dims}{A one- or two-length integer vector of chunksizes for \code{/matrix}, defaults to 'auto' to automatically determine chunksize} +\item{max.size}{Set maximum chunk size in terms of memory usage, unused if \code{chunk.dims} is set; +may pass a character string (eg. \code{3gb}, \code{1200mb}) or exact value in bytes} + +\item{chunk.dims}{Matrix chunk dimensions; auto-determined by default} -\item{chunk.size}{How many rows of \code{data} should we stream to the loom file at any given time?} +\item{chunk.size}{Maximum number of cells read/written to disk at once; auto-determined by default} \item{overwrite}{Overwrite an already existing loom file?} + +\item{verbose}{Display a progress bar} } \description{ Convert objects to loom objects From ce52f9cf404958c1a26df4ff6a5c47ded2f2a445 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Wed, 11 Dec 2019 16:47:42 -0500 Subject: [PATCH 80/83] Add biocViews to DESCRIPTION to facilitate installation of bioc dependencies --- DESCRIPTION | 1 + 1 file changed, 1 insertion(+) diff --git a/DESCRIPTION b/DESCRIPTION index f508a03a2..1f8ad0e6d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -83,6 +83,7 @@ Collate: 'zzz.R' RoxygenNote: 7.0.2 Encoding: UTF-8 +biocViews: Suggests: loomR, testthat, From 10eca2226f682bf107f9a2c0fcdd387f80c0dcff Mon Sep 17 00:00:00 2001 From: Andrew Butler Date: Thu, 12 Dec 2019 09:37:47 -0500 Subject: [PATCH 81/83] fix CellCycleScoring to work with new names fix --- R/utilities.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utilities.R b/R/utilities.R index a52977b2e..e37123559 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -432,7 +432,7 @@ CellCycleScoring <- function( set.ident = FALSE, ... ) { - name <- 'Cell Cycle' + name <- 'Cell.Cycle' features <- list('S.Score' = s.features, 'G2M.Score' = g2m.features) object.cc <- AddModuleScore( object = object, From 933eca00cf2543a867017cb2670403bf41a7cae1 Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Thu, 12 Dec 2019 12:30:38 -0500 Subject: [PATCH 82/83] Require UWOT v0.1.5 or higher See satijalab/seurat#2256 for more details --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1f8ad0e6d..c7a4b4e5d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -62,7 +62,7 @@ Imports: tools, tsne, utils, - uwot + uwot (>= 0.1.5) LinkingTo: Rcpp (>= 0.11.0), RcppEigen, RcppProgress License: GPL-3 | file LICENSE LazyData: true From 04ebc61b5ff7f5ddf5b75c76b6c7155daace94da Mon Sep 17 00:00:00 2001 From: Paul Hoffman Date: Thu, 12 Dec 2019 16:06:57 -0500 Subject: [PATCH 83/83] Update cran-comments --- cran-comments.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cran-comments.md b/cran-comments.md index e81ae694b..1023d2cba 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,11 +1,11 @@ -# Seurat v3.1.1 +# Seurat v3.1.2 ## Test environments -* local Ubuntu 16.04.6 and 18.04.2 installs, R 3.5.3 +* local Ubuntu 16.04.6 and 18.04.2 installs, R 3.6.1 * Ubuntu 16.04.6 (on travis-ci), R 3.6.1 * macOS 10.13.3 (on travis-ci), R 3.6.1 * Windows Server 2012 R2 (on AppVeyor), R 3.6.1 Patched -* win-builder (oldrelease, release, devel) +* win-builder (oldrelease, release, devel, devel_gcc8) ## R CMD check results There were no ERRORs or WARNINGs @@ -33,4 +33,6 @@ There were 3 NOTEs: ## Downstream dependencies -There are three packages that suggest Seurat: BisqueRNA, clustreen, and iCellR; this update does not impact their functionality. +There is one pacakge that imports Seurat: multicross; this update does not impact its functionality + +There are five packages that suggest Seurat: BisqueRNA, clustree, diem, iCellR, and Rmagic; this update does not impact their functionality.