Skip to content

Commit cfa3d3c

Browse files
committed
Merge branch 'staging' into website
2 parents 2807c9b + 9161cac commit cfa3d3c

20 files changed

+283
-21
lines changed

NAMESPACE

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ S3method(.DollarNames,affine2d)
44
S3method(.DollarNames,dimObj)
55
S3method(.DollarNames,giotto)
66
S3method(.DollarNames,metaData)
7+
S3method(.DollarNames,processParam)
78
S3method(.DollarNames,spatEnrObj)
89
S3method(.DollarNames,spatLocsObj)
910
S3method(.DollarNames,terraVectData)
@@ -186,6 +187,7 @@ export(pDataDT)
186187
export(plotGiottoImage)
187188
export(polyStamp)
188189
export(polygon_to_raster)
190+
export(processData)
189191
export(readCellMetadata)
190192
export(readDimReducData)
191193
export(readExprData)
@@ -262,6 +264,7 @@ export(subsetGiotto)
262264
export(subsetGiottoLocs)
263265
export(subsetGiottoLocsMulti)
264266
export(subsetGiottoLocsSubcellular)
267+
export(svkey)
265268
export(t_flex)
266269
export(tessellate)
267270
export(triGrid)
@@ -284,6 +287,7 @@ exportClasses(giottoLargeImage)
284287
exportClasses(giottoPoints)
285288
exportClasses(giottoPolygon)
286289
exportClasses(nnNetObj)
290+
exportClasses(processParam)
287291
exportClasses(spatEnrObj)
288292
exportClasses(spatLocsObj)
289293
exportClasses(spatialGridObj)

NEWS.md

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
- `spatUnit()` and `featType()` method for `giotto` to find existing spatial units and feature types
2626
- expose `make_valid` param and `...` passing for `createGiottoPolygon()` `data.frame` method
2727

28+
## new
29+
- `processData()` generic and `processParam` class
30+
- `svkey` metaprogramming object for storing `spatValue()` parameters for later eval.
31+
2832
# GiottoClass 0.4.6 (2025/01/17)
2933

3034
## bug fixes

R/classes.R

+42-14
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,11 @@ NULL
44
# MISC ####
55
## * Define class unions ####
66

7-
#' @title NULL or char class union
8-
#' @description class to allow either NULL or character
9-
#' @keywords internal
10-
#' @noRd
117
setClassUnion("nullOrChar", c("NULL", "character"))
12-
13-
#' @title NULL or list class union
14-
#' @description class to allow either NULL or list
15-
#' @keywords internal
16-
#' @noRd
178
setClassUnion("nullOrList", c("NULL", "list"))
18-
19-
#' @title NULL or data.table class union
20-
#' @description class to allow either NULL or data.table
21-
#' @keywords internal
22-
#' @noRd
239
setClassUnion("nullOrDatatable", c("NULL", "data.table"))
10+
setClassUnion("nullOrLogical", c("NULL", "logical"))
11+
# see zzz.R for allMatrix
2412

