[413088]: / R / allgenerics.R

Download this file

561 lines (502 with data), 14.3 kB

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