From 550235a0edabf39a2d852a3d330fcad7147eaa88 Mon Sep 17 00:00:00 2001 From: Ines Scheller Date: Tue, 16 Apr 2024 10:23:22 +0200 Subject: [PATCH] ensure that all FRASER1 metrics and jaccard are tested --- R/example_functions.R | 6 ++++- tests/testthat/helper.R | 2 +- tests/testthat/test_fraser_pipeline.R | 2 +- tests/testthat/test_getter_setter.R | 3 +++ tests/testthat/test_plotSampleResults.R | 29 +++++++++++++++++++------ 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/R/example_functions.R b/R/example_functions.R index c4b992be..fb55e9f6 100644 --- a/R/example_functions.R +++ b/R/example_functions.R @@ -54,7 +54,10 @@ createTestFraserSettings <- function(workingDir="FRASER_output"){ #' @rdname createTestFraserDataSet #' @export -createTestFraserDataSet <- function(workingDir="FRASER_output", rerun=FALSE){ +createTestFraserDataSet <- function(workingDir="FRASER_output", rerun=FALSE, + metrics="jaccard"){ + metrics <- match.arg(metrics, several.ok=TRUE, + choices=c("jaccard", "psi5", "psi3", "theta")) # check if file exists already hdf5Files <- file.path(workingDir, "savedObjects", "Data_Analysis", "fds-object.RDS") @@ -84,6 +87,7 @@ createTestFraserDataSet <- function(workingDir="FRASER_output", rerun=FALSE){ suppressMessages({ fds <- annotateRangesWithTxDb(fds) }) # run FRASER pipeline + fitMetrics(fds) <- metrics fds <- FRASER(fds, q=c(jaccard=2, psi5=2, psi3=2, theta=2), iterations=2) # save data for later diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 4ccc7d52..6a8d56a9 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -2,6 +2,6 @@ # helper scripts for the testing step # getFraser <- function(clean=FALSE){ - fds <- createTestFraserDataSet(rerun=clean) + fds <- createTestFraserDataSet(rerun=clean, metrics=psiTypes) fds } diff --git a/tests/testthat/test_fraser_pipeline.R b/tests/testthat/test_fraser_pipeline.R index 45c9b2ff..067407e2 100644 --- a/tests/testthat/test_fraser_pipeline.R +++ b/tests/testthat/test_fraser_pipeline.R @@ -5,7 +5,7 @@ test_that("FRASER function", { expect_is(fds, "FraserDataSet") anames <- c(psiTypes, paste0(c("delta", "predictedMeans", "pvaluesBetaBinomial", "padjBetaBinomial"), "_", - rep(fitMetrics(fds), 5))) + rep(psiTypes, 5))) expect_equal(anames %in% assayNames(fds), !logical(length(anames))) }) diff --git a/tests/testthat/test_getter_setter.R b/tests/testthat/test_getter_setter.R index 36304edd..3dbddf79 100644 --- a/tests/testthat/test_getter_setter.R +++ b/tests/testthat/test_getter_setter.R @@ -5,12 +5,15 @@ test_that("counts", { expect_equal(counts(fds, type="psi5"), K(fds, "psi5")) expect_equal(counts(fds, type="psi3"), K(fds, "psi3")) expect_equal(counts(fds, type="theta"), K(fds, "theta")) + expect_equal(counts(fds, type="jaccard"), K(fds, "jaccard")) expect_equal(counts(fds, type="psi5", side='other'), N(fds, "psi5") - K(fds, "psi5")) expect_equal(counts(fds, type="psi3", side='other'), N(fds, "psi3") - K(fds, "psi3")) expect_equal(counts(fds, type="theta", side='other'), N(fds, "theta") - K(fds, "theta")) + expect_equal(counts(fds, type="jaccard", side='other'), + N(fds, "jaccard") - K(fds, "jaccard")) }) test_that("generic functions", { diff --git a/tests/testthat/test_plotSampleResults.R b/tests/testthat/test_plotSampleResults.R index e259d13e..3da8eda4 100644 --- a/tests/testthat/test_plotSampleResults.R +++ b/tests/testthat/test_plotSampleResults.R @@ -7,18 +7,33 @@ test_that("Results function", { # intron-level results res <- results(fds, aggregate=FALSE, all=TRUE) - expect_equal(length(res), prod(dim(fds))) + res <- as.data.table(res) + for(psiType in psiTypes){ + expect_equal(res[type == psiType, .N], + prod(dim(pVals(fds, level="junction", type=psiType)))) + } res_signif <- results(fds, aggregate=FALSE, all=FALSE, - padjCutoff=NA, deltaPsiCutoff=0.2) - expect_equal(length(res_signif), 1) + padjCutoff=NA, deltaPsiCutoff=0.01) + res_signif <- as.data.table(res_signif) + expect_equal(res_signif[type == "jaccard", .N], 1) + expect_equal(res_signif[type == "psi5", .N], 8) + expect_equal(res_signif[type == "psi3", .N], 3) + expect_equal(res_signif[type == "theta", .N], 6) # gene-level results res_gene <- results(fds, aggregate=TRUE, all=TRUE) - expect_equal(length(res_gene), - prod(dim(pVals(fds, level="gene", type="jaccard")))) + res_gene <- as.data.table(res_gene) + for(psiType in psiTypes){ + expect_equal(res_gene[type == psiType, .N], + prod(dim(pVals(fds, level="gene", type=psiType)))) + } res_gene_signif <- results(fds, aggregate=TRUE, all=FALSE, - padjCutoff=NA, deltaPsiCutoff=0.2) - expect_equal(length(res_gene_signif), 1) + padjCutoff=NA, deltaPsiCutoff=0.01) + res_gene_signif <- as.data.table(res_gene_signif) + expect_equal(res_gene_signif[type == "jaccard", .N], 1) + expect_equal(res_gene_signif[type == "psi5", .N], 4) + expect_equal(res_gene_signif[type == "psi3", .N], 2) + expect_equal(res_gene_signif[type == "theta", .N], 3) })