annotate nmr_bucketing/NmrBucketing_wrapper.R @ 2:3cd762aac7a4 draft

Uploaded
author marie-tremblay-metatoul
date Thu, 20 Apr 2017 08:53:46 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
1 #!/usr/local/public/bin/Rscript --vanilla --slave --no-site-file
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
2
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
3 ## 070115_NmrBucketing2galaxy_v1.R
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
4 ## Marie Tremblay-Franco
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
5 ## MetaboHUB: The French Infrastructure for Metabolomics and Fluxomics
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
6 ## www.metabohub.fr/en
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
7 ## marie.tremblay-franco@toulouse.inra.fr
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
8
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
9 runExampleL <- FALSE
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
10
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
11 if(runExampleL) {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
12 ##------------------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
13 ## Example of arguments
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
14 ##------------------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
15 argLs <- list(StudyDir = "Tlse_BPASourisCerveau",
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
16 upper = "10.0",
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
17 lower = "0.50",
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
18 bucket.width = "0.01",
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
19 exclusion = "TRUE",
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
20 exclusion.zone = list(c(6.5,4.5)),
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
21 graph="Overlay")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
22
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
23 argLs <- c(argLs,
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
24 list(dataMatrixOut = paste(directory,"_NmrBucketing_dataMatrix.tsv",sep=""),
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
25 sampleMetadataOut = paste(directory,"_NmrBucketing_sampleMetadata.tsv",sep=""),
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
26 variableMetadataOut = paste(directory,"_NmrBucketing_variableMetadata.tsv",sep=""),
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
27 graphOut = paste(directory,"_NmrBucketing_graph.pdf",sep=""),
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
28 logOut = paste(directory,"_NmrBucketing_log.txt",sep="")))
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
29 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
30
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
31 ##------------------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
32 ## Options
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
33 ##------------------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
34 strAsFacL <- options()$stringsAsFactors
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
35 options(stringsAsFactors = FALSE)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
36
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
37
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
38 ##------------------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
39 ## Libraries laoding
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
40 ##------------------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
41 # For parseCommandArgs function
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
42 library(batch)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
43 # For cumtrapz function
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
44 library(pracma)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
45
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
46 # R script call
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
47 source_local <- function(fname)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
48 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
49 argv <- commandArgs(trailingOnly = FALSE)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
50 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
51 source(paste(base_dir, fname, sep="/"))
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
52 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
53 #Import the different functions
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
54 source_local("NmrBucketing_script.R")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
55 source_local("DrawSpec.R")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
56
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
57 ##------------------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
58 ## Errors ?????????????????????
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
59 ##------------------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
60
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
61
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
62 ##------------------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
63 ## Constants
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
64 ##------------------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
65 topEnvC <- environment()
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
66 flagC <- "\n"
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
67
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
68
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
69 ##------------------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
70 ## Script
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
71 ##------------------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
72 if(!runExampleL)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
73 argLs <- parseCommandArgs(evaluate=FALSE)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
74
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
75
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
76 ## Parameters Loading
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
77 ##-------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
78 # Inputs
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
79 if (!is.null(argLs[["zipfile"]])){
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
80 fileType="zip"
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
81 zipfile= argLs[["zipfile"]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
82 directory=unzip(zipfile, list=F)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
83 directory=paste(getwd(),strsplit(directory[1],"/")[[1]][2],sep="/")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
84 } else if (!is.null(argLs[["tsvfile"]])){
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
85 fileType="tsv"
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
86 directory <- read.table(argLs[["tsvfile"]],check.names=FALSE,header=TRUE,sep="\t")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
87 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
88
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
89 leftBorder <- argLs[["left_border"]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
90 rightBorder <- argLs[["right_border"]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
91 bucketSize <- argLs[["bucket_width"]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
92 exclusionZones <- argLs[["zone_exclusion_choices.choice"]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
93
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
94 exclusionZonesBorders <- NULL
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
95 if (!is.null(argLs$zone_exclusion_left))
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
96 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
97 for(i in which(names(argLs)=="zone_exclusion_left"))
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
98 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
99 exclusionZonesBorders <- c(exclusionZonesBorders,list(c(argLs[[i]],argLs[[i+1]])))
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
100 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
101 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
102
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
103 graphique <- argLs[["graphType"]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
104
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
105 # Outputs
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
106 nomGraphe <- argLs[["graphOut"]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
107 dataMatrixOut <- argLs[["dataMatrixOut"]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
108 logFile <- argLs[["logOut"]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
109 if (fileType=="zip")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
110 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
111 sampleMetadataOut <- argLs[["sampleOut"]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
112 variableMetadataOut <- argLs[["variableOut"]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
113 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
114
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
115 ## Checking arguments
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
116 ##-------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
117 error.stock <- "\n"
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
118
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
119 if(length(error.stock) > 1)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
120 stop(error.stock)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
121
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
122
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
123 ## Computation
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
124 ##------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
125 outputs <- NmrBucketing(fileType=fileType, fileName=directory, leftBorder=leftBorder, rightBorder=rightBorder, bucketSize=bucketSize,
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
126 exclusionZones=exclusionZones, exclusionZonesBorders=exclusionZonesBorders, graph=graphique, nomFichier=nomGraphe,
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
127 savLog.txtC=logFile)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
128 data_bucket <- outputs[[1]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
129 data_sample <- outputs[[2]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
130 data_variable <- outputs[[3]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
131 ppm <- outputs[[4]]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
132 ppm <- round(ppm,2)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
133
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
134 ## Graphical outputs
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
135 ##------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
136 if (graphique != "None")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
137 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
138 excludedZone <- NULL
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
139 for (c in 1:length(exclusionZonesBorders))
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
140 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
141 excludedZone <- c(excludedZone,exclusionZonesBorders[[c]])
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
142 excludedZone <- sort(excludedZone)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
143 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
144 nbZones <- length(excludedZone)/2
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
145 n <- length(excludedZone)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
146
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
147 # Graphic Device opening
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
148 pdf(nomGraphe,onefile=TRUE)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
149
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
150 if (graphique == "Overlay")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
151 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
152 # Global spectral window
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
153 spectra <- data.frame(t(data_bucket))
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
154 drawSpec(spectra,xlab="", ylab="Intensity", main="")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
155
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
156 ## Zoomed spectral window depending on exclusion zone(s)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
157 if (nbZones != 0)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
158 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
159 BInf <- excludedZone[n]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
160 if (round(BInf,1) == BInf)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
161 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
162 BInf <- BInf+0.01
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
163 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
164 spectra <- data.frame(t(data_bucket[1:(which(ppm == BInf)[[1]]),]))
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
165 drawSpec(spectra,xlab="", ylab="Intensity", main="")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
166 n <- n - 1
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
167
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
168 while (n >= nbZones & nbZones > 1)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
169 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
170 BInf <- excludedZone[n-1]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
171 if (round(BInf,1) > BInf)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
172 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
173 BInf <- BInf+0.01
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
174 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
175 spectra <- data.frame(t(data_bucket[(which(ppm == excludedZone[n])[[1]]):(which(ppm == BInf)[[1]]),]))
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
176 drawSpec(spectra,xlab="", ylab="Intensity", main="")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
177 n <- n - 2
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
178 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
179
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
180 BInf <- excludedZone[1]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
181 if (round(BInf,1) <= BInf)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
182 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
183 BInf <- BInf+0.01
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
184 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
185 spectra <- data.frame(t(data_bucket[(which(ppm == BInf)[[1]]):nrow(data_bucket),]))
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
186 drawSpec(spectra,xlab="", ylab="Intensity", main="")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
187 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
188 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
189 else
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
190 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
191 for (i in 1:ncol(data_bucket))
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
192 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
193 par(mfrow=c((nbZones+2),1))
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
194 n <- length(excludedZone)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
195 spectra <- t(data_bucket[,i])
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
196 names(spectra) <- rownames(data_bucket)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
197 plot(1:length(spectra), spectra, type='l', xlab="", ylab="Intensity", main=colnames(data_bucket)[i], xaxt = "n")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
198 xPos <- 1
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
199 nAxisPos <- 4
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
200 startP <- length(nAxisPos)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
201 endP <- nrow(data_bucket)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
202 GraphRange <- c(startP:endP)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
203 tempVal = trunc(length(GraphRange)/nAxisPos)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
204 xPos = c(0:nAxisPos) * tempVal
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
205 axis(1, at = xPos, labels = rownames(data_bucket)[xPos + startP])
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
206
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
207 ## Zoomed spectral window depending on exclusion zone(s)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
208 if (nbZones != 0)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
209 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
210 BInf <- excludedZone[n]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
211 if (round(BInf,1) == BInf)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
212 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
213 BInf <- BInf+0.01
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
214 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
215 spectra <- t(data_bucket[1:(which(ppm == BInf)[[1]]),i])
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
216 names(spectra) <- rownames(data_bucket)[1:(which(ppm == BInf)[[1]])]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
217 plot(1:length(spectra), spectra, type='l',xlab="", ylab="Intensity", main="", xaxt = "n")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
218 xPos <- 1
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
219 nAxisPos <- 4
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
220 startP <- length(nAxisPos)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
221 endP <- length(spectra)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
222 GraphRange <- c(startP:endP)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
223 tempVal = trunc(length(GraphRange)/nAxisPos)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
224 xPos = c(0:nAxisPos) * tempVal
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
225 axis(1, at = xPos, labels = rownames(data_bucket)[xPos + startP])
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
226 n <- n - 1
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
227
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
228 while (n >= nbZones & nbZones > 1)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
229 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
230 BInf <- excludedZone[n-1]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
231 if (round(BInf,1) > BInf)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
232 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
233 BInf <- BInf+0.01
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
234 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
235 spectra <- t(data_bucket[(which(ppm == excludedZone[n])[[1]]):(which(ppm == BInf)[[1]]),i])
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
236 names(spectra) <- rownames(data_bucket)[(which(ppm == excludedZone[n])[[1]]):(which(ppm == BInf)[[1]])]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
237 plot(1:length(spectra), spectra, type='l',xlab="", ylab="Intensity", main="", xaxt = "n")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
238 xPos <- 1
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
239 nAxisPos <- 4
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
240 startP <- length(nAxisPos)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
241 endP <- length(spectra)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
242 GraphRange <- c(startP:endP)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
243 tempVal = trunc(length(GraphRange)/nAxisPos)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
244 xPos = c(0:nAxisPos) * tempVal
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
245 axis(1, at = xPos, labels = rownames(data_bucket)[xPos + startP])
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
246 n <- n - 2
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
247 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
248
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
249 BInf <- excludedZone[1]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
250 if (round(BInf,1) <= BInf)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
251 {
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
252 BInf <- BInf+0.01
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
253 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
254 spectra <- t(data_bucket[(which(ppm == BInf)[[1]]):nrow(data_bucket),i])
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
255 names(spectra) <- rownames(data_bucket)[(which(ppm == BInf)[[1]]):nrow(data_bucket)]
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
256 plot(1:length(spectra), spectra, type='l',xlab="", ylab="Intensity", main="", xaxt = "n")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
257 xPos <- 1
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
258 nAxisPos <- 4
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
259 startP <- length(nAxisPos)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
260 endP <- length(spectra)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
261 GraphRange <- c(startP:endP)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
262 tempVal = trunc(length(GraphRange)/nAxisPos)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
263 xPos = c(0:nAxisPos) * tempVal
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
264 axis(1, at = xPos, labels = rownames(data_bucket)[xPos + startP])
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
265 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
266 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
267 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
268 dev.off()
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
269 }
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
270 ## Saving
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
271 ##-------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
272 # Data
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
273 data_bucket <- cbind(rownames(data_bucket),data_bucket)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
274 colnames(data_bucket) <- c("Bucket",colnames(data_bucket)[-1])
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
275 write.table(data_bucket,file=argLs$dataMatrixOut,quote=FALSE,row.names=FALSE,sep="\t")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
276 # Sample
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
277 data_sample <- cbind(rownames(data_sample),data_sample)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
278 colnames(data_sample) <- c("Sample",colnames(data_sample)[-1])
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
279 write.table(data_sample,file=argLs$sampleOut,quote=FALSE,row.names=FALSE,sep="\t")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
280 # Variable
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
281 data_variable <- cbind(rownames(data_variable),data_variable)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
282 colnames(data_variable) <- c("Bucket",colnames(data_variable)[-1])
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
283 write.table(data_variable,file=argLs$variableOut,quote=FALSE,row.names=FALSE,sep="\t")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
284
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
285
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
286 ## Ending
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
287 ##---------------------
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
288
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
289 cat("\nEnd of 'NMR bucketing' Galaxy module call: ", as.character(Sys.time()), sep = "")
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
290
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
291 ## sink(NULL)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
292
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
293 options(stringsAsFactors = strAsFacL)
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
294
3cd762aac7a4 Uploaded
marie-tremblay-metatoul
parents:
diff changeset
295 rm(list = ls())