Closed rbutleriii closed 1 month ago
Hi @rbutleriii,
These functionalities should have just been added in GiottoClass 0.3.0
ext()
now works on Giotto objects. It has a couple of params intended for finding the SpatExtent of specific pieces of information, but defaults to all the information in the object.rescale()
and spatShift()
should also work on all the info in the Giotto object by default.giottoImage
extent is now settable. We don't provide methods for set.ext()
, and have instead been writing methods for the ext()<-
replacement function. Currently, the SpatExtent
of giottoImage
, giottoLargeImage
, giottoPoints
, and giottoPolygon
are directly settable this way.For the behavior of the SpatExtent
object, we import this functionality from terra.
Numeric additions to a SpatExtent
will expand one of the bounds, which is why you needed to apply negative values in order perform a shift.
Best, George
Looks good:
library(Giotto)
library(GiottoData)
go <- loadGiottoMini(dataset = 'cosmx')
go <- spatShift(go, dx = 60000, dy = 150000)
go2 <- loadGiottoMini(dataset = 'cosmx')
my_slides <- c("go", "go2")
gobjs <- list(go, go2)
# merge the slides
gobj <- joinGiottoObjects(
gobjs,
gobject_names = my_slides,
join_method = "shift",
x_shift = NULL,
y_shift = NULL,
x_padding = 0,
y_padding = NULL,
verbose = TRUE
)
# plot merged obj
img_list = grep("*-composite", names(gobj@images), value = TRUE)
gobj %>%
spatPlot2D(
point_size = 2,
point_alpha = 0.5,
show_image = TRUE,
image_name = img_list,
return_plot = FALSE,
show_plot = TRUE
)
# shift each slide to the bottom-left most global coords (0,0) prior to merging
gobjs <- lapply(gobjs, function(i) {
coords <- ext(i)
spatShift(i, dx = -coords$xmin, dy = -coords$ymin)
})
# merge the slides
gobj <- joinGiottoObjects(
gobjs,
gobject_names = my_slides,
join_method = "shift",
x_shift = NULL,
y_shift = NULL,
x_padding = 0,
y_padding = NULL,
verbose = TRUE
)
gobj %>%
spatPlot2D(
point_size = 2,
point_alpha = 0.5,
show_image = TRUE,
image_name = img_list,
return_plot = FALSE,
show_plot = TRUE
)
Is there a way to apply the spatial transformations to the entire giotto object, including the images?
I am joining multiple gobjs via![image](https://github.com/drieslab/Giotto/assets/6644896/fc9b0201-07ee-4bc8-9554-b21e7470ed9a)
joinGiottoObjects
shift method, each with several fovs. However each has global coordinates from it's own original slide.I would like to align them each to xmin = 0, ymin = 0 before joining them. Something like this:
That presents two problems: (1) figuring out the absolute bounds of all parts and (2) applying to all parts.
For the first,
ext
does not apply to a gobj:It would appear that I would have to call it on all images, spat_locs, spatNetwork, feature_info, and all polygon types and find the absolute xmin and ymin?
For the second,
spatShift
does appear to apply to a gobj, and seems to shift everything but the images. So for that do I basically have to modify theext
for each image after the initial? I was trying unsuccessfully to apply that withset.ext
, but the way it works is counterintuitive to say the least