Title: | Save and Load Spatial 'Omics Data to/from File |
---|---|
Description: | Save SpatialExperiment objects and their images into file artifacts, and load them back into memory. This is a more portable alternative to serialization of such objects into RDS files. Each artifact is associated with metadata for further interpretation; downstream applications can enrich this metadata with context-specific properties. |
Authors: | Aaron Lun [aut, cre] |
Maintainer: | Aaron Lun <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.7.1 |
Built: | 2024-11-10 03:26:00 UTC |
Source: | https://github.com/bioc/alabaster.spatial |
Load an image as a SpatialImage or subclass thereof.
loadSpatialImage(img.info, project)
loadSpatialImage(img.info, project)
img.info |
Named list containing the metadata for this assay. |
project |
Object specifying the project of interest. |
A SpatialImage containing the image data (or a reference to it).
Aaron Lun
example(read10xVisium, echo=FALSE) img <- imgData(spe)$data[[1]] tmp <- tempfile() dir.create(tmp) meta <- stageObject(img, tmp, "whee") out <- loadSpatialImage(meta, tmp)
example(read10xVisium, echo=FALSE) img <- imgData(spe)$data[[1]] tmp <- tempfile() dir.create(tmp) meta <- stageObject(img, tmp, "whee") out <- loadSpatialImage(meta, tmp)
Read a SpatialExperiment object from its on-disk representation.
readSpatialExperiment(path, metadata, ...)
readSpatialExperiment(path, metadata, ...)
path |
String containing a path to a directory, itself created using the |
metadata |
Named list of metadata for this object, see |
... |
Further arguments passed to |
A SpatialExperiment object.
Aaron Lun
"saveObject,SpatialExperiment-method"
, to save a SpatialExperiment to disk.
library(SpatialExperiment) example(read10xVisium, echo=FALSE) tmp <- tempfile() saveObject(spe, tmp) readObject(tmp)
library(SpatialExperiment) example(read10xVisium, echo=FALSE) tmp <- tempfile() saveObject(spe, tmp) readObject(tmp)
Save a SpatialExperiment object to its on-disk representation.
## S4 method for signature 'SpatialExperiment' saveObject(x, path, ...)
## S4 method for signature 'SpatialExperiment' saveObject(x, path, ...)
x |
A SpatialExperiment object. |
path |
String containing the path to a directory in which to save |
... |
Additional named arguments to pass to specific methods. |
Currently, only PNG and TIFF image formats are supported in the imgData
.
All other images will be re-saved as PNG.
x
is saved to path
and NULL
is invisibly returned.
Aaron Lun
readSpatialExperiment
, to read the SpatialExperiment back into the R session.
library(SpatialExperiment) example(read10xVisium, echo=FALSE) tmp <- tempfile() saveObject(spe, tmp) list.files(tmp, recursive=TRUE)
library(SpatialExperiment) example(read10xVisium, echo=FALSE) tmp <- tempfile() saveObject(spe, tmp) list.files(tmp, recursive=TRUE)
These methods are deprecated and are only documented here for back-compatibility purposes.
## S4 method for signature 'VirtualSpatialImage' stageObject(x, dir, path, child = FALSE, ...) ## S4 method for signature 'StoredSpatialImage' stageObject(x, dir, path, child = FALSE, ...) ## S4 method for signature 'RemoteSpatialImage' stageObject(x, dir, path, child = FALSE, ...)
## S4 method for signature 'VirtualSpatialImage' stageObject(x, dir, path, child = FALSE, ...) ## S4 method for signature 'StoredSpatialImage' stageObject(x, dir, path, child = FALSE, ...) ## S4 method for signature 'RemoteSpatialImage' stageObject(x, dir, path, child = FALSE, ...)
x |
A SpatialImage object. |
dir |
String containing a path to a directory. |
path |
String containing a relative path inside a directory. |
child |
Logical scalar indicating whether |
... |
Further arguments, ignored. |
Each of the different methods will take advantage of any existing files to avoid an actual save.
For example, the RemoteSpatialImage method will download the file directly to path
,
while the StoredSpatialImage method will create a link or copy the file.
The SpatialImage method will fall back to saving the raster directly as a PNG.
An image file is created at file.path(dir, path)
, possibly after appending an appropriate file extension.
The return value should be a named list containing at least:
$schema
, a string specifying the schema to use to validate the metadata.
This may have a package
attribute to specify the package where the schema lives (in its inst/schemas
directory).
path
, a string containing the path to the file containing the assay contents.
This should start with the input path
but can be followed by any necessary file extensions.
child
, whether this is a child resource of a larger object.
Other fields can be provided and will be included in the metadata, provided that they are recognized by the specified schema.
Aaron Lun
example(read10xVisium, echo=FALSE) (img <- imgData(spe)$data[[1]]) # Doing a local run: tmp <- tempfile() dir.create(tmp) stageObject(img, tmp, "whee") # Forcing a re-save: Y <- as(img, "LoadedSpatialImage") stageObject(Y, tmp, "foo")
example(read10xVisium, echo=FALSE) (img <- imgData(spe)$data[[1]]) # Doing a local run: tmp <- tempfile() dir.create(tmp) stageObject(img, tmp, "whee") # Forcing a re-save: Y <- as(img, "LoadedSpatialImage") stageObject(Y, tmp, "foo")