Skip to content

Commit 05bfa89

Browse files
committed
https://github.com/the-ouyang-lab/ShinyCell2/pull/20
1 parent 8c1955c commit 05bfa89

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

R/makeShinyFilesSpatial.R

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,34 @@ makeShinyFilesSpatial <- function(
3030
sc1image = list()
3131
if(class(obj)[1] == "Seurat"){
3232
if(.hasSlot(obj, "images")){
33-
# coordinates
34-
sc1image$coord <- obj@images[[1]]@coordinates
33+
# coordinates - handle both VisiumV1 and VisiumV2 formats
34+
visium_image <- obj@images[[1]]
35+
if ("VisiumV2" %in% class(visium_image)) {
36+
# New VisiumV2 format - coordinates are in boundaries$centroids
37+
coords <- visium_image@boundaries$centroids@coords
38+
# Convert to expected format with imagecol and imagerow columns
39+
sc1image$coord <- data.frame(
40+
tissue = 1, # Default tissue value
41+
row = NA, # Not available in VisiumV2
42+
col = NA, # Not available in VisiumV2
43+
imagecol = coords[, "x"],
44+
imagerow = coords[, "y"]
45+
)
46+
rownames(sc1image$coord) <- rownames(coords)
47+
} else {
48+
# Traditional VisiumV1 format
49+
sc1image$coord <- visium_image@coordinates
50+
}
51+
3552
# uncropped background image
3653
bg_image <- GetImage(obj, mode = "raster") # background image
3754
# bg_grob <- rasterGrob(bg_image, width=unit(1,"npc"), height=unit(1,"npc"),
3855
# interpolate = FALSE) # background image grob
3956
sc1image$bg_image <- bg_image
4057
# sc1image$bg_grob <- bg_grob
58+
4159
# for cropped image generation in the server.R script
42-
sc1image$lowres <- obj@images[[1]]@scale.factors$lowres
60+
sc1image$lowres <- visium_image@scale.factors$lowres
4361

4462
}
4563
} else {

0 commit comments

Comments
 (0)