diff --git a/DESCRIPTION b/DESCRIPTION index 3b59306e3..c7a4b4e5d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: Seurat -Version: 3.1.1 -Date: 2019-09-23 +Version: 3.1.2 +Date: 2019-12-12 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( @@ -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 @@ -81,8 +81,9 @@ Collate: 'tree.R' 'utilities.R' 'zzz.R' -RoxygenNote: 6.1.1 +RoxygenNote: 7.0.2 Encoding: UTF-8 +biocViews: Suggests: loomR, testthat, diff --git a/NAMESPACE b/NAMESPACE index 671813cce..b5b51149c 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) @@ -55,6 +60,8 @@ S3method(GetAssayData,Seurat) S3method(HVFInfo,Assay) S3method(HVFInfo,Seurat) S3method(Idents,Seurat) +S3method(IsGlobal,DimReduc) +S3method(IsGlobal,default) S3method(JS,DimReduc) S3method(JS,JackStrawData) S3method(Key,Assay) @@ -175,6 +182,7 @@ export(CellCycleScoring) export(CellScatter) export(CellSelector) export(Cells) +export(CellsByIdentities) export(CollapseEmbeddingOutliers) export(CollapseSpeciesExpressionMatrix) export(ColorDimSplit) @@ -223,6 +231,7 @@ export(HVFInfo) export(HoverLocator) export(Idents) export(IntegrateData) +export(IsGlobal) export(JS) export(JackStraw) export(JackStrawPlot) @@ -265,12 +274,14 @@ export(ReadH5AD) export(Reductions) export(RegroupIdents) export(RelativeCounts) +export(RenameAssays) export(RenameCells) export(RenameIdents) export(ReorderIdent) export(RestoreLegend) export(RidgePlot) export(RotatedAxis) +export(RowMergeSparseMatrices) export(RunALRA) export(RunCCA) export(RunICA) @@ -481,7 +492,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/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 diff --git a/R/clustering.R b/R/clustering.R index 40560795e..3f33d22b4 100644 --- a/R/clustering.R +++ b/R/clustering.R @@ -158,6 +158,7 @@ FindClusters.Seurat <- function( weights = NULL, node.sizes = NULL, resolution = 0.8, + method = "matrix", algorithm = 1, n.start = 10, n.iter = 10, @@ -183,6 +184,7 @@ FindClusters.Seurat <- function( weights = weights, node.sizes = node.sizes, resolution = resolution, + method = method, algorithm = algorithm, n.start = n.start, n.iter = n.iter, @@ -208,7 +210,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 +423,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 +461,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) { @@ -675,8 +681,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 @@ -703,25 +708,34 @@ 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(adjmatrix = object) + } + } else { + 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"))) { + 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(x = object)), + call. = FALSE + ) } - 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), - #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'") - ) #run leiden from CRAN package (calls python with reticulate) partition <- leiden( object = input, 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/dimensional_reduction.R b/R/dimensional_reduction.R index 657822ed9..f6c9aa043 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) { @@ -811,10 +815,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 +831,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 { @@ -858,7 +861,10 @@ 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. Note that the features must be present +#' 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 @@ -943,7 +949,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{ @@ -976,7 +982,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( @@ -1000,7 +1008,8 @@ RunTSNE.matrix <- function( tsne.reduction <- CreateDimReducObject( embeddings = tsne.data, key = reduction.key, - assay = assay + assay = assay, + global = TRUE ) return(tsne.reduction) } @@ -1109,7 +1118,7 @@ RunTSNE.Seurat <- function( ) } else if (!is.null(x = features)) { RunTSNE( - object = 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, @@ -1247,7 +1256,8 @@ RunUMAP.default <- function( umap.reduction <- CreateDimReducObject( embeddings = umap.output, key = reduction.key, - assay = assay + assay = assay, + global = TRUE ) return(umap.reduction) } @@ -1331,7 +1341,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) } @@ -1843,7 +1858,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/generics.R b/R/generics.R index 58f18c98f..ea923447f 100644 --- a/R/generics.R +++ b/R/generics.R @@ -413,6 +413,28 @@ Idents <- function(object, ... ) { UseMethod(generic = 'Idents<-', object = object) } +#' 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/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 +806,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 +822,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/integration.R b/R/integration.R index 020ee197a..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,232 +938,6 @@ MixingMetric <- function( return(mixing) } -#' 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) -} - #' Prepare an object list that has been run through SCTransform for integration #' #' @param object.list A list of objects to prep for integration @@ -2333,31 +2000,138 @@ FindWeights <- function( slot = 'weights', new.data = weights ) - return(object) -} - - -# Work out the anchor cell offsets for given set of cells in anchor list -# -# @param anchors A dataframe of anchors, from AnchorSet object -# @param dataset Dataset number (1 or 2) -# @param cell Cell number (1 or 2) -# @param cellnames.list List of cell names in all objects -# @param cellnames list of cell names for only the object in question -# -# @return Returns a list of offsets -# -GetCellOffsets <- function(anchors, dataset, cell, cellnames.list, cellnames) { - cell.id <- sapply(X = 1:nrow(x = anchors), FUN = function(x) { - cellnames.list[[anchors[, dataset+3][x]]][anchors[, cell][x]] - }) - cell.offset <- sapply( - X = 1:length(x = cell.id), - FUN = function(x) { - return(which(x = cellnames == cell.id[x])) + return(object) +} + + +# Work out the anchor cell offsets for given set of cells in anchor list +# +# @param anchors A dataframe of anchors, from AnchorSet object +# @param dataset Dataset number (1 or 2) +# @param cell Cell number (1 or 2) +# @param cellnames.list List of cell names in all objects +# @param cellnames list of cell names for only the object in question +# +# @return Returns a list of offsets +# +GetCellOffsets <- function(anchors, dataset, cell, cellnames.list, cellnames) { + cell.id <- sapply(X = 1:nrow(x = anchors), FUN = function(x) { + cellnames.list[[anchors[, dataset+3][x]]][anchors[, cell][x]] + }) + cell.offset <- sapply( + X = 1:length(x = cell.id), + FUN = function(x) { + return(which(x = cellnames == cell.id[x])) + } + ) + 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) } ) - return(cell.offset) + 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 @@ -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). @@ -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 { diff --git a/R/objects.R b/R/objects.R index 690761e68..a004df1e2 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 #' @@ -62,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 @@ -77,6 +80,7 @@ Assay <- setClass( data = 'AnyMatrix', scale.data = 'matrix', key = 'character', + assay.orig = 'OptionalCharacter', var.features = 'vector', meta.features = 'data.frame', misc = 'ANY' @@ -115,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 @@ -133,6 +140,7 @@ DimReduc <- setClass( feature.loadings = 'matrix', feature.loadings.projected = 'matrix', assay.used = 'character', + global = 'logical', stdev = 'numeric', key = 'character', jackstraw = 'JackStrawData', @@ -142,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 @@ -152,7 +162,10 @@ DimReduc <- setClass( #' Graph <- setClass( Class = 'Graph', - contains = "dgCMatrix" + contains = "dgCMatrix", + slots = list( + assay.used = 'OptionalCharacter' + ) ) #' The IntegrationData Class @@ -191,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 #' @@ -203,6 +217,7 @@ SeuratCommand <- setClass( slots = c( name = 'character', time.stamp = 'POSIXct', + assay.used = 'OptionalCharacter', call.string = 'character', params = 'ANY' ) @@ -353,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 @@ -539,6 +594,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 +621,7 @@ CreateDimReducObject <- function( assay = NULL, stdev = numeric(), key = NULL, + global = FALSE, jackstraw = NULL, misc = list() ) { @@ -643,6 +700,7 @@ CreateDimReducObject <- function( feature.loadings = loadings, feature.loadings.projected = projected, assay.used = assay, + global = global, stdev = stdev, key = key, jackstraw = jackstraw, @@ -704,7 +762,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] @@ -890,48 +948,46 @@ 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) } ) 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( @@ -1126,8 +1182,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) { @@ -1141,7 +1203,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) @@ -1183,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 @@ -1369,6 +1499,21 @@ 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") + 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]])) + } + 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)) { @@ -1436,9 +1581,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", @@ -2522,6 +2711,15 @@ Command.Seurat <- function(object, command = NULL, value = NULL, ...) { return(params[[value]]) } +#' @rdname DefaultAssay +#' @export +#' @method DefaultAssay Assay +#' +DefaultAssay.Assay <- function(object, ...) { + object <- UpdateSlots(object = object) + return(slot(object = object, name = 'assay.orig')) +} + #' @rdname DefaultAssay #' @export #' @method DefaultAssay DimReduc @@ -2531,6 +2729,15 @@ DefaultAssay.DimReduc <- function(object, ...) { return(slot(object = object, name = 'assay.used')) } +#' @rdname DefaultAssay +#' @export +#' @method DefaultAssay Graph +#' +DefaultAssay.Graph <- function(object, ...) { + object <- UpdateSlots(object = object) + return(slot(object = object, name = 'assay.used')) +} + #' @rdname DefaultAssay #' @export #' @method DefaultAssay Seurat @@ -2544,6 +2751,26 @@ DefaultAssay.Seurat <- function(object, ...) { return(slot(object = object, name = 'active.assay')) } +#' @rdname DefaultAssay +#' @export +#' @method DefaultAssay SeuratCommand +#' +DefaultAssay.SeuratCommand <- function(object, ...) { + 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) +} + #' @export #' @method DefaultAssay<- DimReduc #' @@ -2553,6 +2780,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 @@ -2831,6 +3067,23 @@ Idents.Seurat <- function(object, ...) { return(object) } +#' @rdname IsGlobal +#' @export +#' @method IsGlobal default +#' +IsGlobal.default <- function(object, ...) { + return(FALSE) +} + +#' @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' #' @@ -2969,6 +3222,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) { @@ -3836,6 +4090,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 = 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( + 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) { @@ -4099,7 +4371,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) } @@ -4526,7 +4798,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 #' @@ -4552,7 +4824,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: ", @@ -5933,50 +6207,90 @@ 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 <- if (is.null(x = value)) { + i + } else { + make.names(names = i) + } + if (any(i != 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 - 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')) { + # 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 + 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 (!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 + 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')) { + # 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 + } else { 'meta.data' - ) + } if (slot.use == 'meta.data') { # Add data to object metadata meta.data <- x[[]] @@ -6037,32 +6351,11 @@ 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))) { - 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), @@ -6094,23 +6387,32 @@ 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)) | + (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 + # 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 @@ -6466,35 +6768,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 @@ -6505,7 +6778,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) )) @@ -6523,10 +6797,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)) } @@ -6625,7 +6899,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') @@ -6705,12 +6979,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), '_') } @@ -6726,6 +7001,38 @@ 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) + object <- do.call(what = 'new', args = object.list) + 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) + } + } + return(object) +} + # 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/R/preprocessing.R b/R/preprocessing.R index f8cbd5acb..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)] @@ -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) @@ -456,7 +458,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) { @@ -580,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 @@ -1064,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) { @@ -1305,6 +1307,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) } @@ -1416,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) { @@ -2110,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 @@ -2499,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 } @@ -2566,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) @@ -2779,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' diff --git a/R/utilities.R b/R/utilities.R index 6b1499345..e37123559 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 @@ -430,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, @@ -560,6 +562,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 +571,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 +983,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 +994,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 @@ -1097,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) @@ -1135,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 @@ -1571,7 +1634,7 @@ IsSCT <- function(assay) { }) return(unlist(x = sct.check)) } - return(!is.null(x = Misc(assay, slot = 'vst.out'))) + 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 @@ -1808,46 +1871,6 @@ 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 -# -#' @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 diff --git a/R/visualization.R b/R/visualization.R index ef84ea18c..8efafc893 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) } @@ -3612,7 +3606,8 @@ ExIPlot <- function( adjust = adjust, cols = cols, pt.size = pt.size, - log = log + log = log, + ... )) } ) @@ -4182,7 +4177,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) @@ -4192,6 +4188,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) { @@ -4279,6 +4281,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) } @@ -4437,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 # @@ -4458,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") } @@ -4490,7 +4503,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 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. 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. 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 a4d6b35ca..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} @@ -25,7 +35,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/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/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/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/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 aea2540ea..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, 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} @@ -24,6 +31,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/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/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{ 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/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/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/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/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 02edfdb1f..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, 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/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/HTODemux.Rd b/man/HTODemux.Rd index 65a4d5f89..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.} @@ -23,7 +31,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/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/IsGlobal.Rd b/man/IsGlobal.Rd new file mode 100644 index 000000000..6850a4bde --- /dev/null +++ b/man/IsGlobal.Rd @@ -0,0 +1,32 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/generics.R, R/objects.R +\name{IsGlobal} +\alias{IsGlobal} +\alias{IsGlobal.default} +\alias{IsGlobal.DimReduc} +\title{Is an object global/persistent?} +\usage{ +IsGlobal(object, ...) + +\method{IsGlobal}{default}(object, ...) + +\method{IsGlobal}{DimReduc}(object, ...) +} +\arguments{ +\item{object}{An object} + +\item{...}{Arguments passed to other methods} +} +\value{ +\code{TRUE} if the object is global/persistent otherwise \code{FALSE} +} +\description{ +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/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/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 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/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/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/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 -} 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/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/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/RowMergeSparseMatrices.Rd b/man/RowMergeSparseMatrices.Rd new file mode 100644 index 000000000..b1667a0da --- /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. +} 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 9825ceffa..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, 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} @@ -30,6 +48,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/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 8e0d69630..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} @@ -47,8 +70,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} } diff --git a/man/RunPCA.Rd b/man/RunPCA.Rd index b56e17a71..a719ea2f1 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} @@ -54,7 +85,10 @@ 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. Note that the features must be present +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} } diff --git a/man/RunTSNE.Rd b/man/RunTSNE.Rd index c6040aa7b..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} @@ -34,7 +67,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/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 1ba86be6c..d39e0791c 100644 --- a/man/ScaleData.Rd +++ b/man/ScaleData.Rd @@ -9,30 +9,63 @@ \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} \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.} 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/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} 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 8d62c7779..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} @@ -37,7 +44,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 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..6fe8c7b65 100644 --- a/man/as.loom.Rd +++ b/man/as.loom.Rd @@ -7,10 +7,17 @@ \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}} 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} 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")