File: SpatialExperiment-colData.Rd

package info (click to toggle)
r-bioc-spatialexperiment 1.16.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,648 kB
  • sloc: makefile: 2
file content (62 lines) | stat: -rw-r--r-- 1,883 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/SpatialExperiment-colData.R
\name{SpatialExperiment-colData}
\alias{SpatialExperiment-colData}
\alias{colData}
\alias{colData<-}
\alias{colData<-,SpatialExperiment,DataFrame-method}
\alias{colData<-,SpatialExperiment,NULL-method}
\title{SpatialExperiment colData}
\usage{
\S4method{colData}{SpatialExperiment,DataFrame}(x) <- value

\S4method{colData}{SpatialExperiment,`NULL`}(x) <- value
}
\arguments{
\item{x}{a \code{\link{SpatialExperiment}}}

\item{value}{a \code{\link[S4Vectors]{DataFrame}}}
}
\value{
a \code{\link{SpatialExperiment}} object with updated \code{colData}
}
\description{
The \code{\link{SpatialExperiment}} class provides a modified \code{colData}
setter, which ensures that the \code{SpatialExperiment} object remains valid.
}
\details{
The \code{colData} setter performs several checks to ensure validity. If the
replacement \code{colData} does not contain a \code{sample_id} column, the
existing \code{sample_id}s will be retained. If the replacement
\code{colData} contains \code{sample_id}s, a check is performed to ensure the
number of unique \code{sample_id}s is the same, i.e. a one-to-one mapping is
possible. If the replacement is \code{NULL}, the \code{sample_id}s are
retained. In addition, checks are performed against the \code{sample_id}s in
\code{\link{imgData}}.
}
\examples{
example(read10xVisium)

# empty replacement retains sample identifiers
colData(spe) <- NULL
names(colData(spe))

# replacement of sample identifiers
# requires one-to-one mapping

## invalid replacement

tryCatch(
  spe$sample_id <- seq(ncol(spe)),
  error = function(e) message(e)) 
  
## valid replacement  
  
old <- c("section1", "section2")
new <- c("sample_A", "sample_B")
idx <- match(spe$sample_id, old)

tmp <- spe
tmp$sample_id <- new[idx]
table(spe$sample_id, tmp$sample_id)
}