Title: | Simple classes and methods for managing Xenium datasets |
---|---|
Description: | Define a relatively light class for managing Xenium data using Bioconductor. Address use of parquet for coordinates, SpatialExperiment for assay and sample data. Address serialization and use of cloud storage. |
Authors: | Vincent Carey [aut, cre] |
Maintainer: | Vincent Carey <[email protected]> |
License: | Artistic-2.0 |
Version: | 1.1.0 |
Built: | 2024-10-31 06:40:09 UTC |
Source: | https://github.com/bioc/xenLite |
formal bracket definition, that leaves parquet geometry information alone.
## S4 method for signature 'XenSPEP,ANY,ANY,ANY' x[i, j, ..., drop = TRUE]
## S4 method for signature 'XenSPEP,ANY,ANY,ANY' x[i, j, ..., drop = TRUE]
x |
instance of XenSPEP |
i |
feature selection |
j |
cell selection |
... |
passed to SpatialExperiment methods |
drop |
logical(1) |
XenSPEP instance
Gives a message and calls callNextMethod.
cache and/or retrieve path to an ome.tif file for demonstration
cacheMtif( cache = BiocFileCache::BiocFileCache(), url = "https://mghp.osn.xsede.org/bir190004-bucket01/BiocXenData/morphology_focus_0001.ome.tif" )
cacheMtif( cache = BiocFileCache::BiocFileCache(), url = "https://mghp.osn.xsede.org/bir190004-bucket01/BiocXenData/morphology_focus_0001.ome.tif" )
cache |
defaults to BiocFileCache::BiocFileCache() |
url |
location where tiff file can be retrieved |
path to cached resource
The tiff file was retrieved after running SFEData::XeniumOutput("v2"), and depicts a pancreas tissue sample.
pa <- cacheMtif() if (!requireNamespace("tiff")) stop("install tiff package to run this example") x <- tiff::readTIFF(pa) plot(0, xlim = c(0, 1000), ylim = c(0, 1000), xlab = " ", ylab = " ") rasterImage(x * 5.5, 0, 0, 1000, 1000)
pa <- cacheMtif() if (!requireNamespace("tiff")) stop("install tiff package to run this example") x <- tiff::readTIFF(pa) plot(0, xlim = c(0, 1000), ylim = c(0, 1000), xlab = " ", ylab = " ") rasterImage(x * 5.5, 0, 0, 1000, 1000)
cache and/or retrieve path to an SFE of V1 lung demo data from 10x
cacheSfeLungNtx( cache = BiocFileCache::BiocFileCache(), url = "https://mghp.osn.xsede.org/bir190004-bucket01/BiocXenData/sfeLung.zip" )
cacheSfeLungNtx( cache = BiocFileCache::BiocFileCache(), url = "https://mghp.osn.xsede.org/bir190004-bucket01/BiocXenData/sfeLung.zip" )
cache |
defaults to BiocFileCache::BiocFileCache() |
url |
location where zip file can be retrieved |
path to cached resource
Lacks transcript coordinates
cache and/or retrieve path to Xenium Lung Adenocarcinoma example data, zipped SPEP accompanied by parquet
cacheXenLuad( cache = BiocFileCache::BiocFileCache(), url = "https://mghp.osn.xsede.org/bir190004-bucket01/BiocXenData/luad_lite.zip" )
cacheXenLuad( cache = BiocFileCache::BiocFileCache(), url = "https://mghp.osn.xsede.org/bir190004-bucket01/BiocXenData/luad_lite.zip" )
cache |
defaults to BiocFileCache::BiocFileCache() |
url |
location where zip file can be retrieved |
path to cached resource
if (interactive()) { pa <- cacheXenLuad() luad <- restoreZipXenSPEP(pa) print(luad) print(slot(luad, "cellbounds_path")) viewSeg(luad, xlim = c(4000, 4500), ylim = c(2000, 2500)) }
if (interactive()) { pa <- cacheXenLuad() luad <- restoreZipXenSPEP(pa) print(luad) print(slot(luad, "cellbounds_path")) viewSeg(luad, xlim = c(4000, 4500), ylim = c(2000, 2500)) }
counts-in-memory version of melanoma 5k dataset
cacheXenPdmelLite( cache = BiocFileCache::BiocFileCache(), url = "https://mghp.osn.xsede.org/bir190004-bucket01/BiocXenData/pdmel_lite.zip" )
cacheXenPdmelLite( cache = BiocFileCache::BiocFileCache(), url = "https://mghp.osn.xsede.org/bir190004-bucket01/BiocXenData/pdmel_lite.zip" )
cache |
defaults to BiocFileCache::BiocFileCache() |
url |
location where zip file can be retrieved |
path to cached resource
if (interactive()) { pa <- cacheXenPdmelLite() pdmel_lite <- restoreZipXenSPEP(pa) print(pdmel_lite) }
if (interactive()) { pa <- cacheXenPdmelLite() pdmel_lite <- restoreZipXenSPEP(pa) print(pdmel_lite) }
counts-in-memory version of prostate 5k dataset
cacheXenProstLite( cache = BiocFileCache::BiocFileCache(), url = "https://mghp.osn.xsede.org/bir190004-bucket01/BiocXenData/prost_lite.zip" )
cacheXenProstLite( cache = BiocFileCache::BiocFileCache(), url = "https://mghp.osn.xsede.org/bir190004-bucket01/BiocXenData/prost_lite.zip" )
cache |
defaults to BiocFileCache::BiocFileCache() |
url |
location where zip file can be retrieved |
path to cached resource
if (interactive()) { pa <- cacheXenProstLite() prost_lite <- restoreZipXenSPEP(pa) print(prost_lite) }
if (interactive()) { pa <- cacheXenProstLite() prost_lite <- restoreZipXenSPEP(pa) print(prost_lite) }
restrict XenSPEP to cells with centroids in specified rectangle, also restrict boundary and transcript location features
clipRect(xsce, xlim, ylim)
clipRect(xsce, xlim, ylim)
xsce |
XenSPEP instance |
xlim |
numeric(2) |
ylim |
numeric(2) |
XenSPEP instance
Could be too RAM-hungry.
args(clipRect)
args(clipRect)
simple app to explore an image
demoapp(simple = FALSE)
demoapp(simple = FALSE)
simple |
logical(1) if TRUE, use a cached tiff for illustration |
No value returned, run for side effect of app initiation.
Navigate file input control to location of tiffs
if (interactive()) demoapp(simple = TRUE)
if (interactive()) demoapp(simple = TRUE)
helper function to map ENS ids to symbols
e2sym(x)
e2sym(x)
x |
character() mix of Ensembl Ids and other strings; the latter are left unchanged |
a vector like x with gene symbols from v79 mapping substituted where possible
e2sym(c("ABC", "ENSG00000213088", "ENSG00000107796", "ENSG00000163017"))
e2sym(c("ABC", "ENSG00000213088", "ENSG00000107796", "ENSG00000163017"))
mapping from ENSG to symbols based on EnsDb.Hsapiens.v79
e79sym
e79sym
character()
character vector
named character vector with values gene symbols, name ENSG ids
data(e79sym) head(e79sym)
data(e79sym) head(e79sym)
method for cell boundary extraction
getCellBoundaries(x)
getCellBoundaries(x)
x |
instance of XenSPEP |
reference to ingested parquet
showMethods("getCellBoundaries")
showMethods("getCellBoundaries")
method for cell boundary extraction
## S4 method for signature 'XenSPEP' getCellBoundaries(x)
## S4 method for signature 'XenSPEP' getCellBoundaries(x)
x |
instance of XenSPEP |
reference to ingested parquet
method for nucleus boundary extraction
getNucleusBoundaries(x)
getNucleusBoundaries(x)
x |
instance of XenSPEP |
reference to ingested parquet
showMethods("getNucleusBoundaries")
showMethods("getNucleusBoundaries")
method for nucleus boundary extraction
## S4 method for signature 'XenSPEP' getNucleusBoundaries(x)
## S4 method for signature 'XenSPEP' getNucleusBoundaries(x)
x |
instance of XenSPEP |
reference to ingested parquet
method for transcript extraction
getTranscripts(x)
getTranscripts(x)
x |
instance of XenSPEP |
reference to ingested parquet
showMethods("getTranscripts")
showMethods("getTranscripts")
method for transcript extraction
## S4 method for signature 'XenSPEP' getTranscripts(x)
## S4 method for signature 'XenSPEP' getTranscripts(x)
x |
instance of XenSPEP |
reference to ingested parquet
showMethods("getTranscripts")
showMethods("getTranscripts")
prepare a XenSPEP for ggplot2 visualization
ggprepSeg(xsce, xlim = c(5800, 6200), ylim = c(6300, 6700))
ggprepSeg(xsce, xlim = c(5800, 6200), ylim = c(6300, 6700))
xsce |
XenSPEP instance |
xlim |
numeric(2) |
ylim |
numeric(2) |
a list with components 'bounds' (data.frame including relevant colData rows (all colData variables) and cell boundary coordinates) and 'txdata', a filtered arrow Table.
This is idiosyncratic. Quintiles of cell_area (values in 'sizq') are produced, and transcript locations are filtered. A more general approach that allows selection of coloring of cells by feature characteristics is needed.
pa <- cacheXenLuad() luad <- restoreZipXenSPEP(pa) hh <- ggprepSeg(luad, c(4000, 4500), c(2000, 2500)) ggplot2::ggplot(hh$bounds, ggplot2::aes( x = vertex_x, y = vertex_y, group = cell_id, colour = sizq, fill = sizq )) + ggplot2::geom_polygon(alpha = .5)
pa <- cacheXenLuad() luad <- restoreZipXenSPEP(pa) hh <- ggprepSeg(luad, c(4000, 4500), c(2000, 2500)) ggplot2::ggplot(hh$bounds, ggplot2::aes( x = vertex_x, y = vertex_y, group = cell_id, colour = sizq, fill = sizq )) + ggplot2::geom_polygon(alpha = .5)
produce a pre-loaded XenSPEP (SpatialExperiment with parquet references)
ingest_xen(folder)
ingest_xen(folder)
folder |
character(1) 'standard' Xenium output folder |
instance of XenSPEP
chkns <- function(pkstring) { if (!requireNamespace(pkstring)) { message(sprintf("install %s to use this feature; returning NULL", pkstring)) return(NULL) } } chkns("SFEData") chkns("HDF5Array") chkns("SingleCellExperiment") if (requireNamespace("SFEData")) { td <- tempdir() z <- SFEData::XeniumOutput("v2", td) ii <- ingest_xen(file.path(td, "xenium2")) print(validObject(ii)) plot(SpatialExperiment::spatialCoords(ii), pch = ".") }
chkns <- function(pkstring) { if (!requireNamespace(pkstring)) { message(sprintf("install %s to use this feature; returning NULL", pkstring)) return(NULL) } } chkns("SFEData") chkns("HDF5Array") chkns("SingleCellExperiment") if (requireNamespace("SFEData")) { td <- tempdir() z <- SFEData::XeniumOutput("v2", td) ii <- ingest_xen(file.path(td, "xenium2")) print(validObject(ii)) plot(SpatialExperiment::spatialCoords(ii), pch = ".") }
read and bind parquet data to XenSPEP
loadGeometry(x)
loadGeometry(x)
x |
instance of XenSPEP |
instance of XenSPEP
read and bind parquet data to XenSPEP
## S4 method for signature 'XenSPEP' loadGeometry(x)
## S4 method for signature 'XenSPEP' loadGeometry(x)
x |
instance of XenSPEP |
instance of XenSPEP
plot method for ggplot2-prepared XenSPEP
plotXenGgprep(x, y, ...)
plotXenGgprep(x, y, ...)
x |
instance of S3 class 'xen_ggprep' |
y |
not used |
... |
not used |
ggplot
roxygen had problems with this
pa <- cacheXenLuad() luad <- restoreZipXenSPEP(pa) hh <- ggprepSeg(luad, c(4000, 4500), c(2000, 2500)) plotXenGgprep(hh)
pa <- cacheXenLuad() luad <- restoreZipXenSPEP(pa) hh <- ggprepSeg(luad, c(4000, 4500), c(2000, 2500)) plotXenGgprep(hh)
print method for ggplot2-prepared XenSPEP
printXenGgprep(x, ...)
printXenGgprep(x, ...)
x |
instance of S3 class 'xen_ggprep' |
... |
not used |
operates with cat()
utility for dealing with cached Xen_SPEP in temp folder
resetParqPaths(xsp, base)
resetParqPaths(xsp, base)
xsp |
instance of XenSPEP |
base |
folder path where parquet files are found |
XenSPEP instance
Will prepend current folder path to parquet-oriented slot values.
use unzip, readRDS, and loadGeometry to restore a XenSPEP
restoreZipXenSPEP(zipf, exdir = tempdir())
restoreZipXenSPEP(zipf, exdir = tempdir())
zipf |
character(1) path to zip file created with 'zipXenSPEP' |
exdir |
character(1) defaults to tempdir(), where contents are unpacked |
instance of XenSPEP
Session folder position will change with setwd(), on.exit ensures return to position when started.
# used implicitly if (interactive()) { example(cacheXenLuad) }
# used implicitly if (interactive()) { example(cacheXenLuad) }
display aspects of XenSPEP
## S4 method for signature 'XenSPEP' show(object)
## S4 method for signature 'XenSPEP' show(object)
object |
instance of XenSPEP |
operates with cat()
naive polygon viewer
viewSeg(x, xlim, ylim, show_tx = FALSE, ...)
viewSeg(x, xlim, ylim, show_tx = FALSE, ...)
x |
instance of XenSPEP |
xlim |
numeric(2) ordered vector of max and min on x |
ylim |
numeric(2) ordered vector of max and min on y |
show_tx |
logical(1) display transcript locations if TRUE, defaults to FALSE. |
... |
passed to polygon() |
run for side effect of plotting
This is more RAM-sparing than clipRect followed by view.
luad <- cacheXenLuad() pa <- cacheXenLuad() luad <- restoreZipXenSPEP(pa) rownames(luad) <- make.names(SummarizedExperiment:::rowData(luad)$Symbol, unique = TRUE) out <- viewSeg(luad, c(5800, 6300), c(1300, 1800), lwd = .5) out$ncells
luad <- cacheXenLuad() pa <- cacheXenLuad() luad <- restoreZipXenSPEP(pa) rownames(luad) <- make.names(SummarizedExperiment:::rowData(luad)$Symbol, unique = TRUE) out <- viewSeg(luad, c(5800, 6300), c(1300, 1800), lwd = .5) out$ncells
naive polygon viewer, will indicate presence of transcripts for two genes in cells
viewSegG2(x, xlim, ylim, gene1, gene2, show_tx = FALSE, ...)
viewSegG2(x, xlim, ylim, gene1, gene2, show_tx = FALSE, ...)
x |
instance of XenSPEP |
xlim |
numeric(2) ordered vector of max and min on x |
ylim |
numeric(2) ordered vector of max and min on y |
gene1 |
character(1) gene to be checked, cell polygon will be filled if gene has non-zero count |
gene2 |
character(1) gene to be checked, cell polygon will be filled if gene has non-zero count |
show_tx |
logical(1) display transcript locations if TRUE, defaults to FALSE. |
... |
passed to polygon() |
Primarily for plotting. A list is invisibly returned with elements polys, ncells and call.
This is more RAM-sparing than clipRect followed by view. Colors are pre-assigned for individual and joint occupancies in this draft of this visualizer.
luad <- cacheXenLuad() pa <- cacheXenLuad() luad <- restoreZipXenSPEP(pa) rownames(luad) <- make.names(SummarizedExperiment:::rowData(luad)$Symbol, unique = TRUE) out <- viewSegG2(luad, c(5800, 6300), c(1300, 1800), lwd = .5, gene1 = "CD4", gene2 = "EPCAM") legend(5800, 1370, fill = c("purple", "cyan", "pink"), legend = c("CD4", "EPCAM", "both")) out$ncells
luad <- cacheXenLuad() pa <- cacheXenLuad() luad <- restoreZipXenSPEP(pa) rownames(luad) <- make.names(SummarizedExperiment:::rowData(luad)$Symbol, unique = TRUE) out <- viewSegG2(luad, c(5800, 6300), c(1300, 1800), lwd = .5, gene1 = "CD4", gene2 = "EPCAM") legend(5800, 1370, fill = c("purple", "cyan", "pink"), legend = c("CD4", "EPCAM", "both")) out$ncells
XenSPEP (SpatialExperiment with parquet references) constructor
XenSPEP(folder)
XenSPEP(folder)
folder |
character(1) 'standard' Xenium output folder |
instance of XenSPEP
# is not used yet args(XenSPEP)
# is not used yet args(XenSPEP)
manage SpatialExperiment with parquet references
serialize the collection of XenSPEP and parquet with zip
zipXenSPEP(xsp, targetfile)
zipXenSPEP(xsp, targetfile)
xsp |
instance of XenSPEP with geometry loaded |
targetfile |
character(1) destination of zip process |
output of zip()
a .rds and three parquet files are zipped together for restoration by 'restoreZipXenSPEP'. The outcome is 'paste0(targetfile, ".zip")'.
zipXenSPEP
zipXenSPEP