changeset 4:265ee538e120 draft default tip

Uploaded
author marie-tremblay-metatoul
date Wed, 09 Aug 2017 06:28:10 -0400
parents f3ec6799c435
children
files nmr_alignement/NmrAlignment_script.R nmr_alignement/NmrAlignment_wrapper.R nmr_alignement/NmrAlignment_xml.xml
diffstat 3 files changed, 84 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/nmr_alignement/NmrAlignment_script.R	Wed Apr 12 04:32:23 2017 -0400
+++ b/nmr_alignement/NmrAlignment_script.R	Wed Aug 09 06:28:10 2017 -0400
@@ -202,8 +202,10 @@
     pList[[i]] = sort(pList[[i]])
     if (verbose) 
       cat("\n Spectrum ", i, " has ", length(pList[[i]]), 
-          " peaks")
+          " peaks \n")
+      cat(myPeakRes)
   }
+  cat("\n")
   return(pList)
 }
 
@@ -368,18 +370,19 @@
                             verbose)
 {
   ## Peak picking
-  cat("\n detect peaks....")
+  cat("\t PEAK DETECTION \n")
   startTime <- proc.time()
   peakList <- detectSpecPeaks(X=data, nDivRange=nDivRange, scales=scales, baselineThresh=baselineThresh,  
                               SNR.Th = SNR.Th, verbose=verbose)
   endTime <- proc.time()
-  cat("Peak detection time:",(endTime[3]-startTime[3])/60," minutes")
+  cat("\t Peak detection time:",(endTime[3]-startTime[3])/60," minutes \n")
+  cat("\n")
 
   ## Reference spectrum determination
   if (reference == 0)
   {
-    cat("\n Find the spectrum reference...")
-    resFindRef<- findRef(peakList)
+    cat("\t DETERMINATION OF THE REFERENCE SPECTRUM \n")
+    resFindRef <- findRef(peakList)
     refInd <- resFindRef$refInd
     cat("\n Order of spectrum for reference \n")
     for (i in 1:length(resFindRef$orderSpec))
@@ -388,15 +391,19 @@
       if (i %% 10 == 0) 
         cat("\n")
     }
-    cat("\n The reference is: ", refInd)
+	cat("\n")
+	cat("\t Reference spectrum:", refInd, "\n")
+    cat("\n")
   }
   else
   {
     refInd=reference
   }
   ## Spectra alignment to the reference
+  cat("\t SPECTRA ALIGNMENT")
   maxshift <- 50
   Y <- dohCluster(data, peakList=peakList, refInd=refInd, maxShift=maxShift, acceptLostPeak, verbose)
+  cat("\n")
 
   ## Output  
   return(Y)
--- a/nmr_alignement/NmrAlignment_wrapper.R	Wed Apr 12 04:32:23 2017 -0400
+++ b/nmr_alignement/NmrAlignment_wrapper.R	Wed Aug 09 06:28:10 2017 -0400
@@ -71,7 +71,7 @@
 leftBorder <- argLs[["left_border"]]
 rightBorder <- argLs[["right_border"]]
 
-		##Exclusion zone(s)
+		## Exclusion zone(s)
 exclusionZones <- argLs[["zone_exclusion_choices.choice"]]
 exclusionZonesBorders <- NULL
 if (!is.null(argLs$zone_exclusion_left))
@@ -91,6 +91,17 @@
 		## Intensity threshold for peak removal
 baselineThresh <- argLs[["baselineThresh"]]
 
+  ## 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"]]
@@ -98,6 +109,17 @@
 graphOut <- argLs[["graphOut"]]
 
 
+## Checking R packages
+##--------------------
+sink(logOut)
+cat("\tPACKAGE INFO\n")
+#pkgs=c("xcms","batch")
+pkgs=c("batch","speaq")
+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="")
+}
+
 ## Checking arguments
 ##-------------------
 error.stock <- "\n"
@@ -122,15 +144,10 @@
 write.table(t.directory.aligned,file=alignedSpectra,row.names=TRUE,quote=FALSE,sep="\t")
 
 
-excludedZone <- NULL
-for (c in 1:length(exclusionZonesBorders))
-{
-  excludedZone <- c(excludedZone,exclusionZonesBorders[[c]])
-  excludedZone <- sort(excludedZone)
-}
-
 ## Graphical output: overlay of raw and estimated spectra
 pdf(graphOut,onefile=TRUE)
+
+graphical.zone.length <- length(graphicalZonesBorders)
 par(mfrow=c(2,1))
 
 raw.spectra <- data.frame(directory.raw)
@@ -142,32 +159,22 @@
 drawSpec(raw.spectra,xlab="", ylab="Raw spectra", main="")
 drawSpec(aligned.spectra,xlab="", ylab="Aligned spectra", main="")
 
-nbZones <- length(excludedZone)/2
-if (nbZones != 0)
+if (graphical.zone.length != 0)
 {
-  n <- length(excludedZone)
-  drawSpec(raw.spectra[,1:which(round(as.numeric(colnames(raw.spectra)),2) == excludedZone[n])[1]],xlab="", ylab="Raw spectra", main="")
-  drawSpec(aligned.spectra[,1:which(round(as.numeric(colnames(aligned.spectra)),2) == excludedZone[n])[1]],xlab="", ylab="Aligned spectra", main="")
-
-  n <- n - 1
-  while (n >= nbZones & nbZones > 1)
+  #   par(mfrow=c(2,1))
+  for (g in 1:graphical.zone.length)
   {
-    drawSpec(raw.spectra[,(which(round(as.numeric(colnames(raw.spectra)),2) == excludedZone[n])[1]):(which(round(as.numeric(colnames(raw.spectra)),2) == excludedZone[n-1])[1])],xlab="", ylab="Raw spectra", main="")
-    drawSpec(aligned.spectra[,(which(round(as.numeric(colnames(aligned.spectra)),2) == excludedZone[n])[1]):(which(round(as.numeric(colnames(aligned.spectra)),2) == excludedZone[n-1])[1])],xlab="", ylab="Aligned spectra", main="")
-    n <- n - 2
+    print(paste(g, graphicalZonesBorders[[g]][1], graphicalZonesBorders[[g]][2]))
+    drawSpec(raw.spectra[,(which(round(as.numeric(colnames(raw.spectra)),2) == graphicalZonesBorders[[g]][1])[1]):(which(round(as.numeric(colnames(raw.spectra)),2) == graphicalZonesBorders[[g]][2])[1])],xlab="", main="")
+    drawSpec(aligned.spectra[,(which(round(as.numeric(colnames(aligned.spectra)),2) == graphicalZonesBorders[[g]][1])[1]):(which(round(as.numeric(colnames(aligned.spectra)),2) == graphicalZonesBorders[[g]][2])[1])],xlab="", main="")
   }
-
-  drawSpec(raw.spectra[,(which(round(as.numeric(colnames(raw.spectra)),2) == excludedZone[1])[1]):ncol(raw.spectra)],xlab="", ylab="Raw spectra", main="")
-  drawSpec(aligned.spectra[,(which(round(as.numeric(colnames(aligned.spectra)),2) == excludedZone[1])[1]):ncol(aligned.spectra)],xlab="", ylab="Aligned spectra", main="")
 }
-drawSpec(raw.spectra[,(which(round(as.numeric(colnames(raw.spectra)),2) == 2.4)[1]):(which(round(as.numeric(colnames(raw.spectra)),2) == 2.8)[1])],xlab="", ylab="Raw spectra", main="")
-drawSpec(aligned.spectra[,(which(round(as.numeric(colnames(aligned.spectra)),2) == 2.4)[1]):(which(round(as.numeric(colnames(aligned.spectra)),2) == 2.8)[1])],xlab="", ylab="Aligned spectra", main="")
-
 dev.off()
 
 
 ## Ending
 ##---------------------
 cat("\nEnd of 'NMR alignment' Galaxy module call: ", as.character(Sys.time()), sep = "")
+sink()
 options(stringsAsFactors = strAsFacL)
 rm(list = ls())
--- a/nmr_alignement/NmrAlignment_xml.xml	Wed Apr 12 04:32:23 2017 -0400
+++ b/nmr_alignement/NmrAlignment_xml.xml	Wed Aug 09 06:28:10 2017 -0400
@@ -1,4 +1,4 @@
-<tool id="NmrAlignment" name="NMR spectra alignment" version="2.0.3">
+<tool id="NmrAlignment" name="NMR spectra alignment" version="2.0.4">
     <description>based on the Cluster-based Peak Alignment (CluPA) algorithm</description>
      <requirements>
         <requirement type="package" version="1.1_4">r-batch</requirement>
@@ -40,6 +40,15 @@
         ## Intensity threshold
         baselineThresh $baselineThresh
 
+		## 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'
         alignedSpectra '$alignedSpectra'
@@ -75,9 +84,24 @@
             </when>
             <when value="no" />
         </conditional>
+		
         <param name="reference" type="integer" value="0" help="Number of the reference spectrum. Default value is 0: automatic determination of the reference spectrum" />
         <param name="nDivRange" type="integer" value="64" help="Size of a single small segment after division of spectra. Default value is 64" />
         <param name="baselineThresh" type="integer" value="1" help="Threshold to remove all peaks with intensity lower this value. Default value is 1" />
+		
+		<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>
@@ -104,6 +128,13 @@
             <param name="reference" value="0" />
             <param name="nDivRange" value="64" />
             <param name="baselineThresh" value="0" />
+            <conditional name="zone_graphical_choices">
+                <param name="choice" value="yes" />
+                <param name="conditions_0|zone_graphical_left" value="4.2" />
+                <param name="conditions_0|zone_graphical_right" value="4.0" />
+                <param name="conditions_1|zone_graphical_left" value="2.8" />
+                <param name="conditions_1|zone_graphical_right" value="2.4" />
+            </conditional>       
             <output name="alignedSpectra" value="MTBLS1_alignedSpectra.tabular" />
         </test>
     </tests>
@@ -234,6 +265,13 @@
     | Default value: 1
     |
 
+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