Skip to content

Commit

Permalink
PR addressing Issue #150 (#184)
Browse files Browse the repository at this point in the history
enhance: adds checks to `plotArrow()` to prevent single-omics and P-integrative methods to be visualised

The file allows for testing of the `plotArrow()` function. Two included tests check for general functionality on DIABLO objects as well as inability to function on `(mint).(s)plsda` objects
  • Loading branch information
Max-Bladen authored Dec 13, 2022
1 parent 2213a71 commit e895692
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/plotArrow.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ plotArrow <- function(object,
object.blocks=c("sgcca", "sgccda", "rgcca")

if (! any(class.object %in% c(object.pls,object.blocks)))
stop( " 'plotArrow' is only implemented for the following objects: pls, plsda, spls, splsda, rcc, sgcca, sgccda, rgcca", call.=FALSE)
stop( " 'plotArrow' is only implemented for the following objects: pls, spls, rcc, sgcca, sgccda, rgcca", call.=FALSE)

if ("DA" %in% class.object && !any(object.blocks %in% class.object)) {
stop("'plotArrow' not implemented for (s)PLSDA or MINT sPLSDA", call.=FALSE)
}

ind.names.position <- match.arg(ind.names.position)
is.multiblock <- ifelse(is.list(object$X), TRUE, FALSE)
Expand Down
38 changes: 38 additions & 0 deletions tests/testthat/test-plotArrow.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
test_that("plotArrow does not function on (mint).(s).plsda objects", code = {

data("stemcells")

X <- stemcells$gene
Y <- stemcells$celltype
S <- stemcells$study

optimal.ncomp <- 4
optimal.keepX <- c(24, 45, 20, 30)

splsda.stemcells <- splsda(X = X, Y = Y,
ncomp = optimal.ncomp,
keepX = optimal.keepX)
expect_error(plotArrow(splsda.stemcells), "'plotArrow' not implemented for (s)PLSDA or MINT sPLSDA", fixed = TRUE)
})

test_that("plotArrow functions on DIABLO objects", code = {

data(breast.TCGA)

X <- list(miRNA = breast.TCGA$data.train$mirna,
mRNA = breast.TCGA$data.train$mrna,
proteomics = breast.TCGA$data.train$protein)
Y <- breast.TCGA$data.train$subtype

optimal.ncomp <- 2
optimal.keepX <- list(miRNA = c(10, 5),
mRNA = c(25,16),
proteomics = c(8,5))
tcga.diablo <- block.splsda(X, Y,
ncomp = optimal.ncomp,
keepX = optimal.keepX)

pA_res <- plotArrow(tcga.diablo)

expect_is(pA_res, "ggplot")
})

0 comments on commit e895692

Please sign in to comment.