2
|
1 #!/usr/local/public/bin/Rscript --vanilla --slave --no-site-file
|
|
2
|
|
3 ## 12012017_Apodization_wrapper.R
|
|
4 ## Manon Martin
|
|
5 ## manon.martin@uclouvain.be
|
|
6
|
|
7
|
|
8 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
9 # Use of runExampleL ?
|
|
10 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
11
|
|
12 runExampleL <- FALSE
|
|
13 #
|
|
14 # if(runExampleL) {
|
|
15 # ##------------------------------
|
|
16 # ## Example of arguments
|
|
17 # ##------------------------------
|
|
18 # argLs <- list(StudyDir = "Tlse_BPASourisCerveau",
|
|
19 # upper = "10.0",
|
|
20 # lower = "0.50",
|
|
21 # bucket.width = "0.01",
|
|
22 # exclusion = "TRUE",
|
|
23 # exclusion.zone = list(c(6.5,4.5)),
|
|
24 # graph="Overlay")
|
|
25 #
|
|
26 # argLs <- c(argLs,
|
|
27 # list(dataMatrixOut = paste(directory,"_NmrBucketing_dataMatrix.tsv",sep=""),
|
|
28 # sampleMetadataOut = paste(directory,"_NmrBucketing_sampleMetadata.tsv",sep=""),
|
|
29 # variableMetadataOut = paste(directory,"_NmrBucketing_variableMetadata.tsv",sep=""),
|
|
30 # graphOut = paste(directory,"_NmrBucketing_graph.pdf",sep=""),
|
|
31 # logOut = paste(directory,"_NmrBucketing_log.txt",sep="")))
|
|
32 # }
|
|
33
|
|
34
|
|
35
|
|
36 ##------------------------------
|
|
37 ## Options
|
|
38 ##------------------------------
|
|
39 strAsFacL <- options()$stringsAsFactors
|
|
40 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
41 # stringsAsFactors = FALSE utilis?? o?? ??
|
|
42 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
43 options(stringsAsFactors = FALSE)
|
|
44
|
|
45
|
|
46
|
|
47
|
|
48 ##------------------------------
|
|
49 ## Libraries loading
|
|
50 ##------------------------------
|
|
51 # For parseCommandArgs function
|
|
52 library(batch)
|
|
53
|
|
54 # R script call
|
|
55 source_local <- function(fname)
|
|
56 {
|
|
57 argv <- commandArgs(trailingOnly = FALSE)
|
|
58 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
|
|
59 source(paste(base_dir, fname, sep="/"))
|
|
60 }
|
|
61 #Import the different functions
|
|
62 source_local("Apodization_Manon.R")
|
|
63
|
|
64 ##------------------------------
|
|
65 ## Errors ?????????????????????
|
|
66 ##------------------------------
|
|
67
|
|
68
|
|
69 ##------------------------------
|
|
70 ## Constants
|
|
71 ##------------------------------
|
|
72 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
73 # interviennent ou ?
|
|
74 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
75
|
|
76 topEnvC <- environment()
|
|
77 flagC <- "\n"
|
|
78
|
|
79
|
|
80 ##------------------------------
|
|
81 ## Script
|
|
82 ##------------------------------
|
|
83 if(!runExampleL)
|
|
84 argLs <- parseCommandArgs(evaluate=FALSE) # If FALSE valeurs par d??faut d??finies dans le software
|
|
85
|
|
86
|
|
87 ## Parameters Loading
|
|
88 ##-------------------
|
|
89 ## Inputs
|
|
90 # data
|
|
91
|
|
92 # --- Galaxy_preformatted data
|
|
93 # data <- read.table(argLs[["dataMatrix"]],check.names=FALSE,header=TRUE,sep="\t")
|
|
94 # rownames(data) <- data[,1]
|
|
95 # data <- data[,-1]
|
|
96 # ---
|
|
97
|
|
98 # --- data from ReadFids
|
|
99 Fid_data <- read.table(argLs[["dataMatrixOut"]],check.names=FALSE,header=TRUE,sep="\t")
|
|
100 Fid_info <- read.table(argLs[["sampleOut"]],check.names=FALSE,header=TRUE,sep="\t")
|
|
101 # ---
|
|
102
|
|
103 # other inputs (cf. XML wrapper)
|
|
104 DT = argLs[["DT"]]
|
|
105 type.apod = argLs[["ApodizationMethod"]]
|
|
106
|
|
107 # set default values for optional arguments
|
|
108 phase=0
|
|
109 rectRatio=1/2
|
|
110 gaussLB=1
|
|
111 expLB=1
|
|
112
|
|
113 # change the default values
|
|
114 if (type.apod %in% c("cos2", "hanning", "hamming")) {
|
|
115 phase = argLs[["phase"]]
|
|
116 }
|
|
117
|
|
118 if (type.apod == "blockexp") {
|
|
119 rectRatio = argLs[["rectRatio"]]
|
|
120 expLB = argLs[["expLB"]]
|
|
121 }
|
|
122
|
|
123 if (type.apod == "blockcos2") {
|
|
124 rectRatio = argLs[["rectRatio"]]
|
|
125 }
|
|
126
|
|
127 if (type.apod == "gauss") {
|
|
128 gaussLB = argLs[["gaussLB"]]
|
|
129 }
|
|
130
|
|
131 if (type.apod == "exp") {
|
|
132 expLB = argLs[["expLB"]]
|
|
133 }
|
|
134
|
|
135 plotWindow = FALSE
|
|
136 returnFactor = FALSE
|
|
137
|
|
138
|
|
139
|
|
140 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
141 # Utility of Outputs ??
|
|
142 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
143 # Outputs
|
|
144 dataMatrixOut <- argLs[["dataMatrixOut"]] # Names from Saving
|
|
145
|
|
146
|
|
147
|
|
148 ## Checking arguments
|
|
149 ##-------------------
|
|
150 error.stock <- "\n"
|
|
151
|
|
152 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
153 # error.stock utilis?? ou ?
|
|
154 #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
155 if(length(error.stock) > 1)
|
|
156 stop(error.stock)
|
|
157
|
|
158
|
|
159 ## Computation
|
|
160 ##------------
|
|
161 outputs <- Apodization(Fid_data = Fid_data, Fid_info = Fid_info, DT = DT,
|
|
162 type.apod = type.apod, phase = phase, rectRatio = rectRatio,
|
|
163 gaussLB = gaussLB, expLB = expLB, plotWindow = plotWindow, returnFactor = returnFactor)
|
|
164
|
|
165 data_matrix <- outputs # Data matrix
|
|
166
|
|
167
|
|
168
|
|
169 ## Saving
|
|
170 ##-------
|
|
171 # Data matrix
|
|
172 data_matrix <- cbind(rownames(data_matrix),data_matrix)
|
|
173 colnames(data_matrix) <- c("Sample",colnames(data_matrix)[-1])
|
|
174 write.table(data_matrix,file=argLs$dataMatrixOut,quote=FALSE,row.names=FALSE,sep="\t")
|
|
175
|
|
176
|
|
177
|
|
178 ## Ending
|
|
179 ##---------------------
|
|
180
|
|
181 cat("\nEnd of 'Apodization' Galaxy module call: ", as.character(Sys.time()), sep = "")
|
|
182
|
|
183 ## sink(NULL)
|
|
184
|
|
185 options(stringsAsFactors = strAsFacL)
|
|
186
|
|
187 rm(list = ls()) |