Skip to content

Commit

Permalink
add 'dirty' variable to plate, let user know when they're using a pla…
Browse files Browse the repository at this point in the history
…te with new settings that need to re-run; fixes #6
  • Loading branch information
daattali committed Mar 23, 2016
1 parent d5d31ea commit 625b59d
Show file tree
Hide file tree
Showing 30 changed files with 86 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,6 +1,6 @@
Package: ddpcr
Title: Analysis and Visualization of Droplet Digital PCR in R and on the Web
Version: 1.1.2
Version: 1.2.0
Authors@R: c(
person("Dean", "Attali", email = "daattali@gmail.com", role = c("aut", "cre"))
)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Expand Up @@ -72,6 +72,7 @@ export(get_wells_btwn)
export(has_signif_negative_cluster)
export(has_step)
export(is_dir)
export(is_dirty)
export(is_empty_plate)
export(is_file)
export(is_range)
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
@@ -0,0 +1,7 @@
# shinyjs 1.2.0

2016-03-22

- Added a 'dirty' bit to a plate, to keep track of whether any changes to the settings have been made that require a re-run of the analysis. Both the shiny app and the command line inform the user if they are using a dirty plate object

- A few bug fixes in the shiny app (don't show in Advanced Settings section the settings that are already shown in Basic Settings, don't show Advanced Settings parameters of other plate types)
17 changes: 17 additions & 0 deletions R/plate-attribs.R
Expand Up @@ -270,6 +270,12 @@ params <- function(plate, category, name) {
#' @export
`params<-` <- function(plate, category, name, value) {
stopifnot(plate %>% inherits("ddpcr_plate"))

# If a setting is changed after any analysis steps took place, mark the
# plate as 'dirty'
if (!is_empty_plate(plate) && status(plate) > step(plate, "INITIALIZE")) {
plate[['dirty']] <- TRUE
}

replace <- 'params'
if (!missing(category)) {
Expand Down Expand Up @@ -552,3 +558,14 @@ y_var <- function(plate) {
params(plate, 'GENERAL', 'Y_VAR') <- value
plate
}

#' Is the plate object dirty (ie has changed since the analysis was run)?
#' @param plate A ddPCR plate
#' @return \code{TRUE} if any plate settings have changed that require the plate
#' analysis to re-run; \code{FALSE} otherwise
#' @keywords internal
#' @export
is_dirty <- function(plate) {
stopifnot(plate %>% inherits("ddpcr_plate"))
plate[['dirty']]
}
4 changes: 4 additions & 0 deletions R/plate-print.R
Expand Up @@ -64,4 +64,8 @@ print.ddpcr_plate <- function(x, ...) {
"\n"
)
}

if (is_dirty(x)) {
cat0("\nNote: some settings have changed, please re-run the analysis with `analyze(plate, restart = TRUE)` for changes to take effect")
}
}
2 changes: 2 additions & 0 deletions R/plate-utils.R
Expand Up @@ -14,6 +14,7 @@ empty_plate <- function() {
params = NULL,
clusters = NULL,
steps = NULL,
dirty = NULL,
version = NULL
)
}
Expand Down Expand Up @@ -44,6 +45,7 @@ init_plate <- function(plate) {

status(plate) <- step(plate, 'INITIALIZE')
plate[['version']] <- as.character(utils::packageVersion("ddpcr"))
plate[['dirty']] <- FALSE
step_end()

plate
Expand Down
1 change: 1 addition & 0 deletions R/plate.R
Expand Up @@ -247,6 +247,7 @@ analyze <- function(plate, restart = FALSE) {
if (restart) {
msg("Restarting analysis")
status(plate) <- 0
plate[['dirty']] <- FALSE
}
steps_left <- length(steps(plate)) - status(plate)
plate %<>% next_step(n = steps_left)
Expand Down
5 changes: 2 additions & 3 deletions R/sample_data.R
Expand Up @@ -24,9 +24,8 @@ NULL

#' @rdname sample_data
#' @export
sample_data_dir <- function(size = c("small", "large")) {
size <- match.arg(size)
system.file("sample_data", size, package = "ddpcr")
sample_data_dir <- function() {
system.file("sample_data", "small", package = "ddpcr")
}

#' @rdname sample_data
Expand Down
4 changes: 3 additions & 1 deletion R/save_load.R
Expand Up @@ -34,6 +34,7 @@ save_plate <- function(plate, file) {
params = params(plate),
clusters = clusters(plate),
steps = steps(plate),
dirty = plate[['dirty']],
version = plate[['version']]
)
saveRDS(object = object, file = file)
Expand Down Expand Up @@ -66,11 +67,12 @@ load_plate <- function(file) {
plate_data(plate) <- object[['plate_data']]
plate_meta(plate) <- object[['plate_meta']]
name(plate) <- object[['name']]
status(plate) <- object[['status']]
params(plate) <- object[['params']]
clusters(plate) <- object[['clusters']]
steps(plate) <- object[['steps']]
plate[['dirty']] <- object[['dirty']]
plate[['version']] <- object[['version']]
status(plate) <- object[['status']]
},
error = function(err) {
err_msg(paste("The given file is not a valid ddPCR file",
Expand Down
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -798,7 +798,7 @@ Now we can analyze the plate

#> Classifying droplets...

#> DONE (0 seconds)
#> DONE (1 seconds)

#> Reclassifying droplets... skipped (not enough wells with significant mutant clusters)

Expand Down Expand Up @@ -1044,6 +1044,7 @@ by running `ddpcr:::init_plate`.
#>
#> status(plate) <- step(plate, 'INITIALIZE')
#> plate[['version']] <- as.character(utils::packageVersion("ddpcr"))
#> plate[['dirty']] <- FALSE
#> step_end()
#>
#> plate
Expand Down
Binary file modified inst/sample_data/empty_plate.rds
Binary file not shown.
Binary file modified inst/sample_data/large/large.rds
Binary file not shown.
Binary file modified inst/sample_data/small/analyzed.rds
Binary file not shown.
Binary file modified inst/sample_data/small/analyzed_pnpp.rds
Binary file not shown.
Binary file modified inst/sample_data/small/small.rds
Binary file not shown.
10 changes: 7 additions & 3 deletions inst/shiny/server.R
Expand Up @@ -24,7 +24,11 @@ shinyServer(function(input, output, session) {
# we have a dataset to work with or if we're waiting for dataset to be chosen
output$datasetChosen <- reactive({ FALSE })
outputOptions(output, 'datasetChosen', suspendWhenHidden = FALSE)


observeEvent(dataValues$plate, {
shinyjs::toggle(id = "plateDirty", condition = is_dirty(dataValues$plate))
})

# save button (download dataset) button is clicked
output$saveBtn <- downloadHandler(
filename = function() {
Expand Down Expand Up @@ -78,10 +82,10 @@ shinyServer(function(input, output, session) {
# hide the loading message
hide("loading-content", TRUE, "fade")

# TODO remove this , for testing purposes only
#TODO remove this , for testing purposes only
# dataValues$plate <- new_plate(dir = sample_data_dir(),
# type = plate_types$fam_positive_pnpp)
#
# output$datasetChosen <- reactive({ TRUE })
# output$datasetChosen <- reactive({ TRUE })
# updateTabsetPanel(session, "mainNav", "settingsTab")
})
10 changes: 7 additions & 3 deletions inst/shiny/server/tab-settings.R
Expand Up @@ -128,15 +128,19 @@ observeEvent(input$wellsUsedPlotBrush, {
# check all advanced settings and save them
observeEvent(input$updateAdvancedSettings, {
withBusyIndicator("resetParamsBtn", {

disable("updateAdvancedSettings")
advanced_param_regex <- "^advanced_setting_param_(.*)__(.*)$"
all_params <-
grep(advanced_param_regex, names(input), value = TRUE)
lapply(all_params, function(x) {

if (!is.null(input[[x]]) && !is.na(input[[x]])) {
major_name <- gsub(advanced_param_regex, "\\1", x)
minor_name <- gsub(advanced_param_regex, "\\2", x)
params(dataValues$plate, major_name, minor_name) <- input[[x]]
if (!is.null(params(dataValues$plate, major_name, minor_name))) {
params(dataValues$plate, major_name, minor_name) <- input[[x]]
}
}
})
enable("updateAdvancedSettings")
Expand Down Expand Up @@ -167,12 +171,12 @@ observeEvent(dataValues$plate, {
lapply(
plate %>% params %>% .[[major_name]] %>% names,
function(minor_name) {
param_name <- sprintf("%s", major_name, minor_name)
param_name <- sprintf("%s::%s", major_name, minor_name)

params_ignore <- c(
"GENERAL::X_VAR", "GENERAL::Y_VAR",
"GENERAL::POSITIVE_NAME", "GENERAL::NEGATIVE_NAME",
"CLASSIFY::X_THRESHOLD", "CLASSIFY::Y_THRESHOLD"
"GENERAL::POSITIVE_DIMENSION"
)

if (param_name %in% params_ignore) {
Expand Down
8 changes: 7 additions & 1 deletion inst/shiny/ui/header.R
Expand Up @@ -17,7 +17,13 @@ column(
"droplets"

),
downloadButton('saveBtn', 'Save data', class = "btn-sm")
downloadButton('saveBtn', 'Save data', class = "btn-sm"),
div(
id = "plateDirty",
class = "alert alert-danger",
strong("Note:"),
"Some settings have changed, please re-run the analysis for changes to take effect"
)
)
)
)
4 changes: 4 additions & 0 deletions inst/shiny/www/style.css
Expand Up @@ -17,6 +17,10 @@ body {
color: #FFFFFF;
}

#plateDirty {
margin-top: 12px;
}

.navbar {
margin-bottom: 0;
}
Expand Down
20 changes: 20 additions & 0 deletions man/is_dirty.Rd

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

2 changes: 1 addition & 1 deletion man/sample_data.Rd

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

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vignettes/overview_files/figure-markdown_strict/plotparams-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vignettes/overview_files/figure-markdown_strict/plotparams-2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vignettes/overview_files/figure-markdown_strict/plotraw-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vignettes/overview_files/figure-markdown_strict/plotsimple-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified vignettes/overview_files/figure-markdown_strict/pnppplot-1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 625b59d

Please sign in to comment.