Skip to content

Commit

Permalink
fixes for rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
zskylarli committed May 30, 2024
1 parent 85b3763 commit bfc424c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions R/SEraster.R
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,8 @@ permutateByRotation <- function(input, n_perm = 1, verbose = FALSE) {
stopifnot("Column 1 and 2 of the spatialCoords slot should be named x and y, respectively." = colnames(pos_orig)[1:2] == c("x", "y"))

lapply(angles, function(angle) {
pos_rotated <- rearrr::rotate_2d(data = pos_orig, degrees = angle, x_col = "x", y_col = "y", origin = as.numeric(midrange_pt), overwrite = TRUE)
pos_rotated <- rearrr::rotate_2d(data = pos_orig, degrees = angle, x_col = "x", y_col = "y", origin = as.numeric(midrange_pt), overwrite = F)
pos_rotated <- as.data.frame(pos_rotated[, c("x_rotated", "y_rotated")])
colnames(pos_rotated) <- c("x", "y")
rownames(pos_rotated) <- rownames(pos_orig)

image_name <- Images(spe, assay = assay_name)[[1]]
class <- class(spe[[image_name]])
Expand Down Expand Up @@ -343,9 +341,8 @@ permutateByRotation <- function(input, n_perm = 1, verbose = FALSE) {
image_name <- Images(input, assay = assay_name)[[1]]
image <- input[[image_name]]
midrange_pt <- rearrr::midrange(pos_orig, cols = c("x", "y"))
pos_rotated <- rearrr::rotate_2d(data = pos_orig, degrees = angle, x_col = "x", y_col = "y", origin = as.numeric(midrange_pt), overwrite = TRUE)
colnames(pos_rotated) <- c("x", "y")
rownames(pos_rotated) <- rownames(pos_orig)
pos_rotated <- rearrr::rotate_2d(data = pos_orig, degrees = angle, x_col = "x", y_col = "y", origin = as.numeric(midrange_pt), overwrite = F)
pos_rotated <- as.data.frame(pos_rotated[, c("x_rotated", "y_rotated")])

class <- class(input[[image_name]])

Expand Down Expand Up @@ -392,11 +389,11 @@ updateVisiumV1 <- function(input, pos_rotated, assay_name, angle, image_name) {
#' @keyword internal
#'
updateVisiumV2 <- function(input, pos_rotated, assay_name, angle, image_name) {
pos_new <- pos_rotated[, c("x", "y")]
pos_new <- pos_rotated[, c("x_rotated", "y_rotated")]
input_fov <- input[[image_name]]

fov <- CreateFOV(
pos_new[, c("x", "y")],
pos_new[, c("x_rotated", "y_rotated")],
type = "centroids",
radius = input_fov@scale.factors[["spot"]],
assay = assay_name,
Expand All @@ -420,14 +417,13 @@ updateVisiumV2 <- function(input, pos_rotated, assay_name, angle, image_name) {
#' @keyword internal
#'
updateFOV <- function(input, pos_rotated, assay_name, angle, image_name) {
pos_new <- pos_rotated[, c("x", "y")]
pos_new$cell <- rownames(pos_rotated)
pos_new <- pos_rotated[, c("x_rotated", "y_rotated")]
input_fov <- input[[image_name]]
pos_new$cell <- Cells(input_fov)
radius <- slot(input_fov$centroids, name = 'radius')

output_boundaries <- list(
"centroids" = CreateCentroids(coords = pos_new[, c("x", "y")], nsides = input_fov[["centroids"]]@nsides, radius = radius, theta = angle),
"segmentation" = input_fov[["segmentation"]]
"centroids" = CreateCentroids(coords = pos_new[, c("x_rotated", "y_rotated")], nsides = input_fov[["centroids"]]@nsides, radius = radius, theta = angle)
)

new.fov <- CreateFOV(
Expand Down
Binary file modified docs/SEraster_files/figure-gfm/unnamed-chunk-15-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/SEraster_files/figure-gfm/unnamed-chunk-15-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/SEraster_files/figure-gfm/unnamed-chunk-15-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bfc424c

Please sign in to comment.