Skip to content

Commit

Permalink
ensure that all FRASER1 metrics and jaccard are tested
Browse files Browse the repository at this point in the history
  • Loading branch information
ischeller committed Apr 16, 2024
1 parent 3b6d034 commit 550235a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
6 changes: 5 additions & 1 deletion R/example_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion tests/testthat/test_fraser_pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
})

Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test_getter_setter.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
29 changes: 22 additions & 7 deletions tests/testthat/test_plotSampleResults.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

})

Expand Down

0 comments on commit 550235a

Please sign in to comment.