tests/testthat/test-do_CNVHeatmap.R

if (base::isFALSE(dep_check[["do_CNVHeatmap"]])){

  testthat::test_that("do_BarPlot: CRAN essentials", {
    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object,
                                            using_metacells = FALSE,
                                            chromosome_locations = human_chr_locations)
    testthat::expect_true(ggplot2::is_ggplot(p))
  })

  testthat::test_that("do_BarPlot: PASS - normal cells all chromosomes", {

    testthat::skip_on_cran()

    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object,
                                            using_metacells = FALSE,
                                            chromosome_locations = human_chr_locations,
                                            flip = TRUE)
    testthat::expect_true(ggplot2::is_ggplot(p))
    
    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                 infercnv_object = infercnv_object,
                                 using_metacells = FALSE,
                                 chromosome_locations = human_chr_locations,
                                 flip = TRUE,
                                 min.cutoff = 0.99,
                                 max.cutoff = 1.01)
    testthat::expect_true(ggplot2::is_ggplot(p))
    
    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                 infercnv_object = infercnv_object,
                                 using_metacells = FALSE,
                                 chromosome_locations = human_chr_locations,
                                 flip = TRUE,
                                 include_chr_arms = TRUE)
    testthat::expect_true(ggplot2::is_ggplot(p))
    
    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                 infercnv_object = infercnv_object,
                                 using_metacells = FALSE,
                                 chromosome_locations = human_chr_locations,
                                 flip = TRUE,
                                 enforce_symmetry = FALSE)
    testthat::expect_true(ggplot2::is_ggplot(p))
    
    out <- SCpubr::do_CNVHeatmap(sample = sample,
                                 infercnv_object = infercnv_object,
                                 using_metacells = FALSE,
                                 chromosome_locations = human_chr_locations,
                                 flip = TRUE,
                                 values.show = TRUE,
                                 values.threshold = 1)
    testthat::expect_true(ggplot2::is_ggplot(p))
    
    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                 infercnv_object = infercnv_object,
                                 using_metacells = FALSE,
                                 chromosome_locations = human_chr_locations,
                                 flip = TRUE)
    testthat::expect_true(ggplot2::is_ggplot(p))
    
    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object,
                                            using_metacells = FALSE,
                                            chromosome_locations = human_chr_locations,
                                            flip = TRUE,
                                            group.by = c("seurat_clusters", "orig.ident", "annotation"))
    testthat::expect_true(ggplot2::is_ggplot(p))
    
    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object,
                                            using_metacells = FALSE,
                                            chromosome_locations = human_chr_locations,
                                            flip = FALSE)
    testthat::expect_true(ggplot2::is_ggplot(p))
    
    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object,
                                            using_metacells = FALSE,
                                            chromosome_locations = human_chr_locations,
                                            flip = FALSE,
                                            group.by = c("seurat_clusters", "orig.ident", "annotation"))
    testthat::expect_true(ggplot2::is_ggplot(p))
    
    out <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object,
                                            using_metacells = FALSE,
                                            chromosome_locations = human_chr_locations,
                                            flip = FALSE,
                                            return_object = TRUE)
    testthat::expect_type(out, "list")
    
    
    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object,
                                            using_metacells = FALSE,
                                            group.by = c("seurat_clusters", "orig.ident"),
                                            chromosome_locations = human_chr_locations,
                                            flip = TRUE)
    testthat::expect_true(ggplot2::is_ggplot(p))
    
    out <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object,
                                            using_metacells = FALSE,
                                            group.by = c("seurat_clusters", "orig.ident"),
                                            chromosome_locations = human_chr_locations,
                                            flip = FALSE,
                                            return_object = TRUE)
    testthat::expect_type(out, "list")
  })

  testthat::test_that("do_CNVHeatmap: PASS - normal cells one chromosome", {

    testthat::skip_on_cran()
    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object,
                                            using_metacells = FALSE,
                                            chromosome_locations = human_chr_locations)
    testthat::expect_true(ggplot2::is_ggplot(p))
  })

  testthat::test_that("do_CNVHeatmap: PASS - metacells all chromosomes", {
    testthat::skip_on_cran()

    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object_metacells,
                                            using_metacells = TRUE,
                                            metacell_mapping = metacell_mapping,
                                            chromosome_locations = human_chr_locations)
    testthat::expect_true(ggplot2::is_ggplot(p))
  })

  

  testthat::test_that("do_CNVHeatmap: PASS - group.by", {
    testthat::skip_on_cran()

    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object_metacells,
                                            using_metacells = TRUE,
                                            metacell_mapping = metacell_mapping,
                                            group.by = "orig.ident",
                                            chromosome_locations = human_chr_locations)
    testthat::expect_true(ggplot2::is_ggplot(p))
  })


  testthat::test_that("do_CNVHeatmap: PASS - legend.position", {
    testthat::skip_on_cran()

    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object_metacells,
                                            using_metacells = TRUE,
                                            metacell_mapping = metacell_mapping,
                                            legend.position = "right",
                                            legend.title = "test",
                                            chromosome_locations = human_chr_locations)
    testthat::expect_true(ggplot2::is_ggplot(p))

    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object_metacells,
                                            using_metacells = TRUE,
                                            metacell_mapping = metacell_mapping,
                                            legend.position = "bottom",
                                            chromosome_locations = human_chr_locations)
    testthat::expect_true(ggplot2::is_ggplot(p))
  })

  testthat::test_that("do_CNVHeatmap: PASS - legend.position", {
    testthat::skip_on_cran()

    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object_metacells,
                                            using_metacells = TRUE,
                                            metacell_mapping = metacell_mapping,
                                            legend.type = "normal",
                                            chromosome_locations = human_chr_locations)
    testthat::expect_true(ggplot2::is_ggplot(p))

    p <- SCpubr::do_CNVHeatmap(sample = sample,
                                            infercnv_object = infercnv_object_metacells,
                                            using_metacells = TRUE,
                                            metacell_mapping = metacell_mapping,
                                            legend.type = "colorbar",
                                            chromosome_locations = human_chr_locations)
    testthat::expect_true(ggplot2::is_ggplot(p))
  })
}

Try the SCpubr package in your browser

Any scripts or data that you put into this service are public.

SCpubr documentation built on Aug. 21, 2025, 6 p.m.