Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GiottoClass 0.4.2 - hotfix makePseudoVisium() #243

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: GiottoClass
Title: Giotto Suite object definitions and framework
Version: 0.4.1
Version: 0.4.2
Authors@R: c(
person("Ruben", "Dries", email = "rubendries@gmail.com",
role = c("aut", "cre"), comment = c(ORCID = "0000-0001-7650-7754")),
Expand Down
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
# GiottoClass 0.4.2 (2024/10/30)

## bug fixes
- fix y spacing of `makePseudoVisium()`

## changes
- `makePseudoVisium()` `micron_scale` (multiplicative scalefactor to get micron scaled values) supercedes `micron_size` which used the inverse.


# GiottoClass 0.4.1 (2024/10/28)

## new
- `buffer()` for `giottoPolygon`, `giottoPoints`, `spatLocsObj`. Default is to crop by voronoi borders with `settleGeom()`
- `settleGeom()` for `giottoPolygon` and `SpatVector` for finding non overlapping borders determined by voronoi

## bug fixes
- fix default method setting in `createNetwork()` for "delaunay" networks


# GiottoClass 0.4.0 (2024/10/27)

Expand Down
27 changes: 20 additions & 7 deletions R/NN_network.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,28 @@ createNetwork <- function(

# check params
type <- match.arg(type, choices = c("sNN", "kNN", "delaunay"))

mdef <- c("dbscan", "geometry", "RTriangle", "deldir")
if (type %in% c("sNN", "kNN")) {
mchoices <- c("dbscan")
if (identical(method, mdef)) method <- mchoices
}
if (type %in% c("delaunay")) {
mchoices <- c("geometry", "RTriangle", "deldir")
if (identical(method, mdef)) method <- mchoices
}

method <- switch(type,
"sNN" = match.arg(method, choices = c("dbscan"), several.ok = TRUE),
"kNN" = match.arg(method, choices = c("dbscan"), several.ok = TRUE),
"delaunay" = match.arg(
method,
choices = c("geometry", "RTriangle", "deldir"),
several.ok = TRUE
)
"sNN" = match.arg(method, choices = mchoices, several.ok = TRUE),
"kNN" = match.arg(method, choices = mchoices, several.ok = TRUE),
"delaunay" = {
method <- method[[1L]]
match.arg(method, choices = mchoices, several.ok = TRUE)
}
)

vmsg(.is_debug = TRUE, sprintf("network\n type: %s\n method: %s",
type, method))

# get common params
alist <- list(
Expand Down
51 changes: 38 additions & 13 deletions R/generate_poly.R
Original file line number Diff line number Diff line change
Expand Up @@ -382,26 +382,46 @@ orthoGrid <- function(extent, ccd, id_prefix = "ID_") {

#' @title makePseudoVisium
#' @name makePseudoVisium
#' @description Generates a pseudo-visium grid of spots across a provided
#' spatial extent
#' @description Generates a visium-like array of spots across a provided
#' spatial extent.
#' @param extent SpatExtent or anything else a SpatExtent can be extracted or
#' created from
#' @param micron_size size of a micrometer relative to spatial coordinates
#' @param micron_scale scalefactor needed to convert the target coordinate
#' space to microns. For supported datasets, this can be found from
#' `instructions(gobject, "micron_scale")`. See details.
#' @param micron_size deprecated. Use `micron_scale`
#' @param name character. (default is 'pseudo_visium') Name of giottoPolygon
#' object to create
#' @details This function generates a pseudo-Visium grid of spots based on the
#' input spatial locations. The micron_size param is used to determine the size
#' of the spots
#' @details This function generates a pseudo-Visium array of spots across the
#' spatial extent provided. The `micron_scale` param is used to determine the
#' scaling of the array relative to the target coordinate system.
#'
#' @section `micron_scale`:
#' If `a` is microns and `b` is dataset coordinate units, `micron_scale` is
#' calculated as `a / b`.
#' @returns A giottoPolygon for the pseudo-visium spots.
#' @examples
#' e <- ext(0, 2000, 0, 2000)
#' x <- makePseudoVisium(extent = e, micron_size = 1)
#' x <- makePseudoVisium(extent = e, micron_scale = 1)
#' plot(x)
#' @concept spatial location
#' @export
makePseudoVisium <- function(extent = NULL,
micron_size = 1,
micron_scale = 1,
micron_size = deprecated(),
name = "pseudo_visium") {

if (is_present(micron_size)) {
micron_size <- 1 / micron_size
}

micron_scale <- deprecate_param(
x = micron_size,
y = micron_scale,
when = "0.4.2",
fun = "makePseudoVisium"
)

e <- ext(extent)[]

# Visium default scale parameters
Expand All @@ -410,27 +430,32 @@ makePseudoVisium <- function(extent = NULL,
visium_gap_um <- 45

# Compute metrics to visium scale
radius <- visium_radius_um / micron_size
cc <- visium_center_center_dist_um / micron_scale
radius <- visium_radius_um / micron_scale
gap <- (visium_gap_um / visium_radius_um) * radius

# Define a data.table with the vertices of a circle centered around (0,0)
stamp_dt <- circleVertices(radius = radius, npoints = 100)

# Create a grid of y points where the circles will be centered
y_seq <- seq(e[["ymin"]] + radius, e[["ymax"]] - radius,
by = 2 * radius + gap
y_seq <- seq(
e[["ymin"]] + radius,
e[["ymax"]] - radius,
# should be sqrt(3) or 1.732051, but seems like it was rounded
by = 1.74 * (cc / 2)
)

# Stagger center point of circles to match visium staggered grid
centers <- data.table::rbindlist(lapply(seq_len(length(y_seq)), function(i) {
dt_list <- lapply(seq_len(length(y_seq)), function(i) {
x_start <- if (i %% 2 == 0) {
e[["xmin"]] + radius + (2 * radius + gap) / 2
} else {
e[["xmin"]] + radius
}
x_seq <- seq(x_start, e[["xmax"]] - radius, by = 2 * radius + gap)
data.table::data.table(sdimx = x_seq, sdimy = y_seq[i])
}))
})
centers <- data.table::rbindlist(dt_list)
centers$cell_ID <- paste0("spot_", seq_len(nrow(centers)))

# Call polyStamp function on centers to generate the pseudo-visium grid
Expand Down
31 changes: 23 additions & 8 deletions man/makePseudoVisium.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading