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

Implemented system to catch unexpected errors #10

Merged
merged 4 commits into from
Dec 11, 2024
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: miaDash
Version: 0.99.4
Version: 0.99.5
Authors@R:
c(person(given = "Giulio", family = "Benedetti", role = c("aut", "cre"),
email = "[email protected]",
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ importFrom(rintrojs,introjs)
importFrom(scater,runMDS)
importFrom(scater,runPCA)
importFrom(shiny,actionButton)
importFrom(shiny,addResourcePath)
importFrom(shiny,checkboxInput)
importFrom(shiny,conditionalPanel)
importFrom(shiny,downloadButton)
Expand Down
6 changes: 5 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ Changes in version 0.99.2
Changes in version 0.99.3
* Added tree import option
* Fixed bugs with RDS and unifrac
* Added clickable title box
* Added clickable title box

Changes in version 0.99.5
* Implemented error check system
* Added mia logo
12 changes: 8 additions & 4 deletions R/miaDash.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@
#' @export
#' @rdname miaDash
#' @importFrom iSEE iSEE
#' @importFrom shiny addResourcePath
#' @importFrom utils packageVersion
#' @importFrom htmltools tags
miaDash <- function() {


addResourcePath("assets", system.file("assets", package = "miaDash"))

iSEE(
landingPage = .landing_page,
appTitle = tags$div(
paste0("Microbiome Analysis Dashboard - v", packageVersion("miaDash")),
tags$img(src = "assets/mia_logo.png", height = "40px", style = "margin-left: 10px"),
style = "cursor: pointer; font-weight: 500",
onclick = "window.location='https://miadash-microbiome.2.rahtiapp.fi/'",
paste0("Microbiome Analysis Dashboard - v",
packageVersion("miaDash"), " \U0001f9a0"))
onclick = "window.location='https://miadash-microbiome.2.rahtiapp.fi/'")

)

}
Expand Down
36 changes: 23 additions & 13 deletions R/observers.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@
fun_args <- list(assays = assay_list, colData = coldata,
rowData = rowdata, rowTree = row.tree, colTree = col.tree)

rObjects$tse <- .update_tse(TreeSummarizedExperiment, fun_args)
rObjects$tse <- .update_tse(
rObjects$tse, TreeSummarizedExperiment, fun_args
)

})

}else if( input$format == "foreign" ){
Expand All @@ -72,14 +75,16 @@
req(input$main.file)

if( input$ftype == "biom" ){

biom_object <- read_biom(input$main.file$datapath)

fun_args <- list(x = biom_object,
removeTaxaPrefixes = input$rm.tax.pref,
rankFromPrefix = input$rank.from.pref)

rObjects$tse <- .update_tse(convertFromBIOM, fun_args)

rObjects$tse <- .update_tse(
rObjects$tse, convertFromBIOM, fun_args
)

} else if( input$ftype == "MetaPhlAn" ){

Expand All @@ -91,7 +96,9 @@
fun_args <- list(file = input$main.file$datapath,
col.data = coldata, tree.file = treefile)

rObjects$tse <- .update_tse(importMetaPhlAn, fun_args)
rObjects$tse <- .update_tse(
rObjects$tse, importMetaPhlAn, fun_args
)

}

Expand Down Expand Up @@ -129,7 +136,7 @@
fun_args <- list(x = rObjects$tse, assay.type = input$subassay,
prevalence = input$prevalence, detection = input$detection)

rObjects$tse <- .update_tse(subset_fun, fun_args)
rObjects$tse <- .update_tse(rObjects$tse, subset_fun, fun_args)

})

Expand All @@ -140,7 +147,9 @@
isolate({

fun_args <- list(x = rObjects$tse, rank = input$taxrank)
rObjects$tse <- .update_tse(agglomerateByRank, fun_args)
rObjects$tse <- .update_tse(
rObjects$tse, agglomerateByRank, fun_args
)

})

Expand Down Expand Up @@ -170,7 +179,9 @@
method = input$trans.method, assay.type = input$assay.type,
MARGIN = input$margin, pseudocount = input$pseudocount)

rObjects$tse <- .update_tse(transformAssay, fun_args)
rObjects$tse <- .update_tse(
rObjects$tse, transformAssay, fun_args
)

})

Expand Down Expand Up @@ -213,7 +224,7 @@
fun_args <- list(x = rObjects$tse, name = name,
assay.type = input$estimate.assay, index = input$alpha.index)

rObjects$tse <- .update_tse(addAlpha, fun_args)
rObjects$tse <- .update_tse(rObjects$tse, addAlpha, fun_args)

})

Expand Down Expand Up @@ -274,11 +285,10 @@
formula = as.formula(input$rda.formula))

}
print(beta_args)

beta_fun <- eval(parse(text = paste0("run", input$bmethod)))
print(beta_fun)
rObjects$tse <- .update_tse(beta_fun, beta_args)


rObjects$tse <- .update_tse(rObjects$tse, beta_fun, beta_args)
})

}
Expand Down
33 changes: 17 additions & 16 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,25 @@

#' @rdname utils
#' @importFrom shiny showNotification
.update_tse <- function(fun, fun_args) {

messages <- c()

withCallingHandlers({

tse <- do.call(fun, fun_args)
.update_tse <- function(tse, fun, fun_args) {

tse <- tryCatch({withCallingHandlers({

do.call(fun, fun_args)

}, message = function(m) {
# nocov start
}, message = function(m) {

showNotification(conditionMessage(m))
invokeRestart("muffleMessage")

})}, error = function(e) {

messages <<- c(messages, conditionMessage(m))
invokeRestart("muffleMessage")

})

# nocov start
lapply(messages, showNotification)
# nocov end
.print_message(e, title = "Unexpected error:")
return(tse)

})
# nocov end

return(tse)
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# miaDash
# miaDash <img src="inst/assets/mia_logo.png" align="right" width="120" />

[![issues](https://img.shields.io/github/issues/microbiome/miaDash)](https://github.com/microbiome/miaDash/issues)
[![pulls](https://img.shields.io/github/issues-pr/microbiome/miaDash)](https://github.com/microbiome/miaDash/pulls)
Expand Down
Binary file added inst/assets/mia_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion man/utils.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ test_that("utils", {
data(package = "mia")$results[idx, "Item"])

expect_no_error(
tse <- .update_tse(transformAssay, list(x = tse, assay.type = "counts",
method = "relabundance"))
tse <- .update_tse(tse, transformAssay,
list(x = tse, assay.type = "counts", method = "relabundance"))
)

item <- NULL
Expand Down
Loading