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

Changeset 4:d61f6ceef5d6 (2016-11-22)
Previous changeset 3:58679e85745f (2016-08-12) Next changeset 5:475d219739ff (2017-03-02)
Commit message:
planemo upload for repository https://github.com/workflow4metabolomics/nmr_bucketing commit a0155b12acca444f72ff761fcce740e71be28a6d-dirty
modified:
NmrBucketing_script.R
NmrBucketing_wrapper.R
NmrBucketing_xml.xml
README.rst
b
diff -r 58679e85745f -r d61f6ceef5d6 NmrBucketing_script.R
--- a/NmrBucketing_script.R Fri Aug 12 05:47:27 2016 -0400
+++ b/NmrBucketing_script.R Tue Nov 22 05:22:03 2016 -0500
[
@@ -5,11 +5,15 @@
 # Starting date : 20-10-2014                                                                   #
 # Version 1 : 18-12-2014                                                                       #
 # Version 2 : 07-01-2015                                                                       #
+# Version 3 : 24-10-2016                                                                       #
 #                                                                                              #
-# Input files : files in included in user-defined directory                                    #
+# Input files : modification on october 2016                                                   #
+#   - Raw bruker files included in user-defined fileName                                      #
+#   - Preprocessed files (alignment, ...) included in p x n dataframe                          #
 ################################################################################################
-NmrBucketing <- function(directory,leftBorder = 10.0,rightBorder = 0.5,bucketSize = 0.04,exclusionZones,exclusionZonesBorders=NULL,
-                         graph=c("None","Overlay","One_per_individual"),nomFichier,savLog.txtC = NULL) 
+NmrBucketing <- function(fileType,fileName,leftBorder = 10.0,rightBorder = 0.5,bucketSize = 0.04,exclusionZones,
+                         exclusionZonesBorders=NULL,graph=c("None","Overlay","One_per_individual"),
+                         nomFichier,savLog.txtC = NULL) 
 {
   ## Option
   ##---------------
@@ -131,13 +135,7 @@
     return(f.bucket)
   }
   
-    
-  # File names
-  FileNames <- list.files(directory)
-  n <- length(FileNames)
-  
   # Exclusion zones
-##  if (exclusionZones == "yes")
   if (!is.null(exclusionZonesBorders))
   {
     exclusion.zone.m <- matrix(exclusionZonesBorders[[1]],nrow=1)
@@ -145,40 +143,78 @@
       for (k in 2:length(exclusionZonesBorders))
         exclusion.zone.m <- rbind(exclusion.zone.m,exclusionZonesBorders[[k]])
   }
-
-  # Reading and Bucketing
-  directory <- paste(directory,"/",sep="")
-
-  i <- 1
-  while (i <= n)
+  
+  ## CHANGES
+    ## Inputs from zip or library (raw files)
+  if (fileType == "zip")
   {
-    # File reading
-    SampleDir <- paste(directory,FileNames[i],"/1/",sep="")
-    setwd(SampleDir)
-    DataDir <- "pdata/1"
-
-    rawSpectrum <- NmRBrucker_read(DataDir,rawSpectrum)
-
-    orderedSpectrum <- rawSpectrum[order(rawSpectrum[,1],decreasing=T), ]
+      # File names
+    FileNames <- list.files(fileName)
+    n <- length(FileNames)
     
-    # Removal of chemical shifts > leftBorder or < rightBorder boundaries
-    truncatedSpectrum <- orderedSpectrum[orderedSpectrum[,1] < leftBorder & orderedSpectrum[,1] > rightBorder, ]
-    truncatedSpectrum[,1] <- round(truncatedSpectrum[,1],3)
-    
-    # Bucketing
-    spectrum.bucket <- NmrBrucker_bucket(truncatedSpectrum)
+    # Reading and Bucketing
+    fileName <- paste(fileName,"/",sep="")
+  
+    i <- 1
+    while (i <= n)
+    {
+      # File reading
+      SampleDir <- paste(fileName,FileNames[i],"/1/",sep="")
+      setwd(SampleDir)
+      DataDir <- "pdata/1"
+  
+      rawSpectrum <- NmRBrucker_read(DataDir,rawSpectrum)
+  
+      orderedSpectrum <- rawSpectrum[order(rawSpectrum[,1],decreasing=T), ]
+      
+      # Removal of chemical shifts > leftBorder or < rightBorder boundaries
+      truncatedSpectrum <- orderedSpectrum[orderedSpectrum[,1] < leftBorder & orderedSpectrum[,1] > rightBorder, ]
+      truncatedSpectrum[,1] <- round(truncatedSpectrum[,1],3)
+      
+      # Bucketing
+      spectrum.bucket <- NmrBrucker_bucket(truncatedSpectrum)
+      
+      # spectrum Concatenation
+      if (i == 1)
+        bucketedSpectra <- spectrum.bucket
+      if (i > 1)
+        bucketedSpectra <- cbind(bucketedSpectra,spectrum.bucket[,2])
+      colnames(bucketedSpectra)[i+1] <- FileNames[i]
+      
+      # Next sample
+      rm(spectrum.bucket)
+      i <- i +1
+    }
+    # Directory
+    cd(fileName)  
+  }
+  
+  ## Inputs from dataset (preprocessed files)
+  if (fileType=="tsv")
+  {
+    FileNames <- colnames(fileName)
+    n <- length(FileNames)
     
-    # spectrum Concatenation
-    if (i == 1)
-      bucketedSpectra <- spectrum.bucket
-    if (i > 1)
-      bucketedSpectra <- cbind(bucketedSpectra,spectrum.bucket[,2])
-    colnames(bucketedSpectra)[i+1] <- FileNames[i]
-    
-    # Next sample
-    rm(spectrum.bucket)
-    i <- i +1
+    for (i in 1:ncol(fileName))
+    {
+      orderedSpectrum <- cbind(as.numeric(rownames(fileName)),fileName[,i])
+      orderedSpectrum <- orderedSpectrum[order(orderedSpectrum[,1],decreasing=T), ]
+      
+      truncatedSpectrum <- orderedSpectrum[orderedSpectrum[,1] < leftBorder & orderedSpectrum[,1] > rightBorder, ]
+      truncatedSpectrum[,1] <- round(truncatedSpectrum[,1],3)
+      
+      # Bucketing
+      spectrum.bucket <- NmrBrucker_bucket(truncatedSpectrum)
+      
+      # spectrum Concatenation
+      if (i == 1)
+        bucketedSpectra <- spectrum.bucket
+      if (i > 1)
+        bucketedSpectra <- cbind(bucketedSpectra,spectrum.bucket[,2])
+      colnames(bucketedSpectra)[i+1] <- colnames(fileName)[i]
+    }
   }
+  
   identifiants <- gsub("([- , * { } | \\[ ])","_",colnames(bucketedSpectra)[-1])
   colnames(bucketedSpectra) <- c(colnames(bucketedSpectra)[1],identifiants)
 
@@ -195,9 +231,6 @@
   rownames(variableMetadata) <- rownames(bucketedSpectra)
   colnames(variableMetadata) <- "VariableOrder"
 
-  # Directory
-  cd(directory)  
-  
   # Bucketed spectra graph
   if (graph != "None")
   {
b
diff -r 58679e85745f -r d61f6ceef5d6 NmrBucketing_wrapper.R
--- a/NmrBucketing_wrapper.R Fri Aug 12 05:47:27 2016 -0400
+++ b/NmrBucketing_wrapper.R Tue Nov 22 05:22:03 2016 -0500
[
@@ -77,18 +77,23 @@
 ## Parameters Loading
 ##-------------------
   # Inputs
-if (!is.null(argLs[["zipfile"]])){
- zipfile= argLs[["zipfile"]]
- directory=unzip(zipfile, list=F)
- directory=paste(getwd(),strsplit(directory[1],"/")[[1]][2],sep="/")
-} else if (!is.null(argLs[["library"]])){
- directory=argLs[["library"]]
-     if(!file.exists(directory)){
- error_message=paste("Cannot access the directory :",directory,".Please verify if the directory exists or not.")
- print(error_message)
- stop(error_message)
- }
-}
+if (!is.null(argLs[["zipfile"]])){
+ fileType="zip"
+ zipfile= argLs[["zipfile"]]
+ directory=unzip(zipfile, list=F)
+ directory=paste(getwd(),strsplit(directory[1],"/")[[1]][2],sep="/")
+} else if (!is.null(argLs[["library"]])){
+ fileType="zip"
+ directory=argLs[["library"]]
+     if(!file.exists(directory)){
+ error_message=paste("Cannot access the directory :",directory,".Please verify if the directory exists or not.")
+ print(error_message)
+ stop(error_message)
+ }
+} else if (!is.null(argLs[["tsvfile"]])){
+ fileType="tsv"
+ directory <- read.table(argLs[["tsvfile"]],check.names=FALSE,header=TRUE,sep="\t")
+}
 
 leftBorder <- argLs[["left_border"]]
 rightBorder <- argLs[["right_border"]]
@@ -111,7 +116,7 @@
 dataMatrixOut <- argLs[["dataMatrixOut"]]
 sampleMetadataOut <- argLs[["sampleOut"]]
 variableMetadataOut <- argLs[["variableOut"]]
-log <- argLs[["logOut"]]
+logFile <- argLs[["logOut"]]
 
 ## Checking arguments
 ##-------------------
@@ -123,7 +128,9 @@
   
 ## Computation
 ##------------
-outputs <- NmrBucketing(directory,leftBorder,rightBorder,bucketSize,exclusionZones,exclusionZonesBorders,graphique,nomGraphe,log)
+outputs <- NmrBucketing(fileType=fileType, fileName=directory, leftBorder=leftBorder, rightBorder=rightBorder, bucketSize=bucketSize, 
+ exclusionZones=exclusionZones, exclusionZonesBorders=exclusionZonesBorders, graph=graphique, nomFichier=nomGraphe, 
+ savLog.txtC=logFile)
 data_bucket <- outputs[[1]]
 data_sample <- outputs[[2]]
 data_variable <- outputs[[3]]
b
diff -r 58679e85745f -r d61f6ceef5d6 NmrBucketing_xml.xml
--- a/NmrBucketing_xml.xml Fri Aug 12 05:47:27 2016 -0400
+++ b/NmrBucketing_xml.xml Tue Nov 22 05:22:03 2016 -0500
b
@@ -1,9 +1,8 @@
-<tool id="NmrBucketing" name="NMR_Bucketing" version="1.0.2">
+<tool id="NmrBucketing" name="NMR_Bucketing" version="1.0.3">
 
     <description> Bucketing and integration of NMR Bruker raw data</description>
 
     <requirements>
-        <requirement type="package" version="3.1.2">R</requirement>
      <requirement type="package" version="1.1_4">r-batch</requirement>
      <requirement type="package" version="1.8.8">r-pracma</requirement>
     </requirements>
@@ -13,12 +12,14 @@
     </stdio>
 
     <command>
-        Rscript $__tool_directory__/NmrBucketing_wrapper.R
+        Rscript '$__tool_directory__/NmrBucketing_wrapper.R'
 
         #if $inputs.input == "lib":
-            library $__app__.config.user_library_import_dir/$__user_email__/$inputs.library
+            library '$__app__.config.user_library_import_dir/$__user_email__/$inputs.library'
+        #elif $inputs.input == "tsv_file":
+            tsvfile '$inputs.tsv_file'
         #elif $inputs.input == "zip_file":
-            zipfile $inputs.zip_file
+            zipfile '$inputs.zip_file'
         #end if
 
 
@@ -44,21 +45,25 @@
 
         ## Outputs
         logOut log.log
-        dataMatrixOut $dataMatrixOut
-        sampleOut $sampleOut
-        variableOut $variableOut
-        graphOut $graphOut; cat log.log
+        dataMatrixOut '$dataMatrixOut'
+        sampleOut '$sampleOut'
+        variableOut '$variableOut'
+        graphOut '$graphOut'; cat log.log
     </command>
 
     <inputs>
         <conditional name="inputs">
             <param name="input" type="select" label="Choose your inputs method" >
                 <option value="zip_file" selected="true">Zip file from your history containing your Bruker directories</option>
+                <option value="tsv_file">Tsv file containing preprocessed spectra (from your history)</option>
                 <option value="lib" >Library directory name</option>
             </param>
             <when value="zip_file">
                 <param name="zip_file" type="data" format="no_unzip.zip" label="Zip file" />
             </when>
+            <when value="tsv_file">
+                <param name="tsv_file" type="data" format="tabular" label="Tsv file" />
+            </when>
             <when value="lib">
                 <param name="library" type="text" size="40" label="Library directory name" help="The name of your directory containing all your data" >
                     <validator type="empty_field"/> 
@@ -103,7 +108,6 @@
             <filter> graphType != "None" </filter>
         </data>
     </outputs>
-
     
     <tests>
         <test>
@@ -147,12 +151,11 @@
 
 **Upstream tools**
 
-========================= ================= ======= =========
-Name                      output file       format  parameter
-========================= ================= ======= =========
-NA                        NA                zip      NA
-========================= ================= ======= =========
-
+========================= ============================ =======
+Name                      output file                  format 
+========================= ============================ =======
+NMRAlignment              NMR_Alignment_alignedSpectra tsv    
+========================= ============================ =======
 
 **Downstream tools**
 
@@ -178,13 +181,16 @@
 +===========================+============+
 | 1 : Choose your inputs    |   zip      |
 +---------------------------+------------+
+| 1 : Choose your inputs    |   tsv      |
++---------------------------+------------+
 
 **Choose your inputs**
 
-You have two methods for your inputs:
+You have three methods for your inputs:
 
-| Zip file (recommended): You can put a zip file containing your inputs: myinputs.zip (containing all your conditions as sub-directories).
+| Zip file (recommended): You can put a zip file containing your inputs as raw Bruker files: myinputs.zip (containing all your conditions as sub-directories).
 | library folder: You must specify the name of your "library" (folder) created within your space project (for example: /projet/externe/institut/login/galaxylibrary/yourlibrary). Your library must contain all your conditions as sub-directories.
+| Tsv file: You can put a tsv file containing your inputs as preprocessed spectra: myinputs.tsv (containing all your conditions in columns and chemical shifts in rows).
 
 .. image:: ./static/images/Mth_Architecture_Repertoire_Bruker.png
 :width: 800
@@ -275,6 +281,10 @@
 Changelog/News
 --------------
 
+**Version 1.0.3 - 24/10/2016**
+
+- ENHANCEMENT: add possibility of bucketing processed files (upstream tools)     
+     
 **Version 1.0.2 - 12/08/2016**
 
 - ENHANCEMENT: x-axis customization: add chemical shift labels 
b
diff -r 58679e85745f -r d61f6ceef5d6 README.rst
--- a/README.rst Fri Aug 12 05:47:27 2016 -0400
+++ b/README.rst Tue Nov 22 05:22:03 2016 -0500
b
@@ -2,6 +2,10 @@
 Changelog/News
 --------------
 
+**Version 1.0.3 - 24/10/2016**
+
+- ENHANCEMENT: add possibility of bucketing processed files (upstream tools)
+
 **Version 1.0.2 - 12/08/2016**
 
 - ENHANCEMENT: x-axis customization: add chemical shift labels