-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathReadFids_wrapper.R
158 lines (113 loc) · 3.93 KB
/
ReadFids_wrapper.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/local/public/bin/Rscript --vanilla --slave --no-site-file
## 08122016_ReadFids_wrapper.R
## Manon Martin
##======================================================
##======================================================
# Preamble
##======================================================
##======================================================
runExampleL <- FALSE
##------------------------------
## Options
##------------------------------
strAsFacL <- options()$stringsAsFactors
options(stringsAsFactors = FALSE)
options(warn=1)
##------------------------------
## Libraries laoding
##------------------------------
library(batch)
library(ggplot2)
library(gridExtra)
library(reshape2)
# R script call
source_local <- function(fname)
{
argv <- commandArgs(trailingOnly = FALSE)
base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
source(paste(base_dir, fname, sep="/"))
}
#Import the different functions
source_local("ReadFids_script.R")
source_local("DrawFunctions.R")
##------------------------------
## Errors ?????????????????????
##------------------------------
##------------------------------
## Constants
##------------------------------
topEnvC <- environment()
flagC <- "\n"
##------------------------------
## Script
##------------------------------
if(!runExampleL)
argLs <- parseCommandArgs(evaluate=FALSE)
sink(argLs$logOut)
##======================================================
##======================================================
## Parameters Loading
##======================================================
##======================================================
## Inputs
# Path
## Bruker FIDs
fileType="Bruker"
zipfile= argLs[["fidzipfile"]]
directory=unzip(zipfile, list=F)
path=paste(getwd(),strsplit(directory[1],"/")[[1]][2],sep="/")
# other inputs from ReadFids
l = argLs[["title_line"]]
subdirs <- argLs[["subdirectories"]]
dirs.names <- argLs[["dirs_names"]]
# Outputs
# dataMatrix <- argLs[["dataMatrix"]]
# sampleMetadata <- argLs[["sampleMetadata"]]
logOut <- argLs[["logOut"]]
nomGraphe <- argLs[["graphOut"]]
## Checking arguments
##-------------------
error.stock <- "\n"
if(length(error.stock) > 1)
stop(error.stock)
##======================================================
##======================================================
## Computation
##======================================================
##======================================================
sink(logOut,append=TRUE)
if(length(warnings())>0){ # or !is.null(warnings())
print("something happened")
}
## Starting
cat("\nStart of 'ReadFids' Galaxy module call: ", as.character(Sys.time()), "\n\n", sep = "")
outputs <- ReadFids(path = path, l=l, subdirs = subdirs, dirs.names = dirs.names)
data_matrix <- outputs[["Fid_data"]] # Data matrix
data_sample <- outputs[["Fid_info"]] # Sample metadata
pdf(nomGraphe, onefile = TRUE, width = 13, height = 13)
title = "Raw FID data"
DrawSignal(data_matrix, subtype = "stacked",
ReImModArg = c(TRUE, FALSE, FALSE, FALSE), vertical = T,
xlab = "Frequency", num.stacked = 4,
main = title, createWindow=FALSE)
invisible(dev.off())
##======================================================
##======================================================
## Saving
##======================================================
##======================================================
# Data matrix
write.table(data_matrix,file=argLs$dataMatrix, quote=FALSE, row.names=TRUE, sep="\t", col.names=TRUE)
# Sample metadata
write.table(data_sample,file=argLs$sampleMetadata, quote=FALSE, row.names=TRUE, sep="\t", col.names=TRUE)
# log file
# write.table(t(data.frame(argLs)), file = argLs$logOut, col.names = FALSE, quote=FALSE)
# input arguments
cat("\n INPUT and OUTPUT ARGUMENTS :\n")
argLs
## Ending
cat("\nEnd of 'ReadFids' Galaxy module call: ", as.character(Sys.time()), sep = "")
sink()
options(stringsAsFactors = strAsFacL)
rm(list = ls())