Skip to content

Commit fef68e4

Browse files
committed
stash draft
Former-commit-id: 4364607 Former-commit-id: b8a4e5456b960c63fe2891c6b3661627d9918ee0
1 parent 9130335 commit fef68e4

4 files changed

Lines changed: 42 additions & 5 deletions

File tree

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ importFrom(SingleCellExperiment,"int_metadata<-")
122122
importFrom(SingleCellExperiment,SingleCellExperiment)
123123
importFrom(SingleCellExperiment,int_colData)
124124
importFrom(SingleCellExperiment,int_metadata)
125+
importFrom(SpatialExperiment,SpatialExperiment)
125126
importFrom(SummarizedExperiment,"assay<-")
126127
importFrom(SummarizedExperiment,"assayNames<-")
127128
importFrom(SummarizedExperiment,"colData<-")
@@ -130,6 +131,7 @@ importFrom(SummarizedExperiment,colData)
130131
importFrom(ZarrArray,ZarrArray)
131132
importFrom(ZarrArray,path)
132133
importFrom(ZarrArray,type)
134+
importFrom(anndataR,read_zarr)
133135
importFrom(arrow,open_dataset)
134136
importFrom(basilisk,BasiliskEnvironment)
135137
importFrom(basilisk,basiliskRun)

R/scratch.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#' @importFrom methods as
2+
#' @importFrom anndataR read_zarr
3+
#' @importFrom SpatialExperiment SpatialExperiment
4+
readSDasSPE <- \(x, i=1) {
5+
if (!requireNamespace("SpatialExperiment", quietly=TRUE))
6+
stop("install the 'SpatialExperiment' package to use this function.")
7+
y <- list.files(file.path(x, "tables"), full.names=TRUE)
8+
if (!length(y))
9+
stop("couldn't find any tables")
10+
if (is.character(i))
11+
i <- match(i, basename(y))
12+
sce <- readTable(y[i])
13+
colData(sce) <- NULL
14+
for (l in setdiff(.LAYERS, "tables")) {
15+
y <- list.files(file.path(x, l), full.names=TRUE)
16+
y <- y[match(region(sce), basename(y))]
17+
if (!is.na(y)) {
18+
t <- basename(dirname(y))
19+
f <- paste0("read",
20+
toupper(substr(t, 1, 1)),
21+
substr(t, 2, nchar(t)-1))
22+
y <- get(f)(y)
23+
xy <- centroids(y, "matrix")
24+
xy <- xy[, c("x", "y")]
25+
}
26+
}
27+
toSpatialExperiment(sce, spatialCoords=xy)
28+
}
29+
30+
require(sf, quietly=TRUE)
31+
x <- file.path("extdata", "blobs.zarr")
32+
x <- system.file(x, package="SpatialData")
33+
(spe <- readSDasSPE(x))

R/utils.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ setMethod("centroids", "ANY", \(x, ...) stop("'centroids' ",
4242
#' @importFrom Matrix summary
4343
setMethod("centroids", "LabelArray", \(x,
4444
as=c("data.frame", "matrix")) {
45-
# TODO: should these be offset by 0.5?
4645
as <- match.arg(as)
4746
y <- data(x)
4847
y <- as(y, "dgCMatrix")
4948
i <- summary(y)
49+
# flip dimensions so that columns=x, rows=y
50+
# TODO: should these be offset by 0.5?
51+
i[, c(1, 2)] <- i[, c(2, 1)]-0.5
5052
xy <- tapply(i[, -3], i[[3]], colMeans)
5153
xy <- do.call(rbind, xy)
5254
xy <- cbind(xy, as.integer(rownames(xy)))

man/SpatialData.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)