Skip to content

Commit 49a1be0

Browse files
author
satijalab
authored
Merge pull request #2416 from satijalab/develop
Seurat v3.1.2
2 parents fc4a4f5 + 9f57968 commit 49a1be0

File tree

111 files changed

+2597
-1255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+2597
-1255
lines changed

DESCRIPTION

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: Seurat
2-
Version: 3.1.1
3-
Date: 2019-09-23
2+
Version: 3.1.2
3+
Date: 2019-12-12
44
Title: Tools for Single Cell Genomics
55
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.
66
Authors@R: c(
@@ -62,7 +62,7 @@ Imports:
6262
tools,
6363
tsne,
6464
utils,
65-
uwot
65+
uwot (>= 0.1.5)
6666
LinkingTo: Rcpp (>= 0.11.0), RcppEigen, RcppProgress
6767
License: GPL-3 | file LICENSE
6868
LazyData: true
@@ -81,8 +81,9 @@ Collate:
8181
'tree.R'
8282
'utilities.R'
8383
'zzz.R'
84-
RoxygenNote: 6.1.1
84+
RoxygenNote: 7.0.2
8585
Encoding: UTF-8
86+
biocViews:
8687
Suggests:
8788
loomR,
8889
testthat,

NAMESPACE

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ S3method("$",JackStrawData)
44
S3method("$",Seurat)
55
S3method("$",SeuratCommand)
66
S3method("$<-",Seurat)
7+
S3method("DefaultAssay<-",Assay)
78
S3method("DefaultAssay<-",DimReduc)
9+
S3method("DefaultAssay<-",Graph)
810
S3method("DefaultAssay<-",Seurat)
911
S3method("Idents<-",Seurat)
1012
S3method("JS<-",DimReduc)
@@ -34,8 +36,11 @@ S3method(AddMetaData,Seurat)
3436
S3method(Cells,DimReduc)
3537
S3method(Cells,default)
3638
S3method(Command,Seurat)
39+
S3method(DefaultAssay,Assay)
3740
S3method(DefaultAssay,DimReduc)
41+
S3method(DefaultAssay,Graph)
3842
S3method(DefaultAssay,Seurat)
43+
S3method(DefaultAssay,SeuratCommand)
3944
S3method(Embeddings,DimReduc)
4045
S3method(Embeddings,Seurat)
4146
S3method(FindClusters,Seurat)
@@ -55,6 +60,8 @@ S3method(GetAssayData,Seurat)
5560
S3method(HVFInfo,Assay)
5661
S3method(HVFInfo,Seurat)
5762
S3method(Idents,Seurat)
63+
S3method(IsGlobal,DimReduc)
64+
S3method(IsGlobal,default)
5865
S3method(JS,DimReduc)
5966
S3method(JS,JackStrawData)
6067
S3method(Key,Assay)
@@ -175,6 +182,7 @@ export(CellCycleScoring)
175182
export(CellScatter)
176183
export(CellSelector)
177184
export(Cells)
185+
export(CellsByIdentities)
178186
export(CollapseEmbeddingOutliers)
179187
export(CollapseSpeciesExpressionMatrix)
180188
export(ColorDimSplit)
@@ -223,6 +231,7 @@ export(HVFInfo)
223231
export(HoverLocator)
224232
export(Idents)
225233
export(IntegrateData)
234+
export(IsGlobal)
226235
export(JS)
227236
export(JackStraw)
228237
export(JackStrawPlot)
@@ -265,12 +274,14 @@ export(ReadH5AD)
265274
export(Reductions)
266275
export(RegroupIdents)
267276
export(RelativeCounts)
277+
export(RenameAssays)
268278
export(RenameCells)
269279
export(RenameIdents)
270280
export(ReorderIdent)
271281
export(RestoreLegend)
272282
export(RidgePlot)
273283
export(RotatedAxis)
284+
export(RowMergeSparseMatrices)
274285
export(RunALRA)
275286
export(RunCCA)
276287
export(RunICA)
@@ -481,7 +492,6 @@ importFrom(reticulate,import)
481492
importFrom(reticulate,np_array)
482493
importFrom(reticulate,py_module_available)
483494
importFrom(reticulate,py_set_seed)
484-
importFrom(reticulate,r_to_py)
485495
importFrom(reticulate,tuple)
486496
importFrom(rlang,"!!")
487497
importFrom(rsvd,rsvd)

NEWS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ All notable changes to Seurat will be documented in this file.
33
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
44

55

6+
## [3.1.2] - 2019-12-11
7+
### Added
8+
- New silent slot updater
9+
- New random seed options to `RunCCA`, `RunTSNE`, `WhichCells`, `HTODemux`, `AddModuleScore`, `VlnPlot`, and `RidgePlot`
10+
- Enhancements for dealing with `Assay`-derived objects
11+
12+
### Changed
13+
- Only run `CalcN` (generates nFeatures and nCounts) when `counts` changes
14+
- Fix issue regarding colons in feature names
15+
- Change object class testing to use `inherits` or `is.*` for R 4.0 compatability
16+
617
## [3.1.1] - 2019-09-20
718
### Added
819
- New `RegroupIdents` function to reassign idents based on metadata column majority

R/clustering.R

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ FindClusters.Seurat <- function(
158158
weights = NULL,
159159
node.sizes = NULL,
160160
resolution = 0.8,
161+
method = "matrix",
161162
algorithm = 1,
162163
n.start = 10,
163164
n.iter = 10,
@@ -183,6 +184,7 @@ FindClusters.Seurat <- function(
183184
weights = weights,
184185
node.sizes = node.sizes,
185186
resolution = resolution,
187+
method = method,
186188
algorithm = algorithm,
187189
n.start = n.start,
188190
n.iter = n.iter,
@@ -208,7 +210,9 @@ FindClusters.Seurat <- function(
208210
)
209211
Idents(object = object) <- factor(x = Idents(object = object), levels = sort(x = levels))
210212
object[['seurat_clusters']] <- Idents(object = object)
211-
object <- LogSeuratCommand(object)
213+
cmd <- LogSeuratCommand(object = object, return.command = TRUE)
214+
slot(object = cmd, name = 'assay.used') <- DefaultAssay(object = object[[graph.name]])
215+
object[[slot(object = cmd, name = 'name')]] <- cmd
212216
return(object)
213217
}
214218

@@ -419,7 +423,8 @@ FindNeighbors.Seurat <- function(
419423
) {
420424
CheckDots(...)
421425
if (!is.null(x = dims)) {
422-
assay <- assay %||% DefaultAssay(object = object)
426+
# assay <- assay %||% DefaultAssay(object = object)
427+
assay <- DefaultAssay(object = object[[reduction]])
423428
data.use <- Embeddings(object = object[[reduction]])
424429
if (max(dims) > ncol(x = data.use)) {
425430
stop("More dimensions specified in dims than have been computed")
@@ -456,6 +461,7 @@ FindNeighbors.Seurat <- function(
456461
}
457462
graph.name <- graph.name %||% paste0(assay, "_", names(x = neighbor.graphs))
458463
for (ii in 1:length(x = graph.name)) {
464+
DefaultAssay(object = neighbor.graphs[[ii]]) <- assay
459465
object[[graph.name[[ii]]]] <- neighbor.graphs[[ii]]
460466
}
461467
if (do.plot) {
@@ -675,8 +681,7 @@ NNHelper <- function(data, query = data, k, method, ...) {
675681
# @keywords graph network igraph mvtnorm simulation
676682
#
677683
#' @importFrom leiden leiden
678-
#' @importFrom methods as is
679-
#' @importFrom reticulate py_module_available import r_to_py
684+
#' @importFrom reticulate py_module_available
680685
#' @importFrom igraph graph_from_adjacency_matrix graph_from_adj_list
681686
#
682687
# @author Tom Kelly
@@ -703,25 +708,34 @@ RunLeiden <- function(
703708
n.iter = 10
704709
) {
705710
if (!py_module_available(module = 'leidenalg')) {
706-
stop("Cannot find Leiden algorithm, please install through pip (e.g. pip install leidenalg).")
711+
stop(
712+
"Cannot find Leiden algorithm, please install through pip (e.g. pip install leidenalg).",
713+
call. = FALSE
714+
)
715+
}
716+
if (method %in% c("matrix", "igraph")) {
717+
if (method == "igraph") {
718+
object <- graph_from_adjacency_matrix(adjmatrix = object)
719+
}
720+
} else {
721+
warning(
722+
"method for Leiden recommended as 'matrix' or 'igraph'",
723+
call. = FALSE,
724+
immediate. = TRUE
725+
)
726+
}
727+
input <- if (inherits(x = object, what = 'list')) {
728+
graph_from_adj_list(adjlist = object)
729+
} else if (inherits(x = object, what = c('dgCMatrix', 'matrix', "Matrix"))) {
730+
graph_from_adjacency_matrix(adjmatrix = object)
731+
} else if (inherits(x = object, what = 'igraph')) {
732+
object
733+
} else {
734+
stop(
735+
paste("method for Leiden not found for class", class(x = object)),
736+
call. = FALSE
737+
)
707738
}
708-
switch(
709-
EXPR = method,
710-
#cast to dense (supported by reticulate for numpy.array)
711-
"matrix" = input <- as(object, "matrix"),
712-
#run as igraph object (passes to reticulate)
713-
"igraph" = switch(
714-
EXPR = is(object),
715-
#generate igraph if needed (will handle updated snn class)
716-
"Graph" = input <- graph_from_adjacency_matrix(adjmatrix = object),
717-
"dgCMatrix" = input <- graph_from_adjacency_matrix(adjmatrix = object),
718-
"igraph" = input <- object,
719-
"matrix" = input <- graph_from_adjacency_matrix(adjmatrix = object),
720-
"list" = input <- graph_from_adj_list(adjlist = object),
721-
stop("SNN object must be a compatible input for igraph")
722-
),
723-
stop("method for leiden must be 'matrix' or 'igraph'")
724-
)
725739
#run leiden from CRAN package (calls python with reticulate)
726740
partition <- leiden(
727741
object = input,

R/differential_expression.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ FindAllMarkers <- function(
136136
return(cond$message)
137137
}
138138
)
139-
if (class(x = genes.de[[i]]) == "character") {
139+
if (is.character(x = genes.de[[i]])) {
140140
messages[[i]] <- genes.de[[i]]
141141
genes.de[[i]] <- NULL
142142
}
@@ -233,7 +233,7 @@ FindConservedMarkers <- function(
233233
verbose = TRUE,
234234
...
235235
) {
236-
if (class(x = meta.method) != "function") {
236+
if (!is.function(x = meta.method)) {
237237
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.")
238238
}
239239
object.var <- FetchData(object = object, vars = grouping.var)
@@ -1412,7 +1412,7 @@ NBModelComparison <- function(y, theta, latent.data, com.fac, grp.fac) {
14121412
),
14131413
silent = TRUE
14141414
)
1415-
if (class(x = fit2)[1] == 'numeric' | class(x = fit4)[1] == 'numeric') {
1415+
if (is.numeric(x = fit2) || is.numeric(x = fit4)) {
14161416
message('One of the glm.nb calls failed')
14171417
return(c(rep(x = NA, 5), freqs))
14181418
}

R/dimensional_reduction.R

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ ProjectDim <- function(
314314
#' @param standardize Standardize matrices - scales columns to have unit variance
315315
#' and mean 0
316316
#' @param num.cc Number of canonical vectors to calculate
317+
#' @param seed.use Random seed to set. If NULL, does not set a seed
317318
#' @param verbose Show progress messages
318319
#'
319320
#' @importFrom irlba irlba
@@ -326,10 +327,13 @@ RunCCA.default <- function(
326327
object2,
327328
standardize = TRUE,
328329
num.cc = 20,
330+
seed.use = 42,
329331
verbose = FALSE,
330332
...
331333
) {
332-
set.seed(seed = 42)
334+
if (!is.null(x = seed.use)) {
335+
set.seed(seed = seed.use)
336+
}
333337
cells1 <- colnames(x = object1)
334338
cells2 <- colnames(x = object2)
335339
if (standardize) {
@@ -811,10 +815,10 @@ RunPCA.default <- function(
811815
cell.embeddings <- pca.results$v
812816
}
813817
else {
818+
total.variance <- sum(RowVar(x = object))
814819
if (approx) {
815820
npcs <- min(npcs, nrow(x = object) - 1)
816821
pca.results <- irlba(A = t(x = object), nv = npcs, ...)
817-
total.variance <- sum(RowVar(x = object))
818822
feature.loadings <- pca.results$v
819823
sdev <- pca.results$d/sqrt(max(1, ncol(object) - 1))
820824
if (weight.by.var) {
@@ -827,7 +831,6 @@ RunPCA.default <- function(
827831
pca.results <- prcomp(x = t(object), rank. = npcs, ...)
828832
feature.loadings <- pca.results$rotation
829833
sdev <- pca.results$sdev
830-
total.variance <- sum(sdev)
831834
if (weight.by.var) {
832835
cell.embeddings <- pca.results$x %*% diag(pca.results$sdev[1:npcs]^2)
833836
} else {
@@ -858,7 +861,10 @@ RunPCA.default <- function(
858861
return(reduction.data)
859862
}
860863

861-
#' @param features Features to compute PCA on
864+
#' @param features Features to compute PCA on. If features=NULL, PCA will be run
865+
#' using the variable features for the Assay. Note that the features must be present
866+
#' in the scaled data. Any requested features that are not scaled or have 0 variance
867+
#' will be dropped, and the PCA will be run using the remaining features.
862868
#'
863869
#' @rdname RunPCA
864870
#' @export
@@ -943,7 +949,7 @@ RunPCA.Seurat <- function(
943949
}
944950

945951
#' @param assay Name of assay that that t-SNE is being run on
946-
#' @param seed.use Random seed for the t-SNE
952+
#' @param seed.use Random seed for the t-SNE. If NULL, does not set the seed
947953
#' @param tsne.method Select the method to use to compute the tSNE. Available
948954
#' methods are:
949955
#' \itemize{
@@ -976,7 +982,9 @@ RunTSNE.matrix <- function(
976982
reduction.key = "tSNE_",
977983
...
978984
) {
979-
set.seed(seed = seed.use)
985+
if (!is.null(x = seed.use)) {
986+
set.seed(seed = seed.use)
987+
}
980988
tsne.data <- switch(
981989
EXPR = tsne.method,
982990
'Rtsne' = Rtsne(
@@ -1000,7 +1008,8 @@ RunTSNE.matrix <- function(
10001008
tsne.reduction <- CreateDimReducObject(
10011009
embeddings = tsne.data,
10021010
key = reduction.key,
1003-
assay = assay
1011+
assay = assay,
1012+
global = TRUE
10041013
)
10051014
return(tsne.reduction)
10061015
}
@@ -1109,7 +1118,7 @@ RunTSNE.Seurat <- function(
11091118
)
11101119
} else if (!is.null(x = features)) {
11111120
RunTSNE(
1112-
object = as.matrix(x = GetAssayData(object = object)[features, cells]),
1121+
object = t(x = as.matrix(x = GetAssayData(object = object)[features, cells])),
11131122
assay = DefaultAssay(object = object),
11141123
seed.use = seed.use,
11151124
tsne.method = tsne.method,
@@ -1247,7 +1256,8 @@ RunUMAP.default <- function(
12471256
umap.reduction <- CreateDimReducObject(
12481257
embeddings = umap.output,
12491258
key = reduction.key,
1250-
assay = assay
1259+
assay = assay,
1260+
global = TRUE
12511261
)
12521262
return(umap.reduction)
12531263
}
@@ -1331,7 +1341,12 @@ RunUMAP.Graph <- function(
13311341
colnames(x = embeddings) <- paste0("UMAP_", 1:n.components)
13321342
# center the embeddings on zero
13331343
embeddings <- scale(x = embeddings, scale = FALSE)
1334-
umap <- CreateDimReducObject(embeddings = embeddings, key = reduction.key, assay = assay)
1344+
umap <- CreateDimReducObject(
1345+
embeddings = embeddings,
1346+
key = reduction.key,
1347+
assay = assay,
1348+
global = TRUE
1349+
)
13351350
return(umap)
13361351
}
13371352

@@ -1843,7 +1858,9 @@ JackRandom <- function(
18431858
weight.by.var = weight.by.var,
18441859
maxit = 1000
18451860
) {
1846-
set.seed(seed = seed.use)
1861+
if (!is.null(x = seed.use)) {
1862+
set.seed(seed = seed.use)
1863+
}
18471864
rand.genes <- sample(
18481865
x = rownames(x = scaled.data),
18491866
size = nrow(x = scaled.data) * prop.use

0 commit comments

Comments
 (0)