Skip to content

Commit

Permalink
Added tests for new function and updating news
Browse files Browse the repository at this point in the history
  • Loading branch information
JulieDevis committed Oct 28, 2024
1 parent d34472e commit 9bd53bb
Show file tree
Hide file tree
Showing 9 changed files with 438 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## CTexploreR 1.1.3

- Add pkgdown config.
- Correcting typo in fetal_germcells_mean_methylation() function name
- Adding tests for new functions


## CTexploreR 1.1.2
Expand Down
267 changes: 267 additions & 0 deletions tests/testthat/_snaps/GTEX_expression/gtex-expression-on-mage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions tests/testthat/test_embryo_expression.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
test_that("embryo_expression() works", {

## returns a SingleCellExperiment
## n valid genes in input returns a SingleCellExperiment of n expected rownames
## returns a warning when an invalid gene is entered
## works with only one gene in input
## error if no dataset is specified
expect_error(embryo_expression("MAGEA1"))
expect_warning(res <- embryo_expression(c("MAGEA1", "xxx"),
dataset = "Petropoulos",
values_only = TRUE), "names invalid")
expect_s4_class(res, "SingleCellExperiment")
expect_equal(nrow(res), 1)
expect_identical(rownames(res), "MAGEA1")


## Test that the function returns a heatmap by default
## Test that returns the expected heatmap
## res <- embryo_expression(c("MAGEA1", "MAGEA3", "MAGEA4"),
## dataset = "Petropoulos")
## expect_s4_class(res, "Heatmap")

## Same with Zhu
expect_warning(res <- embryo_expression(c("MAGEA1", "xxx"),
dataset = "Zhu",
values_only = TRUE), "names invalid")
expect_s4_class(res, "SingleCellExperiment")
expect_equal(nrow(res), 1)
expect_identical(rownames(res), "MAGEA1")

})

