You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I constructed a SpatialExperiment where spe$sample_id was a factor, which did not throw errors, and felt intuitive, given that there were a lot of columns (spots) in my data with only a handful of possible sample IDs. However, this causes problems in various internal functions, where sample ID is assumed to be character (at least this code). This leads to difficult-to-understand errors when performing normal operations on the SpatialExperiment. Perhaps either factors should be supported or errors should be thrown when attempting to set spe$sample_id to a factor.
Here's a reproducible example creating the error:
n <- length(z <- letters)
y <- list(counts = matrix(0, nrow = n, ncol = n))
cd <- DataFrame(a = seq(n), x = seq(n), y = seq(n), z)
spe1 <- SpatialExperiment(
assay = y,
colData = cd,
spatialCoordsNames = c("x", "y")
)
url <- "https://i.redd.it/3pw5uah7xo041.jpg"
spe1 <- addImg(
spe1,
sample_id = "sample01",
image_id = "pomeranian",
imageSource = url,
scaleFactor = NA_real_,
load = TRUE
)
# Works fine, because spe1$sample_id is a character vector
getImg(spe1, sample_id = spe1$sample_id[1], image_id = "pomeranian")
# Fails with difficult-to-understand error when spe1$sample_id is a factor
# of characters
spe1$sample_id = factor(spe1$sample_id)
getImg(spe1, sample_id = spe1$sample_id[1], image_id = "pomeranian")
The error message is Error in .get_img_idx(x, sample_id, image_id) : object 'sid' not found, again because the if statement here doesn't handle factors, leading to sid being undefined here.
I actually first encountered the error when trying to use spatialLIBD::vis_gene() ( I understand that getImg() is not going to be frequently called directly-- it just provokes the error most directly).
Best,
-Nick
The text was updated successfully, but these errors were encountered:
Nick-Eagles
added a commit
to LieberInstitute/visiumStitched
that referenced
this issue
May 29, 2024
Thanks Nick (@Nick-Eagles) for reporting this error, maybe Helena (@HelenaLC) can take a look into this or provide any feedback for possible solutions or violating constraints in case of a sample_id factor.
Hello,
I constructed a
SpatialExperiment
wherespe$sample_id
was a factor, which did not throw errors, and felt intuitive, given that there were a lot of columns (spots) in my data with only a handful of possible sample IDs. However, this causes problems in various internal functions, where sample ID is assumed to be character (at least this code). This leads to difficult-to-understand errors when performing normal operations on theSpatialExperiment
. Perhaps either factors should be supported or errors should be thrown when attempting to setspe$sample_id
to a factor.Here's a reproducible example creating the error:
The error message is
Error in .get_img_idx(x, sample_id, image_id) : object 'sid' not found
, again because the if statement here doesn't handle factors, leading tosid
being undefined here.I actually first encountered the error when trying to use
spatialLIBD::vis_gene()
( I understand thatgetImg()
is not going to be frequently called directly-- it just provokes the error most directly).Best,
-Nick
The text was updated successfully, but these errors were encountered: