[413088]: / tests / testthat / test_conversion.R

Download this file

119 lines (89 with data), 3.5 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
# library
skip_on_ci() # dont test on GitHub actions
# file
h5ad_file <- tempfile(fileext = ".h5ad")
zarr_file <- tempfile(fileext = ".zarr")
ometiff_file <- tempfile(fileext = ".ome.tiff")
test_that("as.AnnData", {
# get data
data("visium_data")
data("xenium_data")
# xenium to anndata
as.AnnData(xenium_data, file = h5ad_file)
as.AnnData(xenium_data, file = h5ad_file, assay = "Assay1")
as.AnnData(xenium_data, file = h5ad_file, flip_coordinates = TRUE)
# visium to anndata
as.AnnData(visium_data, file = h5ad_file)
as.AnnData(visium_data, file = h5ad_file, assay = "Assay1")
as.AnnData(visium_data, file = h5ad_file, flip_coordinates = TRUE)
# xenium to anndata
as.AnnData(xenium_data, file = zarr_file)
as.AnnData(xenium_data, file = zarr_file, assay = "Assay1")
as.AnnData(xenium_data, file = zarr_file, flip_coordinates = TRUE)
# visium to anndata
as.AnnData(visium_data, file = zarr_file)
as.AnnData(visium_data, file = zarr_file, assay = "Assay1")
as.AnnData(visium_data, file = zarr_file, flip_coordinates = TRUE)
# clean file
file.remove(h5ad_file)
unlink(zarr_file, recursive = TRUE)
expect_equal(1,1L)
})
test_that("as.AnnData, python path", {
# get data
data("visium_data")
data("xenium_data")
# python.path
expect_error(as.AnnData(visium_data, file = h5ad_file, python.path = ""))
# python.path
python.path <- system("which python", intern = TRUE)
expect_error(as.AnnData(visium_data, file = zarr_file, python.path = python.path))
expect_error(as.AnnData(visium_data, file = zarr_file, python.path = ""))
# options path
options(voltron.python.path = python.path)
expect_error(as.AnnData(visium_data, file = zarr_file))
options(voltron.python.path = NULL)
expect_true(as.AnnData(visium_data, file = zarr_file))
# clean file
expect_equal(1,1L)
})
test_that("as.ometiff", {
# get image
data.file <- system.file(file.path('extdata', 'DAPI.tif'), package='VoltRon')
# save image
as.OmeTiff(magick::image_read(data.file), out_path = ometiff_file)
# clean file
file.remove(ometiff_file)
expect_equal(1,1L)
})
test_that("as.ometiff, python path", {
# get image
data.file <- system.file(file.path('extdata', 'DAPI.tif'), package='VoltRon')
# save image
as.OmeTiff(magick::image_read(data.file), out_path = ometiff_file)
# python.path
expect_error(as.OmeTiff(magick::image_read(data.file), out_path = ometiff_file, python.path = ""))
# python.path
python.path <- system("which python", intern = TRUE)
expect_error(as.OmeTiff(magick::image_read(data.file), out_path = ometiff_file, python.path = python.path))
# options path
options(voltron.python.path = python.path)
expect_error(as.OmeTiff(magick::image_read(data.file), out_path = ometiff_file))
options(voltron.python.path = NULL)
expect_true(as.OmeTiff(magick::image_read(data.file), out_path = ometiff_file))
# clean file
file.remove(ometiff_file)
expect_equal(1,1L)
})
test_that("as.Seurat", {
# one sample
test1 <- VoltRon::as.Seurat(xenium_data, cell.assay = "Xenium", type = "image")
test1_Voltron <- as.VoltRon(test1, assay_name = "Xenium")
# multiple samples
xenium_data2 <- xenium_data
xenium_data2$Sample <- "sample1"
xenium_data2 <- merge(xenium_data2, xenium_data)
test1 <- VoltRon::as.Seurat(xenium_data2, cell.assay = "Xenium", type = "image")
test1_Voltron <- as.VoltRon(test1, assay_name = "Xenium")
expect_equal(1,1L)
})