From 6db17d2fd46e1e5f599281b5c27eb6b6b9da7474 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Todor=20Kondi=C4=87?= <todor.kondic@uni.lu>
Date: Wed, 19 Jun 2019 16:33:17 +0200
Subject: [PATCH] Add many things

---
 DESCRIPTION            |  3 ++-
 R/mix.R                | 32 ++++++++++++++++++++++++--------
 man/mb.do.Rd           |  5 ++++-
 man/mb.p.Rd            | 27 +++++++++++++++++++++++++++
 man/mb.prep.Rd         |  2 ++
 man/mk_combine_file.Rd | 26 ++++++++++++++++++++++++++
 man/mk_sett_file.Rd    |  3 ---
 7 files changed, 85 insertions(+), 13 deletions(-)
 create mode 100644 man/mb.p.Rd
 create mode 100644 man/mk_combine_file.Rd

diff --git a/DESCRIPTION b/DESCRIPTION
index c7911e7..1587c58 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -21,4 +21,5 @@ Collate:
     'run.R'
 Imports: 
     RMassBank,
-    parallel
+    parallel,
+    yaml
diff --git a/R/mix.R b/R/mix.R
index ac505dd..8594f4d 100644
--- a/R/mix.R
+++ b/R/mix.R
@@ -26,19 +26,38 @@ no_drama_mkdir<-function(path) {
 ##' @param file The name of the YAML specification that will be merged
 ##'     with the template Rmb settings file.
 ##' @return NULL
-##' @author Todor Kondić
 mk_sett_file<-function(sett_alist,file) {
-    require(yaml)
     tmp<-tempfile()
     RMassBank::RmbSettingsTemplate(tmp)
-    sett<-yaml.load_file(tmp)
+    sett<-yaml::yaml.load_file(tmp)
     for (nm in names(sett_alist)) {
         sett[[nm]]<-sett_alist[[nm]]
     }
-    write_yaml(x=sett,file=file)
+    yaml::write_yaml(x=sett,file=file)
     NULL
 }
 
+##' Combine RMB settings with different collisional energies into one
+##' settings file with multiple collisional energy entries.
+##'
+##' .. content for \details{} ..
+##' @title Combine RMB Settings With Different Collisional Energies
+##' @param sett_fns A list of settings files.
+##' @param fname The name of the combined file.
+##' @return fname
+##' @author Todor Kondić
+mk_combine_file<-function(sett_fns,fname) {
+    all_settings <- lapply(sett_fns,yaml::yaml.load_file)
+    comb_settings <- all_settings[[1]]
+    
+    for (n in 1:length(all_settings)) {
+        comb_settings$spectraList[[n]] <- all_settings[[n]]$spectraList[[1]]
+    }
+
+    yaml::write_yaml(x=comb_settings,fname)
+    fname
+}
+
 ##' Generate the RMassBank compound list from the input compound list
 ##' in CSV file src_fn. The input compound list format is either a
 ##' Chemical Dashboard csv file with, at least, PREFERRED_ SMILES
@@ -90,11 +109,8 @@ gen_comp_list<-function(src_fn,dest_fn) {
 ##' @return MsmsWorkspace object.
 ##' @author Todor Kondić
 single.sw<-function(fn_data,stgs_alist,wd,fn_cmpd_list,mode,readMethod="mzR",archdir="archive",lastStep=8) {
-    
-    require(RMassBank)
-    require(yaml)
     ## Generate settings file and load.
-    stgs_alist<-if (is.character(stgs_alist)) yaml.load_file(stgs_alist) else stgs_alist
+    stgs_alist<-if (is.character(stgs_alist)) yaml::yaml.load_file(stgs_alist) else stgs_alist
     sfn<-file.path(wd,paste(fn_data,".ini",sep=''))
     mk_sett_file(stgs_alist,sfn)
     RMassBank::loadRmbSettings(sfn)
diff --git a/man/mb.do.Rd b/man/mb.do.Rd
index a1e5883..73e319d 100644
--- a/man/mb.do.Rd
+++ b/man/mb.do.Rd
@@ -4,12 +4,15 @@
 \alias{mb.do}
 \title{Perform the Mass Bank workflow}
 \usage{
-mb.do(mb, rdir = ".")
+mb.do(mb, rdir = ".", proc = F)
 }
 \arguments{
 \item{mb}{The list of prepared mbWorkspace objects.}
 
 \item{rdir}{Root data dir.}
+
+\item{proc}{Split work between this amount of processes. If FALSE
+(or, 1), run sequential.}
 }
 \value{
 The named list of processed mbWorkspace objects.
diff --git a/man/mb.p.Rd b/man/mb.p.Rd
new file mode 100644
index 0000000..e68fff8
--- /dev/null
+++ b/man/mb.p.Rd
@@ -0,0 +1,27 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/mix.R
+\name{mb.p}
+\alias{mb.p}
+\title{Parallel Mass Bank Workflow}
+\usage{
+mb.p(mb, infodir, fn_stgs, cl = F)
+}
+\arguments{
+\item{mb}{List of mass bank workflow objects}
+
+\item{infodir}{List of subdirs containing info lists.}
+
+\item{fn_stgs}{List of settings files.}
+
+\item{cl}{Cluster.}
+}
+\value{
+A named list of mbWorkspace objects. The names are derived
+from the input mb sequence.
+}
+\description{
+Interface to parallelised Mass Bank workflow.
+}
+\author{
+Todor Kondić
+}
diff --git a/man/mb.prep.Rd b/man/mb.prep.Rd
index 3d17936..43fdac8 100644
--- a/man/mb.prep.Rd
+++ b/man/mb.prep.Rd
@@ -10,6 +10,8 @@ mb.prep(w, rdir = ".")
 \item{w}{A list of spectral workspace inputs.}
 
 \item{rdir}{Data root.}
+
+\item{proc}{Split work between this amount of processes. If FALSE}
 }
 \value{
 Named list of prepared mbWorkspace objects.
diff --git a/man/mk_combine_file.Rd b/man/mk_combine_file.Rd
new file mode 100644
index 0000000..32740c2
--- /dev/null
+++ b/man/mk_combine_file.Rd
@@ -0,0 +1,26 @@
+% Generated by roxygen2: do not edit by hand
+% Please edit documentation in R/mix.R
+\name{mk_combine_file}
+\alias{mk_combine_file}
+\title{Combine RMB Settings With Different Collisional Energies}
+\usage{
+mk_combine_file(sett_fns, fname)
+}
+\arguments{
+\item{sett_fns}{A list of settings files.}
+
+\item{fname}{The name of the combined file.}
+}
+\value{
+fname
+}
+\description{
+Combine RMB settings with different collisional energies into one
+settings file with multiple collisional energy entries.
+}
+\details{
+.. content for \details{} ..
+}
+\author{
+Todor Kondić
+}
diff --git a/man/mk_sett_file.Rd b/man/mk_sett_file.Rd
index 3298e34..cbf885a 100644
--- a/man/mk_sett_file.Rd
+++ b/man/mk_sett_file.Rd
@@ -20,6 +20,3 @@ Produce the Rmb Settings file
 Produce the Rmb Settings file based on the customisation file in
 YAML format.
 }
-\author{
-Todor Kondić
-}
-- 
GitLab