Skip to content
Snippets Groups Projects
run.R 3.02 KiB
Newer Older
Todor Kondic's avatar
Todor Kondic committed
## Copyright (C) 2020 by University of Luxembourg

## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at

##     http://www.apache.org/licenses/LICENSE-2.0

## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.

is_gen_done<-function(dest) {
    fnFlag<-file.path(dest,".gen.DONE")
    file.exists(fnFlag)
}

isPPDone<-function(dest) {
    fnFlag<-file.path(dest,".pp.DONE")
    file.exists(fnFlag)
    
}

setPPDone<-function(dest) {
    fnFlag<-file.path(dest,".pp.DONE")
    if (isPPDone(dest)) file.create(fnFlag)
}

unsetPPDone<-function(dest) {
    fnFlag<-file.path(dest,".pp.DONE")
    if (isPPDone(dest)) unlink(fnFlag,force=T)
}

setGenDone<-function(dest) {
    fnFlag<-file.path(dest,".gen.DONE")
Todor Kondic's avatar
Todor Kondic committed
    file.create(fnFlag)
}

unsetGenDone<-function(dest) {
    fnFlag<-file.path(dest,".gen.DONE")
    if (is_gen_done(dest)) unlink(fnFlag,force=T)
##' Paste with no separator.
##'
##' @title Paste With No Separator
##' @param ... Strings to paste together.
##' @return Pasted string.
##' @author Todor Kondić
attch<-function(...) paste(...,sep='')

Todor Kondic's avatar
Todor Kondic committed
##' Do the prescreening.
##'
##' @title Prescreening on bunch of files.
##' @param fTab File table with Files,ID,wd,Name and mz
##'     columns. Column Files, as well as wd must have all rows
##'     identical.
##' @param extr_fun Extraction function from the backend. 
##' @param limEIC Absolute mz tolerance used to extract precursor EICs.
##' @param limFinePPM Tolerance given in PPM used to associate input
##'     masses with what the instrument assigned as precutsors to MS2.
Todor Kondic's avatar
Todor Kondic committed
##' @param proc Amount of processors, or FALSE. 
##' @param fnLog For parallel execution, dump messages there.
Todor Kondic's avatar
Todor Kondic committed
##' @return Nothing useful.
##' @author Todor Kondić
##' @export
Todor Kondic's avatar
Todor Kondic committed
gen<-function(fTab,limEIC,limFinePPM,rtDelta,proc=F,fnLog='prescreen.log',extr_fun=extr_msnb_ht) {
    message("*** Started to generate prescreen data ...")
    unlink(fnLog)
    fread<-function(fTab) {
        extract(fTab=fTab,
                extr_fun=extr_fun,
                limEIC=limEIC,
Todor Kondic's avatar
Todor Kondic committed
                limFinePPM=limFinePPM,
                rtDelta=rtDelta,
Todor Kondic's avatar
Todor Kondic committed
                limCoarse=0.5,
                fnSpec=FN_SPEC)
Todor Kondic's avatar
Todor Kondic committed

    fns<-unique(fTab$Files)
    fTabs<-lapply(fns,function(fn) fTab[fTab$Files==fn,])
    if (proc>1) {
Todor Kondic's avatar
Todor Kondic committed
        cl<-parallel::makeCluster(spec=proc,type='PSOCK',outfile=fnLog)
Todor Kondic's avatar
Todor Kondic committed
        parallel::clusterEvalQ(cl,library(shinyscreen))
        ## parallel::clusterExport(cl,c("extract"),envir=environment())
        res<-parallel::parLapply(cl,fTabs,fread)
Todor Kondic's avatar
Todor Kondic committed
        parallel::stopCluster(cl)
Todor Kondic's avatar
Todor Kondic committed
    } else {
        lapply(fTabs,fread)
Todor Kondic's avatar
Todor Kondic committed
    message("*** ... done generating prescreen data.")
}