
SpatialMap apply over Regions
dot-smapply.Rd
Wrapper for iteration over the Regions in a SpatialMap object
Usage
.smapply(
object,
...,
all = F,
analyze = NULL,
cores = NULL,
parallel = NULL,
future.init = NULL,
cat.output = NULL,
python = FALSE,
progress = NULL
)
Arguments
- object
The SpatialMap object
- ...
Parameters passed to
lapply
, namely toFUN
- all
Whether to iterate over all Regions in the SpatialMap. Deprecated - now this will be handled by the
analyze
parameter.- analyze
What to analyze (and how). The options are "regions", NULL (activeAnalysis), the name of a currently existing formal analysis, or the name of a column in
object
'sprojectMetadata
(an "informal" analysis).- cores
Parallelization options
- parallel
Parallelization options
- future.init
Whether future framework has been initialized already. Typically you don't need to interact with this mostly internal parameter
- cat.output
Controls return behavior.
Defaults to
NULL
, in which case.smapply
will try to return a validSpatialMap
object.FUN
must return a validRegion
object in this case.Accepts a quoted function name (e.g.
"rbind"
) which will be passed toReduce(f = cat.output)
in order to concatenate the output ofFUN
.Alternatively, pass "none" to return the output as a list (e.g. a list of plots).
- python
Whether or not a Python environment needs to be initialized to run the specified FUN (...).
- progress
Whether or not to display a progress bar when iterating
Value
If
cat.output
isNULL
, returns aSpatialMap
object.If
cat.output
is"none"
, returns alist
object, named by theRegions
or by theAnalysis
.If
cat.output
is a quoted function (e.g."rbind"
), returns that list after concatenation viaReduce(f = cat.output)
Examples
sm_tonsil <- load_sm_data("tonsil")
# Returning a modified SpatialMap object
small_tonsil <- .smapply(object = sm_tonsil, function(r) {
## Retrieve spatial embeddings from Region 'r'
emb <- embeddings(r, "spatial")
## Take the desired subset from the top corner
my.subset <- emb[, "x"] < 1000 & facil::inv(emb[, "y"]) < 1000
## Check that some cells remain (otherwise things could break)
if (sum(my.subset) < 2) {
stop("Subset is empty")
}
## Subset Region r and return
r[my.subset]
})
# Returning a list
thousandth_cells_biomarkers <- .smapply(object = sm_tonsil, function(r) {
dat <- Data(r, "Data")
dat[, 1000]
},
cat.output = "none")
# Returning a dataframe
thousandth_cells_biomarkers_df <- .smapply(object = sm_tonsil, function(r) {
dat <- Data(r, "Data")
thousandth <- t(dat[, 1000, drop = FALSE]) %>%
dplyr::as_tibble()
res <- dplyr::bind_cols(Region = getID(r),
thousandth)
return(res)
},
cat.output = "rbind")