Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plotStudy and getPlottingData functions accept parameter testID. #4

Merged
merged 7 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions R/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
#' @seealso \code{\link{addPlots}}, \code{\link{getPlottingData}}
#'
#' @export
plotStudy <- function(study, modelID, featureID, plotID, libraries = NULL) {
plotStudy <- function(study, modelID, featureID, plotID, testID = NULL, libraries = NULL) {
stopifnot(
is.character(modelID),
is.character(featureID),
is.character(plotID),
is.null(testID) || is.character(testID),
is.null(libraries) || is.character(libraries)
)

Expand Down Expand Up @@ -49,7 +50,7 @@ plotStudy <- function(study, modelID, featureID, plotID, libraries = NULL) {
)
}

plottingData <- getPlottingData(study, modelID, featureID,
plottingData <- getPlottingData(study, modelID, featureID, testID = testID,
libraries = libraries)

# Setup for the plot and ensure everything is properly reset after the
Expand Down Expand Up @@ -136,13 +137,19 @@ resetSearch <- function(pkgNamespaces) {
#' rows are reordered to match the order of this input (and thus match the order
#' of the assays data frame).}
#'
#' \item{\code{results}}{A data frame that contains the test results,
#' filtered to only include the row(s) corresponding to the input featureID(s).
#' If multiple featureIDs are requested, the rows are reordered to match the
#' order of this input. The column order is unchanged.}
#'
#' @seealso \code{\link{addPlots}}, \code{\link{plotStudy}}
#'
#' @export
getPlottingData <- function(study, modelID, featureID, libraries = NULL) {
getPlottingData <- function(study, modelID, featureID, testID = NULL, libraries = NULL) {
stopifnot(
is.character(modelID),
is.character(featureID),
is.null(testID) || is.character(testID),
is.null(libraries) || is.character(libraries)
)
# Deduplicate the featureIDs
Expand Down Expand Up @@ -186,10 +193,26 @@ getPlottingData <- function(study, modelID, featureID, libraries = NULL) {
row.names(featuresPlotting) <- NULL # reset row numbers after filtering
}

if (!isEmpty(testID)) {
results <- getResults(study, modelID = modelID, testID = testID, quiet = TRUE,
libraries = libraries)
if (isEmpty(results)) {
stop(sprintf("The test result (testID) \"%s\" is not available for modelID \"%s\" ", testID, modelID))
}
featureIDAvailable_results <- featureID %in% results[,1]
if (any(!featureIDAvailable_results)) {
stop(sprintf("The feature \"%s\" is not available for testID \"%s\"",
featureID[!featureIDAvailable][1], testID))
}
resultsPlotting <- results[match(featureID, results[,1], nomatch = 0), , drop = FALSE]
}

plottingData <- list(
assays = assaysPlotting,
samples = samplesPlotting,
features = featuresPlotting
)
if (!isEmpty(testID)) plottingData <- c(plottingData, list(results = resultsPlotting))

return(plottingData)
}
65 changes: 65 additions & 0 deletions inst/tinytest/testPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,71 @@ expect_warning(
info = "Warning when assays has a row that is missing from the features table"
)


# getPlottingData (testID) -----------------------------------------------------

plottingData <- getPlottingData(
testStudyObj,
modelID = testModelName,
featureID = "feature_0001",
testID = "test_01"
)

samples <- getSamples(testStudyObj, modelID = testModelName)
assays <- getAssays(testStudyObj, modelID = testModelName)
results <- getResults(testStudyObj, modelID = testModelName, testID = "test_01")

expect_true_xl(
inherits(plottingData, "list")
)

expect_true_xl(
inherits(plottingData[["assays"]], "data.frame")
)

expect_true_xl(
inherits(plottingData[["samples"]], "data.frame")
)

expect_true_xl(
inherits(plottingData[["features"]], "data.frame")
)

expect_true_xl(
inherits(plottingData[["results"]], "data.frame")
)

plottingData <- getPlottingData(
testStudyName,
modelID = testModelName,
featureID = "feature_0001",
testID = "test_01"
)

samples <- getSamples(testStudyName, modelID = testModelName)
assays <- getAssays(testStudyName, modelID = testModelName)
results <- getResults(testStudyName, modelID = testModelName, testID = "test_01")

expect_true_xl(
inherits(plottingData, "list")
)

expect_true_xl(
inherits(plottingData[["assays"]], "data.frame")
)

expect_true_xl(
inherits(plottingData[["samples"]], "data.frame")
)

expect_true_xl(
inherits(plottingData[["features"]], "data.frame")
)

expect_true_xl(
inherits(plottingData[["results"]], "data.frame")
)

# Teardown ---------------------------------------------------------------------

unloadNamespace(testPkgName)
Expand Down
9 changes: 8 additions & 1 deletion man/getPlottingData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/plotStudy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions vignettes/OmicNavigatorAPI.Rnw
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ toJSON(linkFeatures[1:4], pretty = TRUE)
\label{sec:custom-plots}

Display the custom plots provided by the user with \texttt{plotStudy()}. Provided a
study, model, feature, and plot, \texttt{plotStudy()} generates the custom plot.
study, model, feature, test and plot, \texttt{plotStudy()} generates the custom plot.

The featureID is obtained from the first column returned by
\texttt{getResultsTable()} (Section \ref{sec:results-table}). The remaining arguments
Expand All @@ -222,7 +222,8 @@ plotStudy(
study = "ABC",
modelID = "model_01",
featureID = "feature_0001",
plotID = "plotBase"
plotID = "plotBase",
testID = "test_01"
)
@

Expand All @@ -231,7 +232,8 @@ plotStudy(
study = "ABC",
modelID = "model_03",
featureID = "feature_0001",
plotID = "plotGg"
plotID = "plotGg",
testID = "test_01"
)
@

Expand All @@ -245,7 +247,8 @@ plotStudy(
study = "ABC",
modelID = "model_01",
featureID = c("feature_0001", "feature_0002"),
plotID = "plotMultiFeature"
plotID = "plotMultiFeature",
testID = "test_01"
)
@

Expand Down
4 changes: 4 additions & 0 deletions vignettes/OmicNavigatorUsersGuide.Rnw
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,10 @@ plotStudy(study, modelID = "main", featureID = c("21390", "19216"),
plotID = "plotPca")
@

Optionally, data related to test results can be plotted by providing a valid
testID to the plotStudy call. For instance, for modelID = "main" one could call
plotStudy with testID = "basal.vs.lp" to be able to plot its test results.

To make the custom plotting functions available in the app, re-install the study
package with \texttt{installStudy()}.

Expand Down