Alternative experiments of subsets in ExperimentSubset objects
Source:R/ExperimentSubset.R, R/SubsetSingleCellExperiment.R, R/SubsetSpatialExperiment.R, and 1 more
ExperimentSubset-altExp.RdGet or set the alternative experiments (altExps) of
a subset by naming it with subsetName. Without
subsetName, these methods act on the main object, as for
SingleCellExperiment. They exist for the classes that extend
SingleCellExperiment: SubsetSingleCellExperiment,
SubsetSpatialExperiment and SubsetTreeSummarizedExperiment.
Usage
# S4 method for class 'SubsetSingleCellExperiment,character'
altExp(x, e, ...)
# S4 method for class 'SubsetSingleCellExperiment,missing'
altExp(x, e, ...)
# S4 method for class 'SubsetSingleCellExperiment,numeric'
altExp(x, e, ...)
# S4 method for class 'SubsetSingleCellExperiment'
altExps(x, ...)
# S4 method for class 'SubsetSingleCellExperiment'
altExpNames(x, ...)
# S4 method for class 'SubsetSingleCellExperiment,character'
altExpNames(x, ...) <- value
# S4 method for class 'SubsetSingleCellExperiment,ANY'
altExpNames(x, ...) <- value
# S4 method for class 'SubsetSingleCellExperiment,character'
altExp(x, e, withDimnames = TRUE, withColData = FALSE, ...) <- value
# S4 method for class 'SubsetSingleCellExperiment,missing'
altExp(x, e, withDimnames = TRUE, withColData = FALSE, ...) <- value
# S4 method for class 'SubsetSingleCellExperiment,numeric'
altExp(x, e, withDimnames = TRUE, withColData = FALSE, ...) <- value
# S4 method for class 'SubsetSingleCellExperiment'
altExps(x, withDimnames = TRUE, withColData = FALSE, ...) <- value
# S4 method for class 'SubsetSpatialExperiment,character'
altExp(x, e, ...)
# S4 method for class 'SubsetSpatialExperiment,missing'
altExp(x, e, ...)
# S4 method for class 'SubsetSpatialExperiment,numeric'
altExp(x, e, ...)
# S4 method for class 'SubsetSpatialExperiment'
altExps(x, ...)
# S4 method for class 'SubsetSpatialExperiment'
altExpNames(x, ...)
# S4 method for class 'SubsetSpatialExperiment,character'
altExpNames(x, ...) <- value
# S4 method for class 'SubsetSpatialExperiment,ANY'
altExpNames(x, ...) <- value
# S4 method for class 'SubsetSpatialExperiment,character'
altExp(x, e, withDimnames = TRUE, withColData = FALSE, ...) <- value
# S4 method for class 'SubsetSpatialExperiment,missing'
altExp(x, e, withDimnames = TRUE, withColData = FALSE, ...) <- value
# S4 method for class 'SubsetSpatialExperiment,numeric'
altExp(x, e, withDimnames = TRUE, withColData = FALSE, ...) <- value
# S4 method for class 'SubsetSpatialExperiment'
altExps(x, withDimnames = TRUE, withColData = FALSE, ...) <- value
# S4 method for class 'SubsetTreeSummarizedExperiment,character'
altExp(x, e, ...)
# S4 method for class 'SubsetTreeSummarizedExperiment,missing'
altExp(x, e, ...)
# S4 method for class 'SubsetTreeSummarizedExperiment,numeric'
altExp(x, e, ...)
# S4 method for class 'SubsetTreeSummarizedExperiment'
altExps(x, ...)
# S4 method for class 'SubsetTreeSummarizedExperiment'
altExpNames(x, ...)
# S4 method for class 'SubsetTreeSummarizedExperiment,character'
altExpNames(x, ...) <- value
# S4 method for class 'SubsetTreeSummarizedExperiment,ANY'
altExpNames(x, ...) <- value
# S4 method for class 'SubsetTreeSummarizedExperiment,character'
altExp(x, e, withDimnames = TRUE, withColData = FALSE, ...) <- value
# S4 method for class 'SubsetTreeSummarizedExperiment,missing'
altExp(x, e, withDimnames = TRUE, withColData = FALSE, ...) <- value
# S4 method for class 'SubsetTreeSummarizedExperiment,numeric'
altExp(x, e, withDimnames = TRUE, withColData = FALSE, ...) <- value
# S4 method for class 'SubsetTreeSummarizedExperiment'
altExps(x, withDimnames = TRUE, withColData = FALSE, ...) <- valueArguments
- x
An
ExperimentSubsetobject.- e
character(1)orinteger(1)The name or position of the alternative experiment. Leave it out for the first one. WithsubsetName, positions followaltExpNames().- ...
subsetNamecharacter(1)Name of the subset whose alternative experiments to get or set. Leave it out for the main object's.unlinkFor
altExp<-andaltExps<-withsubsetName:TRUE,FALSEor a character vector of"altExpName/assayName"names. Store assays ofvaluethat have the name of a linked altExp assay but different values: withTRUE, every such assay; with names, only those. Any other such assay is an error, and nothing is stored. A message names each assay that is unlinked. DefaultFALSE. Any other value is an error withoutsubsetName.
Other arguments are passed on to the
SingleCellExperimentmethod. WithsubsetName,altExpNames()andaltExpNames<-ignore other arguments.- value
For
altExp<-, aSummarizedExperimentwith one column per column of the subset (or of the main object). ForaltExps<-, a list of them. ForaltExpNames<-, acharactervector of new names, one for each namealtExpNames()returns; withsubsetName, they must all differ, and only the subset's own altExps can get new names.- withDimnames
logical(1)Passed on toaltExp<-oraltExps<-. DefaultTRUE.- withColData
logical(1)Passed on toaltExp<-oraltExps<-. DefaultFALSE.
Value
altExp() returns a SummarizedExperiment,
altExps() a list of them and altExpNames() a
character vector. With subsetName, these are every
altExp the subset sees: the main object's first, then those stored
only on subsets. The setters return x with the change made.
Details
A subset sees the main object's altExps, and those stored on
the subsets it was made from, cut to its own columns (cells). Their
rows (features, such as the proteins of an ADT altExp) are not cut: a
subset's rows pick features of the main object only. These
altExps are linked, as assays are: the subset sees their current
values, and stores only what it changes.
Storing an altExp in a subset with altExp<- or altExps<-
compares it with the linked one of the same name, assay by assay:
A new assay is stored as the subset's own, and the linked assays stay linked.
An assay with the values of the linked one is not stored.
An assay with other values than the linked one needs
unlink, named as"altExpName/assayName", such as"ADT/counts".rowData, colData, metadata and reducedDims are stored when they differ from the linked altExp's, and then replace them whole. An empty one shows the linked one, so a subset can't clear them. Other parts, such as the altExp's own altExps,
colPairsandrowPairs, always come from the linked altExp.An assay the subset already stores itself, after an unlink, is not linked, so storing it again needs no
unlink.An altExp with other rows, rownames or class than the linked one replaces it entirely, so every linked assay counts as changed. It keeps replacing it for as long as the subset stores it, even if the linked altExp later has the same rows, and so does an altExp a subset stores while nothing of that name is linked. To add to the linked altExp instead, remove the subset's with
altExp(x, e, subsetName = s) <- NULLand store it again.
A subset can't remove or rename a linked altExp, or give one of its own
the name of another altExp it sees: an altExp missing
from value in altExps<- stays visible, and
altExp(x, e, subsetName = s) <- NULL removes only what the
subset stores, so the linked altExp shows again.
Changes to a linked altExp carry along to the subsets below it, made from the main object or from the subset that stores it. Its new values show in them. Renaming it renames what they store of it. Removing it, or storing it with other rows or another class, drops what they added to it, with a warning; an altExp a subset stores whole is kept.
Examples
# an object with 10 genes and 20 cells
set.seed(1)
counts <- matrix(rpois(200, lambda = 5), nrow = 10)
rownames(counts) <- paste0("gene", 1:10)
colnames(counts) <- paste0("cell", 1:20)
es <- ExperimentSubset(list(counts = counts))
# counts of 2 proteins in the same 20 cells, as an altExp
adtCounts <- matrix(rpois(40, lambda = 20), nrow = 2)
rownames(adtCounts) <- c("CD3", "CD4")
altExp(es, "ADT") <- SummarizedExperiment(list(counts = adtCounts))
#> Warning: 'colnames(value)' are not the same as 'colnames(x)' for 'altExp<-'.
#> This will be an error in the next release of Bioconductor.
# a subset of the first 5 genes and the first 8 cells
es <- createSubset(es, subsetName = "first", rows = 1:5, cols = 1:8)
# the subset sees ADT for its 8 cells, with both proteins
altExpNames(es, subsetName = "first")
#> [1] "ADT"
adt <- altExp(es, "ADT", subsetName = "first")
dim(adt)
#> [1] 2 8
# add an assay to ADT in the subset only; ADT's counts stay linked
assay(adt, "logcounts") <- log1p(assay(adt, "counts"))
altExp(es, "ADT", subsetName = "first") <- adt
assayNames(altExp(es, "ADT", subsetName = "first"))
#> [1] "counts" "logcounts"
assayNames(altExp(es, "ADT"))
#> [1] "counts"
# a changed linked assay needs unlink
assay(adt, "counts") <- assay(adt, "counts") + 1L
altExp(es, "ADT", subsetName = "first", unlink = "ADT/counts") <- adt
#> Subset 'first' now stores its own 'ADT/counts', unlinked from the main altExp 'ADT'.