Skip to content

Commit dc2f740

Browse files
authored
Merge pull request #28 from mojaveazure/develop
SeuratObject v4.0.3
2 parents b994341 + 843a3b1 commit dc2f740

15 files changed

+438
-783
lines changed

.Rbuildignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
^.*\.h5Seurat$
1717
^.*\.rds$
1818
^.*\.Rds$
19-
^LICENSE$
2019
^data-raw$
2120
^inst$
2221
^tests$
22+
^LICENSE\.md$

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: SeuratObject
22
Type: Package
33
Title: Data Structures for Single Cell Data
4-
Version: 4.0.2
5-
Date: 2021-06-08
4+
Version: 4.0.3
5+
Date: 2021-11-10
66
Authors@R: c(
77
person(given = 'Rahul', family = 'Satija', email = 'rsatija@nygenome.org', role = 'aut', comment = c(ORCID = '0000-0001-9448-8833')),
88
person(given = 'Andrew', family = 'Butler', email = 'abutler@nygenome.org', role = 'aut', comment = c(ORCID = '0000-0003-3608-0463')),
@@ -26,7 +26,7 @@ URL: https://satijalab.org/seurat,
2626
https://github.com/mojaveazure/seurat-object
2727
BugReports:
2828
https://github.com/mojaveazure/seurat-object/issues
29-
License: GPL-3
29+
License: MIT + file LICENSE
3030
Encoding: UTF-8
3131
LazyData: true
3232
RoxygenNote: 7.1.1

LICENSE

Lines changed: 2 additions & 674 deletions
Large diffs are not rendered by default.

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MIT License
2+
3+
Copyright (c) 2021 SeuratObject authors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

NAMESPACE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,18 @@ export(Assays)
157157
export(AttachDeps)
158158
export(Cells)
159159
export(CellsByIdentities)
160+
export(CheckDots)
160161
export(CheckGC)
161162
export(Command)
162163
export(CreateAssayObject)
163164
export(CreateDimReducObject)
164165
export(CreateSeuratObject)
165166
export(DefaultAssay)
167+
export(DefaultDimReduc)
166168
export(Distances)
167169
export(Embeddings)
168170
export(FetchData)
171+
export(FilterObjects)
169172
export(GetAssayData)
170173
export(GetImage)
171174
export(GetTissueCoordinates)
@@ -185,8 +188,10 @@ export(Loadings)
185188
export(LogSeuratCommand)
186189
export(Misc)
187190
export(Neighbors)
191+
export(PackageCheck)
188192
export(Project)
189193
export(Radius)
194+
export(RandomName)
190195
export(Reductions)
191196
export(RenameAssays)
192197
export(RenameCells)

NEWS.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# SeuratObject 4.0.3
2+
3+
## Changed
4+
- Export utility functions (#22)
5+
- Bug fix in names with `Key.Seurat` (#26)
6+
- Improved duplicate key checking and resolution
7+
18
# SeuratObject 4.0.2
29

310
## Changed
@@ -15,7 +22,7 @@
1522
- Allow super classes to replace child classes (#1). For example, allows `Assay`
1623
objects to replace `Seurat::SCTAssay` or `Signac::ChromatinAssay` objects of
1724
the same name
18-
- Better support for creating sparse matrices from `data.table`/`tibble`
25+
- Better support for creating sparse matrices from `data.table`/`tibble`
1926
objects (#4)
2027
- Improved error messages for clashing object names (#7)
2128
- Allow returning a `NULL` if a subset results in zero cells (#9)

R/seurat.R

Lines changed: 89 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,52 @@ FetchData <- function(object, vars, cells = NULL, slot = 'data') {
499499
return(data.fetched)
500500
}
501501

502+
#' Find Sub-objects of a Certain Class
503+
#'
504+
#' Get the names of objects within a \code{Seurat} object that are of a
505+
#' certain class
506+
#'
507+
#' @param object A \code{\link{Seurat}} object
508+
#' @param classes.keep A vector of names of classes to get
509+
#'
510+
#' @return A vector with the names of objects within the \code{Seurat} object
511+
#' that are of class \code{classes.keep}
512+
#'
513+
#' @export
514+
#'
515+
#' @examples
516+
#' FilterObjects(pbmc_small)
517+
#'
518+
FilterObjects <- function(object, classes.keep = c('Assay', 'DimReduc')) {
519+
object <- UpdateSlots(object = object)
520+
slots <- na.omit(object = Filter(
521+
f = function(x) {
522+
sobj <- slot(object = object, name = x)
523+
return(is.list(x = sobj) && !is.data.frame(x = sobj) && !is.package_version(x = sobj))
524+
},
525+
x = slotNames(x = object)
526+
))
527+
slots <- grep(pattern = 'tools', x = slots, value = TRUE, invert = TRUE)
528+
slots <- grep(pattern = 'misc', x = slots, value = TRUE, invert = TRUE)
529+
slots.objects <- unlist(
530+
x = lapply(
531+
X = slots,
532+
FUN = function(x) {
533+
return(names(x = slot(object = object, name = x)))
534+
}
535+
),
536+
use.names = FALSE
537+
)
538+
object.classes <- sapply(
539+
X = slots.objects,
540+
FUN = function(i) {
541+
return(inherits(x = object[[i]], what = classes.keep))
542+
}
543+
)
544+
object.classes <- which(x = object.classes, useNames = TRUE)
545+
return(names(x = object.classes))
546+
}
547+
502548
#' @rdname ObjectAccess
503549
#' @export
504550
#'
@@ -1313,12 +1359,16 @@ Key.Seurat <- function(object, ...) {
13131359
object = object,
13141360
classes.keep = c('Assay', 'DimReduc', 'SpatialImage')
13151361
)
1316-
return(sapply(
1362+
keys <- vapply(
13171363
X = keyed.objects,
13181364
FUN = function(x) {
13191365
return(Key(object = object[[x]]))
1320-
}
1321-
))
1366+
},
1367+
FUN.VALUE = character(length = 1L),
1368+
USE.NAMES = FALSE
1369+
)
1370+
names(x = keys) <- keyed.objects
1371+
return(keys)
13221372
}
13231373

13241374
#' @param reduction Name of reduction to pull feature loadings for
@@ -2766,38 +2816,51 @@ setMethod( # because R doesn't allow S3-style [[<- for S4 classes
27662816
}
27672817
Key(object = value) <- UpdateKey(key = Key(object = value))
27682818
# Check for duplicate keys
2769-
object.keys <- sapply(
2770-
X = FilterObjects(object = x),
2771-
FUN = function(i) {
2772-
return(Key(object = x[[i]]))
2773-
}
2774-
)
2775-
if (Key(object = value) %in% object.keys && is.null(x = FindObject(object = x, name = i))) {
2776-
# Attempt to create a duplicate key based off the name of the object being added
2777-
new.keys <- c(paste0(tolower(x = i), c('_', paste0(RandomName(length = 2L), '_'))))
2778-
# Select new key to use
2779-
key.use <- min(which(x = !new.keys %in% object.keys))
2780-
new.key <- if (is.infinite(x = key.use)) {
2781-
RandomName(length = 17L)
2819+
object.keys <- Key(object = x)
2820+
vkey <- Key(object = value)
2821+
if (vkey %in% object.keys && !isTRUE(x = object.keys[i] == vkey)) {
2822+
new.key <- if (is.na(x = object.keys[i])) {
2823+
# Attempt to create a duplicate key based off the name of the object being added
2824+
new.keys <- paste0(
2825+
paste0(tolower(x = i), c('', RandomName(length = 2L))),
2826+
'_'
2827+
)
2828+
# Select new key to use
2829+
key.use <- min(which(x = !new.keys %in% object.keys))
2830+
new.key <- if (is.infinite(x = key.use)) {
2831+
RandomName(length = 17L)
2832+
} else {
2833+
new.keys[key.use]
2834+
}
2835+
warning(
2836+
"Cannot add objects with duplicate keys (offending key: ",
2837+
Key(object = value),
2838+
"), setting key to '",
2839+
new.key,
2840+
"'",
2841+
call. = FALSE
2842+
)
2843+
new.key
27822844
} else {
2783-
new.keys[key.use]
2845+
# Use existing key
2846+
warning(
2847+
"Cannot add objects with duplicate keys (offending key: ",
2848+
Key(object = value),
2849+
") setting key to original value '",
2850+
object.keys[i],
2851+
"'",
2852+
call. = FALSE
2853+
)
2854+
object.keys[i]
27842855
}
2785-
warning(
2786-
"Cannot add objects with duplicate keys (offending key: ",
2787-
Key(object = value),
2788-
"), setting key to '",
2789-
new.key,
2790-
"'",
2791-
call. = FALSE
2792-
)
27932856
# Set new key
27942857
Key(object = value) <- new.key
27952858
}
27962859
}
27972860
# For Assays, run CalcN
27982861
if (inherits(x = value, what = 'Assay')) {
27992862
if ((!i %in% Assays(object = x)) |
2800-
(i %in% Assays(object = x) && ! identical(
2863+
(i %in% Assays(object = x) && !identical(
28012864
x = GetAssayData(object = x, assay = i, slot = "counts"),
28022865
y = GetAssayData(object = value, slot = "counts"))
28032866
)) {
@@ -3082,48 +3145,6 @@ DefaultImage <- function(object) {
30823145
return(images[[1]])
30833146
}
30843147

3085-
#' Get the names of objects within a Seurat object that are of a certain class
3086-
#'
3087-
#' @param object A \code{\link{Seurat}} object
3088-
#' @param classes.keep A vector of names of classes to get
3089-
#'
3090-
#' @return A vector with the names of objects within the Seurat object that are
3091-
#' of class \code{classes.keep}
3092-
#'
3093-
#' @keywords internal
3094-
#'
3095-
#' @noRd
3096-
#'
3097-
FilterObjects <- function(object, classes.keep = c('Assay', 'DimReduc')) {
3098-
object <- UpdateSlots(object = object)
3099-
slots <- na.omit(object = Filter(
3100-
f = function(x) {
3101-
sobj <- slot(object = object, name = x)
3102-
return(is.list(x = sobj) && !is.data.frame(x = sobj) && !is.package_version(x = sobj))
3103-
},
3104-
x = slotNames(x = object)
3105-
))
3106-
slots <- grep(pattern = 'tools', x = slots, value = TRUE, invert = TRUE)
3107-
slots <- grep(pattern = 'misc', x = slots, value = TRUE, invert = TRUE)
3108-
slots.objects <- unlist(
3109-
x = lapply(
3110-
X = slots,
3111-
FUN = function(x) {
3112-
return(names(x = slot(object = object, name = x)))
3113-
}
3114-
),
3115-
use.names = FALSE
3116-
)
3117-
object.classes <- sapply(
3118-
X = slots.objects,
3119-
FUN = function(i) {
3120-
return(inherits(x = object[[i]], what = classes.keep))
3121-
}
3122-
)
3123-
object.classes <- which(x = object.classes, useNames = TRUE)
3124-
return(names(x = object.classes))
3125-
}
3126-
31273148
#' Find the collection of an object within a Seurat object
31283149
#'
31293150
#' @param object A \code{\link{Seurat}} object

0 commit comments

Comments
 (0)