Diff of /R/allgenerics.R [000000] .. [413088]

Switch to unified view

a b/R/allgenerics.R
1
#' @include zzz.R
2
#'
3
NULL
4
5
####
6
# General ####
7
####
8
9
#' vrFeatures
10
#'
11
#' Get names of the features.
12
#'
13
#' @param object a VoltRon or vrAssay object.
14
#' @param ... arguments passed to other methods.
15
#' 
16
#' @rdname vrFeatures
17
#' @export vrFeatures
18
#' @order 1
19
setGeneric("vrFeatures", function(object, ...) standardGeneric("vrFeatures"))
20
21
#' Feature Data
22
#'
23
#' Get and set feature data from the main.assay
24
#'
25
#' @param object a VoltRon or vrAssay object.
26
#' @param ... arguments passed to other methods.
27
#'
28
#' @rdname vrFeatureData
29
#' @export vrFeatureData
30
#' @order 1
31
setGeneric("vrFeatureData", function(object, ...) standardGeneric("vrFeatureData"))
32
33
#' @rdname vrFeatureData
34
#' @export vrFeatureData<-
35
setGeneric("vrFeatureData<-", function(object, ..., value) standardGeneric("vrFeatureData<-"))
36
37
#' getFeatures
38
#'
39
#' Get variable features of assays
40
#'
41
#' @param object a VoltRon or vrAssay object.
42
#' @param ... arguments passed to other methods.
43
#'
44
#' @rdname getFeatures
45
#' @export getFeatures
46
setGeneric("getFeatures", function(object, ...) standardGeneric("getFeatures"))
47
48
#' vrData
49
#'
50
#' Get data of assays
51
#'
52
#' @param object a VoltRon or vrAssay object.
53
#' @param ... arguments passed to other methods.
54
#'
55
#' @rdname vrData
56
#' @export vrData
57
#' @order 1
58
setGeneric("vrData", function(object, ...) standardGeneric("vrData"))
59
60
#' generateTileData
61
#'
62
#' Generating data matrices for tile-based VoltRon objects from images
63
#'
64
#' @param object a VoltRon or vrAssay object.
65
#' @param ... arguments passed to other methods.
66
#'
67
#' @rdname generateTileData
68
#' @export generateTileData
69
#' @order 1
70
setGeneric("generateTileData", function(object, ...) standardGeneric("generateTileData"))
71
72
#' changeSampleNames
73
#'
74
#' change sample names of VoltRon or other objects
75
#'
76
#' @param object a VoltRon or vrMetadata object.
77
#' @param ... arguments passed to other methods.
78
#'
79
#' @rdname changeSampleNames
80
#'
81
#' @noRd
82
setGeneric("changeSampleNames", function(object, ...) standardGeneric("changeSampleNames"))
83
84
#' changeAssayNames
85
#'
86
#' change assay names of VoltRon or other objects
87
#'
88
#' @param object a VoltRon, vrSample or vrLayer object.
89
#' @param ... arguments passed to other methods.
90
#'
91
#' @rdname changeAssayNames
92
#'
93
#' @noRd
94
setGeneric("changeAssayNames", function(object, ...) standardGeneric("changeAssayNames"))
95
96
####
97
# Assay ####
98
####
99
100
#' Main Assay
101
#'
102
#' Get and set the main assay of a VoltRon object
103
#' 
104
#' @param object a VoltRon object.
105
#' @param ... arguments passed to other methods.
106
#'
107
#' @rdname vrMainAssay
108
#' @export vrMainAssay
109
setGeneric("vrMainAssay", function(object, ...) standardGeneric("vrMainAssay"))
110
111
#' @param value new assay name
112
#' 
113
#' @rdname vrMainAssay
114
#' @export vrMainAssay<-
115
setGeneric("vrMainAssay<-", function(object, ..., value) standardGeneric("vrMainAssay<-"))
116
117
#' Update Assay
118
#'
119
#' update assays from vrAssay to vrAssayV2
120
#' 
121
#' @param object a VoltRon object.
122
#' @param ... arguments passed to other methods.
123
#'
124
#' @rdname updateAssay
125
#' @export updateAssay
126
setGeneric("updateAssay", function(object, ...) standardGeneric("updateAssay"))
127
128
#' Add Assay
129
#'
130
#' add a new assay (vrAssay object) to a VoltRon object
131
#'
132
#' @param object a VoltRon object.
133
#' @param ... arguments passed to other methods.
134
#'
135
#' @rdname addAssay
136
#' @export addAssay
137
setGeneric("addAssay", function(object, ...) standardGeneric("addAssay"))
138
139
#' Get Assay names
140
#'
141
#' Given a VoltRon, vrMetadata or vrAssay object, get/set names of assays.
142
#'
143
#' @param object a VoltRon or vrAssay object.
144
#' @param ... arguments passed to other methods.
145
#'
146
#' @rdname vrAssayNames
147
#' @export vrAssayNames
148
#' @order 1
149
setGeneric("vrAssayNames", function(object, ...) standardGeneric("vrAssayNames"))
150
151
#' @rdname vrAssayNames
152
#' @noRd
153
setGeneric("vrAssayNames<-", function(object, ..., value) standardGeneric("vrAssayNames<-"))
154
155
#' Get assay types
156
#' 
157
#' Given a VoltRon or vrAssay object, get types of assays. 
158
#' Here, an assay type is of either tile, molecule, cell, spot or ROI.
159
#'
160
#' @param object a VoltRon or vrAssay object.
161
#' @param ... arguments passed to other methods.
162
#'
163
#' @rdname vrAssayTypes
164
#' @export vrAssayTypes
165
#' @order 1
166
setGeneric("vrAssayTypes", function(object, ...) standardGeneric("vrAssayTypes"))
167
168
####
169
# Sample ####
170
####
171
172
#' Get Sample names
173
#'
174
#' Given a vrMetadata object, give names of samples
175
#'
176
#' @param object a vrMetadata object.
177
#' @param ... arguments passed to other methods.
178
#'
179
#' @rdname vrSampleNames
180
#' @export vrSampleNames
181
setGeneric("vrSampleNames", function(object, ...) standardGeneric("vrSampleNames"))
182
183
####
184
# Metadata ####
185
####
186
187
#' Metadata
188
#'
189
#' Get the metadata of a VoltRon object.
190
#'
191
#' @param object a VoltRon object.
192
#' @param ... arguments passed to other methods.
193
#'
194
#' @rdname Metadata
195
#' @export Metadata
196
setGeneric("Metadata", function(object, ...) standardGeneric("Metadata"))
197
198
#' @param value new metadata
199
#'
200
#' @rdname Metadata
201
setGeneric("Metadata<-", function(object, ..., value) standardGeneric("Metadata<-"))
202
203
####
204
# Processing ####
205
####
206
207
#' Normalize Data
208
#' 
209
#' Given a VoltRon or vrAssay object, normalize the raw count data.
210
#'
211
#' @param object a VoltRon or vrAssay object.
212
#' @param ... arguments passed to other methods.
213
#' 
214
#' @rdname normalizeData
215
#' @export normalizeData
216
setGeneric("normalizeData", function(object, ...) standardGeneric("normalizeData"))
217
218
####
219
# Embedding ####
220
####
221
222
#' Get Embedding names
223
#'
224
#' Given a VoltRon or vrAssay object, give names of embeddings
225
#'
226
#' @param object a VoltRon or vrAssay object.
227
#' @param ... arguments passed to other methods.
228
#'
229
#' @rdname vrEmbeddingNames
230
#' @export vrEmbeddingNames
231
#' @order 1
232
setGeneric("vrEmbeddingNames", function(object, ...) standardGeneric("vrEmbeddingNames"))
233
234
#' vrEmbeddings
235
#'
236
#' Given a VoltRon or vrAssay object, get embeddings of spatial points
237
#' 
238
#' @param object a VoltRon or vrAssay object.
239
#' @param ... arguments passed to other methods.
240
#' 
241
#' @rdname vrEmbeddings
242
#' @export vrEmbeddings
243
#' @order 1
244
setGeneric("vrEmbeddings", function(object, ...) standardGeneric("vrEmbeddings"))
245
246
#' @param value new embedding data
247
#'
248
#' @rdname vrEmbeddings
249
#' @export vrEmbeddings<-
250
setGeneric("vrEmbeddings<-", function(object, ..., value) standardGeneric("vrEmbeddings<-"))
251
252
####
253
# Feature ####
254
####
255
256
#' addFeature
257
#'
258
#' add a new feature set to a vrAssay (or VoltRon) object
259
#'
260
#' @param object a VoltRon or vrAssay object.
261
#' @param ... arguments passed to other methods.
262
#'
263
#' @rdname addFeature
264
#' @export addFeature
265
#' @order 1
266
setGeneric("addFeature", function(object, ...) standardGeneric("addFeature"))
267
268
#' vrMainFeatureType
269
#'
270
#' Get the main feature type
271
#'
272
#' @param object a VoltRon or vrAssay object.
273
#' @param ... arguments passed to other methods.
274
#'
275
#' @rdname vrMainFeatureType
276
#' @export vrMainFeatureType
277
#' @order 1
278
setGeneric("vrMainFeatureType", function(object, ...) standardGeneric("vrMainFeatureType"))
279
280
#' vrMainFeatureType
281
#'
282
#' Set the main image
283
#'
284
#' @param value the name of main feature set.
285
#'
286
#' @rdname vrMainFeatureType
287
#' @export vrMainFeatureType<-
288
setGeneric("vrMainFeatureType<-", function(object, ..., value) standardGeneric("vrMainFeatureType<-"))
289
290
#' vrFeatureTypeNames
291
#'
292
#' Get the names of the feature types
293
#'
294
#' @param object a VoltRon or vrAssay object.
295
#' @param ... arguments passed to other methods.
296
#'
297
#' @rdname vrFeatureTypeNames
298
#' @export vrFeatureTypeNames
299
#' @order 1
300
setGeneric("vrFeatureTypeNames", function(object, ...) standardGeneric("vrFeatureTypeNames"))
301
302
####
303
# Spatial ####
304
####
305
306
#' vrSpatialPoints
307
#'
308
#' Get and set spatial entities.
309
#'
310
#' @param object a VoltRon, vrSample, vrLayer, vrAssay or vrSpatial object.
311
#' @param ... arguments passed to other methods.
312
#'
313
#' @rdname vrSpatialPoints
314
#' @export vrSpatialPoints
315
#' @order 1
316
#'
317
#' @examples
318
#' vrSpatialPoints(visium_data)
319
#' vrSpatialPoints(visium_data, assay = "Visium")
320
#' vrSpatialPoints(visium_data, assay = "Assay1")
321
setGeneric("vrSpatialPoints", function(object, ...) standardGeneric("vrSpatialPoints"))
322
323
#' @param value names for spatial points
324
#'
325
#' @rdname vrSpatialPoints
326
#' @export vrSpatialPoints<-
327
setGeneric("vrSpatialPoints<-", function(object, ..., value) standardGeneric("vrSpatialPoints<-"))
328
329
#' vrCoordinates
330
#'
331
#' Given a VoltRon, vrAssay or vrSpatial object, get and set the coordinates of assays and coordinate systems
332
#'
333
#' @param object a VoltRon, vrAssay or vrSpatial object.
334
#' @param ... arguments passed to other methods.
335
#'
336
#' @rdname vrCoordinates
337
#' @export vrCoordinates
338
#' @order 1
339
setGeneric("vrCoordinates", function(object, ...) standardGeneric("vrCoordinates"))
340
341
#' @param value coordinates
342
#' 
343
#' @rdname vrCoordinates
344
#' @export vrCoordinates<-
345
setGeneric("vrCoordinates<-", function(object, ..., value) standardGeneric("vrCoordinates<-"))
346
347
#' vrSegments
348
#'
349
#' Given a VoltRon, vrAssay or vrSpatial object, get and set the segment coordinates of assays and coordinate systems
350
#'
351
#' @param object a VoltRon, vrAssay or vrSpatial object.
352
#' @param ... arguments passed to other methods.
353
#'
354
#' @rdname vrSegments
355
#' @export vrSegments
356
#' @order 1
357
setGeneric("vrSegments", function(object, ...) standardGeneric("vrSegments"))
358
359
#' @param value segments
360
#' 
361
#' @rdname vrSegments
362
#' @export vrSegments<-
363
setGeneric("vrSegments<-", function(object, ..., value) standardGeneric("vrSegments<-"))
364
365
#' flipCoordinates
366
#'
367
#' Flip the coordinates of spatial points in the y axis direction. 
368
#'
369
#' @param object a VoltRon, vrAssay or vrSpatial object.
370
#' @param ... arguments passed to other methods.
371
#'
372
#' @rdname flipCoordinates
373
#' @export flipCoordinates
374
#' @order 1
375
setGeneric("flipCoordinates", function(object, ...) standardGeneric("flipCoordinates"))
376
377
####
378
# Image ####
379
####
380
381
#' vrImages
382
#'
383
#' Get images of VoltRon objects
384
#'
385
#' @param object a VoltRon, vrAssay or vrSpatial object.
386
#' @param ... arguments passed to other methods.
387
#'
388
#' @rdname vrImages
389
#' @export vrImages
390
#' @order 1
391
setGeneric("vrImages", function(object, ...) standardGeneric("vrImages"))
392
393
#' @param value a raster image or an image of \code{magick-image} object
394
#' 
395
#' @rdname vrImages
396
#' @export vrImages<-
397
setGeneric("vrImages<-", function(object, ..., value) standardGeneric("vrImages<-"))
398
399
#' vrImageNames
400
#'
401
#' Get names of all images
402
#'
403
#' @param object a VoltRon or vrAssay object.
404
#' @param ... arguments passed to other methods.
405
#'
406
#' @rdname vrImageNames
407
#' @export vrImageNames
408
setGeneric("vrImageNames", function(object, ...) standardGeneric("vrImageNames"))
409
410
#' vrSpatialNames
411
#'
412
#' Get names of all spatial systems
413
#'
414
#' @param object a VoltRon or vrAssay object.
415
#' @param ... arguments passed to other methods.
416
#'
417
#' @rdname vrSpatialNames
418
#' @export vrSpatialNames
419
setGeneric("vrSpatialNames", function(object, ...) standardGeneric("vrSpatialNames"))
420
421
#' vrImageChannelNames
422
#'
423
#' Get names of all image channels
424
#'
425
#' @param object a VoltRon, vrAssay or vrSpatial object.
426
#' @param ... arguments passed to other methods.
427
#'
428
#' @rdname vrImageChannelNames
429
#' @export vrImageChannelNames
430
#'
431
setGeneric("vrImageChannelNames", function(object, ...) standardGeneric("vrImageChannelNames"))
432
433
#' vrMainImage
434
#'
435
#' Get the main image
436
#'
437
#' @param object a VoltRon or vrAssay object.
438
#' @param ... arguments passed to other methods.
439
#'
440
#' @rdname vrMainImage
441
#' @export vrMainImage
442
#' @order 1
443
setGeneric("vrMainImage", function(object, ...) standardGeneric("vrMainImage"))
444
445
#' vrMainSpatial
446
#'
447
#' Get the main spatial system name
448
#'
449
#' @param object a VoltRon or vrAssay object.
450
#' @param ... arguments passed to other methods.
451
#'
452
#' @rdname vrMainSpatial
453
#' @export vrMainSpatial
454
#' @order 1
455
setGeneric("vrMainSpatial", function(object, ...) standardGeneric("vrMainSpatial"))
456
457
#' vrMainImage
458
#'
459
#' Set the main image
460
#'
461
#' @param value the name of main spatial coordinate system.
462
#'
463
#' @rdname vrMainImage
464
#' @export vrMainImage<-
465
setGeneric("vrMainImage<-", function(object, ..., value) standardGeneric("vrMainImage<-"))
466
467
#' vrMainSpatial
468
#'
469
#' Set the main image
470
#'
471
#' @param value the name of main spatial coordinate system
472
#'
473
#' @rdname vrMainSpatial
474
#' @export vrMainSpatial<-
475
setGeneric("vrMainSpatial<-", function(object, ..., value) standardGeneric("vrMainSpatial<-"))
476
477
#' vrMainChannel
478
#'
479
#' Get and set the main channel name of the spatial system.
480
#' @param ... arguments passed to other methods.
481
#'
482
#' @param object a vrAssay or vrSpatial object
483
#'
484
#' @rdname vrMainChannel
485
#' @export vrMainChannel
486
#' @order 1
487
setGeneric("vrMainChannel", function(object, ...) standardGeneric("vrMainChannel"))
488
489
#' @param value the name of main channel of the spatial system
490
#'
491
#' @rdname vrMainChannel
492
#' @export vrMainChannel<-
493
setGeneric("vrMainChannel<-", function(object, ..., value) standardGeneric("vrMainChannel<-"))
494
495
#' resizeImage
496
#'
497
#' Resizing Magick images
498
#'
499
#' @param object a VoltRon, vrAssay or vrSpatial object.
500
#' @param ... arguments passed to other methods.
501
#'
502
#' @rdname resizeImage
503
#' @export resizeImage
504
#'
505
setGeneric("resizeImage", function(object, ...) standardGeneric("resizeImage"))
506
507
#' modulateImage
508
#'
509
#' Modulating Magick images
510
#'
511
#' @param object a VoltRon, vrAssay or vrSpatial object.
512
#' @param ... arguments passed to other methods.
513
#'
514
#' @rdname modulateImage
515
#' @export modulateImage
516
#'
517
setGeneric("modulateImage", function(object, ...) standardGeneric("modulateImage"))
518
519
#' combineChannels
520
#'
521
#' Combining channels into novel channels of the same image
522
#'
523
#' @param object a VoltRon, vrAssay or vrSpatial object.
524
#' @param ... arguments passed to other methods.
525
#'
526
#' @rdname combineChannels
527
#' @export combineChannels
528
#'
529
setGeneric("combineChannels", function(object, ...) standardGeneric("combineChannels"))
530
531
####
532
# Conversion ####
533
####
534
535
#' as.VoltRon
536
#'
537
#' Generic methods for conversion into a VoltRon object
538
#'
539
#' @param object a Seurat or SpatialExperiment object
540
#' @param ... Arguments passed to other methods
541
#'
542
#' @rdname as.VoltRon
543
#' @export as.VoltRon
544
as.VoltRon <- function(object, ...) {
545
  UseMethod(generic = 'as.VoltRon', object = object)
546
}
547
548
#' as.Zarr
549
#'
550
#' Generic methods to save VoltRon or magick-image objects as zarr files
551
#'
552
#' @param object a VoltRon or magick-image object
553
#' @param out_path output path to zarr file
554
#' @param image_id image name
555
#'
556
#' @rdname as.Zarr
557
#' @export as.Zarr
558
#'
559
as.Zarr <- function(object, out_path, image_id) {
560
  UseMethod(generic = 'as.Zarr', object = object)
561
}