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

Various helper functions

* mix.R

** rmbmix.mkdir
   Generates temporary work dir to hold on-the-fly metadata.

** rmbmix.gen_comp_list
   Generate compound list.

** rmbmix.single
   Extend to include the work directory.
parent 3243e55a
No related branches found
No related tags found
No related merge requests found
## 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()
......@@ -11,11 +19,47 @@ rmbmix.mk_sett_file<-function(sett_alist,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.
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
if (is.null(haha)) stop("Unable to read SMILES from the input compound list.")
sz<-length(haha)
outdf<-data.frame(Name=nms,SMILES=haha,ID=1:sz,RT=rep("",sz),CAS=rep("",sz))
write.csv(outdf,file=dest_fn,row.names=F)
}
## Perform the compound mixture workflow on the data file called
## fn_data with settings named list called sett_alist.
rmbmix.single<-function(fn_data,sett_alist) {
## fn_data with settings named list called sett_alist. Argument
## fn_cmpd_list is the compound list. Argument wd is the scratch dir
## to hold generated ini files and the like.
rmbmix.single<-function(fn_data,sett_alist,fn_cmpd_list,wd) {
require(RMassBank)
sfn<-paste(fn_data,".ini",sep='')
## 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)
## Generate settings file and load.
sfn<-file.path(wd,paste(fn_data,".ini",sep=''))
rmbmix.mk_sett_file(sett_alist,sfn)
loadRmbSettings(sfn)
## Make empty workspace.
}
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