Newer
Older
browseFile <- function(title,
buttonName,
txtName,
txtTxt="",
icon="file",
confImport <- shinydashboard::box(title="Import",
shiny::h5("There are two tables that need to be supplied before prescreening starts. One is the compound list, its format being the same like the one for the RMassBank (fields: ID,Name,SMILES,RT,CAS,mz,Level). Another is the compound set table (fields: ID,set). Once those tables are imported, they can further be modified as copies inside the project dir. Shinyscreen will never modify any initial (meta)data. If set field of the compound set table is NA, then that file is in a set of its own. The table format should be CSV with `,' as delimiter and any strings that possibly contain commas should be protected. LibreOffice Calc is helpful when it is needed to convert CSVs from one format to another, as well as protecting strings with quotes. "),
"Compound set table.",
value=""),
shiny::textInput("impGenRMBInp",
"RMassBank settings.",
shinyFiles::shinyFilesButton("impCmpListB",
label="Import compound list.",
title="",
icon=shiny::icon("file"),
shinyFiles::shinyFilesButton("impSetIdB",
label="Import compound set table.",
title="",
icon=shiny::icon("file"),
multiple=T),
shinyFiles::shinyFilesButton("impGenRMBB",
label="Import RMassBank settings.",
title="",
icon=shiny::icon("file"),
multiple=F),
width=NULL)
confmzMLTags <- shinydashboard::box(title="Sets and Tags",
shiny::h5("Shinyscreen uses two properties, tags and sets, to categorise mzML data. Tags are properties of individual files. For example, if a single file represents a collection of spectra acquired at a specific collision energy, that energy could be used as a tag. Tags are used to differentiate the spectra in a chromatogram. Sets are collections of tagged files and are read from the compound set table. Each set is going to be screened for a designated collection of masses."),
shiny::textInput("tagPropInp",
"What is a tag? (example: collision energy; can be left empty.)",
value=""),
shiny::textInput("tagsInp",
"Comma-delimited list of tag types",
value=""),
width=NULL)
confState <- shinydashboard::box(title="Configuration state",
shiny::h5("Saves and restores current configuration."),
shinyFiles::shinySaveButton("saveConfB",
"Save configuration",
title="Save",
filename = "conf-state.rds",
"rds"),
shinyFiles::shinyFilesButton("restoreConfB",
label="Restore configuration",
multiple=F,
title="Restore"),
confPP<-shinydashboard::box(title="Preprocessing settings",
shiny::textInput("confFileTabBase",
"Basic file table.",
value=FN_FTAB_BASE),
shiny::textInput("confFileTabProcInp",
"Preprocessed file table.",
value=FN_FTAB_PP),
shiny::textInput("confResFileTab",
"Resulting file table.",
value=FN_FTAB),
width=NULL)
confmzMLtab <-shinydashboard::box(title="mzML file table",
shiny::h5("Use this file table to assign adduct modes and tags to the data files."),
shinyFiles::shinyFilesButton("mzMLB",
label="Select mzML files",
title="Select mzML files",
shiny::actionButton("mzMLtabSubm",
label="Submit mzML list.",
icon=shiny::icon("check")),
rhandsontable::rHandsontableOutput("mzMLtabCtrl"),
width=NULL)
confLayout <- shiny::fluidRow(shiny::column(confImport,
confState,
width=4),
shiny::column(width=8,
confTab <- shinydashboard::tabItem(tabName="config",
confLayout)
## ***** Compound List Tab *****
cmpListBox<-shinydashboard::box(title="Compound list",
rhandsontable::rHandsontableOutput("cmpListCtrl"),
width=NULL)
cmpListLayout <- shiny::fluidRow(shiny::column(cmpListBox,
cmpListTab <- shinydashboard::tabItem(tabName="compList",
shiny::h5("This is an editable view of the compound list."),
## ***** Sets of compounds *****
setIdBox<-shinydashboard::box(title="Compound sets",
setIdLayout<-shiny::fluidRow(shiny::column(setIdBox,
width = 12))
setIdTab<-shinydashboard::tabItem(tabName="setId",
shiny::h5("This is an editable view of the id/set list."),
setIdLayout)
genBoxParam1<-shinydashboard::box(title="Parameters of the run",
shiny::textInput("genNoProc",
label="Number of processes.",
value=1),
shiny::textInput("ppmLimFine",
label="ppm limit fine",
value=10),
shiny::textInput("eicLim",
label="EIC limit.",
value=1e-3),
shiny::textInput("intTresh",
label="Intensity threshold.",
value=1e5),
shiny::textInput("noiseFac",
label="Signal-to-noise ratio.",
value=3),
shiny::textInput("rtDelta",
label="Retention time Δ",
value=0.5),
width=NULL)
genBoxParam2<-shinydashboard::box(title=NULL,
shiny::selectInput("genSetSelInp",
label="Select set(s).",
choices="",
multiple=T),
shiny::actionButton(inputId="genRunB",
label="Run!",
icon=shiny::icon("bomb")),
width=NULL)
genBoxProcessed<-shinydashboard::box(title="Processed sets",
shiny::actionButton(inputId="genFileTabB",
label="Generate file table.",
icon=shiny::icon("save")),
shiny::actionButton(inputId="genRunPPB",
label="Preprocess!",
icon=shiny::icon("bomb")),
rhandsontable::rHandsontableOutput("genTabProcCtrl"),
width=NULL)
genTab<-shinydashboard::tabItem(tabName = "gen",
shiny::h5("Prepare for prescreening."),
shiny::fluidRow(shiny::column(genBoxProcessed,
shiny::fluidRow(shiny::column(genBoxParam1,width=4)),
shiny::fluidRow(shiny::column(genBoxParam2,width=4)))
## ***** Prescreening *****
preshead <- shinydashboard::dashboardHeader(title = "Prescreening")
presCompInfo <- shiny::fluidRow(shinydashboard::box(title = "MS Prescreening",
width = 7,
height = "80px",
background = "blue",
""),
shinydashboard::box(title = "Compound ID N°",
width = 5,
height = "80px",
background = "olive",
shiny::textOutput("compoundID")))
presPlotBox <- shinydashboard::box(title = "Plot",
width = 7,color = "olive",
solidHeader = FALSE,
collapsible = TRUE,
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
width = "100%",
height = "750px",
click = NULL,
dblclick = NULL,
hover = NULL,
hoverDelay = NULL,
hoverDelayType = NULL,
brush = NULL,
clickId = NULL,
hoverId = NULL),
shiny::textInput("plotname",
"Insert plot name: (e.g. plotname_%i.pdf)",
value="plotCpdID_%i.pdf"),
shiny::actionButton("saveplot",
"Save",
icon = shiny::icon("save")),
shiny::actionButton("saveallplots",
"Save All Plots",
icon = shiny::icon("save")))
presCompSelBox <- shinydashboard::box(title = "Compounds",
width=5,
solidHeader = FALSE,
color = "olive",
collapsible = TRUE,
"",
shiny::br(),
shiny::selectInput("presSelSet",
"Set",
choices="",
multiple=F),
shiny::actionButton("presPrev",
"Previous compound.",
icon = shiny::icon("backward")),
shiny::actionButton("presNext",
"Next compound.",
icon = shiny::icon("forward")),
shiny::selectInput("presSelCmpd",
"Compound",
choices="",
multiple=F))
nvPanel<-shiny::uiOutput("nvPanel")
presQABox <- shinydashboard::box(title = "Prescreening analysis",
width = 5,
solidHeader = FALSE,
collapsible = TRUE,
nvPanel,
shiny::actionButton("submitQA",
"Submit",
icon = shiny::icon("save")),
shiny::textInput("fn_ftable",
"File table Name",
value=FN_FTAB),
shiny::actionButton("savefiletable",
"Save File Table",
icon = shiny::icon("save")))
presPlotParBox <- shinydashboard::box(title = "Plot Parameters",
width=7,
solidHeader = FALSE,
collapsible = TRUE,
"",
shiny::br(),
shiny::numericInput("min_val",
"Minimum x Axis Value",
DEFAULT_RT_RANGE[[1]]),
shiny::numericInput("max_val",
"Maximum x Axis Value",
DEFAULT_RT_RANGE[[2]]),
shiny::radioButtons("yaxis",
"Parameters for y Axis",
c(linear = "linear",
log = "log")),
shiny::numericInput("nice",
"Nice",
DEFAULT_RT_RANGE[[1]]),
shiny::numericInput("steps",
"Steps",
DEFAULT_RT_RANGE[[2]]))
presPlotWidget <- shiny::fluidRow(presPlotBox,
presCompSelBox,
presQABox,
presPlotParBox)
presTab <- shinydashboard::tabItem(tabName = "prescreen",
shiny::h2("Prescreening"),
presCompInfo,
presPlotWidget)
headerText <- "Shinyscreen"
confSideItem <- shinydashboard::menuItem(text="Config",
tabName="config",
compListSideItem <- shinydashboard::menuItem(text="Compound list",
tabName="compList",
setIdSideItem <- shinydashboard::menuItem(text="Compound sets",
tabName="setId",
icon=shiny::icon("table"))
genSideItem <- shinydashboard::menuItem(text="Generate prescreen data",
tabName="gen",
icon=shiny::icon("cogs"))
presSideItem <- shinydashboard::menuItem(text="Prescreening",
tabName="prescreen",
header <- shinydashboard::dashboardHeader(title=headerText)
sidebar <- shinydashboard::dashboardSidebar(shinydashboard::sidebarMenu(confSideItem,
compListSideItem,
body <- shinydashboard::dashboardBody(shinydashboard::tabItems(confTab,
shinydashboard::dashboardPage(header,
sidebar,
body)}
##' @export
shinyScreenApp <- function(projDir=getwd()) {
modeLvl<- c("pH","pNa","pM",
"mH","mFA")
mk_mzMLtab<-function() {
modeLvl<- c("pH","pNa","pM",
"mH","mFA")
res<-data.frame(Files=character(),
mode=factor(levels=modeLvl),
stringsAsFactors=F)
res
}
mk_cmpList<-function() {
data.frame(ID=integer(),
Name=character(),
SMILES=character(),
RT=double(),
CAS=character(),
stringsAsFactors = F)
}
mk_setId<-function() {
data.frame(ID=integer(),
set=character())}
modeLvl<- c("select","pH","pNa","pM",
"mH","mFA")
lSet<-levels(ft$set)
lTag<-levels(ft$tag)
newRow<-data.frame(Files=fn,
mode=factor(modeLvl[[1]],levels=modeLvl),
set=if (length(lSet) > 0) factor(lSet[[1]],levels=lSet) else factor("unspecified"),
tag=if (length(lTag) > 0) factor(lTag[[1]],levels=lTag) else factor("unspecified"),
stringsAsFactors = F)
levels(newRow$mode)<-modeLvl
res<-rbind(ft,newRow,
stringsAsFactors = F,
make.row.names = F)
levels(res$mode)<-modeLvl
readSetId<-function(fn) {
read.csv(file=fn,
header=T,
stringsAsFactors = T,
comment.char = '',
na.strings = c("","NA"))
}
getMz<-function(ids,cmpdL) {
mz<-sapply(ids,function(i) {mzs<-cmpdL$mz[cmpdL$ID==i]
if (length(mzs)>1) mzs[[1]] else mzs
})
names(mz)<-NULL
mz
}
mkCmpdDrop<-function(ids,cmpdL) {
cmpdL$ID<-as.numeric(cmpdL$ID)
mz<-getMz(ids,cmpdL)
entries<-base::Map(function(i,m) paste(i,'; ','mz: ',m,sep=''),ids,mz)
entries
}
queryFileTable <- function(df,set,id) {
df[(df$ID %in% id) & (df$set %in% set),]
}
updateFileTable <- function(df,set,id,linput) {
for (tag in names(linput)) {
entries <- names(linput[[tag]])
cond <- (df$ID %in% id) & (df$tag == tag) & (df$set %in% set)
df[cond,entries] <- linput[[tag]]
}
df
}
getCheckboxValues <- function(tag,input,rv) {
chkbox <- input[[rv$spectProps[[tag]]]]
q <- sapply(QANAMES,function (qn) if (qn %in% chkbox) T else F)
names(q) <- QANAMES
q
}
server <- function(input,output,session) {
rvConf <- shiny::reactiveValues(mzMLtab=mk_mzMLtab(),
tags=list(),
sets=list(),
tagProp="",
setProp="",
projDir=projDir,
currSet=NA,
rvCmpList<- shiny::reactiveValues(df=mk_cmpList())
rvSetId<- shiny::reactiveValues(df=mk_setId())
rvPres<-shiny::reactiveValues(cex=CEX,
rt_digits=RT_DIGITS,
m_digits=M_DIGITS,
pal=PAL,
plot_id=NULL)
## ***** shinyFiles observers *****
wdroot<-c(wd=projDir)
shinyFiles::shinyFileChoose(input, 'impCmpListB',roots=volumes)
shinyFiles::shinyFileChoose(input, 'impSetIdB',roots=volumes)
shinyFiles::shinyFileChoose(input, 'impGenRMBB',roots=volumes)
shinyFiles::shinyFileSave(input, 'saveConfB',roots=wdroot)
shinyFiles::shinyFileChoose(input, 'restoreConfB',roots=wdroot)
shinyFiles::shinyFileChoose(input, 'mzMLB',roots=volumes)
## ***** reactive function definitions *****
getTags<-shiny::reactive({
if (length(input$tagsInp)>0 && !is.na(input$tagsInp)) unlist(strsplit(input$tagsInp, ",")) else list()
})
getSets<-shiny::reactive({
rvCmpList$df #rhandsontable::hot_to_r(input$cmpListCtrl)
})
getSetId<-shiny::reactive({
rvSetId$df #rhandsontable::hot_to_r(input$setIdTabCtrl)
update_tags_mzMLtab<-shiny::reactive({
tags<-getTags()
tagCol<-rvConf$mzMLtab$tag
if (length(levels(tagCol))==0) rvConf$mzMLtab$tag<-factor(tagCol)
rvConf$mzMLtab$tag<-factor(tagCol,levels=tags)
update_sets_mzMLtab<-shiny::reactive({
sets<-getSets()
setCol<-rvConf$mzMLtab$set
if (length(levels(setCol))==0) rvConf$mzMLtab$set<-factor(setCol)
rvConf$mzMLtab$set<-factor(setCol,levels=sets)
fn<-shinyFiles::parseSavePath(root=c(wd=rvConf$projDir),input$saveConfB)[["datapath"]]
sav<-list()
sav<-list(rvConf=list(),
input=list())
shiny::isolate(for (nm in names(rvConf)) {
sav$rvConf[[nm]]<-rvConf[[nm]]
})
sav$input$tagsInp<-input$tagsInp
sav$input$setsInp<-input$setsInp
sav$input$impCmpListInp<-input$impCmpListInp
sav$input$impSetIdInp<-input$impSetIdInp
sav$input$impGenRMBInp<-input$impGenRMBInp
saveRDS(object=sav,file=fn)
}
})
restoreConf<-reactive({
input$restoreConfB
fnobj<-shinyFiles::parseFilePaths(root=c(wd=rvConf$projDir),input$restoreConfB)
fn<-fnobj[["datapath"]]
if (length(fn)>0 && !is.na(fn) && nchar(fn)>0) {
sav<-readRDS(fn)
## shiny::isolate({
## sav<-readRDS(fn)
## for (nm in names(sav$rvConf)) {
## rvConf[[nm]]<-sav$rvConf[[nm]]
## }
shiny::updateTextInput(session=session,
inputId="impGenRMBInp",
value=sav$input$impGenRMBInp)
shiny::updateTextInput(session=session,
inputId="impCmpListInp",
value=sav$input$impCmpListInp)
shiny::updateTextInput(session=session,
inputId="impSetIdInp",
value=sav$input$impSetIdInp)
shiny::updateTextInput(session=session,
inputId="tagsInp",
value=sav$input$tagsInp)
shiny::updateTextInput(session=session,
inputId="confFileTabBase",
value=sav$input$confFileTabBase)
shiny::updateTextInput(session=session,
inputId="confFileTabProcInp",
value=sav$input$confFileTabProcInp)
shiny::updateTextInput(session=session,
inputId="confResFileTab",
value=sav$input$confResFileTab)
getCmpListdf<-shiny::reactive({rvCmpList$df})
shiny::observeEvent(input$restoreConfB,{
message("Restore event observed.")
restoreConf()
})
shiny::observeEvent(input$saveConfB,{
saveConf()
})
shiny::observeEvent(input$impSetIdB,{
fnobj<-shinyFiles::parseFilePaths(roots=volumes,input$impSetIdB)
fn<-fnobj[["datapath"]]
if (length(fn)>0 && !is.na(fn)) {
shiny::updateTextInput(session=session,
inputId="impSetIdInp",
value=fn)
}})
shiny::observeEvent(input$impCmpListB,{
fnobj<-shinyFiles::parseFilePaths(roots=volumes,input$impCmpListB)
fn<-fnobj[["datapath"]]
if (length(fn)>0 && !is.na(fn)) {
shiny::updateTextInput(session=session,
inputId="impCmpListInp",
value=fn)
}})
shiny::observeEvent(input$impGenRMBB,{
fnobj<-shinyFiles::parseFilePaths(roots=volumes,input$impGenRMBB)
fn<-fnobj[["datapath"]]
if (length(fn)>0 && !is.na(fn)) {
shiny::updateTextInput(session=session,
inputId="impGenRMBInp",
value=fn)
}})
shiny::observeEvent(input$impCmpListInp,
{
impCmpFn<-input$impCmpListInp
if (length(impCmpFn)>0 && !is.na(impCmpFn) && nchar(impCmpFn)>0) {
rvConf$impCmpListFn<-impCmpFn
message("rvConf$impCmpListFn is changed to:",impCmpFn)
shiny::observeEvent(rvConf$impCmpListFn,
{
fn<-rvConf$impCmpListFn
if (file.exists(fn)) {
message("Importing compound list from:",fn)
df<-importCmpList(fn)
rvCmpList$df<-df
message("Done importing compound list from: ",fn)
shiny::observeEvent(input$impSetIdInp,
{
fn<-input$impSetIdInp
if (length(fn)>0 && !is.na(fn) && nchar(fn)>0) {
rvConf$impSetIdFn<-fn
message("rvConf$impSetIdFn is changed to:",fn)
}
shiny::observeEvent(rvConf$impSetIdFn,
{
fn<-rvConf$impSetIdFn
if (file.exists(fn)) {
message("Importing compound sets from:",fn)
rvSetId$df<-readSetId(fn)
message("Done importing compound sets from: ",fn)
shiny::observeEvent(rvConf$mzMLtab,{
update_sets_mzMLtab()
update_tags_mzMLtab()
})
shiny::observeEvent(input$mzMLtabCtrl,{
## input$cmpListCtrl
## input$setIdTabCtrl
rvConf$mzMLtab<-rhandsontable::hot_to_r(input$mzMLtabCtrl)
## shiny::isolate({rvConf$mzMLtab<-rhandsontable::hot_to_r(input$mzMLtabCtrl)})
shiny::observeEvent(input$cmpListCtrl,{
df<-rhandsontable::hot_to_r(input$cmpListCtrl)
})
shiny::observeEvent(input$setIdTabCtrl,{
df<-rhandsontable::hot_to_r(input$setIdTabCtrl)
rvSetId$df<-df
shiny::updateSelectInput(session=session,
inputId="genSetSelInp",
choices=levels(df$set))})
## shiny::observeEvent(input$confFileTabBase, {
## fn<-input$confFileTabBase
## if (length(fn)>0 && !is.na(fn)) {
## }
## })
shiny::observeEvent(input$genFileTabB,{
fn<-input$confFileTabBase
message("Generating basic file table in file ",fn)
## files<-adornmzMLTab(rhandsontable::hot_to_r(input$mzMLtabCtrl),projDir=rvConf$projDir)
files<-adornmzMLTab(rvConf$mzMLtab,projDir=rvConf$projDir)
setId<-rvSetId$df
cmpL<-rvCmpList$df
df<-genSuprFileTbl(files,setId,destFn=fn)
df<-addCmpLColsToFileTbl(df,cmpL)
write.csv(x=df,file=fn,row.names=F)
rvConf$fnFTBase<-fn
message("Done generating basic file table in file ",fn)
}
})
shiny::observeEvent(input$genRunB,{
FnRMB<-input$impGenRMBInp
nProc<-as.integer(input$genNoProc)
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
sets<-input$genSetSelInp
message("Selected sets:")
message(str(sets))
message("Number of processes:",nProc)
message("RMassBank settings file:",FnRMB)
message("File table:",fnTab)
if (length(fnTab)>0) {
## fTab<-read.csv(file=fnTab,
## row.names=F,
## heander=T,
## comment.char='',
## na.strings=c("","NA"),
## stringsAsFactors=F)
## mask<-fTab$set %in% sets
## fTab<-fTab[mask,]
for (s in sets) {
message("***** BEGIN set ",s, " *****")
fnCmpdList<-input$impCmpListInp
fnStgs<-input$impGenRMBInp
intTresh<-as.numeric(input$intTresh)
noiseFac<-as.numeric(input$noiseFac)
rtDelta<-as.numeric(input$rtDelta)
ppmLimFine<-as.numeric(input$ppmLimFine)
dest<-rvConf$projDir
eicLim<-as.numeric(input$eicLim)
gc()
gen(fnFileTab=fnTab,
fnCmpdList=fnCmpdList,
fnStgs=fnStgs,
dest=dest,
proc=nProc,
intTresh=intTresh,
noiseFac=noiseFac,
rtDelta=rtDelta,
ppmLimFine=ppmLimFine,
eicLim=eicLim)
message("***** END set ",s, " *****")
shiny::observeEvent(input$genRunPPB,{
shiny::isolate({
sets<-getSets()
cdf<-if (!is.null(input$cmpListCtrl)) rhandsontable::hot_to_r(input$cmpListCtrl) else NULL})
nr<-nrow(cdf)
if (!is.null(nr)) {
if (is.na(nr)) nr<-0
} else nr<-0
if (length(sets)>0 && nr>0) {
doneSets<-sets[sapply(sets,isGenDone)]
if (length(doneSets)>0) {
fnFullTab<-input$confFileTabProcInp
fnBaseTab<-input$confFileTabBase
fnOpen<-""
fnOpen<-if (file.exists(fnFullTab)) fnFullTab else fnBaseTab
fullFTab<-read.csv(file=fnOpen,
comment.char = '',
stringsAsFactors = F)
doneFTab<-fullFTab[fullFTab$set %in% doneSets,]
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
if (nrow(doneFTab)>0) {
fnTmp<-ppInpFt()
write.csv(file=fnTmp,
x=doneFTab,
row.names=F)
message("fnTmp: ",fnTmp)
cmpdL<-rvCmpList$df
maxId<-do.call(max,sapply(doneSets,idsFromFiles))
intTresh<-as.numeric(input$intTresh)
noiseFac<-as.numeric(input$noiseFac)
rtDelta<-as.numeric(input$rtDelta)
## dr<-file.path(dirname(fnCand),sets)
preProc(fnFileTab=fnTmp,
lCmpdList=maxId,
fnDest=fnTmp,
intTresh=intTresh,
noiseFac=noiseFac,
rtDelta=rtDelta)
ppFnTab<-read.csv(file=fnTmp,
comment.char = '',
stringsAsFactors = F)
extNms<-names(ppFnTab)
basNms<-names(fullFTab)
diffNms<-setdiff(extNms,basNms)
nrf<-nrow(fullFTab)
for (nm in diffNms) {
z<-logical(length=nrf)
z<-T
fullFTab[[nm]]<-z
}
fullFTab[fullFTab$set %in% doneSets,]<-ppFnTab
write.csv(file=fnFullTab,
x=fullFTab,
row.names=F)
file.copy(fnFullTab,input$confResFileTab,overwrite=T)
message("Finished preprocessing.")
})
shiny::observeEvent(input$presSelSet,{
sets<-getSets()
if (length(sets)>0 && !is.na(sets)) {
cmpdL<-getCmpdL()
setID<-getSetId()
if (nrow(cmpdL)>0 && nrow(setID)>0) {
set<-input$presSelSet
rvConf$currSet<-set
ids<-setID$ID[setID$set %in% set]
entries<-mkCmpdDrop(ids,cmpdL)
ch<-as.list(1:length(ids))
names(ch)<-entries
shiny::updateSelectInput(session=session,
"presSelCmpd",
choices=ch,
selected = 1)
rvConf$currIDSet<-ids
}
}
})
shiny::observeEvent(rvConf$currSet,{
set<-rvConf$currSet
fTab<-rvConf$fTab
message("set:",set)
message("n ftab:",nrow(fTab))
if (!is.na(set) && length(fTab)>0) {
tags<-rvConf$tags
iSet<-which(set==fTab$set)
tags<-levels(factor(sfTab$tag))
iTag<- match(tags,sfTab$tag)
wd<-sfTab$wd[iTag]
message("wd<")
message(str(wd))
message("wd>")
preID<-ids #sfTab$ID[iTag]
cmpL<-rvCmpList$df
iCmpL<-match(preID,cmpL$ID)
smiles<-cmpL$SMILES[iCmpL]
names(smiles)<-as.character(preID)
names(mz)<-as.character(preID)
## Get the basenames of eic files.
eics <- list.files(path=wd[[1]],patt=".*eic.csv")
eicsPref <- sapply(strsplit(eics,split="\\."),function(x) x[[1]])
eicsID <- as.integer(eicsPref)
maybekids <- sapply(eicsPref,function(x) {paste(x,'.kids.csv',sep='')})
names(eics) <- eicsID
names(maybekids) <- eicsID
plot_id <- function (i,rtrange=NULL,log=input$yaxis) {
i=as.character(i)
mz=mz[[i]]
smile<-smiles[[i]]
plot_id_aux(i,wd=wd,eics=eics,maybekids=maybekids,mass=mz,smile=smile,tags=tags,log=log,rtrange=rtrange,cex=rvPres$cex,pal=rvPres$pal,rt_digits=rvPres$rt_digits,m_digits=rvPres$m_digits,fTab=sfTab)
}
shiny::observeEvent(input$presSelCmpd,{
pos<-input$presSelCmpd
rvConf$currIDSel<-as.numeric(pos)
})
shiny::observeEvent(input$presPrev,{
len<-length(rvConf$currIDSet)
x<-rvConf$currIDSel-1
if (x>0) rvConf$currIDSel<-x
})
shiny::observeEvent(input$presNext,{
len<-length(rvConf$currIDSet)
x<-rvConf$currIDSel+1
if (x<=len) rvConf$currIDSel<-x
})
rvConf$fTab<-read.csv(file=fn,
comment.char = '',
stringsAsFactors = F)
}
})
shiny::observeEvent(rvConf$currIDSel,{
ids<-rvConf$currIDSet
if (length(ids)>0) rvConf$currID<-ids[[rvConf$currIDSel]]
})
shiny::observeEvent(input$submitQA,{
res <- lapply(rvConf$tags,getCheckboxValues,input,rvConf)
names(res) <- rvConf$tags
rvConf$fTab <- updateFileTable(df=rvConf$fTab,
set=input$presSelSet,
id=rvConf$currID,
linput=res)
})
shiny::observeEvent(input$savefiletable,
{
fn<-input$fn_ftable
message("Writing current file table to ",fn)
write.csv(file=fn,x=rvConf$fTab,row.names = F)
})
shiny::observeEvent(input$saveplot,
{
i=rvConf$currID
pfn <-input$plotname
if (is.na(pfn)) pfn <- "plotCpdID_%i.pdf"
fn <- sprintf(pfn,i)
rtrange <- c(input$min_val,input$max_val)
pdf(file=fn, width=12, height=8)
rvPres$plot_id(i,rtrange=rtrange, log=input$yaxis)
dev.off()
message("Plotting compound ", i," to ",fn," done.")
})
shiny::observeEvent(input$saveallplots,
{
i=rvConf$currID
pfn <-input$plotname
if (is.na(pfn)) pfn <- "plotall.pdf"
fn <- sprintf(pfn,i)
pdf(file=fn, width=12, height=8)
for (i in rvConf$currIDSet) {
rvPres$plot_id(i,log=input$yaxis)
message("Plotting compound ", i," done.")
}
dev.off()
})
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
shiny::observe({
fchoice<-shinyFiles::parseFilePaths(root=volumes,input$mzMLB)
paths<-fchoice[["datapath"]]
isolate({
for (pt in paths) {
rvConf$mzMLtab<-extd_mzMLtab(rvConf$mzMLtab,pt)
}
})
})
shiny::observe({
shiny::updateSelectInput(session=session,
inputId="presSelCmpd",
selected=rvConf$currIDSel)
})
shiny::observe({
shiny::invalidateLater(100,
session=session)
output$genTabProcCtrl<-rhandsontable::renderRHandsontable({
sets<-getSets()
genState<-sapply(sets,isGenDone)
df<-if (!is.null(sets)) {data.frame(set=sets,
generated=genState,
stringsAsFactors=F)
} else {data.frame(sets=character(),
generated=logical(),
stringsAsFactors=F)}