Skip to content

Commit

Permalink
Fix/Feat: ord_explore checks/warnings about unavailable counts can be…
Browse files Browse the repository at this point in the history
… disabled with counts_warn = FALSE
  • Loading branch information
david-barnett committed Sep 14, 2024
1 parent 8ff04f9 commit 639761d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
27 changes: 18 additions & 9 deletions R/ord_explore.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#' @param notification_durations
#' length 2 list giving duration in seconds of short and long notifications
#' or NULL for notifications that do not disappear automatically
#' @param counts_warn should a warning be issued if accounts are unavailable?
#' @param ... additional arguments passed to ord_plot
#'
#' @return nothing, opens default browser
Expand Down Expand Up @@ -152,14 +153,15 @@ ord_explore <- function(data,
plot_widths = c(7, 9),
modal_fade = TRUE,
notification_durations = list(2, 20),
counts_warn = TRUE,
...) {
# SETUP -------------------------------------------------------------------

# widths of plots including space for legends, in inches
# TODO how to better handle this choice?
p_width <- plot_widths # 1st is ordination, 2nd is composition

init <- ord_explore_init(data)
init <- ord_explore_init(data, counts_warn = counts_warn)

message("To stop the app: Click red stop button or hit Esc in the console")

Expand Down Expand Up @@ -471,7 +473,7 @@ ord_explore <- function(data,
phylos <- shiny::reactiveValues(
ord1 = init$data, # for ord_plot
comps = ps_seriate( # for comp_barplot (samples can be reordered)
ps = ps_counts(init$data, warn = TRUE),
ps = ps_counts(init$data, warn = counts_warn),
method = seriate_method,
tax_transform = shiny::isolate(ord1chosen$trans),
dist = setdiff(
Expand Down Expand Up @@ -850,7 +852,8 @@ ord_explore <- function(data,
data = init$data, rank = input$rank, trans = input$trans,
dist = if (input$dist == "none") NA else input$dist,
method = input$method,
constraints = input$const, conditions = input$conds
constraints = input$const, conditions = input$conds,
counts_warn = counts_warn
)
}
)
Expand Down Expand Up @@ -891,7 +894,7 @@ ord_explore <- function(data,
)
# for comp_barplot (samples can be reordered)
phylos$comps <- ps_seriate(
ps = ps_counts(init$data, warn = TRUE),
ps = ps_counts(init$data, warn = counts_warn),
method = seriate_method, tax_transform = init$info$trans,
# get current distance, if not "none", else use euclidean
dist = setdiff(
Expand Down Expand Up @@ -923,12 +926,16 @@ ord_explore <- function(data,
#'
#' @return a list of lists
#' @noRd
ord_explore_init <- function(data) {
ord_explore_init <- function(data, counts_warn) {
check_is_phyloseq(data, argName = "data")

# if data is plain phyloseq, validate and convert to psExtra
if (!is(data, "psExtra")) {
data <- tax_transform(phyloseq_validate(data), "identity", rank = "unique")
data <- phyloseq_validate(data, min_tax_length = 3)
data <- tax_transform(
data = data, keep_counts = counts_warn,
trans = "identity", rank = "unique"
)
}

# create a SAMPLE id variable
Expand Down Expand Up @@ -1021,10 +1028,12 @@ ord_build <- function(data,
dist = NA,
method = "auto",
constraints = NULL,
conditions = NULL) {
dat <- ps_counts(data, warn = TRUE)
conditions = NULL,
counts_warn = TRUE
) {
dat <- ps_counts(data, warn = counts_warn)
dat <- tax_agg(ps = dat, rank = rank)
dat <- tax_transform(data = dat, trans = trans)
dat <- tax_transform(data = dat, trans = trans, keep_counts = counts_warn)
if (!identical(dist, NA)) {
dat <- dist_calc(data = dat, dist = dist)
}
Expand Down
3 changes: 3 additions & 0 deletions man/ord_explore.Rd

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

0 comments on commit 639761d

Please sign in to comment.