diff --git a/mix.R b/mix.R deleted file mode 100644 index 8d116043d8d143a34dc932ad8c90d515aa1e9515..0000000000000000000000000000000000000000 --- a/mix.R +++ /dev/null @@ -1,104 +0,0 @@ -## Create a temporary directory to hold the files generated on the -## fly. -rmbmix.mkdir<-function() { - nm<-tempfile(pattern="rmbmix") - dir.create(nm) - nm -} - -## -rmbmix.mk_sett_file<-function(sett_alist,file) { - require(yaml) - tmp<-tempfile() - RmbSettingsTemplate(tmp) - sett<-yaml.load_file(tmp) - for (nm in names(sett_alist)) { - sett[[nm]]<-sett_alist[[nm]] - } - write_yaml(x=sett,file=file) -} - - -## Generate the RMassBank compound list from the input compound list -## in CSV file src_fn. The input compound list format is either -## Chemical Dashboard csv file with, at least, PREFERRED_NAMES and -## SMILES columns _filled_ out, or just an ordinary csv file with -## columns SMILES and Names filled. Argument dest_fn is the -## destination filename. Returns the number of compounds. -rmbmix.gen_comp_list<-function(src_fn,dest_fn) { - df<-read.csv(src_fn) - ## Names - nms<-if ("PREFERRED_NAME" %in% names(df)) df$PREFERRED_NAME else df$Name - if (is.null(nms)) stop("Unable to read compound names from the input compound list.") - - ## SMILES - haha<-df$SMILES - sz<-length(haha) - - ## CAS - casvals<-if ("CASRN" %in% names(df)) df$CASRN else rep(NA,sz) - if (is.null(haha)) stop("Unable to read SMILES from the input compound list.") - - outdf<-data.frame(ID=1:sz,Name=nms,SMILES=haha,CAS=casvals,RT=rep(NA,sz)) - write.csv(outdf,file=dest_fn,row.names=F,na="") - length(nms) -} - - - -## Perform the compound mixture workflow on the data file called -## fn_data with settings named list called stgs_alist. Alternatively, -## stg_alist can be a file name which follows the RMassBank settings -## specification, also in YAML format, containing only parts that -## differ from the default. Argument fn_cmpd_list is the compound -## list. Argument wd is the scratch dir to hold generated ini files -## and the like. Arguments mode and readMethod are the same as in -## msmsRead. -rmbmix.single<-function(fn_data,stgs_alist,fn_cmpd_list,wd,mode,readMethod="mzR",archdir="archive") { - - require(RMassBank) - require(yaml) - ## Generate settings file and load. - stgs_alist<-if (is.character(stgs_alist)) yaml.load_file(stgs_alist) else stgs_alist - sfn<-file.path(wd,paste(fn_data,".ini",sep='')) - rmbmix.mk_sett_file(stgs_alist,sfn) - loadRmbSettings(sfn) - - ## Generate and load the compound list. - fn_comp<-file.path(wd,paste(fn_data,".comp.csv",sep='')) - n_cmpd<-rmbmix.gen_comp_list(fn_cmpd_list,fn_comp) - loadList(fn_comp) - - ## Generate file table. - df_table<-data.frame(Files=rep(fn_data,n_cmpd),ID=1:n_cmpd) - fn_table<-file.path(wd,paste("fn-table.",fn_data,".csv",sep='')) - write.csv(x=df_table,file=fn_table,row.names=F) - - ## Make empty workspace. - w <- newMsmsWorkspace() - ## Run the workflow. - message(paste("Reading in file:",fn_data)) - w <-msmsRead(w,filetable=fn_table,readMethod="mzR",mode=mode) - if (!dir.exists(archdir)) dir.create(archdir) - fn_arch<-file.path(archdir,paste(fn_data,".archive",sep='')) - w<-msmsWorkflow(w, mode=mode, steps=2:8,archivename=fn_arch) - mb<-newMbWorkspace(w) - mb<-resetInfolists(mb) - ## loadInfolists - ## addPeaks - bits<-strsplit(fn_data,split="\\.")[[1]] - fn_info<-if (length(bits)> 1) paste(head(bits,-1),collapse=".") else fn_data - infodir<-fn_info - fn_info<-paste(archdir,"/",fn_info,".csv",sep='') - mb<-mbWorkflow(mb,infolist_path=fn_info) - list(w=w,mb=mb) -} - - -rmbmix.mb2.single<-function(mb,infodir) { - mb <- resetInfolists(mb) - mb <- loadInfolists(mb,infodir) - mbWorkflow(mb) -} -rmbmix.mb2<-Vectorize(rmbmix.mb2.single,vectorize.args=c("mb","infodir"),SIMPLIFY=F) -rmbmix<- Vectorize(rmbmix.single,vectorize.args=c("fn_data","stgs_alist"),SIMPLIFY=F)