Skip to content

Commit

Permalink
enh: relate method for giotto
Browse files Browse the repository at this point in the history
  • Loading branch information
jiajic committed Oct 21, 2024
1 parent 1624544 commit 97a80c4
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
52 changes: 51 additions & 1 deletion R/methods-relate.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#' gpoly <- GiottoData::loadSubObjectMini("giottoPolygon")
#'
#' relate(gpoints, gpoly, relation = "intersects")
#' relate(gpoints, gpoly, relation = "intersects", use_names = FALSE)
NULL
# ---------------------------------------------------------------- #

Expand All @@ -29,7 +30,7 @@ setMethod(
function(x, y, relation,
pairs = TRUE,
na.rm = TRUE,
output = c("data.table", "list", "matrix"),
output = c("data.table", "matrix"),
use_names = TRUE,
...) {
output <- match.arg(output, choices = c("data.table", "matrix"))
Expand Down Expand Up @@ -57,6 +58,55 @@ setMethod(
}
)

#' @rdname relate
#' @param what character. Which type of spatial data in the `giotto` object to
#' relate. One of "polygon", "spatlocs", "points"
#' @param spat_unit spatial unit
#' @param feat_type feature type
#' @param spat_locs_name name of spatlocs to use if what = "spatlocs"
#' @export
setMethod(
"relate", signature(x = "giotto", y = "giottoSpatial"),
function(x, y, ...,
what = c("polygon", "spatlocs", "points"),
spat_unit = NULL,
feat_type = NULL,
spat_locs_name = NULL) {

what <- match.arg(what, c("polygon", "spatlocs", "points"))

spat_unit <- set_default_spat_unit(x, spat_unit = spat_unit)
feat_type <- set_default_feat_type(
x, spat_unit = spat_unit, feat_type = feat_type
)

x <- switch(what,
"polygon" = {
getPolygonInfo(x,
polygon_name = spat_unit,
return_giottoPolygon = TRUE
)
},
"points" = {
getFeatureInfo(x,
feat_type = feat_type,
return_giottoPoints = TRUE
)
},
"spatlocs" = {
getSpatialLocations(x,
spat_unit = spat_unit,
output = "spatLocsObj",
name = spat_locs_name
)
}
)

res <- relate(x, y, ...)
return(res)
}
)




Expand Down
23 changes: 22 additions & 1 deletion man/relate.Rd

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

0 comments on commit 97a80c4

Please sign in to comment.