Skip to content

Commit 9b38929

Browse files
authored
Merge pull request #4608 from satijalab/develop
Seurat v4.0.3
2 parents af2925c + d0cd778 commit 9b38929

24 files changed

+256
-97
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: Seurat
2-
Version: 4.0.2
3-
Date: 2021-05-20
2+
Version: 4.0.3
3+
Date: 2021-06-10
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>, Stuart T, Butler A, et al (2019) <doi:10.1016/j.cell.2019.05.031>, and Hao, Hao, et al (2020) <doi:10.1101/2020.10.12.335331> for more details.
66
Authors@R: c(
@@ -66,7 +66,7 @@ Imports:
6666
scales,
6767
scattermore (>= 0.7),
6868
sctransform (>= 0.3.2),
69-
SeuratObject,
69+
SeuratObject (>= 4.0.2),
7070
shiny,
7171
spatstat.core,
7272
spatstat.geom,

NEWS.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
1-
# Seurat 4.0.2 (2020-03-20)
1+
## Seurat 4.0.3 (2020-06-10)
2+
## Added
3+
- Add `jitter` parameter to `FeatureScatter()`
4+
5+
## Changes
6+
- Fix issues with `as.SingleCellExperiment.Seurat()` for the latest verion of SingleCellExperiment ([#4532](https://github.com/satijalab/seurat/pull/4532))
7+
- Ensure proper reference.reduction is used in `MapQuery()`
8+
- Fix to `UpdateSymbolList()`, no longer searches aliases and exposes the `search.types` parameter in `GeneSymbolThesarus()` ([#4545](https://github.com/satijalab/seurat/issues/4545))
9+
- Transfer `scale.data` slot as well when converting with `as.SingleCellExperiment.Seurat()`
10+
- Enable `alpha` parameter for `SpatialDimPlot()`
11+
- Fix `as.SingleCellExperiment.Seurat()` conversion for atypical `reducedDim` components
12+
13+
# Seurat 4.0.2 (2020-05-20)
214
## Added
315
- New `AddAzimuthScores()` and `AddAzimuthResults()` functions
416
- Add `shuffle` parameter to `FeatureScatter()` ([#4280](https://github.com/satijalab/seurat/pull/4280))

R/integration.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ FindTransferAnchors <- function(
770770
projected <- ifelse(test = reduction == "pcaproject", yes = TRUE, no = FALSE)
771771
reduction.2 <- character()
772772
feature.mean <- NULL
773+
reference.reduction.init <- reference.reduction
773774
if (normalization.method == "SCT") {
774775
# ensure all residuals required are computed
775776
query <- suppressWarnings(expr = GetResidual(object = query, assay = query.assay, features = features, verbose = FALSE))
@@ -1139,6 +1140,7 @@ FindTransferAnchors <- function(
11391140
}
11401141
slot(object = combined.ob, name = "reductions") <- reductions
11411142
command <- LogSeuratCommand(object = combined.ob, return.command = TRUE)
1143+
slot(command, name = 'params')$reference.reduction <- reference.reduction.init
11421144
anchor.set <- new(
11431145
Class = "TransferAnchorSet",
11441146
object.list = list(combined.ob),
@@ -1902,9 +1904,16 @@ MapQuery <- function(
19021904
projectumap.args = list(),
19031905
verbose = TRUE
19041906
) {
1907+
19051908
# determine anchor type
19061909
if (grepl(pattern = "pca", x = slot(object = anchorset, name = "command")$reduction)) {
19071910
anchor.reduction <- "pcaproject"
1911+
# check if the anchorset can be used for mapping
1912+
if (is.null(x = slot(object = anchorset, name = "command")$reference.reduction)) {
1913+
stop('The reference.reduction parameter was not set when running ',
1914+
'FindTransferAnchors, so the resulting AnchorSet object cannot be used ',
1915+
'in the MapQuery function.')
1916+
}
19081917
} else if (grepl(pattern = "cca", x = slot(object = anchorset, name = "command")$reduction)) {
19091918
anchor.reduction <- "cca"
19101919
ref.cca.embedding <- Embeddings(
@@ -1941,6 +1950,7 @@ MapQuery <- function(
19411950
stop("unkown type of anchors")
19421951
}
19431952

1953+
19441954
reference.reduction <- reference.reduction %||%
19451955
slot(object = anchorset, name = "command")$reference.reduction %||%
19461956
anchor.reduction

R/objects.R

Lines changed: 65 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,17 +1039,22 @@ as.Seurat.SingleCellExperiment <- function(
10391039
)
10401040
}
10411041
meta.data <- as.data.frame(x = SummarizedExperiment::colData(x = x))
1042+
if (packageVersion(pkg = "SingleCellExperiment") >= "1.14.0") {
1043+
orig.exp <- SingleCellExperiment::mainExpName(x = x) %||% "originalexp"
1044+
} else {
1045+
orig.exp <- "originalexp"
1046+
}
10421047
if (!is.null(SingleCellExperiment::altExpNames(x = x))) {
10431048
assayn <- assay %||% SingleCellExperiment::altExpNames(x = x)
10441049
if (!all(assay %in% SingleCellExperiment::altExpNames(x = x))) {
10451050
stop("One or more of the assays you are trying to convert is not in the SingleCellExperiment object")
10461051
}
1047-
assayn <- c("originalexp", assayn)
1052+
assayn <- c(orig.exp, assayn)
10481053
} else {
1049-
assayn <- "originalexp"
1054+
assayn <- orig.exp
10501055
}
10511056
for (assay in assayn) {
1052-
if (assay != "originalexp") {
1057+
if (assay != orig.exp) {
10531058
x <- SingleCellExperiment::swapAltExp(x = x, name = assay, saved = NULL)
10541059
}
10551060
# Pull matrices
@@ -1068,7 +1073,7 @@ as.Seurat.SingleCellExperiment <- function(
10681073
# if cell names are NULL, fill with cell_X
10691074
if (is.null(x = colnames(x = mats[[m]]))) {
10701075
warning(
1071-
"The column names of the",
1076+
"The column names of the ",
10721077
names(x = mats)[m],
10731078
" matrix is NULL. Setting cell names to cell_columnidx (e.g 'cell_1').",
10741079
call. = FALSE,
@@ -1106,28 +1111,30 @@ as.Seurat.SingleCellExperiment <- function(
11061111
DefaultAssay(object = object) <- assay
11071112
# add feature level meta data
11081113
md <- SingleCellExperiment::rowData(x = x)
1109-
# replace underscores
1110-
rownames(x = md) <- gsub(pattern = "_", replacement = "-", x = rownames(x = md))
1111-
md <- as.data.frame(x = md)
1112-
# ensure order same as data
1113-
md <- md[rownames(x = object[[assay]]), ]
1114-
object[[assay]] <- AddMetaData(
1115-
object = object[[assay]],
1116-
metadata = md
1117-
)
1114+
if (ncol(x = md) > 0) {
1115+
# replace underscores
1116+
rownames(x = md) <- gsub(pattern = "_", replacement = "-", x = rownames(x = md))
1117+
md <- as.data.frame(x = md)
1118+
# ensure order same as data
1119+
md <- md[rownames(x = object[[assay]]), , drop = FALSE]
1120+
object[[assay]] <- AddMetaData(
1121+
object = object[[assay]],
1122+
metadata = md
1123+
)
1124+
}
11181125
Idents(object = object) <- project
11191126
# Get DimReduc information, add underscores if needed and pull from different alt EXP
11201127
if (length(x = SingleCellExperiment::reducedDimNames(x = x)) > 0) {
11211128
for (dr in SingleCellExperiment::reducedDimNames(x = x)) {
1122-
embeddings <- SingleCellExperiment::reducedDim(x = x, type = dr)
1129+
embeddings <- as.matrix(x = SingleCellExperiment::reducedDim(x = x, type = dr))
11231130
if (is.null(x = rownames(x = embeddings))) {
11241131
rownames(x = embeddings) <- cell.names
11251132
}
1126-
if(!grepl('_$',
1133+
if (isTRUE(x = !grepl('_$',
11271134
gsub(pattern = "[[:digit:]]",
11281135
replacement = "_",
11291136
x = colnames(x = SingleCellExperiment::reducedDim(x = x, type = dr))[1]
1130-
))){
1137+
)))) {
11311138
key <- gsub(
11321139
pattern = "[[:digit:]]",
11331140
replacement = "_",
@@ -1173,36 +1180,65 @@ as.SingleCellExperiment.Seurat <- function(x, assay = NULL, ...) {
11731180
stop("One or more of the assays you are trying to convert is not in the Seurat object")
11741181
}
11751182
experiments <- list()
1176-
for (assayn in assay){
1183+
for (assayn in assay) {
11771184
assays = list(
11781185
counts = GetAssayData(object = x, assay = assayn, slot = "counts"),
1179-
logcounts = GetAssayData(object = x, assay = assayn, slot = "data"))
1186+
logcounts = GetAssayData(object = x, assay = assayn, slot = "data"),
1187+
scaledata = GetAssayData(object = x, assay = assayn, slot = "scale.data"))
11801188
assays <- assays[sapply(X = assays, FUN = nrow) != 0]
11811189
sume <- SummarizedExperiment::SummarizedExperiment(assays = assays)
11821190
experiments[[assayn]] <- sume
11831191
}
11841192
# create one single cell experiment
11851193
sce <- as(object = experiments[[1]], Class = "SingleCellExperiment")
1186-
sce <- SingleCellExperiment::SingleCellExperiment(sce, altExps = experiments)
11871194
orig.exp.name <- names(x = experiments[1])
1188-
sce <- SingleCellExperiment::swapAltExp(x = sce, name = orig.exp.name, saved = NULL)
1195+
if (packageVersion(pkg = "SingleCellExperiment") >= "1.14.0") {
1196+
SingleCellExperiment::mainExpName(sce) <- names(x = experiments[1])
1197+
}
1198+
if (length(x = experiments) > 1) {
1199+
sce <- SingleCellExperiment::SingleCellExperiment(sce, altExps = experiments)
1200+
sce <- SingleCellExperiment::swapAltExp(
1201+
x = sce,
1202+
name = orig.exp.name,
1203+
saved = NULL
1204+
)
1205+
}
11891206
metadata <- x[[]]
11901207
metadata$ident <- Idents(object = x)
11911208
SummarizedExperiment::colData(x = sce) <- S4Vectors::DataFrame(metadata)
1192-
for (assayn in assay){
1193-
sce <- SingleCellExperiment::swapAltExp(x = sce, name = assayn, saved = orig.exp.name)
1194-
SummarizedExperiment::rowData(x = sce) <- S4Vectors::DataFrame(x[[assayn]][[]])
1195-
sce <- SingleCellExperiment::swapAltExp(x = sce, name = orig.exp.name, saved = assayn)
1209+
for (assayn in assay) {
1210+
if (assayn != orig.exp.name) {
1211+
sce <- SingleCellExperiment::swapAltExp(
1212+
x = sce,
1213+
name = assayn,
1214+
saved = orig.exp.name
1215+
)
1216+
SummarizedExperiment::rowData(x = sce) <- S4Vectors::DataFrame(x[[assayn]][[]])
1217+
sce <- SingleCellExperiment::swapAltExp(
1218+
x = sce,
1219+
name = orig.exp.name,
1220+
saved = assayn
1221+
)
1222+
}
11961223
}
11971224
for (dr in FilterObjects(object = x, classes.keep = "DimReduc")) {
11981225
assay.used <- DefaultAssay(object = x[[dr]])
1199-
if (assay.used %in% SingleCellExperiment::altExpNames(x = sce)) {
1200-
sce <- SingleCellExperiment::swapAltExp(x = sce, name = assay.used, saved = orig.exp.name)
1201-
SingleCellExperiment::reducedDim(x = sce, toupper(x = dr)) <- Embeddings(object = x[[dr]])
1202-
sce <- SingleCellExperiment::swapAltExp(x = sce, name = orig.exp.name, saved = assay.used)
1226+
if (assay.used %in% SingleCellExperiment::altExpNames(x = sce) & assay.used != orig.exp.name) {
1227+
sce <- SingleCellExperiment::swapAltExp(
1228+
x = sce,
1229+
name = assay.used,
1230+
saved = orig.exp.name
1231+
)
1232+
}
1233+
SingleCellExperiment::reducedDim(x = sce, type = toupper(x = dr)) <- Embeddings(object = x[[dr]])
1234+
if (assay.used %in% SingleCellExperiment::altExpNames(x = sce) & assay.used != orig.exp.name) {
1235+
sce <- SingleCellExperiment::swapAltExp(
1236+
x = sce,
1237+
name = orig.exp.name,
1238+
saved = assay.used
1239+
)
12031240
}
12041241
}
1205-
sce <- SingleCellExperiment::swapAltExp(x = sce, name = orig.exp.name, saved = NULL)
12061242
return(sce)
12071243
}
12081244

R/utilities.R

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -796,14 +796,25 @@ FastRowScale <- function(
796796
#' @note This function requires internet access
797797
#'
798798
#' @param symbols A vector of gene symbols
799-
#' @param timeout Time to wait before cancelling query in seconds
800-
#' @param several.ok Allow several current gene sybmols for each provided symbol
799+
#' @param timeout Time to wait before canceling query in seconds
800+
#' @param several.ok Allow several current gene symbols for each
801+
#' provided symbol
802+
#' @param search.types Type of query to perform:
803+
#' \describe{
804+
#' \item{\dQuote{\code{alias_symbol}}}{Find alternate symbols for the genes
805+
#' described by \code{symbols}}
806+
#' \item{\dQuote{\code{prev_symbol}}}{Find new new symbols for the genes
807+
#' described by \code{symbols}}
808+
#' }
809+
#' This parameter accepts multiple options and short-hand options
810+
#' (eg. \dQuote{\code{prev}} for \dQuote{\code{prev_symbol}})
801811
#' @param verbose Show a progress bar depicting search progress
802812
#' @param ... Extra parameters passed to \code{\link[httr]{GET}}
803813
#'
804-
#' @return For \code{GeneSymbolThesarus}, if \code{several.ok}, a named list
805-
#' where each entry is the current symbol found for each symbol provided and the
806-
#' names are the provided symbols. Otherwise, a named vector with the same information.
814+
#' @return \code{GeneSymbolThesarus}:, if \code{several.ok}, a named list
815+
#' where each entry is the current symbol found for each symbol provided and
816+
#' the names are the provided symbols. Otherwise, a named vector with the
817+
#' same information.
807818
#'
808819
#' @source \url{https://www.genenames.org/} \url{https://www.genenames.org/help/rest/}
809820
#'
@@ -827,11 +838,13 @@ GeneSymbolThesarus <- function(
827838
symbols,
828839
timeout = 10,
829840
several.ok = FALSE,
841+
search.types = c('alias_symbol', 'prev_symbol'),
830842
verbose = TRUE,
831843
...
832844
) {
833845
db.url <- 'http://rest.genenames.org/fetch'
834-
search.types <- c('alias_symbol', 'prev_symbol')
846+
# search.types <- c('alias_symbol', 'prev_symbol')
847+
search.types <- match.arg(arg = search.types, several.ok = TRUE)
835848
synonyms <- vector(mode = 'list', length = length(x = symbols))
836849
not.found <- vector(mode = 'logical', length = length(x = symbols))
837850
multiple.found <- vector(mode = 'logical', length = length(x = symbols))
@@ -1472,7 +1485,7 @@ RegroupIdents <- function(object, metadata) {
14721485

14731486
#' @rdname UpdateSymbolList
14741487
#'
1475-
#' @return For \code{UpdateSymbolList}, \code{symbols} with updated symbols from
1488+
#' @return \code{UpdateSymbolList}: \code{symbols} with updated symbols from
14761489
#' HGNC's gene names database
14771490
#'
14781491
#' @export
@@ -1494,6 +1507,7 @@ UpdateSymbolList <- function(
14941507
symbols = symbols,
14951508
timeout = timeout,
14961509
several.ok = several.ok,
1510+
search.types = 'prev_symbol',
14971511
verbose = verbose,
14981512
...
14991513
))

0 commit comments

Comments
 (0)