Skip to content

Commit 772f2b9

Browse files
committed
implement transformations for labels before plotting
1 parent 8cf609e commit 772f2b9

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

R/plotLabel.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#'
44
#' @param x \code{SpatialData} object.
55
#' @param i character string or index; the label element to plot.
6+
#' @param j name of target coordinate system.
67
#' @param k index of the scale of an image; by default (NULL), will auto-select
78
#' scale in order to minimize memory-usage and blurring for a target size of
89
#' 800 x 800px; use Inf to plot the lowest resolution available.
@@ -50,12 +51,18 @@ NULL
5051
#' scale_fill_manual scale_fill_gradientn
5152
#' aes geom_raster theme unit guides guide_legend
5253
#' @export
53-
setMethod("plotLabel", "SpatialData", \(x, i=1, k=NULL, c=NULL,
54+
setMethod("plotLabel", "SpatialData", \(x, i=1, j=1, k=NULL, c=NULL,
5455
a=0.5, pal=c("red", "green"), nan=NA, assay=1) {
5556
if (is.numeric(i)) i <- labelNames(x)[i]
5657
i <- match.arg(i, labelNames(x))
57-
y <- as.matrix(.get_multiscale_data(label(x, i), k))
58-
df <- data.frame(x=c(col(y)), y=c(row(y)), z=c(y))
58+
y <- label(x, i)
59+
ym <- as.matrix(.get_multiscale_data(label(x, i), k))
60+
df <- data.frame(x=c(col(ym)), y=c(row(ym)), z=c(ym))
61+
# transformation
62+
if (is.numeric(j))
63+
j <- CTname(y)[j]
64+
ts <- CTpath(x, i, j)
65+
df[,c("x", "y")] <- .trans_xy(df[,c("x", "y")], ts)
5966
aes <- aes(.data[["x"]], .data[["y"]])
6067
if (!is.null(c)) {
6168
stopifnot(length(c) == 1, is.character(c))

man/plotLabel.Rd

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

tests/testthat/test-plotArray.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ test_that("plotLabel()", {
6161
expect_s3_class(q, "ggplot")
6262
expect_equal(q$coordinates$ratio, 1)
6363
expect_is(q$layers[[1]]$mapping$fill, "quosure")
64+
# multiscale
65+
y <- label(x, "blobs_multiscale_labels")
66+
y <- y[,seq_len(32)] # same thing but different
6467
# alpha
6568
q <- p + plotLabel(x, i, a=a <- runif(1))
6669
expect_identical(q$layers[[1]]$aes_params$alpha, a)

vignettes/SpatialData.plot.Rmd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Such labels could be morphological regions annotated by pathologists.
168168

169169
```{r merfish-read}
170170
dir.create(td <- tempfile())
171-
pa <- unzip_spd_demo(
171+
pa <- SpatialData.data:::.unzip_spd_demo(
172172
zipname="merfish.zarr.zip",
173173
dest=td, source="biocOSN")
174174
(x <- readSpatialData(pa, anndataR=FALSE))
@@ -207,7 +207,7 @@ Mouse intestine, 1GB; 4 image resolutions and 3 shapes at 2, 8, and 16 $\mu$m.
207207

208208
```{r visiumhd-read}
209209
dir.create(td <- tempfile())
210-
pa <- unzip_spd_demo(
210+
pa <- SpatialData.data:::.unzip_spd_demo(
211211
zipname="visium_hd_3.0.0_io.zip",
212212
dest=td, source="biocOSN")
213213
(x <- readSpatialData(pa, images=4, shapes=3, tables=FALSE))
@@ -226,7 +226,7 @@ Colorectal carcinoma, 25 MB; no shapes, no points.
226226

227227
```{r mibitof-read}
228228
dir.create(td <- tempfile())
229-
pa <- unzip_spd_demo(
229+
pa <- SpatialData.data:::.unzip_spd_demo(
230230
zipname="mibitof.zip",
231231
dest=td, source="biocOSN")
232232
(x <- readSpatialData(pa, anndataR=FALSE))
@@ -246,7 +246,7 @@ Small lung adenocarcinoma, 250 MB; 1 image, 2 labels, 2 tables.
246246

247247
```{r mcmicro-read}
248248
dir.create(td <- tempfile())
249-
pa <- unzip_spd_demo(
249+
pa <- SpatialData.data:::.unzip_spd_demo(
250250
zipname="mcmicro_io.zip",
251251
dest=td, source="biocOSN")
252252
(x <- readSpatialData(pa, anndataR=FALSE))
@@ -273,7 +273,7 @@ plotSpatialData() + plotImage(x,
273273

274274
```{r steinbock-read}
275275
dir.create(td <- tempfile())
276-
pa <- unzip_spd_demo(
276+
pa <- SpatialData.data:::.unzip_spd_demo(
277277
zipname="steinbock_io.zip",
278278
dest=td, source="biocOSN")
279279
x <- readSpatialData(pa, anndataR=FALSE)

0 commit comments

Comments
 (0)