Skip to content
Snippets Groups Projects
Unverified Commit ad9fc7bc authored by Todor Kondic's avatar Todor Kondic
Browse files

mix,resources,app: Drop config save/restore; replace with state

parent 5ada5694
No related branches found
No related tags found
No related merge requests found
......@@ -34,5 +34,6 @@ export(save_plots)
export(setup_phase)
export(sort_spectra)
export(subset_summary)
export(tk_save_file)
import(data.table)
importFrom(shiny,validate)
......@@ -701,6 +701,7 @@ read_setid <- function(fn,cmpds) {
write_conf <- function(m,fn) {
m$conf$data <- get_fn_ftab(m)
if (NROW(m$input$tab$mzml)>0) tab2file(tab=m$input$tab$mzml,file=file.path(m$conf$project,FN_DATA_TAB))
yaml::write_yaml(x=m$conf,file=fn)
......@@ -1252,3 +1253,21 @@ plot_leg_ms2 <- function(df,style_fun) {
cowplot::get_legend(plot)
}
#' @export
tk_save_file <- function (default = "", caption = "Select files", filters = NULL, index = 1) {
args <- list("tk_getSaveFile", title = caption)
if (nzchar(default))
args <- c(args, initialdir = dirname(default), initialfile = basename(default))
if (!is.null(filters)) {
if (!is.character(filters) || length(dim(filters)) !=
2 || ncol(filters) != 2)
stop("'filters' must be a 2-column character matrix")
f <- filters
f[] <- paste0("{", filters, "}")
ff <- apply(f, 1, paste, collapse = " ")
fff <- paste0("{", ff, "}")
args <- c(args, filetypes = paste(fff, collapse = " "))
}
as.character(do.call(tcltk::tcl, args))
}
......@@ -198,8 +198,7 @@ REPORT_TITLE <- "Plots of EICs and MS2 Spectra"
PLOT_FEATURES <- c("set",
"adduct",
"tag",
"ID",
"CE")
"ID")
## Select the most fundamental group of entries. Within this group,
## each ID is unique.
......
......@@ -348,6 +348,44 @@ shinyscreen::rt_input(input_rt = "plot_rt_max",
pref = "max:")
```
### Grouping plots
<details><summary>How to group plots?</summary>
The _Select plot group_ and _Select plot label_ controls control how
the data is visually grouped together. The _plot group_ groups
together multiple curves in a single graph. Each curve in a graph is
designated by the _plot label_.
</details>
<div style= "display: flex; vertical-align:top; ">
<div style="padding-right:0.5em;">
```{r, echo=F}
p_feats <- 1:length(shinyscreen:::PLOT_FEATURES)
names(p_feats) <- shinyscreen:::PLOT_FEATURES
selectInput(inputId = "plot_grp_plot",
label = "Select plot group",
choices = p_feats,
selected = p_feats[[shinyscreen:::FIG_DEF_CONF$grouping[["plot"]]]],
width = "100%")
```
</div>
<div style="padding-left:0.5em;">
```{r, echo=F}
p_feats <- 1:length(shinyscreen:::PLOT_FEATURES)
names(p_feats) <- shinyscreen:::PLOT_FEATURES
selectInput(inputId = "plot_label",
label = "Select plot label",
choices = p_feats,
selected = p_feats[[shinyscreen:::FIG_DEF_CONF$grouping[["label"]]]],
width = "100%")
```
</div>
</div>
## Report
```{r, echo=F}
......@@ -370,33 +408,19 @@ DT::dataTableOutput("setid_table")
# Save and Restore
## Save and Restore from a Config File
Shinyscreen uses _YAML_ config files to initialise the
computation. These operations only save and restore the input
parameters of your computation, _**not**_ your data.
```{r, echo=FALSE}
actionButton(inputId = "conf_file_load_b",
label= "Load project config")
```
Shinyscreen can start from either a previously saved _state_ file (in
RDS format), or from a _YAML_ config file. States saved using GUI can
also be used from the script.
```{r, echo=FALSE}
actionButton(inputId = "conf_file_save_b",
label= "Save config")
actionButton(inputId = "state_file_load_b",
label= "Restore project state")
```
## Restore the project
To retrieve a previously extracted data, restore the project state
here. It is also possible to load it in a script (the state is saved
in the _RDS_ format).
```{r, echo=FALSE}
actionButton(inputId = "state_file_load_b",
label= "Restore project state")
actionButton(inputId = "state_file_save_b",
label= "Save project state")
```
......@@ -505,8 +529,6 @@ ord_asc <- grepl("^-.+",shinyscreen:::DEF_INDEX_SUMM)
ord_asc <- factor(ifelse(ord_asc, "descending", "ascending"),levels = c("ascending","descending"))
def_ord_summ <- shinyscreen:::dtable("Column Name"=ord_nms,"Direction"=ord_asc)
update_gui <- function(in_conf, session) {
upd_unit <- function(entry,inp_val,inp_unit,choices) {
if (isTruthy(entry)) {
......@@ -584,7 +606,7 @@ update_gui <- function(in_conf, session) {
## Files
df <- shinyscreen:::file2tab(in_conf$data)
df[,tag:=as.character(tag),with=T]
rv_dfiles(df[,.(File=Files,tag)])
rv_dfiles(df[,.(File=Files,tag),by=c("Files","tag"),mult="first"])
nms <- colnames(df)
nms <- nms[nms!="Files"]
fdt <- df[,..nms]
......@@ -791,7 +813,8 @@ observe({
observe({
dtab <- rv_datatab()
dfiles <- rv_dfiles()
print(dtab)
print(dfiles)
message("(config) Generating mzml from rv.")
isolate(rv_state$input$tab$mzml <- dtab[dfiles,on="tag"])
......@@ -872,56 +895,52 @@ observeEvent(input$plot_b,{
eval(z)
})
observeEvent(input$conf_file_save_b,
{
state <- rf_conf_state()
ftab <- get_fn_ftab(state)
fconf <- get_fn_conf(state)
yaml::write_yaml(state$conf,
file = fconf)
shinyscreen:::tab2file(tab=state$input$tab$mzml,file=ftab)
message("Written data-file table to ",ftab)
message("Written config to ",fconf)
})
observeEvent(input$conf_file_load_b,
{
filters <- matrix(c("YAML files", ".yaml",
observeEvent(input$state_file_load_b,{
filters <- matrix(c("RDS files", ".rds",
"YAML config files", ".yaml",
"All files", "*"),
2, 2, byrow = TRUE)
3, 2, byrow = TRUE)
fn <- tcltk::tk_choose.files(filters=filters,
multi = F)
message("(config) Loading config from: ", paste(fn,collapse = ","))
message("(config) Loading state from: ", paste(fn,collapse = ","))
fn <- if (length(fn)>0 && nchar(fn[[1]])>0) fn else ""
if (nchar(fn) > 0) {
state <- new_state_fn_conf(fn)
conf <- state$conf
update_gui(conf,session=session)
}
if (grepl("yaml",fn)) {
state <- new_state_fn_conf(fn)
conf <- state$conf
update_gui(conf,session=session)
} else {
state <- readRDS(file=fn)
z <- shinyscreen::merge2rev(rv_state,lst = state)
eval(z)
update_gui(rv_state$conf, session=session)
}
}
})
observeEvent(input$state_file_load_b,{
observeEvent(input$state_file_save_b,{
filters <- matrix(c("RDS files", ".rds",
"All files", "*"),
2, 2, byrow = TRUE)
fn <- tcltk::tk_choose.files(filters=filters,
multi = F)
message("(config) Loading state from: ", paste(fn,collapse = ","))
fn <- tk_save_file(filters=filters,
default = "state.rds")
message("(config) Saving state to: ", paste(fn,collapse = ","))
fn <- if (length(fn)>0 && nchar(fn[[1]])>0) fn else ""
if (nchar(fn) > 0) {
state <- readRDS(file=fn)
z <- shinyscreen::merge2rev(rv_state,lst = state)
print(z)
eval(z)
update_gui(rv_state$conf, session=session)
m <- rev2list(rv_state)
ftab <- get_fn_ftab(m)
fconf <- get_fn_conf(m)
yaml::write_yaml(m$conf,
file = fconf)
shinyscreen:::tab2file(tab=m$input$tab$mzml,file=ftab)
m$conf$data <- ftab
saveRDS(object=m,file=fn)
}
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment