changeset 2:908e1345d7ca draft

Uploaded
author marie-tremblay-metatoul
date Fri, 31 Mar 2017 09:56:39 -0400
parents 58eecef626da
children f3ec6799c435
files nmr_alignement/NmrAlignment_script.R nmr_alignement/NmrAlignment_wrapper.R nmr_alignement/NmrAlignment_xml.xml
diffstat 3 files changed, 48 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/nmr_alignement/NmrAlignment_script.R	Thu Mar 02 10:23:37 2017 -0500
+++ b/nmr_alignement/NmrAlignment_script.R	Fri Mar 31 09:56:39 2017 -0400
@@ -425,13 +425,43 @@
 #   - data.read: n x p matrix                                                                  #
 #   - data.aligned: n x p matrix                                                               #
 ################################################################################################
-nmr.alignment <- function(directory, leftBorder= 10.0, rightBorder= 0.5, exclusionZones=FALSE, 
+nmr.alignment <- function(fileType, directory, leftBorder= 10.0, rightBorder= 0.5, exclusionZones=FALSE, 
                           exclusionZonesBorders=NULL, reference=0, nDivRange=64, baselineThresh=50000, maxshift=50, verbose=FALSE)
 {
-  data.read <- NmrRead(directory=directory, leftBorder=leftBorder, rightBorder=rightBorder, exclusionZones=exclusionZones, exclusionZonesBorders=exclusionZonesBorders)
-  rownames(data.read) <- data.read[,1]
-  data.read <- data.read[,-1]
-  data.read <- t(data.read)
+  if (fileType=="zip")
+  {  
+	data.read <- NmrRead(directory=directory, leftBorder=leftBorder, rightBorder=rightBorder, exclusionZones=exclusionZones, exclusionZonesBorders=exclusionZonesBorders)
+	rownames(data.read) <- data.read[,1]
+	data.read <- data.read[,-1]
+	data.read <- t(data.read)
+  }
+  if (fileType=="tsv")
+  {
+    data.read <- t(directory)
+    ppm <- round(as.numeric(colnames(data.read)),2)
+
+    if (!is.null(exclusionZonesBorders))
+    {
+      excludedZone <- NULL
+      for (c in 1:length(exclusionZonesBorders))
+      {
+        excludedZone <- c(excludedZone,exclusionZonesBorders[[c]])
+        excludedZone <- sort(excludedZone)
+      }
+
+      nbZones <- length(excludedZone)/2
+      n <- length(excludedZone)
+      data <- data.read[,1:which(ppm == excludedZone[n])[1]]
+      n <- n - 1
+      while (n >= nbZones & nbZones > 1)
+      {
+        data <- cbind(data, data.read[,(which(ppm == excludedZone[n])[1]):(which(ppm == excludedZone[n-1])[1])])
+        n <- n - 2
+      }
+      data <- cbind(data, data.read[,(which(ppm == excludedZone[1])[1]):ncol(data.read)])
+      data.read <- data
+    }
+  }
   data.aligned <- cluPA.alignment(data=data.read, reference=reference, nDivRange=nDivRange, 
                                   baselineThresh=baselineThresh, maxshift=maxshift, verbose=verbose)
 
--- a/nmr_alignement/NmrAlignment_wrapper.R	Thu Mar 02 10:23:37 2017 -0500
+++ b/nmr_alignement/NmrAlignment_wrapper.R	Fri Mar 31 09:56:39 2017 -0400
@@ -57,16 +57,21 @@
 	# Inputs
 		## Library of spectra to align
 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")
 }
 
 
@@ -110,7 +115,7 @@
   
 ## Computation
 ##------------
-directory.alignement <- nmr.alignment(directory=directory,leftBorder=leftBorder,rightBorder=rightBorder,exclusionZones=exclusionZones,
+directory.alignement <- nmr.alignment(fileType=fileType,directory=directory,leftBorder=leftBorder,rightBorder=rightBorder,exclusionZones=exclusionZones,
                                   exclusionZonesBorders=exclusionZonesBorders, reference=reference, nDivRange=nDivRange, 
                                   baselineThresh=baselineThresh, maxshift=50, verbose=FALSE)
 directory.raw <- directory.alignement[[1]]
--- a/nmr_alignement/NmrAlignment_xml.xml	Thu Mar 02 10:23:37 2017 -0500
+++ b/nmr_alignement/NmrAlignment_xml.xml	Fri Mar 31 09:56:39 2017 -0400
@@ -1,4 +1,4 @@
-<tool id="NmrAlignment" name="NMR spectra alignment" version="2.0.1">
+<tool id="NmrAlignment" name="NMR spectra alignment" version="2.0.2">
 	<description>based on the Cluster-based Peak Alignment (CluPA) algorithm</description>
 	 <requirements>
         <requirement type="package" version="3.1.2">R</requirement>
@@ -15,6 +15,8 @@
 		## File input
         #if $inputs.input == "lib":
             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'
         #end if
@@ -50,11 +52,15 @@
         <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"/>