26 changes: 26 additions & 0 deletions tests/testthat/test_embryos_mean_methylation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
test_that("embryos_mean_methylation() works", {

## returns a RangedSummarizedExperiment when values_only is set to TRUE
res <- embryos_mean_methylation(
genes = c("MAGEA1", "MAGEA2", "MAGEA4"),
values_only = TRUE)
expect_s4_class(res, "RangedSummarizedExperiment")
expect_equal(nrow(res), 3)

## selects the expected cell types
my_stages <- c("Morula", "Blastocyst")
res <- embryos_mean_methylation(stage = my_stages, genes = "MAGEA1",
values_only = TRUE)
expect_equal(nrow(res), 1)
expect_true(all(unique(colData(res)$Stage) %in% my_stages))

## no valid gene in input returns an empty matrix
expect_warning(res_no_gene <- embryos_mean_methylation(
genes = "xxx", values_only = TRUE), "valid types")
expect_equal(nrow(res_no_gene), 0)

## Test that the function returns a heatmap by default
## res <- embryos_mean_methylation(
## genes = c("MAGEA1", "MAGEA2", "MAGEA4", "TDRD1"))
## expect_s4_class(res, "Heatmap")
})
20 changes: 20 additions & 0 deletions tests/testthat/test_fetal_germcells_expression.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
test_that("fetal_germcells_expression() works", {

## returns a SingleCellExperiment
## n valid genes in input returns a SingleCellExperiment of n expected rownames
## returns a warning when an invalid gene is entered
## works with only one gene in input

expect_warning(res <- fetal_germcells_expression(c("MAGEA1", "xxx"),
values_only = TRUE), "names invalid")
expect_s4_class(res, "SingleCellExperiment")
expect_equal(nrow(res), 1)
expect_identical(rownames(res), "MAGEA1")


## Test that the function returns a heatmap by default
## Test that returns the expected heatmap
## res <- fetal_germcells_expression(c("MAGEA1", "MAGEA3", "MAGEA4"))
## expect_s4_class(res, "Heatmap")

})
20 changes: 20 additions & 0 deletions tests/testthat/test_fetal_germcells_mean_methylation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
test_that("fetal_germcells_mean_methylation() works", {

## returns a SummarizedExperiment when values_only is set to TRUE
res <- fetal_germcells_mean_methylation(
genes = c("MAGEA1", "MAGEA2", "MAGEA4"),
values_only = TRUE)
expect_s4_class(res, "SummarizedExperiment")
expect_equal(nrow(res), 3)


## no valid gene in input returns an empty matrix
expect_warning(res_no_gene <- fetal_germcells_mean_methylation(
genes = "xxx", values_only = TRUE), "valid types")
expect_equal(nrow(res_no_gene), 0)

## Test that the function returns a heatmap by default
## res <- fetal_germcells_mean_methylation(
## genes = c("MAGEA1", "MAGEA2", "MAGEA4", "TDRD1"))
## expect_s4_class(res, "Heatmap")
})
24 changes: 24 additions & 0 deletions tests/testthat/test_hESC_expression.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
test_that("hESC_expression() works", {

## returns a SummarizedExperiment
res <- hESC_expression(genes = c("MAGEA1", "MAGEA3"),
values_only = TRUE)
expect_s4_class(res, "SummarizedExperiment")
expect_equal(nrow(res), 2)
expect_identical(sort(rowData(res)$external_gene_name),
sort(c("MAGEA1", "MAGEA3")))

## Test the "log_TPM" units argument
res_in_log <- hESC_expression(c("MAGEA1", "MAGEA3"),
units = "log_TPM",
values_only = TRUE)
expect_equal(assay(res_in_log)[, "H1"], log1p(assay(res)[, "H1"]))

# Check default genes with CTP
res_includeCTP <- hESC_expression(include_CTP = TRUE, values_only = TRUE)
expect_equal(nrow(res_includeCTP), nrow(CT_genes))

## Test that the function returns a heatmap
## res <- hESC_expression(genes = c("MAGEA1", "MAGEA3"))
## expect_s4_class(res, "Heatmap")
})
27 changes: 27 additions & 0 deletions tests/testthat/test_hESC_mean_methylation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
test_that("hESC_mean_methylation() works", {

## returns a SummarizedExperiment when values_only is set to TRUE
## the na.omit parameter set to FALSE keeps genes with missing values
res <- hESC_mean_methylation(
genes = c("MAGEA1", "MAGEA2", "MAGEA4"),
na.omit = FALSE, values_only = TRUE)
expect_s4_class(res, "SummarizedExperiment")
expect_equal(nrow(res), 3)

## the na.omit parameter set to TRUE removes genes with missing values
res_na_omit <- hESC_mean_methylation(
genes = c("MAGEA1", "MAGEA2", "MAGEA4"),
na.omit = TRUE, values_only = TRUE)
expect_identical(na.omit(res), res_na_omit)

## no valid gene in input returns an empty matrix
expect_warning(res_no_gene <- hESC_mean_methylation(
genes = "xxx", values_only = TRUE), "valid types")
expect_equal(nrow(res_no_gene), 0)

## Test that the function returns a heatmap by default
## res <- hESC_mean_methylation(
## genes = c("MAGEA1", "MAGEA2", "MAGEA4", "TDRD1"))
## expect_s4_class(res, "Heatmap")

})
20 changes: 20 additions & 0 deletions tests/testthat/test_oocytes_expression.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
test_that("oocytes_expression() works", {

## returns a SingleCellExperiment
## n valid genes in input returns a SingleCellExperiment of n expected rownames
## returns a warning when an invalid gene is entered
## works with only one gene in input

expect_warning(res <- oocytes_expression(c("MAGEA1", "xxx"),
values_only = TRUE), "names invalid")
expect_s4_class(res, "SingleCellExperiment")
expect_equal(nrow(res), 1)
expect_identical(rownames(res), "MAGEA1")


## Test that the function returns a heatmap by default
## Test that returns the expected heatmap
## res <- oocytes_expression(c("MAGEA1", "MAGEA3", "MAGEA4"))
## expect_s4_class(res, "Heatmap")

})

0 comments on commit 9bd53bb

Please sign in to comment.