| Title: | Language agnostic on disk serialization of SpatialFeatureExperiment |
|---|---|
| Description: | Builds upon the existing ArtifactDB project, expending alabaster.spatial for language agnostic on disk serialization of SpatialFeatureExperiment. |
| Authors: | Lambda Moses [aut, cre] (ORCID: <https://orcid.org/0000-0002-7092-9427>) |
| Maintainer: | Lambda Moses <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.5.0 |
| Built: | 2026-05-30 09:41:19 UTC |
| Source: | https://github.com/bioc/alabaster.sfe |
BioFormatsImage from alabaster on disk representationReads the metadata and imgSource will point to the file within the
on disk representation of SFE. The image itself should not be moved or the
BioFormatsImabe object will no longer work.
readBioFormatsImage(path, metadata = NULL, ...)readBioFormatsImage(path, metadata = NULL, ...)
path |
String containing a path to a directory, itself created with a |
metadata |
Named list containing metadata for the object - most importantly, the |
... |
Ignored, but used for other methods. |
A BioFormatsImage object for SFE.
Other readObject-SFE-image:
readExtImage(),
readSpatRaster()
library(SFEData) fp <- tempfile() x1 <- XeniumOutput(dataset = "v1", file_path = file.path(fp, "xenium1")) x2 <- XeniumOutput("v2", file_path = file.path(fp, "xenium2")) # Single file OME-TIFF fsave <- file.path(fp, "bfi1") sfe <- readXenium(x1) bfi <- getImg(sfe) bfi <- affineImg(bfi, M = matrix(c(cos(pi/6), sin(pi/6), -sin(pi/6), cos(pi/6)), nrow = 2), v = c(0,0)) saveObject(bfi, fsave) bfi2 <- readObject(fsave) unlink(fsave, recursive = TRUE) # Multi file OME-TIFF fsave <- file.path(fp, "bfi2") sfe <- readXenium(x2) bfi <- getImg(sfe) saveObject(bfi, fsave) bfi2 <- readObject(fsave) unlink(fsave, recursive = TRUE)library(SFEData) fp <- tempfile() x1 <- XeniumOutput(dataset = "v1", file_path = file.path(fp, "xenium1")) x2 <- XeniumOutput("v2", file_path = file.path(fp, "xenium2")) # Single file OME-TIFF fsave <- file.path(fp, "bfi1") sfe <- readXenium(x1) bfi <- getImg(sfe) bfi <- affineImg(bfi, M = matrix(c(cos(pi/6), sin(pi/6), -sin(pi/6), cos(pi/6)), nrow = 2), v = c(0,0)) saveObject(bfi, fsave) bfi2 <- readObject(fsave) unlink(fsave, recursive = TRUE) # Multi file OME-TIFF fsave <- file.path(fp, "bfi2") sfe <- readXenium(x2) bfi <- getImg(sfe) saveObject(bfi, fsave) bfi2 <- readObject(fsave) unlink(fsave, recursive = TRUE)
ExtImage from diskRead ExtImage from disk
readExtImage(path, metadata = NULL, ...)readExtImage(path, metadata = NULL, ...)
path |
String containing a path to a directory, itself created with a |
metadata |
Named list containing metadata for the object - most importantly, the |
... |
Arguments passed to |
A ExtImage object for SFE.
Other readObject-SFE-image:
readBioFormatsImage(),
readSpatRaster()
library(SFEData) fp <- tempfile() fsave <- file.path(fp, "exi") x1 <- XeniumOutput(dataset = "v1", file_path = file.path(fp, "xenium1")) sfe <- readXenium(x1) bfi <- getImg(sfe) exi <- toExtImage(bfi) saveObject(exi, fsave) exi2 <- readObject(fsave) unlink(fsave, recursive = TRUE)library(SFEData) fp <- tempfile() fsave <- file.path(fp, "exi") x1 <- XeniumOutput(dataset = "v1", file_path = file.path(fp, "xenium1")) sfe <- readXenium(x1) bfi <- getImg(sfe) exi <- toExtImage(bfi) saveObject(exi, fsave) exi2 <- readObject(fsave) unlink(fsave, recursive = TRUE)
sf from alabaster on disk representationRead the GeoParquet file into R. GeoParquet should also work in any
programming language that supports arrow. Newer version of GDAL with
Parquet driver is not strictly necessary if the geometry's WKB can be
converted to whichever language specific object such as sfc in R.
readSF(path, metadata = NULL)readSF(path, metadata = NULL)
path |
String containing a path to a directory, itself created with a |
metadata |
Named list containing metadata for the object - most importantly, the |
An sf data frame
library(sf) fp <- tempfile() df <- as.data.frame(matrix(rnorm(10), ncol = 2)) df <- st_as_sf(df, coords = names(df), crs = NA) saveObject(df, path = fp) df2 <- readObject(fp)library(sf) fp <- tempfile() df <- as.data.frame(matrix(rnorm(10), ncol = 2)) df <- st_as_sf(df, coords = names(df), crs = NA) saveObject(df, path = fp) df2 <- readObject(fp)
Read SFE object from alabaster on disk representation
readSpatialFeatureExperiment(path, metadata = NULL, ...)readSpatialFeatureExperiment(path, metadata = NULL, ...)
path |
String containing a path to a directory, itself created with a |
metadata |
Named list containing metadata for the object - most importantly, the |
... |
Further arguments to pass to individual methods. |
A SpatialFeatureExperiment object
library(SFEData) fp <- tempfile() fn <- file.path(fp, "vizgen") d <- VizgenOutput(dataset = "cellpose", file_path = fn) suppressWarnings(sfe <- readVizgen(d)) fsave <- file.path(fp, "sfe_save") saveObject(sfe, fsave) sfe2 <- readObject(fsave)library(SFEData) fp <- tempfile() fn <- file.path(fp, "vizgen") d <- VizgenOutput(dataset = "cellpose", file_path = fn) suppressWarnings(sfe <- readVizgen(d)) fsave <- file.path(fp, "sfe_save") saveObject(sfe, fsave) sfe2 <- readObject(fsave)
SpatRaster from alabaster on disk representationNot the same as terra::rast; here this function also reads the
metadata file.
readSpatRaster(path, metadata = NULL, ...)readSpatRaster(path, metadata = NULL, ...)
path |
String containing a path to a directory, itself created with a |
metadata |
Named list containing metadata for the object - most importantly, the |
... |
Arguments passed to |
A SpatRasterImage object for SFE.
Other readObject-SFE-image:
readBioFormatsImage(),
readExtImage()
library(SFEData) fp <- tempfile() fn <- file.path(fp, "vizgen") d <- VizgenOutput(dataset = "cellpose", file_path = fn) suppressWarnings(sfe <- readVizgen(d)) img <- getImg(sfe) class(img) fsave <- file.path(fp, "img") saveObject(img, fsave) img2 <- readObject(fsave)library(SFEData) fp <- tempfile() fn <- file.path(fp, "vizgen") d <- VizgenOutput(dataset = "cellpose", file_path = fn) suppressWarnings(sfe <- readVizgen(d)) img <- getImg(sfe) class(img) fsave <- file.path(fp, "img") saveObject(img, fsave) img2 <- readObject(fsave)
BioFormatsImage for alabaster
This function copies the original file to a pre-defined location within the
directory that stores the on disk representation of the SFE object for data
sharing. Since BioFormatsImage is essentially just some metadata in
memory and it never loads the image into memory (once the image is loaded
into memory it becomes ExtImage), once the original image is moved,
the BioFormatsImage object will no longer work, which is why the
pre-defined location is important. This function also saves the metadata,
which includes spatial extent and affine transformations.
## S4 method for signature 'BioFormatsImage' saveObject(x, path, ...)## S4 method for signature 'BioFormatsImage' saveObject(x, path, ...)
x |
A Bioconductor object of the specified class. |
path |
String containing the path to a directory in which to save |
... |
Ignored |
x is saved into path and NULL is invisibly returned.
Other saveObject-SFE-image:
saveObject,ExtImage-method,
saveObject,SpatRaster-method
library(SFEData) fp <- tempfile() fsave <- file.path(fp, "bfi2") x1 <- XeniumOutput(dataset = "v1", file_path = file.path(fp, "xenium1")) sfe <- readXenium(x1) bfi <- getImg(sfe) saveObject(bfi, fsave) bfi2 <- readObject(fsave) unlink(fsave, recursive = TRUE)library(SFEData) fp <- tempfile() fsave <- file.path(fp, "bfi2") x1 <- XeniumOutput(dataset = "v1", file_path = file.path(fp, "xenium1")) sfe <- readXenium(x1) bfi <- getImg(sfe) saveObject(bfi, fsave) bfi2 <- readObject(fsave) unlink(fsave, recursive = TRUE)
ExtImage to disk for alabaster
Save ExtImage to disk for alabaster
## S4 method for signature 'ExtImage' saveObject(x, path, ...)## S4 method for signature 'ExtImage' saveObject(x, path, ...)
x |
A Bioconductor object of the specified class. |
path |
String containing the path to a directory in which to save |
... |
Extra arguments passed to |
x is saved into path and NULL is invisibly returned.
Other saveObject-SFE-image:
saveObject,BioFormatsImage-method,
saveObject,SpatRaster-method
library(SFEData) fp <- tempfile() fsave <- file.path(fp, "exi") x1 <- XeniumOutput(dataset = "v1", file_path = file.path(fp, "xenium1")) sfe <- readXenium(x1) bfi <- getImg(sfe) exi <- toExtImage(bfi) saveObject(exi, fsave) exi2 <- readObject(fsave) unlink(fsave, recursive = TRUE)library(SFEData) fp <- tempfile() fsave <- file.path(fp, "exi") x1 <- XeniumOutput(dataset = "v1", file_path = file.path(fp, "xenium1")) sfe <- readXenium(x1) bfi <- getImg(sfe) exi <- toExtImage(bfi) saveObject(exi, fsave) exi2 <- readObject(fsave) unlink(fsave, recursive = TRUE)
sf to disk for alabaster
sf data frames are saved as GeoParquet.
## S4 method for signature 'sf' saveObject(x, path)## S4 method for signature 'sf' saveObject(x, path)
x |
A Bioconductor object of the specified class. |
path |
String containing the path to a directory in which to save |
x is saved into path and NULL is invisibly returned.
library(sf) fp <- tempfile() df <- as.data.frame(matrix(rnorm(10), ncol = 2)) df <- st_as_sf(df, coords = names(df), crs = NA) saveObject(df, path = fp)library(sf) fp <- tempfile() df <- as.data.frame(matrix(rnorm(10), ncol = 2)) df <- st_as_sf(df, coords = names(df), crs = NA) saveObject(df, path = fp)
Save SFE objects to disk in an interoperable, language agnostic format that
may also facilitate out of memory operations via HDF5 (non-spatial, inherited
from alabaster.sce) and Apache Parquet (geometries).
## S4 method for signature 'SpatialFeatureExperiment' saveObject(x, path, ...)## S4 method for signature 'SpatialFeatureExperiment' saveObject(x, path, ...)
x |
A Bioconductor object of the specified class. |
path |
String containing the path to a directory in which to save |
... |
Additional named arguments to pass to specific methods. |
There's no new arguments for ... for the SFE,
SpatialExperiment, and SingleCellExperiment methods, but there
is an argument that can be specified for ... in the
SummarizedExperiment method of saveObject.
At present, spatial results in featureData for geometries and
dimension reductions (see colFeatureData) and parameters of
spatial analyses (see getParams) are not save because those
parts of the SFE object are more experimental and are subject to change.
colFeatureData where global spatial results are stored for columns of
colData(x) is saved by the alabaster saveObject method
for DataFrame.
x is saved into path and NULL is invisibly returned.
library(SpatialFeatureExperiment) library(Voyager) library(SFEData) library(SingleCellExperiment) library(scater) fp <- tempfile() fn <- file.path(fp, "vizgen") d <- VizgenOutput(dataset = "cellpose", file_path = fn) suppressWarnings(sfe1 <- readVizgen(d, add_molecules = TRUE)) colGraph(sfe1, "knn5") <- findSpatialNeighbors(sfe1, method = "knearneigh", k = 5) SpatialFeatureExperiment::centroids(sfe1)$foo <- rnorm(ncol(sfe1)) sfe1 <- logNormCounts(sfe1) sfe1 <- runMoransI(sfe1, colGraphName = "knn5") sfe1 <- colDataMoransI(sfe1, features = c("transcript_count", "anisotropy", "perimeter_area_ratio", "solidity")) sfe1 <- colGeometryMoransI(sfe1, colGeometryName = "centroids", features = "foo") sfe1 <- runPCA(sfe1, ncomponents = 10) sfe1 <- reducedDimMoransI(sfe1, components = 1:10) sfe1 <- runUnivariate(sfe1, type = "localmoran", features = rownames(sfe1)[1]) fsave <- file.path(fp, "sfe_vizgen") saveObject(sfe1, fsave) sfe2 <- readObject(fsave) unlink(fsave, recursive = TRUE)library(SpatialFeatureExperiment) library(Voyager) library(SFEData) library(SingleCellExperiment) library(scater) fp <- tempfile() fn <- file.path(fp, "vizgen") d <- VizgenOutput(dataset = "cellpose", file_path = fn) suppressWarnings(sfe1 <- readVizgen(d, add_molecules = TRUE)) colGraph(sfe1, "knn5") <- findSpatialNeighbors(sfe1, method = "knearneigh", k = 5) SpatialFeatureExperiment::centroids(sfe1)$foo <- rnorm(ncol(sfe1)) sfe1 <- logNormCounts(sfe1) sfe1 <- runMoransI(sfe1, colGraphName = "knn5") sfe1 <- colDataMoransI(sfe1, features = c("transcript_count", "anisotropy", "perimeter_area_ratio", "solidity")) sfe1 <- colGeometryMoransI(sfe1, colGeometryName = "centroids", features = "foo") sfe1 <- runPCA(sfe1, ncomponents = 10) sfe1 <- reducedDimMoransI(sfe1, components = 1:10) sfe1 <- runUnivariate(sfe1, type = "localmoran", features = rownames(sfe1)[1]) fsave <- file.path(fp, "sfe_vizgen") saveObject(sfe1, fsave) sfe2 <- readObject(fsave) unlink(fsave, recursive = TRUE)
SpatRaster to disk for alabaster
Intended for SpatRasterImage which really is SpatRaster that
also inherits from SPE's SpatialImage. Besides writeRaster,
this function also writes a metadata file in the alabaster framework.
If the image is not loaded into memory and the original file is already
spatially registered, e.g. it has a spatial extent, then the original file
is copied to a pre-defined place in the on-disk representation of SFE and
writeRaster is not called.
## S4 method for signature 'SpatRaster' saveObject(x, path, ...)## S4 method for signature 'SpatRaster' saveObject(x, path, ...)
x |
A Bioconductor object of the specified class. |
path |
String containing the path to a directory in which to save |
... |
Extra parameters passed to |
x is saved into path and NULL is invisibly returned.
Other saveObject-SFE-image:
saveObject,BioFormatsImage-method,
saveObject,ExtImage-method
library(SFEData) fp <- tempfile() fn <- file.path(fp, "vizgen") d <- VizgenOutput(dataset = "cellpose", file_path = fn) suppressWarnings(sfe <- readVizgen(d)) img <- getImg(sfe) class(img) fsave <- file.path(fp, "img") saveObject(img, fsave) img2 <- readObject(fsave)library(SFEData) fp <- tempfile() fn <- file.path(fp, "vizgen") d <- VizgenOutput(dataset = "cellpose", file_path = fn) suppressWarnings(sfe <- readVizgen(d)) img <- getImg(sfe) class(img) fsave <- file.path(fp, "img") saveObject(img, fsave) img2 <- readObject(fsave)