testthat::context('Testing normalization')
setwd(here::here('')) # workspace is reset per file
# normalize ------------------------------------
testthat::test_that('normalize() check args', {
testthat::expect_error(
normalize(tempfile(), 'CPM_top'),
'top_n must be specified for CPM_top method'
)
testthat::expect_error(
normalize(tempfile(), 'CPM_rm'),
'rm_gene_type must be specified for CPM_rm method'
)
testthat::expect_error(
normalize(tempfile(), 'CPM_refer'),
'refer_gene_id must be specified for CPM_refer method'
)
})
# norm_SCnorm ----------------------
testthat::test_that('norm_SCnorm()', {
mat_SCnorm <- suppressMessages(norm_SCnorm(sim_mat*10))
testthat::expect_true(is.matrix(mat_SCnorm))
testthat::expect_identical(dim(mat_SCnorm), dim(sim_mat))
})
# norm_tmm ----------------------
testthat::test_that('norm_tmm()', {
testthat::expect_identical(suppressWarnings(norm_tmm(sim_mat)), sim_mat)
testthat::expect_warning(
suppressMessages(norm_tmm(sim_mat)),
"norm_tmm() is deprecated, returning the original matrix.",
fixed = TRUE
)
testthat::expect_message(
suppressWarnings(norm_tmm(sim_mat)),
'scater::normaliseExprs(., "TMM")',
fixed = TRUE
)
})
# norm_rle ----------------------
testthat::test_that('norm_rle()', {
testthat::expect_identical(suppressWarnings(norm_rle(sim_mat)), sim_mat)
testthat::expect_warning(
suppressMessages(norm_rle(sim_mat)),
"norm_rle() is deprecated, returning the original matrix.",
fixed = TRUE
)
testthat::expect_message(
suppressWarnings(norm_rle(sim_mat)),
'scater::normaliseExprs(., "RLE")',
fixed = TRUE
)
})
# norm_cpm_total ----------------------
testthat::test_that('norm_cpm_total()', {
mat_cpm <- norm_cpm_total(sim_mat)
testthat::expect_true(is.matrix(mat_cpm))
testthat::expect_identical(dim(mat_cpm), dim(sim_mat))
})
# norm_cpm_top ----------------------
testthat::test_that('norm_cpm_top()', {
mat_cpm_top <- norm_cpm_top(sim_mat, 20)
testthat::expect_true(is.matrix(mat_cpm_top))
testthat::expect_identical(dim(mat_cpm_top), dim(sim_mat))
})
testthat::test_that('norm_cpm_top() error', {
norm_cpm_top(sim_mat, nrow(sim_mat))
testthat::expect_error(
norm_cpm_top(sim_mat, nrow(sim_mat) + 1),
'too few feature for CPM top n normalization'
)
})
# norm_cpm_rm -----------------
testthat::test_that('norm_cpm_rm()', {
mat_cpm_rm <- norm_cpm_rm(sim_mat, c('miRNA', 'piRNA'))
testthat::expect_true(is.matrix(mat_cpm_rm))
testthat::expect_identical(dim(mat_cpm_rm), dim(sim_mat))
})
testthat::test_that('norm_cpm_rm()', {
norm_cpm_rm(sim_mat, 'lncRNA')
testthat::expect_error(
norm_cpm_rm(sim_mat, 'noRNA'),
'unknown transcript type to remove for CPM normalization'
)
})
# norm_cpm_refer -----------------
testthat::test_that('norm_cpm_refer()', {
mat_cpm_refer <- norm_cpm_refer(sim_mat, suggest_refer$id)
testthat::expect_true(is.matrix(mat_cpm_refer))
testthat::expect_identical(dim(mat_cpm_refer), dim(sim_mat))
})
testthat::test_that('norm_cpm_refer()', {
# test only one reference gene
norm_cpm_refer(sim_mat, rownames(sim_mat)[1])
testthat::expect_error(
norm_cpm_refer(sim_mat, 'non-exist-RNA'),
'can\'t find any reference genes in the matrix for CPM normalization'
)
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.