2513
#' @title gIndex
2614
#' @description
@@ -306,6 +294,7 @@ terraVectData <- setClass(
306294

307295
# UTILITY ####
308296

297+
# ** affine2d ####
309298
setClass(
310299
Class = "affine2d",
311300
slots = list(
@@ -328,7 +317,46 @@ setClass(
328317
)
329318
)
330319

320+
# ** processParam ####
331321

322+
#' @title Parameter Classes for Data Processing Operations
323+
#' @name processParam
324+
#' @description
325+
#' Utility class that defines a data processing procedure and any params used
326+
#' in performing it. Packages defining processing methods will create their own
327+
#' child classes. These parameter objects are intended to be passed alongside
328+
#' the data to process to [processData()].
329+
#' @slot param list. Named parameters to use with the intended processing
330+
#' operation. These can be accessed and updated using the `$` operator.
331+
#' @export
332+
setClass("processParam", contains = "VIRTUAL", slots = list(param = "list"))
333+
334+
335+
336+
# ** svkey ####
337+
338+
#' @name svkey
339+
#' @title Spatial Value Key
340+
#' @description
341+
#' A metaprogramming object that references a set of information to get
342+
#' from a `giotto` object when used as `svkey@get(gobject)`.
343+
#' Referenced data will be retrieved as a `data.table` via [spatValues()]
344+
#' @keywords internal
345+
setClass("svkey",
346+
slots = list(
347+
feats = "character",
348+
spat_unit = "nullOrChar",
349+
feat_type = "nullOrChar",
350+
expression_values = "nullOrChar",
351+
spat_loc_name = "nullOrChar",
352+
spat_enr_name = "nullOrChar",
353+
poly_info = "nullOrChar",
354+
dim_reduction_to_use = "nullOrChar",
355+
dim_reduction_name = "nullOrChar",
356+
verbose = "nullOrLogical",
357+
get = "function"
358+
)
359+
)
332360

333361
# SUBCLASSES ####
334362

R/generics.R

+19
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,24 @@ setGeneric(
8686
)
8787

8888

89+
#' @title Data Processing
90+
#' @name processData
91+
#' @description Generic for processing an object containing measured values.
92+
#' Specific methods should be defined for this generic to
93+
#' perform pre or post processing specific to a data class type. No methods
94+
#' are exported from \pkg{GiottoClass}. The methods, which may
95+
#' differ depending on the input data, are attached from other packages which
96+
#' focus on analyses and/or alternative data representations with specific ways
97+
#' to implement those analyses.
98+
#' @param x a data object
99+
#' @param param a [processParam] inheriting object
100+
#' @param ... additional arguments, for use in specific methods
101+
#' @returns An object of the same class containing the processed
102+
#' @export
103+
setGeneric("processData", function(x, param, ...) standardGeneric("processData"))
104+
105+
# Methods and documentations found in methods-spatShift.R
106+
89107
setGeneric("spatShift", function(x, ...) standardGeneric("spatShift"))
90108
setGeneric("affine", function(x, y, ...) standardGeneric("affine"))
91109
setGeneric("shear", function(x, ...) standardGeneric("shear"))
@@ -100,6 +118,7 @@ if (!isGeneric("area")) {
100118
setGeneric("overlaps", function(x, ...) standardGeneric("overlaps"))
101119

102120

121+
103122
# Giotto subnesting ####
104123
# All methods and documentations found in methods-nesting.R
105124

R/methods-extract.R

+41-1
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,29 @@ setMethod("$", signature("affine2d"), function(x, name) {
349349
c("affine", "order", "rotate", "shear", "scale", "translate")
350350
}
351351

352+
#' @rdname subset_dollar
353+
#' @section \code{`$`} methods:
354+
#' Select param from `processParam` inheriting objects
355+
#' @export
356+
setMethod("$", signature("processParam"), function(x, name) {
357+
x@param[[name]]
358+
})
359+
#' @export
360+
.DollarNames.processParam <- function(x, pattern) {
361+
names(x@param)
362+
}
363+
364+
#' @rdname replace_dollar
365+
#' @section \code{`$<-`} methods:
366+
#' Set values by param name into `processParam` inheriting objects
367+
#' @export
368+
setMethod(
369+
"$<-", signature("processParam"),
370+
function(x, name, value) {
371+
x@param[[name]] <- value
372+
return(initialize(x))
373+
}
374+
)
352375

353376
# [ S4 access generic ####
354377

@@ -1174,6 +1197,7 @@ setMethod(
11741197
}
11751198
)
11761199

1200+
# * affine2d ####
11771201
#' @rdname subset_bracket
11781202
#' @export
11791203
setMethod(
@@ -1202,8 +1226,24 @@ setMethod(
12021226
}
12031227
)
12041228

1229+
# * processParam ####
1230+
#' @rdname subset_bracket
1231+
#' @export
1232+
setMethod("[",
1233+
signature(x = "processParam",
1234+
i = "missing", j = "missing", drop = "missing"),
1235+
function(x) x@param
1236+
)
12051237

1206-
1238+
#' @rdname replace_bracket
1239+
#' @export
1240+
setMethod("[<-",
1241+
signature(x = "processParam", i = "missing", j = "missing", value = "list"),
1242+
function(x, value) {
1243+
x@param <- value
1244+
return(initialize(x))
1245+
}
1246+
)
12071247

12081248

12091249
# giotto subsets ####

R/methods-initialize.R

-2
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,6 @@ setMethod("initialize", signature("giottoAffineImage"), function(.Object, ...) {
240240

241241

242242

243-
244-
245243
## * Initialize
246244
# setMethod('initialize', 'nnNetObj',
247245
# function(.Object, ...) {

R/methods-names.R

+6
Original file line numberDiff line numberDiff line change
@@ -134,3 +134,9 @@ setMethod("names<-", signature(x = "giottoLargeImage"), function(x, value) {
134134
names(x[]) <- value
135135
x
136136
})
137+
#' @rdname names
138+
setMethod("names", signature("processParam"), function(x) names(x@param))
139+
setMethod("names<-", signature("processParam"), function(x, value) {
140+
names(x@param) <- value
141+
x
142+
})

R/methods-show.R

+29-3
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,11 @@ setMethod("as.character", signature("giottoImage"), function(x, ...) {
741741
sprintf("<%s> %s", class(x), objName(x))
742742
})
743743

744-
744+
#' @rdname as.character
745+
#' @export
746+
setMethod("as.character", signature("svkey"), function(x, ...) {
747+
sprintf("<svkey> feats: '%s'", paste(x@feats, collapse = "', '"))
748+
})
745749

746750

747751

@@ -792,6 +796,7 @@ setMethod(
792796
)
793797

794798

799+
# affine2d ####
795800

796801
#' @rdname show
797802
setMethod("show", signature("affine2d"), function(object) {
@@ -827,9 +832,30 @@ setMethod("as.character", signature("giottoLargeImage"), function(x, ...) {
827832
sprintf("<%s> %s", class(x), objName(x))
828833
})
829834

835+
# processParam ####
836+
setMethod("show", signature("processParam"), function(object) {
837+
cat(sprintf("<%s>\n", class(object)))
838+
cat("params:\n")
839+
print_list(object[])
840+
})
830841

831-
832-
842+
# svkey ####
843+
setMethod("show", signature("svkey"), function(object) {
844+
cat(sprintf("<%s>\n", class(object)))
845+
plist <- list(
846+
feats = sprintf("'%s'", paste(object@feats, collapse = "' '")))
847+
plist$spat_unit <- object@spat_unit
848+
plist$feat_type <- object@feat_type
849+
plist$expression_values <- object@expression_values
850+
plist$spat_loc_name <- object@spat_loc_name
851+
plist$spat_enr_name <- object@spat_enr_name
852+
plist$poly_info <- object@poly_info
853+
plist$dim_reduction_to_use <- object@dim_reduction_to_use
854+
plist$dim_reduction_name <- object@dim_reduction_name
855+
plist$verbose <- object@verbose
856+
857+
print_list(plist)
858+
})
833859

834860

835861
# show helpers ####

R/package_imports.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#' @importMethodsFrom terra as.data.frame as.polygons as.points
2424
#' @importMethodsFrom terra nrow ncol
2525
#' @importMethodsFrom terra hist density
26-
#' @importClassesFrom terra SpatExtent SpatVector
2726
#' @importMethodsFrom terra area
27+
#' @importClassesFrom terra SpatExtent SpatVector
2828
#' @import GiottoUtils
2929
#' @import data.table
3030
#' @import utils

R/slot_accessors.R

+35
Original file line numberDiff line numberDiff line change
@@ -6353,6 +6353,41 @@ spatValues <- function(gobject,
63536353
}
63546354

63556355

6356+
## svkey ####
6357+
6358+
#' @describeIn spatValues Create a `svkey` defining a `spatValues()` call
6359+
#' for deferred use. Handy for contexts where the full `giotto` object is not
6360+
#' available.
6361+
#' @export
6362+
svkey <- function(feats,
6363+
spat_unit = NULL,
6364+
feat_type = NULL,
6365+
expression_values = NULL,
6366+
spat_loc_name = NULL,
6367+
poly_info = NULL,
6368+
dim_reduction_to_use = NULL,
6369+
dim_reduction_name = NULL,
6370+
verbose = NULL) {
6371+
if (missing(feats)) stop("'feats' to get must be provided", call. = FALSE)
6372+
a <- get_args_list()
6373+
svk <- do.call(new, c(list(Class = "svkey"), a))
6374+
svk@get <- function(gobject) {
6375+
spatValues(
6376+
gobject = gobject,
6377+
feats = svk@feats,
6378+
spat_unit = svk@spat_unit,
6379+
feat_type = svk@feat_type,
6380+
expression_values = svk@expression_values,
6381+
spat_loc_name = svk@spat_loc_name,
6382+
poly_info = svk@poly_info,
6383+
dim_reduction_to_use = svk@dim_reduction_to_use,
6384+
dim_reduction_name = svk@dim_reduction_name,
6385+
verbose = svk@verbose
6386+
)
6387+
}
6388+
svk
6389+
}
6390+
63566391

63576392
# internals ####
63586393

man/as.character.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/names.Rd

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)