Skip to content

Commit

Permalink
Merge pull request #2416 from satijalab/develop
Browse files Browse the repository at this point in the history
Seurat v3.1.2
  • Loading branch information
satijalab authored Dec 13, 2019
2 parents fc4a4f5 + 9f57968 commit 49a1be0
Show file tree
Hide file tree
Showing 111 changed files with 2,597 additions and 1,255 deletions.
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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) <doi:10.1038/nbt.3192>, Macosko E, Basu A, Satija R, et al (2015) <doi:10.1016/j.cell.2015.05.002>, and Butler A and Satija R (2017) <doi:10.1101/164889> for more details.
Authors@R: c(
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
12 changes: 11 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -175,6 +182,7 @@ export(CellCycleScoring)
export(CellScatter)
export(CellSelector)
export(Cells)
export(CellsByIdentities)
export(CollapseEmbeddingOutliers)
export(CollapseSpeciesExpressionMatrix)
export(ColorDimSplit)
Expand Down Expand Up @@ -223,6 +231,7 @@ export(HVFInfo)
export(HoverLocator)
export(Idents)
export(IntegrateData)
export(IsGlobal)
export(JS)
export(JackStraw)
export(JackStrawPlot)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
58 changes: 36 additions & 22 deletions R/clustering.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
}

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions R/differential_expression.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
Expand Down
39 changes: 28 additions & 11 deletions R/dimensional_reduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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(
Expand All @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 49a1be0

Please sign in to comment.