Repository 'nmr_annotation'
hg clone https://toolshed.g2.bx.psu.edu/repos/marie-tremblay-metatoul/nmr_annotation

Changeset 2:7304ec2c9ab7 (2018-07-30)
Previous changeset 1:b55559a2854f (2018-03-28) Next changeset 3:9b45c0a33573 (2018-09-03)
Commit message:
Uploaded
added:
nmr_preprocessing/.Rhistory
nmr_preprocessing/.shed.yml
nmr_preprocessing/Apodization_wrapper_Manon.R
nmr_preprocessing/DrawFunctions.R
nmr_preprocessing/Int_Funct.R
nmr_preprocessing/NmrPreprocessing_script.R
nmr_preprocessing/NmrPreprocessing_wrapper.R
nmr_preprocessing/NmrPreprocessing_xml.xml
nmr_preprocessing/README.rst
nmr_preprocessing/ReadFids.R
nmr_preprocessing/ReadFids_Manon.R
nmr_preprocessing/ReadFids_script.R
nmr_preprocessing/ReadFids_wrapper.R
nmr_preprocessing/ReadFids_xml.xml
nmr_preprocessing/macros.xml
nmr_preprocessing/ptw.R
nmr_preprocessing/static/images/Mth_Travaux.png
nmr_preprocessing/static/images/NmrPreprocessing.png
nmr_preprocessing/static/images/ReadFids.png
nmr_preprocessing/test-data/MTBLS1.zip
nmr_preprocessing/test-data/MTBLS1_alignedSpectra.tabular
nmr_preprocessing/test-data/NMR_Preprocessing_dataMatrix.tabular
nmr_preprocessing/test-data/NMR_ReadFids_dataMatrix.tabular
nmr_preprocessing/test-data/sampleMetadata.tabular
removed:
DrawSpec.R
Library.Rdata
asics_wrapper.R
asics_xml.xml
static/images/NmrAnnotation_ASICS.png
test-data/ADG_007.zip
test-data/MTBLS1_177_NMR_Annotation.pdf
test-data/MTBLS1_177_NMR_Annotation_proportionEstimation.tabular
b
diff -r b55559a2854f -r 7304ec2c9ab7 DrawSpec.R
--- a/DrawSpec.R Wed Mar 28 09:48:25 2018 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
[
@@ -1,74 +0,0 @@
-drawSpec <- function (X, startP = -1, endP = -1, groupLabel = NULL, useLog = -1, highBound = -1, lowBound = -1, 
-                      xlab = NULL, ylab = NULL, main = NULL, nAxisPos = 4, offside = 0) 
-{
-  groupLabel_name = groupLabel
-  X = as.data.frame(X)
-#  colnames(X) = c(1:ncol(X))
-  X = as.matrix(X)
-  if (highBound != -1) {
-    for (i in 1:nrow(X)) {
-      myIndex = which(X[i, ] > highBound)
-      X[i, myIndex] = highBound
-    }
-  }
-  if (lowBound != -1) {
-    for (i in 1:nrow(X)) {
-      myIndex = which(X[i, ] < lowBound)
-      X[i, myIndex] = lowBound
-    }
-  }
-  if (is.null(groupLabel)) {
-    groupLabel = c(1:nrow(X))
-    groupLabel = as.factor(groupLabel)
-  }
-  else {
-    levels(groupLabel) = c(1:length(levels(groupLabel)))
-  }
-  if (startP == -1) 
-    startP = 1
-  if (endP == -1) 
-    endP = ncol(X)
-  if (is.null(xlab)) {
-    xlab = "index"
-  }
-  if (is.null(ylab)) {
-    ylab = "intensity"
-  }
-  if (is.null(main)) {
-    main = paste(" ", startP + offside, "-", endP + offside)
-  }
-  GraphRange <- c(startP:endP)
-  yn <- X[, GraphRange]
-  if (useLog != -1) 
-    yn = log(yn)
-  if (length(yn) > ncol(X))
-  {
-    plot(yn[1, ], ylim = c(min(yn), max(yn)), type = "n", ylab = ylab, xlab = xlab, main = main, xaxt = "n")
-    tempVal = trunc(length(GraphRange)/nAxisPos)
-    xPos = c(0:nAxisPos) * tempVal
-    axis(1, at = xPos, labels = colnames(X)[xPos + startP + offside])
-    for (i in 1:length(levels(groupLabel))) 
-    {
-      groupLabelIdx = which(groupLabel == levels(groupLabel)[i])
-      color <- palette(rainbow(length(levels(groupLabel))))
-      for (j in 1:length(groupLabelIdx)) 
-      {
-        lines(yn[groupLabelIdx[j], ], col = color[i])
-      }
-    }
-    if (!is.null(groupLabel_name)) 
-    {
-      legendPos = "topleft"
-      legend(legendPos, levels(groupLabel_name), col = as.integer(levels(groupLabel)), text.col = "black", pch = c(19, 19), bg = "gray90")
-    }
-  }
-  if (length(yn) == ncol(X))
-  {
-    plot(yn, ylim = c(min(yn), max(yn)), type = "n", ylab = ylab, xlab = xlab, main = main, xaxt = "n")
-    tempVal = trunc(length(GraphRange)/nAxisPos)
-    xPos = c(0:nAxisPos) * tempVal
-#    axis(1, at = xPos, labels = xPos + startP + offside)
-    axis(1, at = xPos, labels = colnames(X)[xPos + startP + offside])
-    lines(yn)
-  }
-}
\ No newline at end of file
b
diff -r b55559a2854f -r 7304ec2c9ab7 Library.Rdata
b
Binary file Library.Rdata has changed
b
diff -r b55559a2854f -r 7304ec2c9ab7 asics_wrapper.R
--- a/asics_wrapper.R Wed Mar 28 09:48:25 2018 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
[
@@ -1,198 +0,0 @@
-#!/usr/local/public/bin/Rscript --vanilla --slave --no-site-file
-
-## 29122017_asics_wrapper.R
-## Remi Servien, Patrick Tardivel, Marie Tremblay-Franco and Gaelle Lefort
-## marie.tremblay-franco@inra.fr
-
-runExampleL <- FALSE
-
-##------------------------------
-## Options
-##------------------------------
-strAsFacL <- options()$stringsAsFactors
-options(stringsAsFactors=FALSE)
-
-
-##------------------------------
-## Libraries loading
-##------------------------------
-# ParseCommandArgs function
-library(batch) 
-library(ASICS) 
-
-
-
-# R script call
-source_local <- function(fname)
-{
-argv <- commandArgs(trailingOnly=FALSE)
-base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
-source(paste(base_dir, fname, sep="/"))
-}
-#Import the different functions
-source_local("DrawSpec.R")
-
-
-##------------------------------
-## Errors ?????????????????????
-##------------------------------
-
-
-##------------------------------
-## Constants
-##------------------------------
-topEnvC <- environment()
-flagC <- "\n"
-
-
-##------------------------------
-## Script
-##------------------------------
-if(!runExampleL)
-    argLs <- parseCommandArgs(evaluate=FALSE)
-
-# Standards loading
-load(argLs[["standards"]])
-
-## Parameters Loading
-##-------------------
-# Inputs
-## Spectrum to annotate
-zipfile= argLs[["zipfile"]]
-directory=unzip(zipfile, list=F)
-directory=paste(getwd(),strsplit(directory[1],"/")[[1]][2],sep="/")
-
-
-##Exclusion zone(s)
-exclusionZones <- argLs[["zone_exclusion_choices.choice"]]
-exclusionZonesBorders <- NULL
-if (!is.null(argLs$zone_exclusion_left))
-{
-   for(i in which(names(argLs)=="zone_exclusion_left"))
-   {
-#     exclusionZonesBorders <- c(exclusionZonesBorders,list(c(argLs[[i]],argLs[[i+1]])))
-     exclusionZonesBorders <- c(exclusionZonesBorders,argLs[[i]],argLs[[i+1]])
-   }
-  exclusionZonesBorders <- matrix(exclusionZonesBorders, byrow=T, ncol=2)
-}
-if (is.null(argLs$zone_exclusion_left))
-{
-  exclusionZonesBorders <- matrix(c(0,0), byrow=T, ncol=2)
-}
-## Maximal allowed shift
-shift <- argLs[["shift"]]
-
-## Graphical zone(s)
-graphicalZones <- argLs[["zone_graphical_choices.choice"]]
-graphicalZonesBorders <- NULL
-if (!is.null(argLs$zone_exclusion_left))
-{
-  for(i in which(names(argLs)=="zone_graphical_left"))
-  {
-    graphicalZonesBorders <- c(graphicalZonesBorders,list(c(argLs[[i]],argLs[[i+1]])))
-  }
-}
-
-# Outputs
-logOut <- argLs[["logOut"]]
-proportionEstimation <- argLs[["proportionEstimation"]]
-graphOut <- argLs[["graphOut"]]
-
-sink(logOut)
-cat("\tPACKAGE INFO\n")
-# pkgs=c("batch", "ASICS")
-pkgs=c("batch", "ASICS")
-for(pkg in pkgs) {
-    suppressPackageStartupMessages( stopifnot( library(pkg, quietly=TRUE, logical.return=TRUE, character.only=TRUE)))
-    cat(pkg,"\t",as.character(packageVersion(pkg)),"\n",sep="")
-}
-cat("\n")
-
-
-## Checking arguments
-##-------------------
-error.stock <- "\n"
-if(length(error.stock) > 1)
-  stop(error.stock)
-  
-  
-## Computation
-##------------
-# annotation.Asics <- ASICS(directory, exclusion.areas=matrix(exclusionZonesBorders, byrow=T, ncol=2), 
-#                            max.shift=shift, which.spectra="last", library.metabolites=NULL, 
-#                            threshold.noise=0.02, seed=1234, nb.iter.signif=400)
-annotation.Asics <- ASICS(directory, exclusion.areas=exclusionZonesBorders, 
-                          max.shift=shift, which.spectra="last", library.metabolites=NULL, 
-                          threshold.noise=0.02, seed=1234, nb.iter.signif=400)
-
-
-## Saving
-##-------
-# Identified metabolites
-metabolites.estimation <- present_metabolites(annotation.Asics)
-colnames(metabolites.estimation) <- c("Metabolite",colnames(metabolites.estimation)[-1])
-write.table(metabolites.estimation,file=argLs$proportionEstimation,row.names=FALSE,quote=FALSE,sep="\t") 
-
-
-## Graphical display
-##------------------
-# Raw and annotated spectra comparison
-pdf(graphOut,onefile=TRUE)
-
-## Graphical output: overlay of raw and estimated spectra
-ppm.metabolites.estimation <- data.frame(round(ppm_grid(annotation.Asics),3), 
-                                         original_mixture(annotation.Asics))
-colnames(ppm.metabolites.estimation) <- c("PPM", "EstimatedProportion")
-ppm.metabolites.estimation <- ppm.metabolites.estimation[order(ppm.metabolites.estimation[,1],decreasing=T), ]
-
-mix <- data.frame(t(ppm.metabolites.estimation[,2]))
-colnames(mix) <- ppm.metabolites.estimation[,1]
-ppm <- ppm.metabolites.estimation[,1]
-
-estimatedMix <- data.frame(round(ppm_grid(annotation.Asics),3), reconstituted_mixture(annotation.Asics))
-colnames(estimatedMix) <- c("PPM","EstimatedProportion")
-estimatedMix <- estimatedMix[order(estimatedMix[,1],decreasing=T), ]
-estimatedMix <- estimatedMix[,2]
-
-## Whole spectra
-GraphRange <- 1:ncol(mix)
-tempVal <- trunc(length(GraphRange)/10)
-xPos <- c(10:0) * tempVal
-plot(1:ncol(mix), mix, type='l', xlab="", main="", xaxt="n", ylab="")
-axis(1, at=xPos, labels=colnames(mix)[xPos + 1])
-lines(estimatedMix, col="red")
-legend("topleft",legend=c("Real Mixture","Estimated Composition"),lty=c(1,1),col=c("black","red"))
-
-## Zoomed spectral window depending on user-selected zone(s)
-graphical.zone.length <- length(graphicalZonesBorders)
-if (graphical.zone.length != 0)
-
-  #   par(mfrow=c(2,1))
-for (g in 1:graphical.zone.length)
-  {
-     print(g)
-     plot(1:length((which(round(as.numeric(colnames(mix)),2) == graphicalZonesBorders[[g]][1])[1]):(which(round(as.numeric(colnames(mix)),2) == max(graphicalZonesBorders[[g]][2],0.5))[1])), 
-          mix[(which(round(as.numeric(colnames(mix)),2) == graphicalZonesBorders[[g]][1])[1]):(which(round(as.numeric(colnames(mix)),2) == max(graphicalZonesBorders[[g]][2],0.5))[1])], type='l', xlab="", ylab="Intensity", main="", xaxt="n")
-     lines(estimatedMix[(which(round(as.numeric(colnames(mix)),2) == graphicalZonesBorders[[g]][1])[1]):(which(round(as.numeric(colnames(mix)),2) == max(graphicalZonesBorders[[g]][2],0.5))[1])],col="red")
-    
-     xPos <- 1
-     nAxisPos <- 4
-     startP <- length(nAxisPos) 
-     endP <- length((which(round(as.numeric(colnames(mix)),2) == graphicalZonesBorders[[g]][1])[1]):(which(round(as.numeric(colnames(mix)),2) == max(graphicalZonesBorders[[g]][2],0.5))[1]))
-     GraphRange <- c(startP:endP)
-     tempVal <- trunc(length(GraphRange)/nAxisPos)
-     xPos <- c(0:nAxisPos) * tempVal
-     noms <- ppm.metabolites.estimation[xPos + which(ppm == round(graphicalZonesBorders[[g]][1],1))[1],1]
-     axis(1, at=xPos, labels=noms)
-   }
-
-invisible(dev.off())
-
-
-## Ending
-##---------------------
-cat("\nEnd of 'NMR annotation' Galaxy module call: ", as.character(Sys.time()), sep="")
-options(stringsAsFactors=strAsFacL)
-rm(list=ls())
-sink()
-
b
diff -r b55559a2854f -r 7304ec2c9ab7 asics_xml.xml
--- a/asics_xml.xml Wed Mar 28 09:48:25 2018 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
[
@@ -1,226 +0,0 @@
-<tool id="NmrAnnotation" name="NMR_Annotation" version="1.0.0">
-
-    <description> Annotation of complex mixture NMR spectra and metabolite proportion estimation </description>
-
-    <requirements>
-        <requirement type="package" version="1.1_4">r-batch</requirement>
-        <requirement type="package" version="1.0.1">r-asics</requirement>
-    </requirements>
-
-    <stdio>
-        <exit_code range="1:" level="fatal" />
-    </stdio>
-
-    <command><![CDATA[
-        ## Wrapper
-        Rscript '$__tool_directory__/asics_wrapper.R' standards '$__tool_directory__/Library.Rdata'
-
-        ## Bruker files
-        zipfile '$zip_file'
-
-        ## Exclusion zone
-        zone_exclusion_choices.choice ${zone_exclusion_choices.choice}
-        #if str($zone_exclusion_choices.choice) == 'yes':
-            #for $i in $zone_exclusion_choices.conditions:
-                zone_exclusion_left ${i.zone_exclusion_left}
-                zone_exclusion_right ${i.zone_exclusion_right}
-            #end for
-        #end if
-
-        ## Maximal shift (spectrum alignement)
-        shift $shift
-
-        ## Graphical zone
-        zone_graphical_choices.choice ${zone_graphical_choices.choice}
-        #if str($zone_graphical_choices.choice) == 'yes':
-            #for $i in $zone_graphical_choices.conditions:
-                zone_graphical_left ${i.zone_graphical_left}
-                zone_graphical_right ${i.zone_graphical_right}
-            #end for
-        #end if
-
-        ## Outputs
-        logOut '$logOut'
-        proportionEstimation '$proportionEstimation'
-        graphOut '$graphOut'
-    ]]></command>
-
-    <inputs>
-        <param name="zip_file" type="data" format="no_unzip.zip, zip" label="Zip file" />
-
-    <conditional name="zone_exclusion_choices">
-        <param name="choice" type="select" label="Exclusion zone(s)" help="Choose if you want to exclude particular zone(s)" >
-            <option value="yes" > yes </option>
-            <option value="no" selected="true"> no </option>
-        </param>
-        <when value="yes">
-            <repeat name="conditions" title="exclusion zones">
-                <param name="zone_exclusion_left" label="Left exclusion zone border" type="float" value="10.0" />
-                <param name="zone_exclusion_right" label="Right exclusion zone border" type="float" value="10.0" />
-            </repeat>
-        </when>
-        <when value="no" />
-    </conditional>
-
-    <param name="shift" type="float" value="0.01" help="Maximal allowed shift for spectra alignment. Default value is 0.01 ppm" />
-
-    <conditional name="zone_graphical_choices">
-        <param name="choice" type="select" label="Graphical zone(s)" help="Choose if you want to display particular zone(s)" >
-            <option value="yes" > yes </option>
-            <option value="no" selected="true"> no </option>
-        </param>
-        <when value="yes">
-            <repeat name="conditions" title="grapical zones">
-                <param name="zone_graphical_left" label="Left graphical zone border" type="float" value="10.0" />
-                <param name="zone_graphical_right" label="Right graphical zone border" type="float" value="10.0" />
-            </repeat>
-        </when>
-        <when value="no" />
-    </conditional>
-    </inputs>
-
-    <outputs>
-        <data format="txt" name="logOut" label="${tool.name}_log" />
-        <data format="tabular" name="proportionEstimation" label="${tool.name}_proportionEstimation" />
-        <data format="pdf" name="graphOut" label="${tool.name}_graph" />
-    </outputs>
-
-    <tests>
-        <test>
-            <param name="zip_file" value="ADG_007.zip" ftype="zip" />
-            <output name="proportionEstimation" value="MTBLS1_177_NMR_Annotation_proportionEstimation.tabular" />
-            <output name="graphOut"  value="MTBLS1_177_NMR_Annotation.pdf" compare="sim_size" delta="300" />
-        </test>
-    </tests>
-
-    <help><![CDATA[
-
-.. class:: infomark
-
-**Authors** Marie Tremblay-Franco (marie.tremblay-franco@inra.fr), Patrick Tardivel (patrick.tardivel@inra.fr), RĂ©mi Servien (remi.servien@inra.fr) and Gaelle Lefort (gaelle.lefort@inra.fr)
-
-.. class:: infomark
-
-**Please cite**
-
-Tardivel P., Servien R. and Concordet D. Non asymptotic active set properties of lasso-type estimators in small-dimension (submitted)
-Tardivel P., Servien R., Canlet C., Tremblay-Franco M., Debrauwer L. and Concordet D. ASICS: an automatic method for identification and quantification of metabolites in NMR 1D 1H spectra (in preparation)
-
----------------------------------------------------
-
-==============
-NMR Annotation
-==============
-
------------
-Description
------------
-
-ASICS, based on a strong statistical theory, handles automatically the metabolite identification and quantification
-
------------------
-Workflow position
------------------
-
-**Upstream tools**
-
-========================= ================= ======= =========
-Name                      output file       format  parameter
-========================= ================= ======= =========
-NA                        NA                NA      NA
-========================= ================= ======= =========
-
-
-**Downstream tools**
-
-========================= ================= ======= =========
-Name                      output file       format  parameter
-========================= ================= ======= =========
-NA                        NA                NA      NA
-========================= ================= ======= =========
-
-
-
------------
-Input files
------------
-
-+---------------------------+------------+
-| Parameter : num + label   |   Format   |
-+===========================+============+
-| 1 : Choose your inputs    |   zip      |
-+---------------------------+------------+
-
-**Choose your inputs**
-
-You have two methods for your inputs:
-
-| Zip file : You can put a zip file containing one condition (sample): myinputs.zip.
-
-.. image:: ./static/images/Mth_Architecture_Repertoire_Bruker.png
-
-----------
-Parameters
-----------
-
-Exclusion zone(s)
-| Spectral regions to exclude, water, solvent or contaminant resonances
-| If YES: parameters **Lower exclusion zone** and **Upper exclusion zone** are visible,
-| If NO: no zone to exclude
-| Default value is NO
-|
-
-Left exclusion zone
-| Upper boundary of exclusion zone
-
-
-Right exclusion zone
-| Lower boundary of exclusion zone
-
-| *Notes:*
-| - these parameters can be used several times using the "Add new exclusion zones" button
-
-
-Shift
-| Maximum variation of the chemical shift (due to experimental conditions) of a peak of a fixed metabolite allowed in the warping function
-
-
-Graphical zone(s)
-| Spectral regions to display
-| If YES: parameters **Lower graphical zone** and **Upper graphical zone** are visible,
-| If NO: no zone to display
-| Default value is NO
-
-
-------------
-Output files
-------------
-
-proportionEstimation.tsv
-| tabular output
-| Array with p rows (corresponding to the identified metabolites) and 1 column containing the estimated relative intensities
-
-
-spectra.pdf
-| pdf output
-| Graphical chart of real and estimated spectrum (whole spectral width and zooms depending on exclusion zone(s))
-
-
-
----------------------------------------------------
-
--------
-Example
--------
-
-.. image:: ./static/images/NmrAnnotation_ASICS.png
-
-
-   ]]></help>
-
-   <citations>
-       <citation type="doi">10.1007/s11306-017-1244-5</citation>
-       <citation type="doi">10.1093/bioinformatics/btu813</citation>
-   </citations>
-
-</tool>
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/.shed.yml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/.shed.yml Mon Jul 30 10:33:03 2018 -0400
[
@@ -0,0 +1,7 @@
+categories: [Metabolomics]
+description: '[Metabolomics][W4M][NMR] NMR Preprocessing - Preprocessing of 1D NMR spectra from FID to baseline correction'
+homepage_url: http://workflow4metabolomics.org
+long_description: 'Part of the W4M project: http://workflow4metabolomics.org'
+name: nmr_preprocessing
+owner: marie-tremblay-metatoul
+remote_repository_url: https://github.com/workflow4metabolomics/nmr_preprocessing
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/Apodization_wrapper_Manon.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/Apodization_wrapper_Manon.R Mon Jul 30 10:33:03 2018 -0400
[
@@ -0,0 +1,187 @@
+#!/usr/local/public/bin/Rscript --vanilla --slave --no-site-file
+
+## 12012017_Apodization_wrapper.R
+## Manon Martin
+## manon.martin@uclouvain.be
+
+
+#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
+# Use of runExampleL ?
+#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
+
+runExampleL <- FALSE
+# 
+# if(runExampleL) {
+#   ##------------------------------
+#   ## Example of arguments
+#   ##------------------------------
+#   argLs <- list(StudyDir = "Tlse_BPASourisCerveau",
+#                 upper = "10.0",
+#                 lower = "0.50",
+#                 bucket.width = "0.01",
+#                 exclusion = "TRUE",
+#                 exclusion.zone = list(c(6.5,4.5)),
+#                 graph="Overlay")
+#   
+#   argLs <- c(argLs,
+#              list(dataMatrixOut = paste(directory,"_NmrBucketing_dataMatrix.tsv",sep=""),
+#                   sampleMetadataOut = paste(directory,"_NmrBucketing_sampleMetadata.tsv",sep=""),
+#                   variableMetadataOut = paste(directory,"_NmrBucketing_variableMetadata.tsv",sep=""),
+#                   graphOut = paste(directory,"_NmrBucketing_graph.pdf",sep=""),
+#                   logOut = paste(directory,"_NmrBucketing_log.txt",sep="")))
+# }
+
+
+
+##------------------------------
+## Options
+##------------------------------
+strAsFacL <- options()$stringsAsFactors
+#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+# stringsAsFactors = FALSE utilis?? o?? ??
+#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+options(stringsAsFactors = FALSE)
+
+
+
+
+##------------------------------
+## Libraries loading
+##------------------------------
+# For parseCommandArgs function
+library(batch) 
+
+# R script call
+source_local <- function(fname)
+{
+  argv <- commandArgs(trailingOnly = FALSE)
+  base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
+  source(paste(base_dir, fname, sep="/"))
+}
+#Import the different functions
+source_local("Apodization_Manon.R")
+
+##------------------------------
+## Errors ?????????????????????
+##------------------------------
+
+
+##------------------------------
+## Constants
+##------------------------------
+#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+# interviennent ou ?
+#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+topEnvC <- environment()
+flagC <- "\n"
+
+
+##------------------------------
+## Script
+##------------------------------
+if(!runExampleL)
+  argLs <- parseCommandArgs(evaluate=FALSE) # If FALSE valeurs par d??faut d??finies dans le software
+
+
+## Parameters Loading
+##-------------------
+## Inputs
+# data
+
+# --- Galaxy_preformatted data
+# data <- read.table(argLs[["dataMatrix"]],check.names=FALSE,header=TRUE,sep="\t")
+# rownames(data) <- data[,1]
+# data <- data[,-1]
+# --- 
+
+# --- data from ReadFids
+Fid_data <- read.table(argLs[["dataMatrixOut"]],check.names=FALSE,header=TRUE,sep="\t")
+Fid_info <- read.table(argLs[["sampleOut"]],check.names=FALSE,header=TRUE,sep="\t")
+# --- 
+
+# other inputs (cf. XML wrapper)
+DT =  argLs[["DT"]]
+type.apod = argLs[["ApodizationMethod"]]
+
+# set default values for optional arguments
+phase=0
+rectRatio=1/2
+gaussLB=1
+expLB=1
+
+# change the default values
+if (type.apod %in% c("cos2", "hanning", "hamming")) {
+  phase = argLs[["phase"]]
+} 
+
+if (type.apod == "blockexp") {
+  rectRatio = argLs[["rectRatio"]] 
+  expLB = argLs[["expLB"]]
+}
+
+if (type.apod == "blockcos2") {
+  rectRatio = argLs[["rectRatio"]]
+}
+                     
+if (type.apod == "gauss") {
+gaussLB = argLs[["gaussLB"]]
+}
+
+if (type.apod == "exp") {
+  expLB = argLs[["expLB"]]
+}
+
+plotWindow = FALSE
+returnFactor = FALSE
+
+
+
+#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
+# Utility of Outputs ??
+#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
+# Outputs
+dataMatrixOut <- argLs[["dataMatrixOut"]] # Names from Saving
+
+
+
+## Checking arguments
+##-------------------
+error.stock <- "\n"
+
+#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
+# error.stock utilis?? ou ?
+#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
+if(length(error.stock) > 1)
+  stop(error.stock)
+
+
+## Computation
+##------------
+outputs <- Apodization(Fid_data = Fid_data, Fid_info = Fid_info, DT = DT, 
+                        type.apod = type.apod, phase = phase, rectRatio = rectRatio, 
+                        gaussLB = gaussLB, expLB = expLB, plotWindow = plotWindow, returnFactor = returnFactor) 
+  
+data_matrix <- outputs # Data matrix
+
+
+
+## Saving
+##-------
+# Data matrix
+data_matrix <- cbind(rownames(data_matrix),data_matrix)
+colnames(data_matrix) <- c("Sample",colnames(data_matrix)[-1])
+write.table(data_matrix,file=argLs$dataMatrixOut,quote=FALSE,row.names=FALSE,sep="\t")
+
+
+
+## Ending
+##---------------------
+
+cat("\nEnd of 'Apodization' Galaxy module call: ", as.character(Sys.time()), sep = "")
+
+## sink(NULL)
+
+options(stringsAsFactors = strAsFacL)
+
+rm(list = ls())
\ No newline at end of file
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/DrawFunctions.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/DrawFunctions.R Mon Jul 30 10:33:03 2018 -0400
[
b'@@ -0,0 +1,268 @@\n+require(ggplot2)\r\n+require(gridExtra)\r\n+require(reshape2)\r\n+\r\n+\r\n+Draw <- function(Signal_data, type.draw = c("signal", "pca"), output = c("default", \r\n+                                                                         "window", "png", "pdf"), dirpath = ".", filename = "%003d", height = 480, \r\n+                 width = 640, pdf.onefile = TRUE, ...) {\r\n+  \r\n+  # Data initialisation and checks ----------------------------------------------\r\n+  type.draw <- match.arg(type.draw)\r\n+  output <- match.arg(output)\r\n+  fullpath <- paste(file.path(dirpath, filename), output, sep = ".")\r\n+  createFile <- TRUE\r\n+  createWindow <- FALSE\r\n+  \r\n+  # Drawing --------------------------------------------------------------------\r\n+  # output\r\n+  switch(output, default = {\r\n+    createFile <- FALSE\r\n+  }, window = {\r\n+    createWindow <- TRUE\r\n+    createFile <- FALSE\r\n+  }, png = {\r\n+    grDevices::png(fullpath, width, height)\r\n+  }, pdf = {\r\n+    grDevices::pdf(fullpath, width = width/72, height = height/72, \r\n+                   onefile = pdf.onefile)\r\n+  }, {\r\n+    stop("Unknown output type.")\r\n+  })\r\n+  \r\n+  # Drawing type (signal/spectrum or PCA)\r\n+  funs <- list(signal = DrawSignal, pca = DrawPCA)\r\n+  if (type.draw %in% names(funs)) {\r\n+    fun <- funs[[type.draw]]\r\n+  } else {\r\n+    stop(paste("Unknown type:", type.draw))\r\n+  }\r\n+  \r\n+  # Plot finalisation ----------------------------------------------\r\n+  if (is.vector(Signal_data)) {\r\n+    Signal_data <- vec2mat(Signal_data)\r\n+  }\r\n+  fun(Signal_data, createWindow = createWindow, ...)\r\n+  if (createFile) {\r\n+    grDevices::dev.off()\r\n+  }\r\n+}\r\n+\r\n+\r\n+\r\n+#####   DrawSignal\r\n+\r\n+DrawSignal <- function(Signal_data, subtype = c("stacked", "together", \r\n+                                                "separate", "diffmean", "diffmedian", "diffwith"), \r\n+                       ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, \r\n+                       xlab = "rowname", RowNames = NULL, row = 1, num.stacked = 4, \r\n+                       main = NULL, createWindow) {\r\n+  # nticks\r\n+  \r\n+  # Data initialisation and checks ----------------------------------------------\r\n+  \r\n+  subtype <- match.arg(subtype)\r\n+  vec <- is.vector(Signal_data)\r\n+  if (vec) {\r\n+    Signal_data <- vec2mat(Signal_data)\r\n+  }\r\n+  \r\n+  n <- nrow(Signal_data)\r\n+  m <- ncol(Signal_data)\r\n+  \r\n+  if (n < num.stacked){\r\n+    num.stacked <- n\r\n+  }\r\n+  \r\n+  scale <- colnames(Signal_data)\r\n+  \r\n+  num.plot <- sum(ReImModArg)\r\n+  \r\n+  Var <- rowname <- value <- NULL  # only for R CMD check\r\n+  \r\n+  # Drawing array\r\n+  if (num.plot <= 0) {\r\n+    stop("Nothing selected in ReImModArg.")\r\n+  } else if (num.plot <= 2) {\r\n+    if (vertical)  {\r\n+      nrow <- num.plot\r\n+      ncol <- 1\r\n+    } else  {\r\n+      nrow <- 1\r\n+      ncol <- num.plot\r\n+    }\r\n+  } else {\r\n+    nrow <- 2\r\n+    ncol <- 2\r\n+  }\r\n+  \r\n+  # RowNames \r\n+  if (is.null(RowNames))  {\r\n+    RowNames <- rownames(Signal_data)\r\n+    if (is.null(RowNames))  {\r\n+      RowNames <- 1:n\r\n+    }\r\n+  } else {\r\n+    if (!is.vector(RowNames)) {\r\n+      stop("RowNames is not a vector")\r\n+    }\r\n+    if (length(RowNames) != n)  {\r\n+      stop(paste("RowNames has length", length(RowNames), "and there are", n, "FIDs."))\r\n+    }\r\n+  }\r\n+  \r\n+  if (n == 1) {\r\n+    RowNames <- deparse(substitute(Signal_data))\r\n+  }\r\n+  \r\n+  elements <- list()\r\n+  if (ReImModArg[1]) {\r\n+    elements[["Re"]] <- Re(Signal_data)\r\n+    rownames(elements[["Re"]]) <- RowNames\r\n+  }\r\n+  if (ReImModArg[2]) {\r\n+    elements[["Im"]] <- Im(Signal_data)\r\n+    rownames(elements[["Im"]]) <- RowNames\r\n+  }\r\n+  if (ReImModArg[3]) {\r\n+    elements[["Mod"]] <- Mod(Signal_data)\r\n+    rownames(elements[["Mod"]]) <- RowNames\r\n+  }\r\n+  if (ReImModArg[4]) {\r\n+    elements[["Arg"]] <- Arg(Signal_data)\r\n+    rownames(elements[["Arg"]]) <- RowNames\r\n+  }\r\n+  \r\n+  \r\n+  \r\n+  \r\n+  # Drawing --------------------------------------------------------------------\r\n+  \r\n+  y = x = NULL # only for R CMD '..b'<- ggplot2::ggplot(data = df, ggplot2::aes(x = x, y = y)) + \r\n+            ggplot2::geom_line(size = 1) + \r\n+            ggplot2::theme(legend.position = "none") + \r\n+            ggplot2::labs(x = xlab, y = name) +\r\n+            ggplot2::ggtitle(RowNames[i]) +\r\n+            ggplot2::theme_bw()\r\n+          \r\n+          if ((df[1, "x"] - df[(dim(df)[1]), "x"]) > 0) {\r\n+            plots[[name]] <- plots[[name]] + ggplot2::scale_x_reverse()\r\n+          }\r\n+          \r\n+        } else   {\r\n+          \r\n+          if (n == 1 ) {\r\n+            melted <- data.frame(rowname = rep(name, m), \r\n+                                 Var = as.numeric(scale), value = elements[[name]][i,])\r\n+          } else if (last==i){ \r\n+            melted <- data.frame(rowname = rep(rownames(elements[[name]])[i], m), \r\n+                                 Var = as.numeric(scale), value = elements[[name]][i,])\r\n+          } else {melted <- reshape2::melt(elements[[name]][i:last, ], \r\n+                                           varnames = c("rowname", "Var"))\r\n+          }\r\n+          \r\n+          \r\n+          plots[[name]] <- ggplot2::ggplot(data = melted, ggplot2::aes(x = Var, y = value)) + \r\n+            ggplot2::geom_line(size = 0.3) + \r\n+            ggplot2::facet_grid(rowname ~ ., scales = "free_y") + \r\n+            ggplot2::theme(legend.position = "none") + \r\n+            ggplot2::labs(x = xlab, y = name) +\r\n+            ggplot2::ggtitle(label = main) +\r\n+            ggplot2::theme_bw()\r\n+          \r\n+          if ((melted[1, "Var"] - melted[(dim(melted)[1]), "Var"]) > 0) {\r\n+            plots[[name]] <- plots[[name]] + ggplot2::scale_x_reverse()\r\n+          }\r\n+        }\r\n+      }\r\n+      \r\n+      if (subtype == "stacked")  {\r\n+        do.call(gridExtra::grid.arrange, c(plots, list(nrow = nrow, ncol = ncol)))\r\n+      } \r\n+      \r\n+      i <- last + 1\r\n+    }\r\n+  } else if (subtype %in% c("together", "diffmean", "diffmedian", "diffwith")) {\r\n+    \r\n+    # TOGHETER or DIFFMEAN or DIFFMEDIAN or DIFFWITH ===============\r\n+    \r\n+    rainbow_colors <- grDevices::rainbow(n)\r\n+    \r\n+    if (createWindow) {\r\n+      grDevices::dev.new(noRStudioGD = TRUE)\r\n+    }\r\n+    graphics::par(mfrow = c(nrow, ncol))\r\n+    \r\n+    plots <- list()\r\n+    \r\n+    # Loop for Re, Im, Mod and Arg\r\n+    for (name in names(elements)) {\r\n+      # Get this part of the signal\r\n+      element <- elements[[name]]\r\n+      \r\n+      # Express the signal according to a reference if asked by `subtype\'\r\n+      if (subtype == "diffmean")  {\r\n+        element <- sweep(element, MARGIN = 2, colMeans(element),  `-`)\r\n+      } else if (subtype == "diffmedian") {\r\n+        element <- sweep(element, MARGIN = 2, matrixStats::colMedians(element), `-`)\r\n+      } else if (subtype == "diffwith")  {\r\n+        element <- sweep(element, MARGIN = 2, element[row, ], `-`)\r\n+        if (row == 1 & n > 1)  {\r\n+          # Since we use plot on the first row and lines on the following, the y\r\n+          # scale is calculated at the first row so if the first row is all 0, it\r\n+          # causes problems\r\n+          tmp <- element[1, ]\r\n+          element[1, ] <- element[2, ]\r\n+          element[2, ] <- tmp\r\n+        }\r\n+      }\r\n+      \r\n+      \r\n+      melted <- reshape2::melt(elements[[name]], varnames = c("rowname", "Var"))\r\n+      \r\n+      \r\n+      plots[[name]] <- ggplot2::ggplot(melted, ggplot2::aes(x = Var, \r\n+                                                            y = value, group = rowname, colour = rowname)) + ggplot2::geom_line() + \r\n+        ggplot2::labs(x = xlab, y = name) + ggplot2::scale_colour_discrete(name = NULL) + \r\n+        ggplot2::ggtitle(main)\r\n+      \r\n+      if ((melted[1, "Var"] - melted[(dim(melted)[1]), "Var"]) > \r\n+          0)  {\r\n+        plots[[name]] <- plots[[name]] + ggplot2::scale_x_reverse()\r\n+      }\r\n+      \r\n+      do.call(gridExtra::grid.arrange, c(plots, list(nrow = nrow, \r\n+                                                     ncol = ncol)))\r\n+    }\r\n+  }\r\n+  \r\n+  \r\n+}\r\n'
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/Int_Funct.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/Int_Funct.R Mon Jul 30 10:33:03 2018 -0400
[
@@ -0,0 +1,236 @@
+beginTreatment <- function(name, Signal_data = NULL, Signal_info = NULL, 
+                           force.real = FALSE) {
+  
+  cat("Begin", name, "\n")
+  
+  
+  # Formatting the Signal_data and Signal_info -----------------------
+  
+  vec <- is.vector(Signal_data)
+  if (vec) {
+    Signal_data <- vec2mat(Signal_data)
+  }
+  if (is.vector(Signal_info)) {
+    Signal_info <- vec2mat(Signal_info)
+  }
+  if (!is.null(Signal_data)) {
+    if (!is.matrix(Signal_data)) {
+      stop("Signal_data is not a matrix.")
+    }
+    if (!is.complex(Signal_data) && !is.numeric(Signal_data)) {
+      stop("Signal_data contains non-numerical values.")
+    }
+  }
+  if (!is.null(Signal_info) && !is.matrix(Signal_info)) {
+    stop("Signal_info is not a matrix.")
+  }
+  
+  
+  Original_data <- Signal_data
+  
+  # Extract the real part of the spectrum ---------------------------
+  
+  if (force.real) {
+    if (is.complex(Signal_data)) {
+      Signal_data <- Re(Signal_data)
+    } else {
+      # The signal is numeric Im(Signal_data) is zero anyway so let's avoid
+      # using complex(real=...,imaginary=0) which would give a complex signal
+      # in endTreatment()
+      force.real <- FALSE
+    }
+  }
+  
+  
+  # Return the formatted data and metadata entries --------------------
+  
+  return(list(start = proc.time(), vec = vec, force.real = force.real, 
+              Original_data = Original_data, Signal_data = Signal_data, Signal_info = Signal_info))
+}
+
+binarySearch <- function(a, target, lower = TRUE) {
+  # search the index i in a such that a[i] == target 
+  # if it doesn't exists and lower, it searches the closer a[i] such that a[i] < target
+  # if !lower, it seraches the closer a[i] such that a[i] > target 
+  # a should be monotone but can be increasing or decreasing
+  
+  # if a is increasing INVARIANT: a[amin] < target < a[amax]
+  N <- length(a)
+  if ((a[N] - target) * (a[N] - a[1]) <= 0) {
+    return(N)
+  }
+  if ((a[1] - target) * (a[N] - a[1]) >= 0) {
+    return(1)
+  }
+  amin <- 1
+  amax <- N
+  while (amin + 1 < amax) {
+    amid <- floor((amin + amax)/2)
+    if ((a[amid] - target) * (a[amax] - a[amid]) < 0) {
+      amin <- amid
+    } else if ((a[amid] - target) * (a[amax] - a[amid]) > 0) {
+      amax <- amid
+    } else {
+      # a[amid] == a[amax] or a[amid] == target In both cases, a[amid] ==
+      # target
+      return(amid)
+    }
+  }
+  if (xor(lower, a[amin] > a[amax])) {
+    # (lower && a[amin] < a[amax]) || (!lower && a[min] > a[max]) 
+    # If increasing and we want the lower, we take amin 
+    # If decreasing and we want the bigger, we take amin too
+    return(amin)
+  } else {
+    return(amax)
+  }
+}
+
+checkArg <- function(arg, checks, can.be.null=FALSE) {
+  check.list <- list(bool=c(is.logical, "a boolean"),
+                     int =c(function(x){x%%1==0}, "an integer"),
+                     num =c(is.numeric, "a numeric"),
+                     str =c(is.character, "a string"),
+                     pos =c(function(x){x>0}, "positive"),
+                     pos0=c(function(x){x>=0}, "positive or zero"),
+                     l1 =c(function(x){length(x)==1}, "of length 1")
+  )
+  if (is.null(arg)) {
+    if (!can.be.null) {
+      stop(deparse(substitute(arg)), " is null.")
+    }
+  } else {
+    if (is.matrix(arg)) {
+      stop(deparse(substitute(arg)), " is not scalar.")
+    }
+    for (c in checks) {
+      if (!check.list[[c]][[1]](arg)) {
+        stop(deparse(substitute(arg)), " is not ", check.list[[c]][[2]], ".")
+      }
+    }
+  }
+}
+
+endTreatment <- function(name, begin_info, Signal_data) {
+  
+  # begin_info: object outputted from beginTreatment
+  
+  
+  # Formatting the entries and printing process time -----------------------
+  end_time <- proc.time()  # record it as soon as possible
+  start_time <- begin_info[["start"]]
+  delta_time <- end_time - start_time
+  delta <- delta_time[]
+  cat("End", name, "\n")
+  cat("It lasted", round(delta["user.self"], 3), "s user time,", round(delta["sys.self"],3),
+      "s system time and", round(delta["elapsed"], 3), "s elapsed time.\n")
+  
+  
+  if (begin_info[["force.real"]]) {
+    # The imaginary part is left untouched
+    i <- complex(real = 0, imaginary = 1)
+    Signal_data <- Signal_data + i * Im(begin_info[["Original_data"]])
+  }
+  
+  if (begin_info[["vec"]]) {
+    Signal_data <- Signal_data[1, ]
+  }
+  
+  # Return the formatted data and metadata entries --------------------
+  return(Signal_data)
+}
+
+Interpol <- function(t, y) {
+  # y: sample
+  # t : warping function
+  
+  m <- length(y)
+  # t <= m-1
+  # because if t > m-1, y[ti+1] will be NA when we compute g
+  valid <- 1 <= t & t <= m-1 # FIXME it was '<' in Bubble v2
+  s <- (1:m)[valid]
+  ti <- floor(t[s])
+  tr <- t[s] - ti
+  g <- y[ti + 1] - y[ti]
+  f <- y[ti] + tr * g
+  list(f=f, s=s, g=g)
+}
+
+vec2mat <- function(vec) {
+  
+  return(matrix(vec, nrow = 1, dimnames = list(c(1), names(vec)))) 
+  
+}
+
+getArg <- function(arg, info, argname, can.be.absent=FALSE) {
+  if (is.null(arg)) {
+    start <- paste("impossible to get argument", argname, "it was not given directly and");
+    if (!is.matrix(info)) {
+      stop(paste(start, "the info matrix was not given"))
+    }
+    if (!(argname %in% colnames(info))) {
+      if (can.be.absent) {
+        return(NULL)
+      } else {
+        stop(paste(start, "is not in the info matrix"))
+      }
+    }
+    if (nrow(info) < 1) {
+      stop(paste(start, "the info matrix has no row"))
+    }
+    arg <- info[1,argname]
+    if (is.na(arg)) {
+      stop(paste(start, "it is NA in the info matrix"))
+    }
+  }
+  return(arg)
+}
+
+binarySearch <- function(a, target, lower = TRUE) {
+  # search the index i in a such that a[i] == target 
+  # if it doesn't exists and lower, it searches the closer a[i] such that a[i] < target
+  # if !lower, it seraches the closer a[i] such that a[i] > target 
+  # a should be monotone but can be increasing or decreasing
+  
+  # if a is increasing INVARIANT: a[amin] < target < a[amax]
+  N <- length(a)
+  if ((a[N] - target) * (a[N] - a[1]) <= 0) {
+    return(N)
+  }
+  if ((a[1] - target) * (a[N] - a[1]) >= 0) {
+    return(1)
+  }
+  amin <- 1
+  amax <- N
+  while (amin + 1 < amax) {
+    amid <- floor((amin + amax)/2)
+    if ((a[amid] - target) * (a[amax] - a[amid]) < 0) {
+      amin <- amid
+    } else if ((a[amid] - target) * (a[amax] - a[amid]) > 0) {
+      amax <- amid
+    } else {
+      # a[amid] == a[amax] or a[amid] == target In both cases, a[amid] ==
+      # target
+      return(amid)
+    }
+  }
+  if (xor(lower, a[amin] > a[amax])) {
+    # (lower && a[amin] < a[amax]) || (!lower && a[min] > a[max]) 
+    # If increasing and we want the lower, we take amin 
+    # If decreasing and we want the bigger, we take amin too
+    return(amin)
+  } else {
+    return(amax)
+  }
+}
+
+# returns the discrete borders of the interval for a numeric vector a
+
+indexInterval <- function (a, from, to, inclusive=TRUE) {
+  # If inclusive and from <= to, we need to take the lower
+  # If not inclusive and from > to, we need to take the lower too
+  lowerFrom <- xor(inclusive, from > to)
+  fromIndex <- binarySearch(a, from, lowerFrom)
+  toIndex <- binarySearch(a, to, !lowerFrom)
+  return(fromIndex:toIndex)
+}
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/NmrPreprocessing_script.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/NmrPreprocessing_script.R Mon Jul 30 10:33:03 2018 -0400
[
b'@@ -0,0 +1,1244 @@\n+## ==========================\r\n+# Internal functions\r\n+## ==========================\r\n+\r\n+# beginTreatment \r\n+beginTreatment <- function(name, Signal_data = NULL, Signal_info = NULL, \r\n+                           force.real = FALSE) {\r\n+  \r\n+  cat("Begin", name, "\\n")\r\n+  \r\n+  \r\n+  # Formatting the Signal_data and Signal_info -----------------------\r\n+  \r\n+  vec <- is.vector(Signal_data)\r\n+  if (vec) {\r\n+    Signal_data <- vec2mat(Signal_data)\r\n+  }\r\n+  if (is.vector(Signal_info)) {\r\n+    Signal_info <- vec2mat(Signal_info)\r\n+  }\r\n+  if (!is.null(Signal_data)) {\r\n+    if (!is.matrix(Signal_data)) {\r\n+      stop("Signal_data is not a matrix.")\r\n+    }\r\n+    if (!is.complex(Signal_data) && !is.numeric(Signal_data)) {\r\n+      stop("Signal_data contains non-numerical values.")\r\n+    }\r\n+  }\r\n+  if (!is.null(Signal_info) && !is.matrix(Signal_info)) {\r\n+    stop("Signal_info is not a matrix.")\r\n+  }\r\n+  \r\n+  \r\n+  Original_data <- Signal_data\r\n+  \r\n+  # Extract the real part of the spectrum ---------------------------\r\n+  \r\n+  if (force.real) {\r\n+    if (is.complex(Signal_data)) {\r\n+      Signal_data <- Re(Signal_data)\r\n+    } else {\r\n+      # The signal is numeric Im(Signal_data) is zero anyway so let\'s avoid\r\n+      # using complex(real=...,imaginary=0) which would give a complex signal\r\n+      # in endTreatment()\r\n+      force.real <- FALSE\r\n+    }\r\n+  }\r\n+  \r\n+  \r\n+  # Return the formatted data and metadata entries --------------------\r\n+  \r\n+  return(list(start = proc.time(), vec = vec, force.real = force.real, \r\n+              Original_data = Original_data, Signal_data = Signal_data, Signal_info = Signal_info))\r\n+}\r\n+\r\n+# endTreatment \r\n+endTreatment <- function(name, begin_info, Signal_data) {\r\n+  \r\n+  # begin_info: object outputted from beginTreatment\r\n+  \r\n+  \r\n+  # Formatting the entries and printing process time -----------------------\r\n+  end_time <- proc.time()  # record it as soon as possible\r\n+  start_time <- begin_info[["start"]]\r\n+  delta_time <- end_time - start_time\r\n+  delta <- delta_time[]\r\n+  cat("End", name, "\\n")\r\n+  cat("It lasted", round(delta["user.self"], 3), "s user time,", round(delta["sys.self"],3),\r\n+      "s system time and", round(delta["elapsed"], 3), "s elapsed time.\\n")\r\n+  \r\n+  \r\n+  if (begin_info[["force.real"]]) {\r\n+    # The imaginary part is left untouched\r\n+    i <- complex(real = 0, imaginary = 1)\r\n+    Signal_data <- Signal_data + i * Im(begin_info[["Original_data"]])\r\n+  }\r\n+  \r\n+  if (begin_info[["vec"]]) {\r\n+    Signal_data <- Signal_data[1, ]\r\n+  }\r\n+  \r\n+  # Return the formatted data and metadata entries --------------------\r\n+  return(Signal_data)\r\n+}\r\n+\r\n+# checkArg \r\n+checkArg <- function(arg, checks, can.be.null=FALSE) {\r\n+  check.list <- list(bool=c(is.logical, "a boolean"),\r\n+                     int =c(function(x){x%%1==0}, "an integer"),\r\n+                     num =c(is.numeric, "a numeric"),\r\n+                     str =c(is.character, "a string"),\r\n+                     pos =c(function(x){x>0}, "positive"),\r\n+                     pos0=c(function(x){x>=0}, "positive or zero"),\r\n+                     l1 =c(function(x){length(x)==1}, "of length 1")\r\n+  )\r\n+  if (is.null(arg)) {\r\n+    if (!can.be.null) {\r\n+      stop(deparse(substitute(arg)), " is null.")\r\n+    }\r\n+  } else {\r\n+    if (is.matrix(arg)) {\r\n+      stop(deparse(substitute(arg)), " is not scalar.")\r\n+    }\r\n+    for (c in checks) {\r\n+      if (!check.list[[c]][[1]](arg)) {\r\n+        stop(deparse(substitute(arg)), " is not ", check.list[[c]][[2]], ".")\r\n+      }\r\n+    }\r\n+  }\r\n+}\r\n+\r\n+# getArg \r\n+getArg <- function(arg, info, argname, can.be.absent=FALSE) {\r\n+  if (is.null(arg)) {\r\n+    start <- paste("impossible to get argument", argname, "it was not given directly and");\r\n+    if (!is.matrix(info)) {\r\n+      stop(paste(start, "the info matrix was not given"))\r\n+    }\r\n+    if (!(argname %in% colnames(info))) {\r\n+      if (can.be.absent) {\r\n+        return(NULL)\r\n+      } else {\r\n+        stop(pas'..b'else  {\r\n+      colindex <- 1:m\r\n+    }\r\n+    \r\n+    Int <- vector("list", length(exclude.bc))\r\n+    for (i in 1:length(exclude.bc))  {\r\n+      Int[[i]] <- indexInterval(colindex, from = exclude.bc[[i]][1], \r\n+                                to = exclude.bc[[i]][2], inclusive = TRUE)\r\n+    }\r\n+    exclude_index <- unlist(Int)\r\n+  }\r\n+  \r\n+  # Baseline Correction implementation definition ----------------------\r\n+  \r\n+  # 2 Ways: either use the function asysm from the ptw package or by \r\n+  # built-in functions \r\n+  if (ptw.bc) {\r\n+    asysm <- ptw::asysm\r\n+  } else {\r\n+    difsmw <- function(y, lambda, w, d) {\r\n+      # Weighted smoothing with a finite difference penalty cf Eilers, 2003.\r\n+      # (A perfect smoother) \r\n+      # y: signal to be smoothed \r\n+      # lambda: smoothing parameter \r\n+      # w: weights (use0 zeros for missing values) \r\n+      # d: order of differences in penalty (generally 2)\r\n+      m <- length(y)\r\n+      W <- Matrix::Diagonal(x=w)\r\n+      E <- Matrix::Diagonal(m)\r\n+      D <- Matrix::diff(E, differences = d)\r\n+      C <- Matrix::chol(W + lambda * t(D) %*% D)\r\n+      x <- Matrix::solve(C, Matrix::solve(t(C), w * y))\r\n+      return(as.numeric(x))\r\n+      \r\n+    }\r\n+    asysm <- function(y, lambda, p, eps, exclude_index) {\r\n+      # Baseline estimation with asymmetric least squares\r\n+      # y: signal\r\n+      # lambda: smoothing parameter (generally 1e5 to 1e8)\r\n+      # p: asymmetry parameter (generally 0.001)\r\n+      # d: order of differences in penalty (generally 2)\r\n+      # eps: 1e-8 in ptw package\r\n+      m <- length(y)\r\n+      w <- rep(1, m)\r\n+      i <- 1\r\n+      repeat {\r\n+        z <- difsmw(y, lambda, w, d = 2)\r\n+        w0 <- w\r\n+        p_vect <- rep((1-p), m) # if y <= z + eps\r\n+        p_vect[y > z + eps | y < 0] <- p  # if y > z + eps | y < 0\r\n+        if(!is.null(exclude_index)){\r\n+          p_vect[exclude_index] <- 0 # if exclude area\r\n+        }\r\n+        \r\n+        w <- p_vect  \r\n+        # w <- p * (y > z + eps | y < 0) + (1 - p) * (y <= z + eps)\r\n+        \r\n+        if (sum(abs(w - w0)) == 0) {\r\n+          break\r\n+        }\r\n+        i <- i + 1\r\n+        if (i > maxIter) {\r\n+          warning("cannot find Baseline estimation in asysm")\r\n+          break\r\n+        }\r\n+      }\r\n+      return(z)\r\n+    }\r\n+  }\r\n+  \r\n+  # Baseline estimation ----------------------------------------------\r\n+  Baseline <- matrix(NA, nrow = nrow(Spectrum_data), ncol = ncol(Spectrum_data))\r\n+  \r\n+  # for (k in 1:n) {\r\n+  # Baseline[k, ] <- asysm(y = Spectrum_data[k, ], lambda = lambda, p = p, eps = eps)\r\n+  \r\n+  if (ptw.bc ){\r\n+    Baseline <- apply(Spectrum_data,1, asysm, lambda = lambda, p = p, \r\n+                      eps = eps)\r\n+  }else {\r\n+    Baseline <- apply(Spectrum_data,1, asysm, lambda = lambda, p = p, \r\n+                      eps = eps, exclude_index = exclude_index)\r\n+  }\r\n+  \r\n+  \r\n+  Spectrum_data <- Spectrum_data - t(Baseline)\r\n+  # }\r\n+  \r\n+  # Data finalisation ----------------------------------------------\r\n+  Spectrum_data <- endTreatment("BaselineCorrection", begin_info, Spectrum_data)  # FIXME create removeImaginary filter ??\r\n+  \r\n+  if (returnBaseline) {\r\n+    return(list(Spectrum_data = Spectrum_data, Baseline = Baseline))\r\n+  } else {\r\n+    return(Spectrum_data)\r\n+  }\r\n+}\r\n+\r\n+\r\n+\r\n+## ====================================================\r\n+# NegativeValuesZeroing   \r\n+## ====================================================\r\n+\r\n+NegativeValuesZeroing <- function(Spectrum_data) {\r\n+  # Data initialisation and checks ----------------------------------------------\r\n+  begin_info <- beginTreatment("NegativeValuesZeroing", Spectrum_data, force.real = T)\r\n+  Spectrum_data <- begin_info[["Signal_data"]]\r\n+  \r\n+  # NegativeValuesZeroing ----------------------------------------------\r\n+  Spectrum_data[Spectrum_data < 0] <- 0\r\n+  \r\n+  # Data finalisation ----------------------------------------------\r\n+  return(endTreatment("NegativeValuesZeroing", begin_info, Spectrum_data))\r\n+}\r\n+\r\n+\r\n'
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/NmrPreprocessing_wrapper.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/NmrPreprocessing_wrapper.R Mon Jul 30 10:33:03 2018 -0400
[
b'@@ -0,0 +1,411 @@\n+#!/usr/local/public/bin/Rscript --vanilla --slave --no-site-file\r\n+\r\n+## 170116_NmrPreprocessing.R\r\n+## Manon Martin and Marie Tremblay-Franco\r\n+\r\n+##======================================================\r\n+##======================================================\r\n+# Preamble\r\n+##======================================================\r\n+##======================================================\r\n+\r\n+runExampleL <- FALSE\r\n+\r\n+\r\n+##------------------------------\r\n+## Options\r\n+##------------------------------\r\n+strAsFacL <- options()$stringsAsFactors\r\n+options(stringsAsFactors = FALSE)\r\n+\r\n+##------------------------------\r\n+## Libraries laoding\r\n+##------------------------------\r\n+library(batch)\r\n+library(ptw)\r\n+library(Matrix)\r\n+library(ggplot2)\r\n+library(gridExtra)\r\n+library(reshape2)\r\n+\r\n+\r\n+# R script call\r\n+source_local <- function(fname)\r\n+{\r\n+\targv <- commandArgs(trailingOnly = FALSE)\r\n+\tbase_dir <- dirname(substring(argv[grep("--file=", argv)], 8))\r\n+\tsource(paste(base_dir, fname, sep="/"))\r\n+}\r\n+#Import the different functions\r\n+source_local("NmrPreprocessing_script.R")\r\n+source_local("DrawFunctions.R")\r\n+\r\n+##------------------------------\r\n+## Script\r\n+##------------------------------\r\n+runExampleL <- FALSE\r\n+\r\n+\r\n+if(!runExampleL)\r\n+  argLs <- parseCommandArgs(evaluate=FALSE)\r\n+\r\n+sink(argLs$logOut)\r\n+\r\n+\r\n+##------------------------------\r\n+## Errors ?????????????????????\r\n+##------------------------------\r\n+\r\n+\r\n+##------------------------------\r\n+## Constants\r\n+##------------------------------\r\n+topEnvC <- environment()\r\n+flagC <- "\\n"\r\n+\r\n+\r\n+\r\n+\r\n+# log file\r\n+# print(argLs[["logOut"]])\r\n+\r\n+## Starting\r\n+cat("\\nStart of \'Preprocessing\' Galaxy module call: ", as.character(Sys.time()), "\\n", sep = "")\r\n+\r\n+\r\n+##======================================================\r\n+##======================================================\r\n+## Parameters Loading\r\n+##======================================================\r\n+##======================================================\r\n+\r\n+# graphical inputs\r\n+FirstOPCGraph <- argLs[["FirstOPCGraph"]]\r\n+SSGraph <- argLs[["SSGraph"]]\r\n+ApodGraph <- argLs[["ApodGraph"]]\r\n+FTGraph <- argLs[["FTGraph"]]\r\n+SRGraph <- argLs[["SRGraph"]]\r\n+ZeroOPCGraph <- argLs[["ZeroOPCGraph"]]\r\n+BCGraph <- argLs[["BCGraph"]]\r\n+FinalGraph <- argLs[["FinalGraph"]]\r\n+\r\n+\r\n+# 1rst order phase correction ------------------------\r\n+  # Inputs\r\n+\t## Data matrix\r\n+Fid_data0 <- read.table(argLs[["dataMatrixFid"]],header=TRUE, check.names=FALSE, sep=\'\\t\')\r\n+# Fid_data0 <- Fid_data0[,-1]\r\n+Fid_data0 <- as.matrix(Fid_data0)\r\n+\r\n+\t## Samplemetadata\r\n+samplemetadataFid <- read.table(argLs[["sampleMetadataFid"]],check.names=FALSE,header=TRUE,sep="\\t")\r\n+samplemetadataFid <- as.matrix(samplemetadataFid)\r\n+\r\n+\r\n+# water and solvent(s) correction ------------------------\r\n+  # Inputs\r\n+lambda <- argLs[["lambda"]]\r\n+\r\n+\r\n+\r\n+# apodization -----------------------------------------\r\n+  # Inputs\r\n+phase=0\r\n+rectRatio=1/2\r\n+gaussLB=1\r\n+expLB=1\r\n+apodization <- argLs[["apodizationMethod"]]\r\n+\r\n+if (apodization==\'exp\'){\r\n+  expLB <- argLs[["expLB"]]\r\n+  } else if (apodization==\'cos2\'){\r\n+  phase <- argLs[["phase"]]\r\n+  } else if (apodization==\'hanning\'){\r\n+  phase <- argLs[["phase"]]\r\n+  } else if (apodization==\'hamming\'){\r\n+  phase <- argLs[["phase"]]\r\n+  } else if (apodization==\'blockexp\'){\r\n+  rectRatio <- argLs[["rectRatio"]]\r\n+  expLB <- argLs[["expLB"]]\r\n+  } else if (apodization==\'blockcos2\'){\r\n+  rectRatio <- argLs[["rectRatio"]]\r\n+  } else if (apodization==\'gauss\'){\r\n+  rectRatio <- argLs[["rectRatio"]]\r\n+  gaussLB <- argLs[["gaussLB"]]\r\n+  }\t\t\r\n+\r\n+\r\n+# Fourier transform ----------------------------------\r\n+  # Inputs\r\n+\r\n+\r\n+# Zero Order Phase Correction -------------------------------\r\n+  # Inputs\r\n+\r\n+angle = NULL\r\n+excludeZOPC = NULL\r\n+\r\n+\r\n+zeroOrderPhaseMethod <- argLs[["zeroOrderPhaseMethod"]]\r\n+\t\t\t\t\t\t\t\t\t\t   \r\n+if (zeroOrderPhaseMethod==\'manual\'){\r\n+  angle <- argLs[["angle"]]\r\n+}\r\n+\r\n+excludeZone'..b'_data, subtype = "stacked",\r\n+             ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, \r\n+             xlab = "Frequency", num.stacked = 4, \r\n+             main = title, createWindow=FALSE)\r\n+}\r\n+\r\n+\r\n+\r\n+# ZeroOrderPhaseCorrection ---------------------------------\r\n+Spectrum_data  <- ZeroOrderPhaseCorrection(Spectrum_data, type.zopc = zeroOrderPhaseMethod,\r\n+                                           plot_rms = NULL, returnAngle = FALSE,\r\n+                                           createWindow = TRUE,angle = angle,\r\n+                                           plot_spectra = FALSE,\r\n+                                           ppm.zopc = TRUE, exclude.zopc = excludeZOPC)\r\n+\r\n+\r\n+# InternalReferencing ---------------------------------\r\n+# if (shiftReferencing=="YES") {\r\n+Spectrum_data <- InternalReferencing(Spectrum_data, samplemetadataFid, method = "max", range = shiftReferencingRange,\r\n+                                     ppm.value = ppmvalue, shiftHandling = shiftHandling, ppm.ir = TRUE,\r\n+                                     fromto.RC = shiftReferencingRangeList, pc = pctNearValue)\r\n+\r\n+if (SRGraph == "YES") {\r\n+  title = "Spectra after Shift Referencing"\r\n+  DrawSignal(Spectrum_data, subtype = "stacked",\r\n+             ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, \r\n+             xlab = "Frequency", num.stacked = 4, \r\n+             main = title, createWindow=FALSE)\r\n+}\r\n+\r\n+# }\r\n+\r\n+if (ZeroOPCGraph == "YES") {\r\n+title = "Spectra after Zero Order Phase Correction"\r\n+DrawSignal(Spectrum_data, subtype = "stacked",\r\n+           ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, \r\n+           xlab = "Frequency", num.stacked = 4, \r\n+           main = title, createWindow=FALSE)\r\n+}\r\n+\r\n+\r\n+# BaselineCorrection ---------------------------------\t\t\t\t\t\t\t\t\t \r\n+Spectrum_data <- BaselineCorrection(Spectrum_data, ptw.bc = TRUE, lambda.bc = lambdaBc, \r\n+                                    p.bc = pBc, eps = epsilon, ppm.bc = TRUE, \r\n+                                    exclude.bc = excludeBC,\r\n+                                    returnBaseline = F) \r\n+\r\n+\r\n+\r\n+if (BCGraph == "YES") {\r\n+title = "Spectra after Baseline Correction"\r\n+DrawSignal(Spectrum_data, subtype = "stacked",\r\n+           ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, \r\n+           xlab = "Frequency", num.stacked = 4, \r\n+           main = title, createWindow=FALSE)\r\n+}\r\n+\r\n+\r\n+# NegativeValuesZeroing ---------------------------------\r\n+if (NegativetoZero=="YES") {\r\n+  Spectrum_data <- NegativeValuesZeroing(Spectrum_data)\r\n+}\r\n+\r\n+if (FinalGraph == "YES") {\r\n+  title = "Final preprocessed spectra"\r\n+  DrawSignal(Spectrum_data, subtype = "stacked",\r\n+             ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T, \r\n+             xlab = "Frequency", num.stacked = 4, \r\n+             main = title, createWindow=FALSE)\r\n+}\r\n+\r\n+invisible(dev.off())\r\n+\r\n+\r\n+data_variable <- matrix(NA, nrow = 1, ncol = dim(Spectrum_data)[2], dimnames = list("ID", NULL)) \r\n+colnames(data_variable) <- colnames(Spectrum_data)\r\n+data_variable[1,] <- colnames(data_variable)\r\n+\r\n+\r\n+##======================================================\r\n+##======================================================\r\n+## Saving\r\n+##======================================================\r\n+##======================================================\r\n+\r\n+# Data Matrix\r\n+write.table(t(Re(Spectrum_data)),file=argLs$dataMatrix, quote=FALSE, row.names=TRUE, sep="\\t", col.names=TRUE)\r\n+\r\n+# Variable metadata\r\n+write.table(data_variable,file=argLs$variableMetadata, quote=FALSE, row.names=TRUE, sep="\\t", col.names=TRUE)\r\n+\r\n+# log file\r\n+# write.table(t(data.frame(argLs)), file = argLs$logOut, col.names = FALSE, quote=FALSE)\r\n+\r\n+# input arguments\r\n+cat("\\n INPUT and OUTPUT ARGUMENTS :\\n")\r\n+\r\n+argLs\r\n+\r\n+\r\n+## Ending\r\n+\r\n+cat("\\nEnd of \'Preprocessing\' Galaxy module call: ", as.character(Sys.time()), sep = "")\r\n+\r\n+sink()\r\n+\r\n+options(stringsAsFactors = strAsFacL)\r\n+\r\n+rm(list = ls())\r\n'
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/NmrPreprocessing_xml.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/NmrPreprocessing_xml.xml Mon Jul 30 10:33:03 2018 -0400
b
b'@@ -0,0 +1,591 @@\n+<tool id="NMR_Preprocessing" name="NMR_Preprocessing" version="1.2.0">\r\n+\t<description> Preprocessing of 1D NMR spectra </description>\r\n+\r\n+    <stdio>\r\n+        <exit_code range="1:" level="fatal" />\r\n+    </stdio>\r\n+\t\r\n+  \t<command>\r\n+  \t    ## Wrapper\r\n+        Rscript $__tool_directory__/NmrPreprocessing_wrapper.R\r\n+\r\n+\t## Data matrix of FID spectra\r\n+\t\tdataMatrixFid $dataMatrixFid\r\n+\t\t\t## Sample metadata matrix\r\n+\t\tsampleMetadataFid $sampleMetadataFid\r\n+\t\t\r\n+\t\t\r\n+\t\t## First order phase correction\r\n+\t\t\t## Graphical display\r\n+\t\tFirstOPCGraph $GDC.FirstOPCGraph\r\n+\t\t\r\n+\t\t## Water and / or solvents suppression\r\n+\t\t    ## Smoothing parameter\r\n+        lambda $SS.lambda\r\n+\r\n+\t\t\t## Graphical display\r\n+\t\tSSGraph $SS.SSGraph\r\n+\t\t\r\n+\t\t\r\n+\t\t## Apodization\r\n+\t\t\t\t## Graphical display\r\n+\t\tApodGraph $Apod.ApodGraph\r\n+\t\r\n+\t    apodizationMethod $Apod.apodizationMethod.method\r\n+\t\t    #if $Apod.apodizationMethod.method == "exp":\r\n+\t\t\t    ## Line broadening for the exponential window\r\n+\t\t\t    expLB $Apod.apodizationMethod.expLB \r\n+\t\t    #end if\r\n+\t\t    #if $Apod.apodizationMethod.method == "cos2":\r\n+\t\t\t    ## Phase\r\n+\t\t\t    phase $Apod.apodizationMethod.phase\r\n+\t\t    #end if\r\n+\t\t    #if $Apod.apodizationMethod.method == "hanning":\r\n+\t\t\t    ## Phase\r\n+\t\t\t    phase $Apod.apodizationMethod.phase\r\n+\t\t    #end if\r\n+\t\t    #if $Apod.apodizationMethod.method == "hamming":\r\n+\t\t\t    ## Phase\r\n+\t\t\t    phase $Apod.apodizationMethod.phase\r\n+\t\t    #end if\r\n+\t\t    #if $Apod.apodizationMethod.method == "blockexp":\r\n+\t\t\t    ## Proportion of signal in the window\r\n+\t\t\t    rectRatio $Apod.apodizationMethod.rectRatio\r\n+\t\t\t    expLB $Apod.apodizationMethod.expLB \r\n+\t\t    #end if\t\t\t\r\n+\t\t    #if $Apod.apodizationMethod.method == "blockcos2":\r\n+\t\t\t    ## Proportion of signal in the window\r\n+\t\t\t    rectRatio $Apod.apodizationMethod.rectRatio\r\n+\t\t    #end if\t\t\t\r\n+\t\t    #if $Apod.apodizationMethod.method == "gauss":\r\n+\t\t\t    ## Line broadening for the gaussian window\r\n+\t\t\t    gaussLB $Apod.apodizationMethod.gaussLB \r\n+\t\t    #end if\r\n+\t\r\n+\t\t## Fourier transform\r\n+\t\t\t## Graphical display\r\n+\t\t\tFTGraph $FT.FTGraph\r\n+\t\t\r\n+\t\t\r\n+\t\t\r\n+\t\t\r\n+\t\t## Zero order phase correction\r\n+\t\t## Graphical display\r\n+\t\t\tZeroOPCGraph $ZOPC.ZeroOPCGraph\r\n+\t\t\t\r\n+\t\tzeroOrderPhaseMethod $ZOPC.zeroOrderPhaseMethod\r\n+\t\t\r\n+\t\texcludeZoneZeroPhase.choice ${ZOPC.excludeZoneZeroPhase.choice}\r\n+        #if str($ZOPC.excludeZoneZeroPhase.choice) == "YES":\r\n+            #for $i in $ZOPC.excludeZoneZeroPhase.conditions:\r\n+                excludeZoneZeroPhase_left ${i.excludeZoneZeroPhase_left}\r\n+                excludeZoneZeroPhase_right ${i.excludeZoneZeroPhase_right}\r\n+            #end for\r\n+        #end if\t\t\r\n+\r\n+    ## Shift referencing\r\n+  \t\t\t## Graphical display\r\n+  \t\t\tSRGraph $SR.SRGraph\r\n+  \t\t\r\n+  \t\t\t## Definition of the search zone\r\n+  \t\t\tshiftReferencingRange $SR.shiftReferencingRange.method\r\n+  \t\t\t#if $SR.shiftReferencingRange.method == "nearvalue":\r\n+  \t\t\t\tpctNearValue $SR.shiftReferencingRange.pctNearValue\r\n+  \t\t\t#end if\r\n+  \t\t\t#if $SR.shiftReferencingRange.method == "window":\r\n+  \t\t\t\t#for $i in $SR.shiftReferencingRange.conditions:\r\n+                 \t \tshiftReferencingRangeLeft ${i.shiftReferencingRangeLeft}\r\n+                 \t \tshiftReferencingRangeRight ${i.shiftReferencingRangeRight}\r\n+                 \t #end for\r\n+  \t\t\t#end if\r\n+  \t\t\tshiftHandling $SR.shiftHandling\r\n+  \t\t\tppmvalue $SR.ppmvalue \r\n+\t\t\r\n+\t\t## Baseline correction\r\n+\t\t## Graphical display\r\n+\t\t\tBCGraph $BC.BCGraph\r\n+\t\t\t\r\n+\t\t  lambdaBc $BC.lambdaBc\r\n+\t\t  pBc $BC.pBc\r\n+\t\t  epsilon $BC.epsilon\r\n+\t\t\r\n+\t\texcludeZoneBC.choice ${BC.excludeZoneBC.choice}\r\n+        #if str($BC.excludeZoneBC.choice) == "YES":\r\n+            #for $i in $BC.excludeZoneBC.conditions:\r\n+                excludeZoneBC_left ${i.excludeZoneBC_left}\r\n+                excludeZoneBC_right ${i.excludeZoneBC_right}\r\n+            #end for\r\n+        #end if\t\t\r\n+\r\n+\t\t\r\n+\t\t## sets negative intensities to zero\r\n+\t\tNegativetoZero $NZ.NegativetoZero\r\n+\t\t\t\t\r\n'..b': The first part of the signal (described by the proportion of signal in the window) is left unchanged and the second is multiplied by exp(-t/LineBroadening) starting at value 1.\r\n+\r\n+* blockcos2: The first part is left unchanged as with blockexp and the second part is multiplied by a cosinus squared where its value starts at 1 at the end of the block and ends at 0 at the end of the signal.\r\n+\r\n+* gauss: The signal is multiplied by a gaussian window centered at the beginning of the FID and with sigma=1/LineBroadening.\r\n+\r\n+* hanning: The signal is multiplied by a hanning window : 0.5 + 0.5 cos.\r\n+\r\n+* hamming: The signal is multiplied by a hamming window : 0.54 + 0.46 cos.\r\n+\r\n+\r\n+\r\n+\r\n+**Zero Order Phase Correction**\r\n+-----------------------------------\r\n+\r\n+**Zero Order Phase correction method**:\r\n+\r\n+* rms: A positiveness criterion is applied on the spectrum with a quantile probability parameter to trim the values.\r\n+\r\n+* max: Optimization of the maximal spectral intensity.\r\n+\r\n+\r\n+**Exclusion area(s) for the Zero Order Phase Correction**: enables to optimize the criterion with excluded spectral window(s), by default the water region is excluded.\r\n+\r\n+\r\n+**Shift Referencing**\r\n+----------------------\r\n+\r\n+The **searching window** can be adapted:\r\n+\r\n+* nearvalue: the search concentrates around the value of the reference peak in ppm.\r\n+\r\n+* all: search accross the whole ppm axis.\r\n+\r\n+* window: the search is operated in the windows defined by the Search_zone bounds.\r\n+\r\n+\r\n+**shiftHandling**: spectra can be shifted differently, we can handle misalignment of the left and right of the spectrum by different ways:\r\n+\r\n+* zerofilling: The extremities at which a spectrum is not defined are replaced by 0. It makes sense since in practice the spectrum is close to zero at the extremities.\r\n+\r\n+* NAfilling: The extremities at which a spectrum is not defined are replaced by NA. \r\n+\r\n+* circular: The spectra are shifted circularly which means that the end of a spectrum is reproduced at the beginning. \r\n+\r\n+* cut: The ppm values for which some spectra are not defined are removed.\r\n+\r\n+\r\n+**value of the reference peak**: the value in ppm of the reference peak. By default the value is 0 ppm.\r\n+\r\n+\r\n+\r\n+**Baseline Correction**\r\n+----------------------------\r\n+\r\n+**Smoothing parameter**: the larger it is, the smoother the estimated baseline will be.\r\n+\r\n+**Asymmetry parameter**:  the smaller it is, the less the estimated baseline will try to follow peaks when it is under the spectrum and the more it will try to be under the spectrum.\r\n+\r\n+**numerical precision**:  numerical precision for convergence when estimating the baseline. \r\n+\r\n+**Exclusion area(s) for the Baseline Correction**: enables to optimize the criterion with excluded spectral window(s), by default the water region is excluded.\r\n+\r\n+\r\n+\r\n+**Negative intensities to Zero**\r\n+------------------------------------\r\n+**Set negative intensities to zero**: the set of negative intensities to zero is optional.\r\n+\r\n+\r\n+------------\r\n+Output files\r\n+------------\r\n+\r\n+NMR_Preprocessing_dataMatrix\r\n+\t| tabular output\r\n+\t| Data matrix with n rows (descriptors) and p columns (samples) containing the preprocessed spectra.\r\n+\t|\r\n+\r\n+NMR_Preprocessing_variableMetadata\r\n+\t| tabular output\r\n+\t| Data matrix with 1 row (ppm value) and p columns (descriptors).\r\n+\t|\r\n+\t\r\n+NMR_Preprocessing_log\r\n+\t| text output\r\n+\t| Contains warnings and the input parameters\r\n+\t|\r\n+\t\r\n+NMR_Preprocessing_graph.pdf\r\n+\t| pdf output\r\n+\t| line plots of preprocessed spectra\r\n+\t|\r\n+\r\n+   </help>\r\n+    \r\n+   <citations>\r\n+     \r\n+     <citation type="bibtex">@PhDThesis{Rousseau2011,\r\n+      title = {Statistical contribution to the analysis of metabonomics data in $^1$H NMR spectroscopy},\r\n+      author = {Rousseau, R.},\r\n+      school = {Institut de Statistique, Biostatistique et Sciences Actuarielles, Universit{\\\'e} catholique de Louvain},\r\n+      year = {2011}}\r\n+      </citation>\r\n+      \r\n+    </citations>\r\n+ \r\n+</tool>\r\n'
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/README.rst
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/README.rst Mon Jul 30 10:33:03 2018 -0400
b
@@ -0,0 +1,23 @@
+
+Changelog/News
+--------------
+**Version 2017-11-28 - 28/11/2017**
+
+* Updated R scripts and the help section of NMR_ReadFids and NMR_preprocessing
+* Added sections
+* Created a variableMetadata file in output of the NMR_preprocessing module
+* Homogenised the input-output file names with the other modules
+* Suppressed the option ptw for the baseline correction, set to TRUE all the time now
+* Shift referencing: other values than 0 are admitted
+* The log file recovers the input/output parameters
+* Added an exclusion zone for the computation of the Baseline Correction criterion
+* Switched Internal Referencing (goes second) and Zero Order Phase Correction (goes first)
+
+
+
+**Version 2017-02-13 - 13/02/2017**
+* Implementation of NMR_ReadFids and NMR_preprocessing
+
+
+Test Status
+-----------
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/ReadFids.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/ReadFids.R Mon Jul 30 10:33:03 2018 -0400
[
b'@@ -0,0 +1,382 @@\n+################################################################################################\r\n+#\r\n+#   Read FIDs in Bruker format\r\n+#\r\n+#\r\n+################################################################################################\r\n+\r\n+# ReadFid ==============================================================================\r\n+ReadFid <- function(path) {\r\n+  \r\n+  # Read 1D FID using Bruker XWinNMR and TopSpin format.  It is inspired of the\r\n+  # matNMR matlab library which deals with 2D FID and also other formats\r\n+  # Read also the parameters in the acqus file\r\n+  \r\n+  paramFile <- file.path(path, "acqus")\r\n+  # BYTEORDA: 0 -> Little Endian 1 -> Big Endian\r\n+  params <- readParams(paramFile, c("TD", "BYTORDA", "DIGMOD", "DECIM", "DSPFVS", \r\n+                                    "SW_h", "SW", "O1"))\r\n+  \r\n+  if (params[["DSPFVS"]] >= 20) {\r\n+    # The group delay first order phase correction is given directly from version 20\r\n+    grpdly <- readParams(paramFile, c("GRPDLY"))\r\n+    params[["GRPDLY"]] <- grpdly[["GRPDLY"]]\r\n+  }\r\n+  TD <- params[["TD"]]\r\n+  endianness <- if (params$BYTORDA) \r\n+    "big" else "little"\r\n+  if (TD%%2 != 0) {\r\n+    stop(paste("Only even numbers are allowed for size in TD because it is complex \r\n+               data with the real and imaginary part for each element.", \r\n+               "The TD value is in the", paramFile, "file"))\r\n+  }\r\n+  \r\n+  # Interpret params Dwell Time, time between 2 data points in the FID\r\n+  params[["DT"]] <- 1/(2 * params[["SW_h"]])\r\n+  \r\n+  # Read fid\r\n+  fidFile <- file.path(path, "fid")\r\n+  fidOnDisk <- readBin(fidFile, what = "int", n = TD, size = 4L, endian = endianness)\r\n+  \r\n+  # Real size that is on disk (it should be equal to TD2, except for TopSpin/Bruker\r\n+  # (which is our case) according to matNMR as just discussed\r\n+  TDOnDisk <- length(fidOnDisk)\r\n+  if (TDOnDisk < TD) {\r\n+    warning("Size is smaller than expected, the rest is filled with zero so the size is the same for every fid")\r\n+    fidGoodSize <- sapply(vector("list", length = TD), function(x) 0)\r\n+    fidGoodSize[1:TDOnDisk] <- fidOnDisk\r\n+    \r\n+  } else if (TDOnDisk > TD) {\r\n+    warning("Size is bigger than expected, the rest ignored so the size is the same for every fid")\r\n+    fidGoodSize <- fidOnDisk(1:TD)\r\n+    \r\n+  } else {\r\n+    fidGoodSize <- fidOnDisk\r\n+  }\r\n+  \r\n+  fidRePart <- fidGoodSize[seq(from = 1, to = TD, by = 2)]\r\n+  fidImPart <- fidGoodSize[seq(from = 2, to = TD, by = 2)]\r\n+  fid <- complex(real = fidRePart, imaginary = fidImPart)\r\n+  \r\n+  return(list(fid = fid, params = params))\r\n+}\r\n+\r\n+\r\n+\r\n+\r\n+# getDirsContainingFid ==============================================================================\r\n+getDirsContainingFid <- function(path) {\r\n+  subdirs <- dir(path, full.names = TRUE)\r\n+  if (length(subdirs) > 0) {\r\n+    cond <- sapply(subdirs, function(x)  {\r\n+      content <- dir(x)\r\n+      # subdirs must contain fid, acqu and acqus files\r\n+      return("fid" %in% content && "acqu" %in% content && "acqus" %in% content)\r\n+    })\r\n+    subdirs <- subdirs[cond]\r\n+  }\r\n+  return(subdirs)\r\n+}\r\n+\r\n+\r\n+\r\n+\r\n+\r\n+\r\n+# beginTreatment ==============================================================================\r\n+\r\n+beginTreatment <- function(name, Signal_data = NULL, Signal_info = NULL, \r\n+                           force.real = FALSE) {\r\n+  \r\n+  cat("Begin", name, "\\n")\r\n+  \r\n+  \r\n+  # Formatting the Signal_data and Signal_info -----------------------\r\n+  \r\n+  vec <- is.vector(Signal_data)\r\n+  if (vec) {\r\n+    Signal_data <- vec2mat(Signal_data)\r\n+  }\r\n+  if (is.vector(Signal_info)) {\r\n+    Signal_info <- vec2mat(Signal_info)\r\n+  }\r\n+  if (!is.null(Signal_data)) {\r\n+    if (!is.matrix(Signal_data)) {\r\n+      stop("Signal_data is not a matrix.")\r\n+    }\r\n+    if (!is.complex(Signal_data) && !is.numeric(Signal_data)) {\r\n+      stop("Signal_data contains non-numerical values.")\r\n+    }\r\n+  }\r\n+  if (!is.null(Signal_info) && !is.matrix(Signal_info)) {\r\n+    stop("S'..b'ttern <- paste("\\\\$", paramName, "=", sep = "")\r\n+    occurences <- grep(pattern, lines)\r\n+    if (length(occurences) == 0L)  {\r\n+      stop(paste(file, "has no field", pattern))\r\n+    }\r\n+    if (length(occurences) > 1L) {\r\n+      warning(paste(file, "has more that one field", pattern, " I take the first one"))\r\n+    }\r\n+    line <- lines[occurences[1]]\r\n+    \r\n+    # Cut beginning and end of the line \'##$TD= 65536\' -> \'65536\'\r\n+    igual = as.numeric(regexpr("=", line))\r\n+    \r\n+    first <- igual\r\n+    while (first <= nchar(line) & !isDigit(substr(line, first, first))) {\r\n+      first <- first + 1\r\n+    }\r\n+    last <- nchar(line)\r\n+    while (last > 0 & !isDigit(substr(line, last, last)))  {\r\n+      last <- last - 1\r\n+    }\r\n+    params[paramName] <- as.numeric(substr(line, first, last))\r\n+  }\r\n+  return(params)\r\n+}\r\n+\r\n+\r\n+\r\n+# ReadFids ==============================================================================\r\n+ReadFids <- function(path, l = 1, subdirs = FALSE) {\r\n+  \r\n+  # Data initialisation and checks ----------------------------------------------\r\n+  begin_info <- beginTreatment("ReadFids")\r\n+  checkArg(path, c("str"))\r\n+  checkArg(l, c("pos"))\r\n+  if (file.exists(path) == FALSE) {\r\n+    stop(paste("Invalid path:", path))\r\n+  }\r\n+  \r\n+  \r\n+  # Extract the FIDs and their info ----------------------------------------------\r\n+  \r\n+  if (subdirs == FALSE) {\r\n+    fidDirs <- getDirsContainingFid(path)\r\n+    n <- length(fidDirs)\r\n+    if (n == 0L)  {\r\n+      stop(paste("No valid fid in", path))\r\n+    }\r\n+    fidNames <- sapply(X = fidDirs, FUN = getTitle, l = l, subdirs = subdirs,  USE.NAMES = F)\r\n+    for (i in 1:n)  {\r\n+      fidList <- ReadFid(fidDirs[i])\r\n+      fid <- fidList[["fid"]]\r\n+      info <- fidList[["params"]]\r\n+      m <- length(fid)\r\n+      if (i == 1)  {\r\n+        Fid_data <- matrix(nrow = n, ncol = m, dimnames = list(fidNames, \r\n+                                                               info[["DT"]] * (0:(m - 1))))\r\n+        Fid_info <- matrix(nrow = n, ncol = length(info), dimnames = list(fidNames, \r\n+                                                                          names(info)))\r\n+      }\r\n+      Fid_data[i, ] <- fid\r\n+      Fid_info[i, ] <- unlist(info)\r\n+    }\r\n+    \r\n+  } else  {\r\n+    maindirs <- dir(path, full.names = TRUE)\r\n+    Fid_data <- numeric()\r\n+    Fid_info <- numeric()\r\n+    \r\n+    fidDirs <- c()\r\n+    for (j in maindirs) {\r\n+      fd <- getDirsContainingFid(j)\r\n+      n <- length(fd)\r\n+      if (n > 0L)  {\r\n+        fidDirs <- c(fidDirs, fd)\r\n+      } else {warning(paste("No valid fid in",j ))}\r\n+    }\r\n+    \r\n+    fidNames <- sapply(X = fidDirs, FUN = getTitle, l = l, subdirs = subdirs, USE.NAMES = F)\r\n+    for (i in 1:length(fidNames))  {\r\n+      fidList <- ReadFid(fidDirs[i])\r\n+      fid <- fidList[["fid"]]\r\n+      info <- fidList[["params"]]\r\n+      m <- length(fid)\r\n+      if (i == 1)  {\r\n+        Fid_data <- matrix(nrow = length(fidNames), ncol = m, dimnames = list(fidNames, \r\n+                                                                              info[["DT"]] * (0:(m - 1))))\r\n+        Fid_info <- matrix(nrow = length(fidNames), ncol = length(info), dimnames = list(fidNames, \r\n+                                                                                         names(info)))\r\n+      }\r\n+      Fid_data[i, ] <- fid\r\n+      Fid_info[i, ] <- unlist(info)\r\n+    }\r\n+    \r\n+    \r\n+  }\r\n+  \r\n+  # Check for non-unique IDs ----------------------------------------------\r\n+  NonnuniqueIds <- sum(duplicated(row.names(Fid_data)))\r\n+  cat("dim Fid_data: ", dim(Fid_data), "\\n")\r\n+  cat("IDs: ", rownames(Fid_data), "\\n")\r\n+  cat("non-unique IDs?", NonnuniqueIds, "\\n")\r\n+  if (NonnuniqueIds > 0) {\r\n+    warning("There are duplicated IDs: ", Fid_data[duplicated(Fid_data)])\r\n+  }\r\n+  \r\n+  \r\n+  # Return the results ----------------------------------------------\r\n+  return(list(Fid_data = endTreatment("ReadFids", begin_info, Fid_data), Fid_info = Fid_info))\r\n+  \r\n+}\r\n+\r\n+\r\n'
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/ReadFids_Manon.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/ReadFids_Manon.R Mon Jul 30 10:33:03 2018 -0400
[
b'@@ -0,0 +1,386 @@\n+################################################################################################\r\n+#\r\n+#   Read FIDs in Bruker format\r\n+#\r\n+#\r\n+################################################################################################\r\n+\r\n+# ReadFid ==============================================================================\r\n+ReadFid <- function(path) {\r\n+  \r\n+  # Read 1D FID using Bruker XWinNMR and TopSpin format.  It is inspired of the\r\n+  # matNMR matlab library which deals with 2D FID and also other formats\r\n+  # Read also the parameters in the acqus file\r\n+  \r\n+  paramFile <- file.path(path, "acqus")\r\n+  # BYTEORDA: 0 -> Little Endian 1 -> Big Endian\r\n+  params <- readParams(paramFile, c("TD", "BYTORDA", "DIGMOD", "DECIM", "DSPFVS", \r\n+                                    "SW_h", "SW", "O1"))\r\n+  \r\n+  if (params[["DSPFVS"]] >= 20) {\r\n+    # The group delay first order phase correction is given directly from version 20\r\n+    grpdly <- readParams(paramFile, c("GRPDLY"))\r\n+    params[["GRPDLY"]] <- grpdly[["GRPDLY"]]\r\n+  }\r\n+  TD <- params[["TD"]]\r\n+  endianness <- if (params$BYTORDA) \r\n+    "big" else "little"\r\n+  if (TD%%2 != 0) {\r\n+    stop(paste("Only even numbers are allowed for size in TD because it is complex \r\n+               data with the real and imaginary part for each element.", \r\n+               "The TD value is in the", paramFile, "file"))\r\n+  }\r\n+  \r\n+  # Interpret params Dwell Time, time between 2 data points in the FID\r\n+  params[["DT"]] <- 1/(2 * params[["SW_h"]])\r\n+  \r\n+  # Read fid\r\n+  fidFile <- file.path(path, "fid")\r\n+  fidOnDisk <- readBin(fidFile, what = "int", n = TD, size = 4L, endian = endianness)\r\n+  \r\n+  # Real size that is on disk (it should be equal to TD2, except for TopSpin/Bruker\r\n+  # (which is our case) according to matNMR as just discussed\r\n+  TDOnDisk <- length(fidOnDisk)\r\n+  if (TDOnDisk < TD) {\r\n+    warning("Size is smaller than expected, the rest is filled with zero so the size is the same for every fid")\r\n+    fidGoodSize <- sapply(vector("list", length = TD), function(x) 0)\r\n+    fidGoodSize[1:TDOnDisk] <- fidOnDisk\r\n+    \r\n+  } else if (TDOnDisk > TD) {\r\n+    warning("Size is bigger than expected, the rest ignored so the size is the same for every fid")\r\n+    fidGoodSize <- fidOnDisk(1:TD)\r\n+    \r\n+  } else {\r\n+    fidGoodSize <- fidOnDisk\r\n+  }\r\n+  \r\n+  fidRePart <- fidGoodSize[seq(from = 1, to = TD, by = 2)]\r\n+  fidImPart <- fidGoodSize[seq(from = 2, to = TD, by = 2)]\r\n+  fid <- complex(real = fidRePart, imaginary = fidImPart)\r\n+  \r\n+  return(list(fid = fid, params = params))\r\n+}\r\n+\r\n+\r\n+\r\n+\r\n+# getDirsContainingFid ==============================================================================\r\n+getDirsContainingFid <- function(path) {\r\n+  subdirs <- dir(path, full.names = TRUE)\r\n+  if (length(subdirs) > 0) {\r\n+    cond <- sapply(subdirs, function(x)  {\r\n+      content <- dir(x)\r\n+      # subdirs must contain fid, acqu and acqus files\r\n+      return("fid" %in% content && "acqu" %in% content && "acqus" %in% content)\r\n+    })\r\n+    subdirs <- subdirs[cond]\r\n+  }\r\n+  return(subdirs)\r\n+}\r\n+\r\n+\r\n+\r\n+\r\n+\r\n+\r\n+# beginTreatment ==============================================================================\r\n+\r\n+beginTreatment <- function(name, Signal_data = NULL, Signal_info = NULL, \r\n+                           force.real = FALSE) {\r\n+  \r\n+  cat("Begin", name, "\\n")\r\n+  \r\n+  \r\n+  # Formatting the Signal_data and Signal_info -----------------------\r\n+  \r\n+  vec <- is.vector(Signal_data)\r\n+  if (vec) {\r\n+    Signal_data <- vec2mat(Signal_data)\r\n+  }\r\n+  if (is.vector(Signal_info)) {\r\n+    Signal_info <- vec2mat(Signal_info)\r\n+  }\r\n+  if (!is.null(Signal_data)) {\r\n+    if (!is.matrix(Signal_data)) {\r\n+      stop("Signal_data is not a matrix.")\r\n+    }\r\n+    if (!is.complex(Signal_data) && !is.numeric(Signal_data)) {\r\n+      stop("Signal_data contains non-numerical values.")\r\n+    }\r\n+  }\r\n+  if (!is.null(Signal_info) && !is.matrix(Signal_info)) {\r\n+    stop("S'..b'as no field", pattern))\r\n+    }\r\n+    if (length(occurences) > 1L) {\r\n+      warning(paste(file, "has more that one field", pattern, " I take the first one"))\r\n+    }\r\n+    line <- lines[occurences[1]]\r\n+    \r\n+    # Cut beginning and end of the line \'##$TD= 65536\' -> \'65536\'\r\n+    igual = as.numeric(regexpr("=", line))\r\n+    \r\n+    first <- igual\r\n+    while (first <= nchar(line) & !isDigit(substr(line, first, first))) {\r\n+      first <- first + 1\r\n+    }\r\n+    last <- nchar(line)\r\n+    while (last > 0 & !isDigit(substr(line, last, last)))  {\r\n+      last <- last - 1\r\n+    }\r\n+    params[paramName] <- as.numeric(substr(line, first, last))\r\n+  }\r\n+  return(params)\r\n+}\r\n+\r\n+\r\n+\r\n+# ReadFids ==============================================================================\r\n+ReadFids <- function(path, l = 1, subdirs = FALSE, subdirs.names = FALSE) {\r\n+\r\n+  # Data initialisation and checks ----------------------------------------------\r\n+  begin_info <- beginTreatment("ReadFids")\r\n+  checkArg(path, c("str"))\r\n+  checkArg(l, c("pos"))\r\n+  if (file.exists(path) == FALSE) {\r\n+    stop(paste("Invalid path:", path))\r\n+  }\r\n+  \r\n+  \r\n+  # Extract the FIDs and their info ----------------------------------------------\r\n+  \r\n+  if (subdirs == FALSE) {\r\n+    fidDirs <- getDirsContainingFid(path)\r\n+    n <- length(fidDirs)\r\n+    if (n == 0L)  {\r\n+      stop(paste("No valid fid in", path))\r\n+    }\r\n+    fidNames <- sapply(X = fidDirs, FUN = getTitle, l = l, subdirs = subdirs,  USE.NAMES = F)\r\n+    for (i in 1:n)  {\r\n+      fidList <- ReadFid(fidDirs[i])\r\n+      fid <- fidList[["fid"]]\r\n+      info <- fidList[["params"]]\r\n+      m <- length(fid)\r\n+      if (i == 1)  {\r\n+        Fid_data <- matrix(nrow = n, ncol = m, dimnames = list(fidNames, \r\n+                                                               info[["DT"]] * (0:(m - 1))))\r\n+        Fid_info <- matrix(nrow = n, ncol = length(info), dimnames = list(fidNames, \r\n+                                                                          names(info)))\r\n+      }\r\n+      Fid_data[i, ] <- fid\r\n+      Fid_info[i, ] <- unlist(info)\r\n+    }\r\n+    \r\n+  } else  {\r\n+    maindirs <- dir(path, full.names = TRUE) # subdirectories\r\n+    Fid_data <- numeric()\r\n+    Fid_info <- numeric()\r\n+    \r\n+    fidDirs <- c()\r\n+    for (j in maindirs) {\r\n+      fd <- getDirsContainingFid(j) # recoved FIDs from subdirectories\r\n+      n <- length(fd)\r\n+      if (n > 0L)  {\r\n+        fidDirs <- c(fidDirs, fd)\r\n+      } else {warning(paste("No valid fid in",j ))}\r\n+    }\r\n+    \r\n+    if (subdirs.names==TRUE) {\r\n+      fidNames <- dir(path)\r\n+    } else {fidNames <- sapply(X = fidDirs, FUN = getTitle, l = l, subdirs = subdirs, USE.NAMES = F)}\r\n+    \r\n+    for (i in 1:length(fidNames))  {\r\n+      fidList <- ReadFid(fidDirs[i])\r\n+      fid <- fidList[["fid"]]\r\n+      info <- fidList[["params"]]\r\n+      m <- length(fid)\r\n+      if (i == 1)  {\r\n+        Fid_data <- matrix(nrow = length(fidNames), ncol = m, dimnames = list(fidNames, \r\n+                                                                              info[["DT"]] * (0:(m - 1))))\r\n+        Fid_info <- matrix(nrow = length(fidNames), ncol = length(info), dimnames = list(fidNames, \r\n+                                                                                         names(info)))\r\n+      }\r\n+      Fid_data[i, ] <- fid\r\n+      Fid_info[i, ] <- unlist(info)\r\n+    }\r\n+    \r\n+    \r\n+  }\r\n+  \r\n+  # Check for non-unique IDs ----------------------------------------------\r\n+  NonnuniqueIds <- sum(duplicated(row.names(Fid_data)))\r\n+  cat("dim Fid_data: ", dim(Fid_data), "\\n")\r\n+  cat("IDs: ", rownames(Fid_data), "\\n")\r\n+  cat("non-unique IDs?", NonnuniqueIds, "\\n")\r\n+  if (NonnuniqueIds > 0) {\r\n+    warning("There are duplicated IDs: ", Fid_data[duplicated(Fid_data)])\r\n+  }\r\n+  \r\n+  \r\n+  # Return the results ----------------------------------------------\r\n+  return(list(Fid_data = endTreatment("ReadFids", begin_info, Fid_data), Fid_info = Fid_info))\r\n+  \r\n+}\r\n+\r\n+\r\n+\r\n'
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/ReadFids_script.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/ReadFids_script.R Mon Jul 30 10:33:03 2018 -0400
[
b'@@ -0,0 +1,404 @@\n+################################################################################################\r\n+#\r\n+#   Read FIDs in Bruker format\r\n+#\r\n+#\r\n+################################################################################################\r\n+\r\n+\r\n+# vec2mat ==============================================================================\r\n+vec2mat <- function(vec) {\r\n+  return(matrix(vec, nrow = 1, dimnames = list(c(1), names(vec)))) \r\n+}\r\n+\r\n+\r\n+# ReadFid ==============================================================================\r\n+ReadFid <- function(path) {\r\n+  \r\n+  # Read 1D FID using Bruker XWinNMR and TopSpin format.  It is inspired of the\r\n+  # matNMR matlab library which deals with 2D FID and also other formats\r\n+  # Read also the parameters in the acqus file\r\n+  \r\n+  paramFile <- file.path(path, "acqus")\r\n+  # BYTEORDA: 0 -> Little Endian 1 -> Big Endian\r\n+  params <- readParams(paramFile, c("TD", "BYTORDA", "DIGMOD", "DECIM", "DSPFVS", \r\n+                                    "SW_h", "SW", "O1"))\r\n+  \r\n+  if (params[["DSPFVS"]] >= 20) {\r\n+    # The group delay first order phase correction is given directly from version 20\r\n+    grpdly <- readParams(paramFile, c("GRPDLY"))\r\n+    params[["GRPDLY"]] <- grpdly[["GRPDLY"]]\r\n+  }\r\n+  TD <- params[["TD"]]\r\n+  endianness <- if (params$BYTORDA) \r\n+    "big" else "little"\r\n+  if (TD%%2 != 0) {\r\n+    stop(paste("Only even numbers are allowed for size in TD because it is complex \r\n+               data with the real and imaginary part for each element.", \r\n+               "The TD value is in the", paramFile, "file"))\r\n+  }\r\n+  \r\n+  # Interpret params Dwell Time, time between 2 data points in the FID\r\n+  params[["DT"]] <- 1/(2 * params[["SW_h"]])\r\n+  \r\n+  # Read fid\r\n+  fidFile <- file.path(path, "fid")\r\n+  fidOnDisk <- readBin(fidFile, what = "int", n = TD, size = 4L, endian = endianness)\r\n+  \r\n+  # Real size that is on disk (it should be equal to TD2, except for TopSpin/Bruker\r\n+  # (which is our case) according to matNMR as just discussed\r\n+  TDOnDisk <- length(fidOnDisk)\r\n+  if (TDOnDisk < TD) {\r\n+    warning("Size is smaller than expected, the rest is filled with zero so the size is the same for every fid")\r\n+    fidGoodSize <- sapply(vector("list", length = TD), function(x) 0)\r\n+    fidGoodSize[1:TDOnDisk] <- fidOnDisk\r\n+    \r\n+  } else if (TDOnDisk > TD) {\r\n+    warning("Size is bigger than expected, the rest ignored so the size is the same for every fid")\r\n+    fidGoodSize <- fidOnDisk(1:TD)\r\n+    \r\n+  } else {\r\n+    fidGoodSize <- fidOnDisk\r\n+  }\r\n+  \r\n+  fidRePart <- fidGoodSize[seq(from = 1, to = TD, by = 2)]\r\n+  fidImPart <- fidGoodSize[seq(from = 2, to = TD, by = 2)]\r\n+  fid <- complex(real = fidRePart, imaginary = fidImPart)\r\n+  \r\n+  return(list(fid = fid, params = params))\r\n+}\r\n+\r\n+\r\n+\r\n+\r\n+# getDirsContainingFid ==============================================================================\r\n+getDirsContainingFid <- function(path) {\r\n+  subdirs <- dir(path, full.names = TRUE)\r\n+  if (length(subdirs) > 0) {\r\n+    cond <- sapply(subdirs, function(x)  {\r\n+      content <- dir(x)\r\n+      # subdirs must contain fid, acqu and acqus files\r\n+      return("fid" %in% content && "acqu" %in% content && "acqus" %in% content)\r\n+    })\r\n+    subdirs <- subdirs[cond]\r\n+  }\r\n+  return(subdirs)\r\n+}\r\n+\r\n+\r\n+\r\n+\r\n+\r\n+\r\n+# beginTreatment ==============================================================================\r\n+\r\n+beginTreatment <- function(name, Signal_data = NULL, Signal_info = NULL, \r\n+                           force.real = FALSE) {\r\n+  \r\n+  cat("Begin", name, "\\n")\r\n+  \r\n+  \r\n+  # Formatting the Signal_data and Signal_info -----------------------\r\n+  \r\n+  vec <- is.vector(Signal_data)\r\n+  if (vec) {\r\n+    Signal_data <- vec2mat(Signal_data)\r\n+  }\r\n+  if (is.vector(Signal_info)) {\r\n+    Signal_info <- vec2mat(Signal_info)\r\n+  }\r\n+  if (!is.null(Signal_data)) {\r\n+    if (!is.matrix(Signal_data)) {\r\n+      stop("Signal_data is not a matrix.")\r\n+    }\r\n+    if '..b'paramName] <- as.numeric(substr(line, first, last))\r\n+  }\r\n+  return(params)\r\n+}\r\n+\r\n+\r\n+\r\n+# ReadFids ==============================================================================\r\n+\r\n+ReadFids <- function(path, l = 1, subdirs = FALSE, dirs.names = FALSE) {\r\n+  \r\n+  # Data initialisation and checks ----------------------------------------------\r\n+  begin_info <- beginTreatment("ReadFids")\r\n+  checkArg(path, c("str"))\r\n+  checkArg(l, c("pos"))\r\n+  if (file.exists(path) == FALSE) {\r\n+    stop(paste("Invalid path:", path))\r\n+  }\r\n+  \r\n+  \r\n+  # Extract the FIDs and their info ----------------------------------------------\r\n+  \r\n+  if (subdirs == FALSE) {\r\n+    fidDirs <- getDirsContainingFid(path)\r\n+    n <- length(fidDirs)\r\n+    if (n == 0L)  {\r\n+      stop(paste("No valid fid in", path))\r\n+    }\r\n+    if (dirs.names) {\r\n+      separator <- .Platform$file.sep\r\n+      path_elem <- strsplit(fidDirs,separator)\r\n+      fidNames <- sapply(path_elem, function(x) x[[length(path_elem[[1]])]])\r\n+    }else {fidNames <- sapply(X = fidDirs, FUN = getTitle, l = l, subdirs = subdirs,  USE.NAMES = F)}\r\n+    \r\n+    for (i in 1:n)  {\r\n+      fidList <- ReadFid(fidDirs[i])\r\n+      fid <- fidList[["fid"]]\r\n+      info <- fidList[["params"]]\r\n+      m <- length(fid)\r\n+      if (i == 1)  {\r\n+        Fid_data <- matrix(nrow = n, ncol = m, dimnames = list(fidNames, \r\n+                                                               info[["DT"]] * (0:(m - 1))))\r\n+        Fid_info <- matrix(nrow = n, ncol = length(info), dimnames = list(fidNames, \r\n+                                                                          names(info)))\r\n+      }\r\n+      Fid_data[i, ] <- fid\r\n+      Fid_info[i, ] <- unlist(info)\r\n+    }\r\n+    \r\n+  } else  {\r\n+    maindirs <- dir(path, full.names = TRUE) # subdirectories\r\n+    Fid_data <- numeric()\r\n+    Fid_info <- numeric()\r\n+    \r\n+    fidDirs <- c()\r\n+    for (j in maindirs) {\r\n+      fd <- getDirsContainingFid(j) # recoved FIDs from subdirectories\r\n+      n <- length(fd)\r\n+      if (n > 0L)  {\r\n+        fidDirs <- c(fidDirs, fd)\r\n+      } else {warning(paste("No valid fid in",j ))}\r\n+    }\r\n+    \r\n+    if (dirs.names==TRUE) {\r\n+      if (length(fidDirs)!= length(dir(path))) { # at least one subdir contains more than 1 FID\r\n+        separator <- .Platform$file.sep\r\n+        path_elem <- strsplit(fidDirs,separator)\r\n+        fidNames <- sapply(path_elem, function(x) paste(x[[length(path_elem[[1]])-1]],\r\n+                                                        x[[length(path_elem[[1]])]], sep = "_"))\r\n+      }else {fidNames <- dir(path)}\r\n+      \r\n+    } else {fidNames <- sapply(X = fidDirs, FUN = getTitle, l = l, subdirs = subdirs, USE.NAMES = F)}\r\n+    \r\n+    for (i in 1:length(fidNames))  {\r\n+      fidList <- ReadFid(fidDirs[i])\r\n+      fid <- fidList[["fid"]]\r\n+      info <- fidList[["params"]]\r\n+      m <- length(fid)\r\n+      if (i == 1)  {\r\n+        Fid_data <- matrix(nrow = length(fidNames), ncol = m, dimnames = list(fidNames, \r\n+                                                                              info[["DT"]] * (0:(m - 1))))\r\n+        Fid_info <- matrix(nrow = length(fidNames), ncol = length(info), dimnames = list(fidNames, \r\n+                                                                                         names(info)))\r\n+      }\r\n+      Fid_data[i, ] <- fid\r\n+      Fid_info[i, ] <- unlist(info)\r\n+    }\r\n+    \r\n+    \r\n+  }\r\n+  \r\n+  # Check for non-unique IDs ----------------------------------------------\r\n+  NonnuniqueIds <- sum(duplicated(row.names(Fid_data)))\r\n+  cat("dim Fid_data: ", dim(Fid_data), "\\n")\r\n+  cat("IDs: ", rownames(Fid_data), "\\n")\r\n+  cat("non-unique IDs?", NonnuniqueIds, "\\n")\r\n+  if (NonnuniqueIds > 0) {\r\n+    warning("There are duplicated IDs: ", Fid_data[duplicated(Fid_data)])\r\n+  }\r\n+  \r\n+  \r\n+  # Return the results ----------------------------------------------\r\n+  return(list(Fid_data = endTreatment("ReadFids", begin_info, Fid_data), Fid_info = Fid_info))\r\n+  \r\n+}\r\n+\r\n'
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/ReadFids_wrapper.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/ReadFids_wrapper.R Mon Jul 30 10:33:03 2018 -0400
[
@@ -0,0 +1,158 @@
+#!/usr/local/public/bin/Rscript --vanilla --slave --no-site-file
+
+## 08122016_ReadFids_wrapper.R
+## Manon Martin
+## manon.martin@uclouvain.be
+
+##======================================================
+##======================================================
+# Preamble
+##======================================================
+##======================================================
+
+runExampleL <- FALSE
+
+
+##------------------------------
+## Options
+##------------------------------
+strAsFacL <- options()$stringsAsFactors
+options(stringsAsFactors = FALSE)
+options(warn=1)
+
+##------------------------------
+## Libraries laoding
+##------------------------------
+library(batch) 
+library(ggplot2)
+library(gridExtra)
+library(reshape2)
+
+
+# R script call
+source_local <- function(fname)
+{
+  argv <- commandArgs(trailingOnly = FALSE)
+  base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
+  source(paste(base_dir, fname, sep="/"))
+}
+#Import the different functions
+source_local("ReadFids_script.R")
+source_local("DrawFunctions.R")
+##------------------------------
+## Errors ?????????????????????
+##------------------------------
+
+
+##------------------------------
+## Constants
+##------------------------------
+topEnvC <- environment()
+flagC <- "\n"
+
+
+##------------------------------
+## Script
+##------------------------------
+if(!runExampleL)
+  argLs <- parseCommandArgs(evaluate=FALSE)
+
+sink(argLs$logOut)
+
+##======================================================
+##======================================================
+## Parameters Loading
+##======================================================
+##======================================================
+
+ ## Inputs
+ # Path
+ ## Bruker FIDs
+fileType="Bruker"
+zipfile= argLs[["fidzipfile"]]
+directory=unzip(zipfile, list=F)
+path=paste(getwd(),strsplit(directory[1],"/")[[1]][2],sep="/")
+
+
+# other inputs from ReadFids
+l = argLs[["title_line"]]
+subdirs <- argLs[["subdirectories"]]
+dirs.names <- argLs[["dirs_names"]]
+
+
+# Outputs
+# dataMatrix <- argLs[["dataMatrix"]]
+# sampleMetadata <- argLs[["sampleMetadata"]]
+logOut <- argLs[["logOut"]]
+nomGraphe <- argLs[["graphOut"]]
+
+
+
+## Checking arguments
+##-------------------
+error.stock <- "\n"
+
+if(length(error.stock) > 1)
+  stop(error.stock)
+
+
+
+##======================================================
+##======================================================
+## Computation
+##======================================================
+##======================================================
+sink(logOut,append=TRUE)
+
+if(length(warnings())>0){ # or !is.null(warnings())
+  print("something happened")
+}
+
+## Starting
+cat("\nStart of 'ReadFids' Galaxy module call: ", as.character(Sys.time()), "\n\n", sep = "")
+
+outputs <- ReadFids(path = path, l=l, subdirs = subdirs, dirs.names = dirs.names) 
+
+data_matrix <- outputs[["Fid_data"]] # Data matrix
+data_sample <- outputs[["Fid_info"]] # Sample metadata
+
+
+
+pdf(nomGraphe, onefile = TRUE, width = 13, height = 13)
+title = "Raw FID data"
+DrawSignal(data_matrix, subtype = "stacked",
+             ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T,
+             xlab = "Frequency", num.stacked = 4,
+             main = title, createWindow=FALSE)
+invisible(dev.off())
+
+##======================================================
+##======================================================
+## Saving
+##======================================================
+##======================================================
+
+# Data matrix
+write.table(data_matrix,file=argLs$dataMatrix, quote=FALSE, row.names=TRUE, sep="\t", col.names=TRUE)
+
+# Sample metadata
+write.table(data_sample,file=argLs$sampleMetadata, quote=FALSE, row.names=TRUE, sep="\t", col.names=TRUE)
+
+# log file
+# write.table(t(data.frame(argLs)), file = argLs$logOut, col.names = FALSE, quote=FALSE)
+
+# input arguments
+cat("\n INPUT and OUTPUT ARGUMENTS :\n")
+
+argLs
+
+## Ending
+
+cat("\nEnd of 'ReadFids' Galaxy module call: ", as.character(Sys.time()), sep = "")
+
+sink()
+
+
+options(stringsAsFactors = strAsFacL)
+
+rm(list = ls())
\ No newline at end of file
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/ReadFids_xml.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/ReadFids_xml.xml Mon Jul 30 10:33:03 2018 -0400
b
@@ -0,0 +1,228 @@
+<tool id="NMR_Read" name="NMR_Read" version="1.2.0">
+ <description> Read Bruker NMR raw files</description>
+
+    <stdio>
+        <exit_code range="1:" level="fatal" />
+    </stdio>
+
+   <command>
+       ## Wrapper
+        Rscript $__tool_directory__/ReadFids_wrapper.R
+
+ ## File input
+        fidzipfile $fidzipfile
+
+ ## Title line
+ title_line $title_line
+
+ ## Subdirectories
+ subdirectories $subdirectories
+
+ ## Use subdirectories names as FID names?
+ dirs_names $dirs_names
+
+        ## Outputs
+        dataMatrix $dataMatrix
+        sampleMetadata $sampleMetadata
+        logOut $logOut
+        graphOut $graphOut
+
+ </command>
+
+   <inputs>
+ <param name="fidzipfile" type="data" format="no_unzip.zip" label="Bruker FID file" />
+        
+ <param name="title_line" label="Specify the line in the title file to recover the FID names (usually in pdata/1/title)" type="integer" value="1" size="100" help="Default value is line 1"/>
+
+        <param name="subdirectories" label="Presence of subdirectories?" type="select" help="Select 'FALSE' when there is no subdirectories, 'TRUE' if there are subdirectories">
+            <option value="FALSE"> FALSE </option>
+            <option value="TRUE"> TRUE </option>
+        </param>
+        
+        <param name="dirs_names" label="Use (sub)directories names as FID names?" type="select" help="Select 'TRUE' to use the subdirectories names as the FID names (instead of looking in the title file)">
+            <option value="FALSE"> FALSE </option>
+            <option value="TRUE"> TRUE </option>
+        </param>
+ </inputs>
+
+
+
+ <outputs>
+ <data format="tabular" name="dataMatrix" label="${tool.name}_dataMatrix" />
+ <data format="tabular" name="sampleMetadata" label="${tool.name}_sampleMetadata" />
+ <data format="txt" name="logOut" label="${tool.name}_log" />
+ <data format="pdf" name="graphOut" label="${tool.name}_graph" />
+ </outputs>
+
+
+ <tests>
+        <test>
+          <param name="fidzipfile" value="MTBLS1.zip" ftype="zip" />
+          <param name="title_line" value="1" />
+          <param name="subdirectories" value="TRUE" />
+          <param name="dirs_names" value="TRUE" />
+           
+          <output name="dataMatrix" value="NMR_ReadFids_dataMatrix.tabular" />
+  
+        </test>
+  </tests>
+
+  
+  
+ <help>
+
+.. class:: infomark
+
+**Authors** Manon Martin (manon.martin@uclouvain.be) and Marie Tremblay-Franco (marie.tremblay-franco@inra.fr; Galaxy integration)
+
+.. class:: infomark
+
+
+=============
+NMR Read
+=============
+
+-----------
+Description
+-----------
+
+Nuclear Magnetic Resonance Bruker files reading (from the PEPS-NMR R package (https://github.com/ManonMartin/PEPSNMR))
+
+-----------------
+Workflow position
+-----------------
+
+**Upstream tools**
+
+========================= ================= =======
+Name                      output file       format
+========================= ================= =======
+NA                        NA                NA
+========================= ================= =======
+
+
+**Downstream tools**
+
++-----------------------+--------------------------+--------+
+| Name                  | Output file              | Format |
++=======================+==========================+========+
+|NMR_Preprocessing      | dataMatrix               | Tabular|
++-----------------------+--------------------------+--------+
+|NMR_Preprocessing      |  sampleMetadata          | Tabular|
++-----------------------+--------------------------+--------+
+|NMR_Preprocessing      |     NMR_Read_log         | TXT    |
++-----------------------+--------------------------+--------+
+|NMR_Preprocessing      |     NMR_Read_graph       | PDF    |
++-----------------------+--------------------------+--------+
+|NMR_Alignement         |     dataMatrix           | Tabular|
++-----------------------+--------------------------+--------+
+|NMR_Bucketing          |     dataMatrix           | Tabular|
++-----------------------+--------------------------+--------+
+|Normalization          |     dataMatrix           | Tabular|
++-----------------------+--------------------------+--------+
+|Univariate             |     variableMetadata     | Tabular|
++-----------------------+--------------------------+--------+
+|Multivariate           |     sampleMetadata       | Tabular|
++-----------------------+--------------------------+--------+
+|                       |     variableMetadata     | Tabular|
++-----------------------+--------------------------+--------+
+
+
+-----------
+Input files
+-----------
+
++---------------------------+-----------------+
+| Parameter : num + label   |   Format        |
++===========================+=================+
+| 1 : Choose your inputs    |     zip         |
++---------------------------+-----------------+
+
+
+**Choose your inputs**
+
+    | Zip file (recommended) of FID Bruker files: you can put a zip file containing your FID Bruker files: myinputs.zip.
+
+
+----------
+Parameters
+----------
+
+FID Title line
+ | Line in the acqus file to find the FID title (name)
+ |
+
+subdirectories
+ | Organization of individual's files
+ | TRUE: will search inside subdirectories for FIDs and will merge them to have unique FID and info matrices.
+ |
+
+dirs_names
+ | Use the (sub)directories names as FID names?
+ |
+
+
+------------
+Output files
+------------
+
+NMR_Read_dataMatrix
+ | tabular output
+ | Data matrix with n rows (samples) and p columns (time) containing the raw FIDs.
+ |
+
+NMR_Read_sampleMetadata
+ | tabular output
+ | Data matrix with n rows (samples) containing the acquisition parameters for each sample.
+ |
+
+NMR_Read_log
+ | Text output
+ | Contains warnings
+ |
+
+
+NMR_Read_graph
+ | pdf output
+ | line plots of FID
+ |
+
+
+Creating the zip file
+-----------------------
+
+.. class:: warningmark you must use the 7Zip software (http://www.7-zip.org/) to zip under Windows.
+
+Must contain at least the following files for every sample: fid, acqu and acqus
+
+.. image:: ./static/images/ReadFids.png 
+    :height: 400 
+
+
+
+**Possible structure and parameters values:**
+
+
+(1) use title file and presence of sub-directories: set the FID Title line, subdirectories = TRUE,  dirs_names = FALSE
+(2) use title file and no sub-directories: set the FID Title line, subdirectories = FALSE,  dirs_names = FALSE
+(3) don't use title file and presence of sub-directories: subdirectories = TRUE,  dirs_names = TRUE
+(4) don't use title file and no sub-directories: subdirectories = FALSE,  dirs_names = TRUE
+
+
+
+   </help>
+   
+   
+   <citations>
+     
+      <citation type="bibtex">@PhDThesis{Rousseau2011,
+      title = {Statistical contribution to the analysis of metabonomics data in $^1$H NMR spectroscopy},
+      author = {Rousseau, R.},
+      school = {Institut de Statistique, Biostatistique et Sciences Actuarielles, Universit{\'e} catholique de Louvain},
+      year = {2011}}
+      </citation>
+      
+   </citations> 
+   
+   
+</tool>
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/macros.xml
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/macros.xml Mon Jul 30 10:33:03 2018 -0400
b
@@ -0,0 +1,71 @@
+<?xml version="1.0"?>
+<macros>
+    <token name="@WRAPPER_VERSION@">3.2.0</token>
+
+    <xml name="requirements">
+        <requirements>
+            <requirement type="package" version="1.1_4">r-batch</requirement>
+            <requirement type="package" version="2.2.1">r-ggplot2</requirement>
+            <requirement type="package" version="2.3">r-gridextra</requirement>
+            <requirement type="package" version="1.4.3">r-reshape2</requirement>
+            <yield />
+        </requirements>
+    </xml>
+
+    <xml name="stdio">
+        <stdio>
+            <exit_code range="1" level="fatal" />
+        </stdio>
+    </xml>
+
+
+    <token name="@HELP_AUTHORS@">
+.. class:: infomark
+
+**Authors** Manon Martin (manon.martin@uclouvain.be) and Marie Tremblay-Franco (marie.tremblay-franco@inra.fr; Galaxy integration)
+
+.. class:: infomark
+
+| Contact support@workflow4metabolomics.org for any questions or concerns about the Galaxy implementation of this tool.
+
+---------------------------------------------------
+
+    </token>
+
+    <token name="@HELP_CHANGELOG@">
+
+---------------------------------------------------
+
+Changelog/News
+--------------
+**Version 3.2.0**
+
+* Updated R scripts and the help section of NMR_ReadFids and NMR_preprocessing
+* Added sections
+* Created a variableMetadata file in output of the NMR_preprocessing module
+* Homogenised the input-output file names with the other modules
+* Suppressed the option ptw for the baseline correction, set to TRUE all the time now
+* Shift referencing: other values than 0 are admitted
+* The log file recovers the input/output parameters
+* Added an exclusion zone for the computation of the Baseline Correction criterion
+* Switched Internal Referencing (goes second) and Zero Order Phase Correction (goes first)
+
+**Version 3.1.0**
+
+* Implementation of NMR_ReadFids and NMR_preprocessing
+
+    </token>
+
+    <xml name="citation">
+        <citations>
+            <citation type="bibtex">@PhDThesis{Rousseau2011,
+            title = {Statistical contribution to the analysis of metabonomics data in $^1$H NMR spectroscopy},
+            author = {Rousseau, R.},
+            school = {Institut de Statistique, Biostatistique et Sciences Actuarielles, Universit{\'e} catholique de Louvain},
+            year = {2011}}
+            </citation>
+            <citation type="doi">10.1093/bioinformatics/btu813</citation>
+        </citations>
+    </xml>
+
+</macros>
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/ptw.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/ptw.R Mon Jul 30 10:33:03 2018 -0400
[
@@ -0,0 +1,98 @@
+ptw <- function (ref, samp, selected.traces, init.coef = c(0, 1, 0), 
+          try = FALSE, warp.type = c("individual", "global"), optim.crit = c("WCC", 
+                                                                             "RMS"), mode = c("forward", "backward"), smooth.param = ifelse(try, 
+                                                                                                                                            0, 1e+05), trwdth = 20, trwdth.res = trwdth, verbose = FALSE, 
+          ...) 
+{
+  optim.crit <- match.arg(optim.crit)
+  warp.type <- match.arg(warp.type)
+  mode <- match.arg(mode)
+  if (is.vector(ref)) 
+    ref <- matrix(ref, nrow = 1)
+  if (is.vector(samp)) 
+    samp <- matrix(samp, nrow = 1)
+  if (nrow(ref) > 1 && nrow(ref) != nrow(samp)) 
+    stop("The number of references does not equal the number of samples")
+  if (length(dim(ref)) > 2) 
+    stop("Reference cannot be an array")
+  if (length(dim(samp)) > 2) 
+    stop("Sample cannot be an array")
+  if (nrow(samp) == 1) 
+    warp.type <- "individual"
+  r <- nrow(samp)
+  if (!missing(selected.traces)) {
+    samp <- samp[selected.traces, , drop = FALSE]
+    if (nrow(ref) > 1) 
+      ref <- ref[selected.traces, , drop = FALSE]
+  }
+  if (is.vector(init.coef)) 
+    init.coef <- matrix(init.coef, nrow = 1)
+  if (warp.type == "global") {
+    if (nrow(init.coef) != 1) 
+      stop("Only one warping function is allowed with global alignment.")
+  }
+  else {
+    if (nrow(init.coef) != nrow(samp)) 
+      if (nrow(init.coef) == 1) {
+        init.coef <- matrix(init.coef, byrow = TRUE, 
+                            nrow = nrow(samp), ncol = length(init.coef))
+      }
+    else {
+      stop("The number of warping functions does not match the number of samples")
+    }
+  }
+  if (warp.type == "individual") {
+    w <- matrix(0, nrow(samp), ncol(ref))
+    a <- matrix(0, nrow(samp), ncol(init.coef))
+    v <- rep(0, nrow(samp))
+    warped.sample <- matrix(NA, nrow = nrow(samp), ncol = ncol(samp))
+    for (i in 1:nrow(samp)) {
+      if (verbose & nrow(samp) > 1) 
+        cat(ifelse(nrow(ref) == 1, paste("Warping sample", 
+                                         i, "with the reference \n"), paste("Warping sample", 
+                                                                            i, "with reference \n", i)))
+      if (nrow(ref) == 1) {
+        rfrnc <- ref
+      }
+      else {
+        rfrnc <- ref[i, , drop = FALSE]
+      }
+      quad.res <- pmwarp(rfrnc, samp[i, , drop = FALSE], 
+                         optim.crit, init.coef[i, ], try = try, mode = mode, 
+                         smooth.param = smooth.param, trwdth = trwdth, 
+                         trwdth.res = trwdth.res, ...)
+      w[i, ] <- quad.res$w
+      a[i, ] <- quad.res$a
+      v[i] <- quad.res$v
+      warped.sample[i, ] <- c(warp.sample(samp[i, , drop = FALSE], 
+                                          w[i, ], mode = mode))
+    }
+  }
+  else {
+    if (nrow(ref) == 1) 
+      ref <- matrix(ref, nrow = nrow(samp), ncol = ncol(ref), 
+                    byrow = TRUE)
+    if (verbose) {
+      if (nrow(ref) == 1) {
+        cat("Simultaneous warping of samples with reference... \n")
+      }
+      else {
+        cat("Simultaneous warping of samples with references... \n")
+      }
+    }
+    quad.res <- pmwarp(ref, samp, optim.crit, c(init.coef), 
+                       try = try, mode = mode, smooth.param = smooth.param, 
+                       trwdth = trwdth, trwdth.res = trwdth.res, ...)
+    w <- t(as.matrix(quad.res$w))
+    a <- t(as.matrix(quad.res$a))
+    v <- quad.res$v
+    warped.sample <- t(warp.sample(samp, w, mode))
+  }
+  if (verbose) 
+    cat("\nFinished.\n")
+  result <- list(reference = ref, sample = samp, warped.sample = warped.sample, 
+                 warp.coef = a, warp.fun = w, crit.value = v, optim.crit = optim.crit, 
+                 mode = mode, warp.type = warp.type)
+  class(result) <- "ptw"
+  result
+}
\ No newline at end of file
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/static/images/Mth_Travaux.png
b
Binary file nmr_preprocessing/static/images/Mth_Travaux.png has changed
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/static/images/NmrPreprocessing.png
b
Binary file nmr_preprocessing/static/images/NmrPreprocessing.png has changed
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/static/images/ReadFids.png
b
Binary file nmr_preprocessing/static/images/ReadFids.png has changed
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/test-data/MTBLS1.zip
b
Binary file nmr_preprocessing/test-data/MTBLS1.zip has changed
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/test-data/MTBLS1_alignedSpectra.tabular
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/test-data/MTBLS1_alignedSpectra.tabular Mon Jul 30 10:33:03 2018 -0400
b
b'@@ -0,0 +1,29802 @@\n+ADG10003u_007\tADG10003u_009\tADG10003u_015\tADG10003u_017\tADG10003u_021\tADG10003u_023\tADG10003u_051\tADG10003u_053\tADG10003u_067\tADG10003u_071\tADG10003u_073\tADG10003u_087\tADG10003u_089\tADG10003u_097\r\n+9.2997\t-0.00172384578396177\t-0.000133260203713335\t0.00188546634303473\t0.00145955595536551\t0.00266060722603239\t-0.00456406825398832\t-0.00131195747929342\t0.000299817194153485\t0.000241533956195763\t-0.00349445210212112\t0.00449073847864704\t-0.00150200410788306\t-0.00479292634495511\t-0.00845701750085149\r\n+9.2994\t-0.002312062118707\t-0.000821498405692276\t0.00530663314770368\t0.0031937690024524\t-0.00295334219789086\t-0.00562040636826083\t0.000544476077311362\t0.000328645770514397\t0.00269356222036034\t-3.40676966964021e-05\t0.00203230500493516\t-0.000176706365633302\t-0.00197312886982787\t-0.00571063951344053\r\n+9.2991\t0.00293819295016693\t0.000917760076187904\t0.00843046810963003\t-0.000269595302370741\t0.00164391778956326\t-0.00116020450231351\t0.00180051068287967\t0.00190620953248653\t0.0037736553777559\t0.0093018774151955\t-0.000394479670034688\t-0.003086471186395\t0.00198994473348899\t-0.00300222608200099\r\n+9.2988\t-0.00452049127972714\t-0.00104938317666152\t0.00739844285463343\t-0.00723747846021565\t0.00239897800809775\t0.00247439274074376\t0.00110713566571126\t0.00128511387066643\t0.00345596457000934\t0.00696433078367433\t0.00224254345372155\t-0.00566245731651603\t0.000398110507158\t-0.00679345467506024\r\n+9.2985\t-0.00679644435394394\t0.00108834623376689\t0.00259733552669646\t-0.000234823010309861\t-0.00287387338820875\t0.00360433314397773\t0.00131195747929342\t0.000999710964693405\t0.000689024945235094\t0.00650078671387083\t0.0031892946618048\t-0.00307469076201945\t-0.00265731165999202\t-0.0097797246393341\r\n+9.2982\t-0.00277642443085087\t0.00566634173332424\t-0.00691481595689443\t-0.0028308607137917\t-0.00725637584172303\t-0.0016260295153459\t0.00171405323393041\t0.000538453742918813\t0.00428868693222166\t0.0079838484938265\t0.00181890167627456\t0.00292768088283286\t-0.00247963078733168\t-0.00681381248043622\r\n+9.2979\t0.0018982524688494\t0.00520336893713099\t-0.00477951684143076\t-0.00662236101521466\t-0.00714026189728136\t-0.00179792959811773\t0.00189382983412648\t-0.00159037646257698\t0.00846508420011296\t0.00553739693024306\t0.000491234569046061\t0.0065864843534735\t-0.000949387194169153\t-0.000196700416808458\r\n+9.2976\t0.00679969416794806\t0.00526852564607191\t0.000441679666812651\t-0.00120910742140804\t-0.00213479215285431\t-0.000118151042806551\t0.000152672876120703\t-0.00308433735310247\t0.00592967252184167\t-0.000913405212245339\t0.00251223643157335\t0.00205224809642454\t-0.00322256779992628\t0.00248695352160624\r\n+9.2973\t0.0142226304437968\t0.00623769076398707\t0.000127692305908127\t0.00213321409459558\t-0.00336112584864566\t0.000102171598492551\t-0.00158299472004702\t-0.00277298872840462\t0.00392207785486584\t0.00206109565013233\t0.00669824219090419\t-0.00475364666104364\t-0.000766236100799773\t0.00362478977883671\r\n+9.297\t0.0095699800612356\t0.0038963057105373\t0.00351092154143045\t-0.00115056672717896\t-0.00313273291572552\t0.00197273503440119\t0.00124299737120294\t-0.000204042257132233\t0.00372445916343294\t-0.00169081888112061\t0.00880017455307183\t-0.00277600791899761\t0.00325660472878254\t-0.00132985988091201\r\n+9.2967\t0.00329603358106473\t0.00164692585915988\t-0.00187004456695887\t0.00352938764417924\t-0.00634216495071527\t0.00176403380714863\t0.00254534846727977\t-0.000827380141558176\t0.00593828880796603\t0.000819579424622461\t0.00804286401174449\t-0.00315985341323439\t0.00436989594345592\t-0.00604406735284172\r\n+9.2964\t0.00459126500692792\t0.00211219059988875\t-0.0050096097404826\t0.00286563300585258\t-0.00620346737671246\t0.00252983657025749\t0.000727340443541328\t-0.00440212361031127\t0.00549691260262785\t0.00261260139583228\t0.00773247972122436\t0.0021570447882654\t0.000121155258666913\t-0.000861080146308356\r\n+9.2961\t-0.000111938037919595\t0.00239344493647291\t-0.00924072822465575\t0.00409058602870609\t-0.00303387627311829\t-0.00573516783197047\t0.00190686706849184\t-0.00350107044027521\t0.00336757815105623\t0.00231464867144653\t0.0069998100303461'..b'77632683724\t-0.00376535913578589\t-0.00189051397424559\t-0.00680797781709899\t0.00220797768670862\t0.000364413311229752\t0.00462651624799079\t0.00499289330198562\t-0.0113395726998991\r\n+0.2037\t-0.00173576176864353\t0.000437761406301544\t0.000580167215973881\t0.00201899371750953\t0.00560137929048828\t-0.0079577632683724\t-0.00376535913578589\t-0.00127838720284889\t-0.00680797781709899\t-0.00129066306664566\t-0.00171378245188136\t-0.000434157723340709\t0.00830663144706259\t-0.00234747504423297\r\n+0.2034\t-0.00247527499980266\t0.000416806484833108\t-0.00300200293092705\t0.00609923608971649\t0.00340480173600446\t-0.0079577632683724\t-0.00376535913578589\t0.00338543581731644\t-0.00680797781709899\t-7.53957221969555e-06\t-0.00361949226184836\t0.00424659756187919\t0.00552958273377266\t0.00552741926505671\r\n+0.2031\t0.00054344111957739\t-0.00068660109873922\t0.00441371231291134\t0.00608933258881308\t0.00585129058742422\t-0.0079577632683724\t-0.00376535913578589\t0.00275184777240662\t-0.00680797781709899\t0.00633435763820644\t-0.00334233921000737\t0.00861222649505304\t0.00292555507550204\t0.00768149515821787\r\n+0.2028\t8.88282494458724e-05\t-0.00183519273172786\t0.0110009697459545\t0.00410885248592794\t0.0110917579111525\t-0.0079577632683724\t-0.0011345824749015\t0.00165508060063147\t-0.00738054392729838\t0.00380245758946646\t-0.00781250596947208\t0.00850792065422783\t0.00171359728729891\t0.000210180585233094\r\n+0.2025\t0.00254316000344422\t-0.0030761169874368\t0.00813837967075322\t0.00410885248592794\t0.0103098530008755\t-0.0079577632683724\t0.00219162771384057\t0.00228354356529936\t-0.00133941557526741\t-0.00210186518880179\t-0.00742752093906001\t0.00598911866742981\t0.0043536878820958\t0.004245152631848\r\n+0.2022\t0.00234564353008287\t-0.0045118565286726\t-0.00333850608490233\t0.00410885248592794\t0.0111906145537597\t-0.0079577632683724\t0.00279820219694485\t0.00318267483024469\t-0.0019044771781972\t-0.00718297837804551\t-0.00844050856165338\t0.00561705359756858\t0.00229810050009832\t0.00193399151071813\r\n+0.2019\t-0.000822564033486575\t-0.0040515030976629\t-0.00796658108526813\t0.00410885248592794\t0.0111910406599779\t-0.0038357929737381\t0.00141728460956096\t1.28127006048498e-05\t0.000142307693408781\t-0.0043810499464742\t-0.00639260522019536\t0.00376237303494238\t0.00180395722938159\t-0.00401076276454617\r\n+0.2016\t-0.00322453767297415\t-0.00410487266327783\t-0.00458643620496098\t0.00410885248592794\t0.011761383832951\t-0.000322736352584289\t0.00112291758099565\t-0.000356513394329946\t0.00264936901088379\t-0.00804193112425971\t-0.00513162665317331\t0.00391821823241064\t-0.00198893172965399\t-0.00319700076046307\r\n+0.2013\t-0.00509715272023551\t0.00140921846875231\t0.00132164620970126\t-0.00839068612096886\t0.0126843299014305\t0.000420792033602021\t0.0003677872431492\t0.000191870191557626\t0.00253318812056178\t-0.00941497099849093\t-0.00805778415972288\t0.00426009596480952\t-0.00233902585503262\t0.000656676776114392\r\n+0.201\t0.000761178657853248\t0.00155000934736837\t0.00579704562691605\t-0.00447396155256717\t0.00786613383987363\t-0.00118828958625933\t0.00191750270705306\t-0.000602517245943062\t0.00493796578339922\t-0.00887212179867285\t-0.00843078785918261\t-0.0009743392660614\t-0.000338140680125548\t0.00136672401497122\r\n+0.2007\t0.00609592889083422\t0.00516571556261739\t0.00594756216141645\t-0.00749474940590659\t0.00803891991132721\t0.00248480359082712\t-0.0030404202880487\t-0.00130433292157371\t0.00596802889233075\t-0.00572141834108675\t-0.00758938193834072\t-0.00445790892411569\t0.00262611114187379\t0.00898632044062698\r\n+0.2004\t0.00381564273127859\t0.00426530878077054\t0.00435325895069397\t-0.00396602199512091\t0.00999751714298286\t0.00384741438778465\t-0.00201699739036767\t-0.00225087117875699\t0.00396905051147928\t-0.00392727939621475\t-0.00596308580869628\t-0.00598543728481245\t0.00439076382245708\t0.000253097039809485\r\n+0.2001\t0.00347693989396059\t0.00341008604834\t0.0123071941795799\t0.00155969135338893\t0.00947255428224105\t0.00357649017282454\t0.0018327606836782\t-0.0032220738846046\t0.00134108324354955\t0.00179022953705438\t-0.00319313773022348\t-0.00350001316707849\t0.0046579942341321\t-0.00175132147329041\r\n'
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/test-data/NMR_Preprocessing_dataMatrix.tabular
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/test-data/NMR_Preprocessing_dataMatrix.tabular Mon Jul 30 10:33:03 2018 -0400
b
b'@@ -0,0 +1,32775 @@\n+ADG10003u_007\tADG10003u_009\tADG10003u_015\tADG10003u_017\tADG10003u_021\r\n+14.7716051547065\t27995.2602475479\t0\t0\t0\t0\r\n+14.7709944297239\t21820.6112209023\t0\t0\t0\t9282.46338620005\r\n+14.7703837047413\t16804.1463119503\t0\t0\t0\t21399.2370465374\r\n+14.7697729797587\t22761.9561602237\t0\t0\t0\t8320.33670169059\r\n+14.769162254776\t8855.84533049769\t0\t0\t161893.217461913\t8654.67427355276\r\n+14.7685515297934\t45681.8157259186\t0\t0\t213798.078183151\t3716.88187801026\r\n+14.7679408048108\t42887.8393218557\t231028.939905532\t87619.4219644039\t174799.119358441\t0\r\n+14.7673300798282\t45228.4228910777\t242346.146496302\t96337.8203459769\t171745.949798763\t22373.0630666607\r\n+14.7667193548455\t10293.4100422818\t225293.026840293\t79370.6440630477\t200584.881159985\t21452.0256345089\r\n+14.7661086298629\t0\t245285.819551763\t69560.8357985485\t179330.518953706\t1950.50439851916\r\n+14.7654979048803\t13044.6754912699\t233535.172341967\t65047.0032134874\t127872.13530892\t3012.88881598104\r\n+14.7648871798977\t4920.41074544238\t201604.010562397\t84405.7524606462\t171144.225774693\t17670.5984104513\r\n+14.7642764549151\t0\t232621.753105165\t110712.849399177\t166439.137637547\t31901.5651309056\r\n+14.7636657299324\t65384.1831233796\t233133.318336144\t73248.8881443986\t129854.318833915\t4687.69634044946\r\n+14.7630550049498\t13600.4721083151\t217171.068258467\t66496.1984350221\t144309.08022644\t13375.4966725283\r\n+14.7624442799672\t44271.6491409284\t220686.042391172\t90678.2783542555\t119152.267531273\t20656.0386823816\r\n+14.7618335549846\t35447.0104378641\t183305.405845727\t76758.0593715163\t152829.493529299\t14905.7914250899\r\n+14.7612228300019\t71978.3416776496\t175865.850388352\t84050.6305526296\t107362.39162051\t23048.9072310994\r\n+14.7606121050193\t0\t185435.868012505\t62226.1841309215\t116043.008135369\t1935.76613588012\r\n+14.7600013800367\t74935.382296241\t175157.520956269\t84403.982736055\t133465.727032329\t17974.5284015586\r\n+14.7593906550541\t0\t168749.842348465\t54463.3920228496\t95644.5896184567\t0\r\n+14.7587799300714\t9688.94925525378\t177787.635612028\t60397.8755736976\t54914.616377079\t11358.9329289211\r\n+14.7581692050888\t43229.1380476547\t207779.628540759\t71667.8949785616\t115329.981565123\t15691.8635213768\r\n+14.7575584801062\t52329.5419367276\t159832.940617551\t76513.9172561913\t127829.674630625\t9214.4631463097\r\n+14.7569477551236\t78783.6541477487\t163418.032210608\t67298.0082662236\t117537.044687667\t17241.4659343255\r\n+14.7563370301409\t46501.6128634408\t155114.087330952\t50776.9312345112\t139904.877454933\t27330.794761756\r\n+14.7557263051583\t49403.0225184631\t166503.964408641\t79898.1142400997\t112062.237050819\t19820.6529608801\r\n+14.7551155801757\t17929.6619876989\t148260.406459392\t68947.9566800193\t91049.9164381642\t18955.3563541751\r\n+14.7545048551931\t65288.6703391545\t138887.980475729\t72234.6928980223\t109645.467247561\t20174.6500498892\r\n+14.7538941302105\t82846.9212932246\t168518.488166259\t55879.2429527194\t103340.236428519\t19497.3317140377\r\n+14.7532834052278\t20185.8942936665\t174570.701884557\t72963.9396902977\t80717.614683456\t18627.6838078966\r\n+14.7526726802452\t24075.5179676409\t144051.33760028\t43848.8371415068\t89707.2681139155\t28211.1179361611\r\n+14.7520619552626\t29087.1858311688\t159448.546826885\t44382.0545628283\t61163.8024795214\t22431.4203167819\r\n+14.75145123028\t0\t140799.135068209\t99242.337136801\t72590.5484373062\t13588.6577439234\r\n+14.7508405052973\t13788.650529223\t137275.899810131\t48185.2065874425\t122776.708586063\t0\r\n+14.7502297803147\t45776.0087253786\t144484.315500785\t74868.5521844315\t101826.620364699\t3009.71339431044\r\n+14.7496190553321\t7430.50262570535\t132775.484641131\t32155.1076365146\t91024.7345285534\t9214.12167141928\r\n+14.7490083303495\t45201.5925023925\t145074.285534827\t25182.5991986715\t97904.7552432658\t25568.5844473654\r\n+14.7483976053668\t10869.7843821115\t85495.708141428\t20567.7267959793\t88126.2087050361\t14806.61904746\r\n+14.7477868803842\t58724.894101491\t113373.585380593\t90234.0716013522\t33101.0185496309\t14821.1706176362\r\n+14.7471761554016\t37011.9053841691\t122044.269767062\t77718.6912699187\t70345.7552847863\t9033.49511142412\r\n+14.746565430419\t53953.3710003688\t923'..b'233\t56091.0329124115\t13785.5437186784\t24517.525886621\t77393.3003459935\t22806.5836463638\r\n+-5.21864497651496\t95271.4804109781\t25258.2568666021\t39136.8636353963\t89487.3579235256\t6512.78534802136\r\n+-5.21925570149758\t84642.046191929\t34606.6491363958\t0\t72769.2133874604\t23439.4398121739\r\n+-5.2198664264802\t103626.41587394\t0\t15223.641733809\t23526.5900674434\t20026.596130921\r\n+-5.22047715146283\t83913.9093732063\t0\t4087.95547400204\t92897.21541942\t25649.2080348374\r\n+-5.22108787644545\t104074.626641938\t0\t32351.863999043\t36343.0606788519\t0\r\n+-5.22169860142807\t80033.6929035247\t0\t1027.61448883879\t38847.973318032\t21702.5728199682\r\n+-5.2223093264107\t81256.448630568\t16639.4148744572\t19815.6787936976\t94720.6927588634\t9946.66893267387\r\n+-5.22292005139332\t51462.8014447756\t30200.8171744159\t36681.2410237453\t92917.8866424875\t4364.35716948588\r\n+-5.22353077637594\t64003.3114838995\t3673.30583060352\t20930.9547020872\t57272.4977614591\t18322.7284537568\r\n+-5.22414150135857\t28139.2792075945\t17489.0060490482\t35127.8227999644\t64351.5329411713\t23843.5067022958\r\n+-5.22475222634119\t91764.0689140822\t0\t28297.1813715125\t90936.0383239264\t36080.0223870204\r\n+-5.22536295132381\t82694.6105746544\t26086.5508518998\t14173.4061646828\t77329.5052358563\t0\r\n+-5.22597367630644\t66404.2652549884\t21546.5868233964\t2631.75534772935\t89721.5445636178\t18115.6369546203\r\n+-5.22658440128906\t93838.2190917268\t46018.6766416407\t15898.8341737854\t49306.9081457379\t0\r\n+-5.22719512627168\t72041.2421704539\t2882.18149365438\t39936.983438689\t105374.471438442\t17275.0163921979\r\n+-5.22780585125431\t81588.6331611664\t32047.3942964197\t31328.3607000565\t78869.5419613461\t782.685754871334\r\n+-5.22841657623693\t93936.1687421534\t7340.06864209939\t21314.2882837874\t16473.0107636467\t25455.3849158172\r\n+-5.22902730121955\t64995.9422106001\t27739.0532356662\t15743.8024877714\t84782.2675069961\t12403.6603472982\r\n+-5.22963802620218\t60771.1302675189\t20091.4798984081\t17039.8900502895\t72348.0455944446\t10801.8525648924\r\n+-5.2302487511848\t96510.5728016341\t28216.1768870641\t33752.7874840866\t98852.5622043253\t28911.1565567843\r\n+-5.23085947616742\t88305.5208362822\t16104.5169451112\t9243.34518523604\t121235.062198148\t6304.73075572893\r\n+-5.23147020115004\t70250.8627642358\t31641.4115810876\t27678.802211328\t71384.787049899\t20165.422883212\r\n+-5.23208092613267\t64763.6110146298\t40002.7552748451\t27094.7501565098\t112854.864845268\t22880.3702738751\r\n+-5.23269165111529\t84945.1040077067\t4545.28966643714\t0\t111108.660013046\t12412.9797249703\r\n+-5.23330237609791\t129690.041744252\t0\t48307.8753675322\t143210.468055929\t17925.3376670017\r\n+-5.23391310108054\t114850.962036166\t38762.8505654453\t35659.4381442069\t111184.673286245\t0\r\n+-5.23452382606316\t124851.359354096\t7755.23650922778\t3420.22272110438\t110175.780730879\t20578.7013435836\r\n+-5.23513455104578\t107188.833744101\t1058.97615289368\t0\t87991.5014585232\t17874.6784868715\r\n+-5.23574527602841\t103782.149429569\t26910.2846563134\t9645.13198233415\t101644.284480318\t8381.26221414196\r\n+-5.23635600101103\t143359.946496284\t27663.2967007793\t21066.6949492662\t124953.935120636\t7151.23818329217\r\n+-5.23696672599365\t98170.517307091\t7975.50462918408\t15676.5350046159\t135895.441311671\t22355.7091703624\r\n+-5.23757745097628\t64148.1482368948\t36074.2937855784\t17507.7727904534\t119490.681324343\t13577.6723609028\r\n+-5.2381881759589\t103101.352755161\t41802.9866991295\t42552.6467230021\t97950.3706039905\t26906.5335908104\r\n+-5.23879890094152\t130747.356850558\t37938.2775539559\t28456.7996429502\t157667.466141347\t14934.5241083397\r\n+-5.23940962592415\t122302.249563884\t46359.7666440134\t22790.9274400894\t143659.330733121\t16105.1160098214\r\n+-5.24002035090677\t134032.568882135\t0\t21983.7580527431\t112282.966571831\t31920.1825255567\r\n+-5.24063107588939\t0\t0\t0\t139625.517930121\t34113.441327679\r\n+-5.24124180087202\t0\t33831.5766284231\t0\t158770.287071939\t0\r\n+-5.24185252585464\t0\t49856.9571287011\t18399.7414273817\t133535.480976215\t0\r\n+-5.24246325083726\t0\t0\t9567.52639632698\t109040.718494841\t0\r\n+-5.24307397581988\t0\t0\t4624.77826940714\t0\t0\r\n+-5.24368470080251\t0\t4769.5110939967\t59415.5822153283\t0\t0\r\n'
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/test-data/NMR_ReadFids_dataMatrix.tabular
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/test-data/NMR_ReadFids_dataMatrix.tabular Mon Jul 30 10:33:03 2018 -0400
b
b'@@ -0,0 +1,6 @@\n+0\t3.56999999999999e-05\t7.13999999999998e-05\t0.0001071\t0.0001428\t0.000178499999999999\t0.000214199999999999\t0.000249899999999999\t0.000285599999999999\t0.000321299999999999\t0.000356999999999999\t0.000392699999999999\t0.000428399999999999\t0.000464099999999999\t0.000499799999999998\t0.000535499999999998\t0.000571199999999998\t0.000606899999999998\t0.000642599999999998\t0.000678299999999998\t0.000713999999999998\t0.000749699999999998\t0.000785399999999998\t0.000821099999999998\t0.000856799999999997\t0.000892499999999997\t0.000928199999999997\t0.000963899999999997\t0.000999599999999997\t0.0010353\t0.001071\t0.0011067\t0.0011424\t0.0011781\t0.0012138\t0.0012495\t0.0012852\t0.0013209\t0.0013566\t0.0013923\t0.001428\t0.0014637\t0.0014994\t0.0015351\t0.0015708\t0.0016065\t0.0016422\t0.00167789999999999\t0.00171359999999999\t0.00174929999999999\t0.00178499999999999\t0.00182069999999999\t0.00185639999999999\t0.00189209999999999\t0.00192779999999999\t0.00196349999999999\t0.00199919999999999\t0.00203489999999999\t0.00207059999999999\t0.00210629999999999\t0.00214199999999999\t0.00217769999999999\t0.00221339999999999\t0.00224909999999999\t0.00228479999999999\t0.00232049999999999\t0.00235619999999999\t0.00239189999999999\t0.00242759999999999\t0.00246329999999999\t0.00249899999999999\t0.00253469999999999\t0.00257039999999999\t0.00260609999999999\t0.00264179999999999\t0.00267749999999999\t0.00271319999999999\t0.00274889999999999\t0.00278459999999999\t0.00282029999999999\t0.00285599999999999\t0.00289169999999999\t0.00292739999999999\t0.00296309999999999\t0.00299879999999999\t0.00303449999999999\t0.00307019999999999\t0.00310589999999999\t0.00314159999999999\t0.00317729999999999\t0.00321299999999999\t0.00324869999999999\t0.00328439999999999\t0.00332009999999999\t0.00335579999999999\t0.00339149999999999\t0.00342719999999999\t0.00346289999999999\t0.00349859999999999\t0.00353429999999999\t0.00356999999999999\t0.00360569999999999\t0.00364139999999999\t0.00367709999999999\t0.00371279999999999\t0.00374849999999999\t0.00378419999999999\t0.00381989999999999\t0.00385559999999999\t0.00389129999999999\t0.00392699999999999\t0.00396269999999999\t0.00399839999999999\t0.00403409999999999\t0.00406979999999999\t0.00410549999999999\t0.00414119999999999\t0.00417689999999999\t0.00421259999999999\t0.00424829999999999\t0.00428399999999999\t0.00431969999999999\t0.00435539999999999\t0.00439109999999999\t0.00442679999999999\t0.00446249999999999\t0.00449819999999999\t0.00453389999999999\t0.00456959999999999\t0.00460529999999999\t0.00464099999999999\t0.00467669999999999\t0.00471239999999999\t0.00474809999999999\t0.00478379999999999\t0.00481949999999999\t0.00485519999999998\t0.00489089999999999\t0.00492659999999998\t0.00496229999999998\t0.00499799999999999\t0.00503369999999998\t0.00506939999999998\t0.00510509999999998\t0.00514079999999998\t0.00517649999999998\t0.00521219999999998\t0.00524789999999998\t0.00528359999999998\t0.00531929999999998\t0.00535499999999998\t0.00539069999999998\t0.00542639999999998\t0.00546209999999998\t0.00549779999999998\t0.00553349999999998\t0.00556919999999998\t0.00560489999999998\t0.00564059999999998\t0.00567629999999998\t0.00571199999999998\t0.00574769999999998\t0.00578339999999998\t0.00581909999999998\t0.00585479999999998\t0.00589049999999998\t0.00592619999999998\t0.00596189999999998\t0.00599759999999998\t0.00603329999999998\t0.00606899999999998\t0.00610469999999998\t0.00614039999999998\t0.00617609999999998\t0.00621179999999998\t0.00624749999999998\t0.00628319999999998\t0.00631889999999998\t0.00635459999999998\t0.00639029999999998\t0.00642599999999998\t0.00646169999999998\t0.00649739999999998\t0.00653309999999998\t0.00656879999999998\t0.00660449999999998\t0.00664019999999998\t0.00667589999999998\t0.00671159999999998\t0.00674729999999998\t0.00678299999999998\t0.00681869999999998\t0.00685439999999998\t0.00689009999999998\t0.00692579999999998\t0.00696149999999998\t0.00699719999999998\t0.00703289999999998\t0.00706859999999998\t0.00710429999999998\t0.00713999999999998\t0.00717569999999998\t0.00721139999999998\t0.00724709999999998\t0.00728279999999998\t0.00731849999999998\t0.00735419999999998\t0.00738989999999998\t0.00742559999999'..b'12-862i\t-334+248i\t498+744i\t719-92i\t27-800i\t-555+19i\t125+712i\t1008+67i\t536-610i\t-327-264i\t-99+741i\t830+273i\t664-396i\t-381-516i\t-295+454i\t668+386i\t592-476i\t-261-481i\t-716+277i\t234+603i\t880-319i\t132-458i\t-411+332i\t469+912i\t961-187i\t140-946i\t-435-2i\t170+613i\t696+346i\t235-754i\t-686+45i\t-256+1064i\t778+462i\t433-864i\t-26-502i\t-200+334i\t719+351i\t658-503i\t-143-667i\t-576+487i\t251+437i\t659-213i\t-221-550i\t-420+81i\t439+621i\t1077-149i\t208-710i\t-567-120i\t147+783i\t734-126i\t220-371i\t-430-280i\t-87+584i\t590+546i\t674-526i\t-358-232i\t-306+735i\t1015+344i\t907-573i\t-162-537i\t-571+230i\t442+417i\t1027-508i\t-103-635i\t-413+223i\t25+984i\t859+159i\t67-571i\t-481+14i\t405+681i\t675+132i\t441-452i\t-437-293i\t-203+487i\t504+196i\t417-310i\t-473-365i\t-252+632i\t381+379i\t823-373i\t-274-613i\t-377+360i\t403+591i\t921-217i\t-81-718i\t-769+255i\t153+607i\t934-192i\t158-727i\t-492+55i\t184+796i\t1025+183i\t425-555i\t-208-399i\t109+447i\t796+448i\t711-1017i\t-691-584i\t-355+320i\t397+510i\t534-616i\t-340-431i\t-469+462i\t350+936i\t735-304i\t59-621i\t-434+165i\t270+655i\t851-48i\t145-474i\t-465+76i\t135+543i\t673+258i\t260-579i\t-527-301i\t-193+608i\t951+231i\t715-570i\t-334-471i\t-294+455i\t528+505i\t721-420i\t-92-335i\t-519+330i\t377+526i\t730+17i\t-37-716i\t-583+179i\t356+403i\t583-41i\t-50-685i\t-686+139i\t-128+786i\t736+304i\t505-647i\t-915-167i\t62+535i\t675+386i\t576-662i\t-215-211i\t-191+590i\t846+427i\t546-390i\t-433-665i\t-443+342i\t395+374i\t312-266i\t-118-608i\t-465+283i\t358+729i\t1157-43i\t315-911i\t-387-146i\t215+513i\t894+35i\t348-865i\t-678-133i\t-330+775i\t892+302i\t577-415i\t-351-437i\t-350+607i\t834+595i\t670-636i\t-243-544i\t-399+520i\t466+559i\t826-399i\t56-612i\t-718+38i\t71+1006i\t1068+41i\t533-738i\t-317+203i\t11+738i\t981+17i\t693-702i\t-323-405i\t-259+531i\t809+80i\t460-849i\t-373-223i\t-603+492i\t596+483i\t776-439i\t-333-561i\t-276+343i\t446+676i\t648-288i\t-155-616i\t-459+190i\t361+549i\t697+82i\t31-713i\t-386+98i\t10+894i\t828+282i\t466-588i\t-829-370i\t-13+638i\t928+361i\t621-509i\t-407-364i\t-257+432i\t861+403i\t630-471i\t-30-605i\t-203+409i\t376+632i\t896-609i\t-102-861i\t-535+312i\t267+436i\t588-165i\t-82-705i\t-681+37i\t-95+640i\t681+94i\t271-489i\t-337-81i\t-140+691i\t798+173i\t657-719i\t-162-485i\t-89+366i\t673+438i\t552-638i\t-360-480i\t-167+342i\t827+605i\t841-176i\t135-337i\t-483+382i\t242+524i\t907+35i\t184-514i\t-600-204i\t84+629i\t576+52i\t216-434i\t-432-2i\t-284+878i\t1000+514i\t767-482i\t-246-593i\t-16+486i\t667+554i\t807-719i\t-490-431i\t-477+406i\t538+834i\t726-343i\t-177-294i\t-454+322i\t415+793i\t894-11i\t35-755i\t-348-51i\t443+802i\t931-71i\t370-910i\t-447-558i\t-208+538i\t711+390i\t405-726i\t-350-125i\t-368+487i\t662+658i\t627-404i\t-157-239i\t-414+548i\t414+568i\t726-389i\t-142-799i\t-578+206i\t118+845i\t717-46i\t37-343i\t-662+85i\t210+756i\t922+1i\t199-799i\t-440-389i\t-296+828i\t836+448i\t521-463i\t-408-464i\t-348+727i\t681+861i\t828-445i\t-361-487i\t-367+588i\t629+529i\t765-509i\t-380-540i\t-672+230i\t445+577i\t824-60i\t9-524i\t-764+36i\t-148+910i\t822+160i\t385-750i\t-396-175i\t-53+714i\t981+413i\t624-427i\t-371-287i\t-390+455i\t587+454i\t630-327i\t-277-627i\t-389+806i\t539+434i\t730-311i\t150-772i\t-287+246i\t251+783i\t768-137i\t30-452i\t-717-150i\t5+938i\t644+26i\t155-663i\t-575-107i\t-153+692i\t828+353i\t543-641i\t-180-575i\t-133+601i\t393+380i\t348-531i\t-435-418i\t-399+700i\t394+726i\t795-127i\t-246-350i\t-440+293i\t670+748i\t1045+224i\t56-708i\t-723+60i\t145+578i\t904+61i\t427-664i\t-514-229i\t135+719i\t781+431i\t602-590i\t-319-227i\t-336+577i\t582+313i\t662-773i\t-325-694i\t-531+251i\t199+400i\t518-335i\t-64-710i\t-679+310i\t319+831i\t885-89i\t74-574i\t-432+148i\t149+693i\t760-92i\t151-579i\t-450-297i\t-236+673i\t728+168i\t461-633i\t-474-207i\t-148+751i\t1029+485i\t793-584i\t-156-593i\t-168+153i\t595+609i\t715-447i\t-232-501i\t-714+7i\t302+800i\t751-232i\t145-694i\t-554+121i\t24+715i\t922-105i\t250-747i\t-555-207i\t-122+606i\t763+227i\t334-482i\t-435-235i\t-302+635i\t866+508i\t780-411i\t-401-678i\t-268+345i\t268+664i\t986-371i\t-76-811i\t-638+338i\t64+696i\t1009-395i\t415-523i\t-448+59i\t210+798i\t686+229i\t321-688i\t-519-222i\t-128+509i\t646-53i\t372-706i\t-645-262i\t-164+524i\t612+410i\t582-497i\t-214-375i\t-436+415i\t660+504i\t871-282i\t-119-712i\t-446+259i\t437+617i\t830-257i\t310-532i\t-715-203i\t-112+1075i\t652+166i\t259-330i\t-368-172i\t307+779i\t792+395i\n'
b
diff -r b55559a2854f -r 7304ec2c9ab7 nmr_preprocessing/test-data/sampleMetadata.tabular
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nmr_preprocessing/test-data/sampleMetadata.tabular Mon Jul 30 10:33:03 2018 -0400
b
@@ -0,0 +1,6 @@
+TD BYTORDA DIGMOD DECIM DSPFVS SW_h SW O1 DT
+ADG10003u_007 65536 1 1 12 12 14005.6022408964 20.0116255056133 3290.5 3.56999999999999e-05
+ADG10003u_009 65536 1 1 12 12 14005.6022408964 20.0116255056133 3290.5 3.56999999999999e-05
+ADG10003u_015 65536 1 1 12 12 14005.6022408964 20.0116255056133 3290.5 3.56999999999999e-05
+ADG10003u_017 65536 1 1 12 12 14005.6022408964 20.0116255056133 3290.5 3.56999999999999e-05
+ADG10003u_021 65536 1 1 12 12 14005.6022408964 20.0116255056133 3290.5 3.56999999999999e-05
b
diff -r b55559a2854f -r 7304ec2c9ab7 static/images/NmrAnnotation_ASICS.png
b
Binary file static/images/NmrAnnotation_ASICS.png has changed
b
diff -r b55559a2854f -r 7304ec2c9ab7 test-data/ADG_007.zip
b
Binary file test-data/ADG_007.zip has changed
b
diff -r b55559a2854f -r 7304ec2c9ab7 test-data/MTBLS1_177_NMR_Annotation.pdf
b
Binary file test-data/MTBLS1_177_NMR_Annotation.pdf has changed
b
diff -r b55559a2854f -r 7304ec2c9ab7 test-data/MTBLS1_177_NMR_Annotation_proportionEstimation.tabular
--- a/test-data/MTBLS1_177_NMR_Annotation_proportionEstimation.tabular Wed Mar 28 09:48:25 2018 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
b
@@ -1,40 +0,0 @@
-Metabolite Relative_Concentration
-Creatinine 0.0569174516124917
-Citrate 0.0285947900676533
-AceticAcid 0.00931139835139612
-L-Glycine 0.00700618802859799
-ThreonicAcid 0.00312228402191229
-Lactose 0.00274471352269867
-Malonate 0.0026239869463794
-Indoxylsulfate 0.00256983041226207
-L-Arabitol 0.00247809838365845
-L-GlutamicAcid 0.00219750986486448
-Threitol 0.00185008716865122
-L-Alanine 0.00176514469439213
-HippuricAcid 0.00173759535227614
-Betaine 0.00163016358478906
-MalicAcid 0.00154536802871288
-1,3-Diaminopropane 0.00150129592201832
-2-oxoglutarate 0.00142533208121273
-Dimethylamine 0.00131575320617744
-L-Aspartate 0.00127266582522283
-AscorbicAcid 0.00100873973025415
-L-Asparagine 0.00099187237086438
-GuanidinoaceticAcid 0.000925290560878349
-Ethanolamine 0.00089279079362688
-Glycerol 0.00088244833185825
-5,6-Dihydro-5-Methyluracil 0.000849548732878672
-Creatine 0.00079525125560122
-MethylmalonicAcid 0.000792506060661937
-Xylitol 0.000787992683508674
-Taurine 0.000787744798563012
-Succinate 0.000527784171596945
-4-HydroxyphenylAceticAcid 0.000522123163032416
-Methylguanidine 0.000486125204031847
-Myo-Inositol 0.0004425385208034
-beta-HydroxyisovalericAcid 0.000419265217514307
-Propionate 0.000392879831159886
-TMAO 0.000391632855219129
-L-Valine 0.000329117139315598
-Isobutyrate 0.000312582908447652
-CholineChloride 0.000306877971629503