Switch to unified view

a b/tests/testthat/test-clustering.R
1
test_that("spatial", {
2
  
3
  # get data
4
  data("xenium_data")
5
  
6
  # profile neighbors, kNN
7
  xenium_data <- getProfileNeighbors(xenium_data, method = "kNN", k = 10, data.type = "pca")
8
  graphs <- vrGraph(xenium_data, graph.type = "kNN")
9
  expect_true(inherits(graphs,"igraph"))
10
  expect_true(length(igraph::E(graphs)) > 0)
11
  xenium_data <- getClusters(xenium_data, graph = "kNN", label = "cluster_knn")
12
  expect_true(is.numeric(unique(xenium_data$cluster_knn)))
13
  
14
  # profile neighbors, SNN
15
  xenium_data <- getProfileNeighbors(xenium_data, method = "SNN", k = 10, data.type = "pca")
16
  graphs <- vrGraph(xenium_data, graph.type = "SNN")
17
  expect_true(inherits(graphs,"igraph"))
18
  expect_true(length(igraph::E(graphs)) > 0)
19
  xenium_data <- getClusters(xenium_data, graph = "SNN", label = "cluster_SNN")
20
  expect_true(is.numeric(unique(xenium_data$cluster_SNN)))
21
  
22
  # check parameters
23
  expect_error(xenium_data <- getClusters(xenium_data, graph = "SNN", label = "cluster_SNN", resolution = 0))
24
  expect_error(xenium_data <- getClusters(xenium_data, graph = "SNN", label = "cluster_SNN", resolution = c(0,1)))
25
  expect_error(xenium_data <- getClusters(xenium_data, graph = "SNN", label = "cluster_SNN", resolution = -0.5))
26
  expect_error(xenium_data <- getClusters(xenium_data, graph = "SNN", label = "cluster_SNN", resolution = 1, abundance_limit = 0))
27
  expect_error(xenium_data <- getClusters(xenium_data, graph = "SNN", label = "cluster_SNN", resolution = 1, abundance_limit = 1.1))
28
  
29
  # return
30
  expect_equal(1,1L)
31
})