-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathipo4retgroup.r
executable file
·148 lines (113 loc) · 4.67 KB
/
ipo4retgroup.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
#!/usr/bin/env Rscript
# Authors Gildas Le Corguille and Yann Guitton
# Setup R error handling to go to stderr for better error messages in Galaxy
options(show.error.messages = F, error = function() {
cat(geterrmessage(), file = stderr())
q("no", 1, F)
})
# ----- LOG FILE -----
log_file <- file("log.txt", open = "wt")
sink(log_file)
sink(log_file, type = "output")
# ----- PACKAGE -----
options(bitmapType = "cairo")
cat("\tPACKAGE INFO\n")
pkgs <- c("parallel", "BiocGenerics", "Biobase", "Rcpp", "mzR", "xcms", "rsm", "igraph", "CAMERA", "IPO", "snow", "batch")
for (pkg in pkgs) {
cat(pkg, "\t", as.character(packageVersion(pkg)), "\n", sep = "")
suppressWarnings(suppressPackageStartupMessages(stopifnot(library(pkg, quietly = TRUE, logical.return = TRUE, character.only = TRUE))))
}
source_local <- function(fname) {
argv <- commandArgs(trailingOnly = FALSE)
base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
source(paste(base_dir, fname, sep = "/"))
}
cat("\n\n")
# ----- ARGUMENTS -----
cat("\tARGUMENTS INFO\n")
listArguments <- parseCommandArgs(evaluate = FALSE) # interpretation of arguments given in command line as an R list of objects
write.table(as.matrix(listArguments), col.names = F, quote = F, sep = "\t")
cat("\n\n")
# ----- ARGUMENTS PROCESSING -----
cat("\tINFILE PROCESSING INFO\n")
# image is an .RData file necessary to use xset variable given by previous tools
if (!is.null(listArguments[["image"]])) {
load(listArguments[["image"]])
listArguments[["image"]] <- NULL
}
# Import the different functions
source_local("lib.r")
cat("\n\n")
# ----- PROCESSING INFILE -----
cat("\tARGUMENTS PROCESSING INFO\n")
parametersOutput <- "IPO_parameters4retcorGroup.tsv"
if (!is.null(listArguments[["parametersOutput"]])) {
parametersOutput <- listArguments[["parametersOutput"]]
listArguments[["parametersOutput"]] <- NULL
}
if (!is.null(listArguments[["sampleMetadataFile"]])) {
sample.metadata.file <- listArguments[["sampleMetadataFile"]]
listArguments[["sampleMetadataFile"]] <- NULL
}
# necessary to unzip .zip file uploaded to Galaxy
# thanks to .zip file it's possible to upload many file as the same time conserving the tree hierarchy of directories
if (!is.null(listArguments[["zipfile"]])) {
zipfile <- listArguments[["zipfile"]]
listArguments[["zipfile"]] <- NULL
}
if (!is.null(listArguments[["singlefile_galaxyPath"]])) {
singlefile_galaxyPath <- listArguments[["singlefile_galaxyPath"]]
listArguments[["singlefile_galaxyPath"]] <- NULL
singlefile_sampleName <- listArguments[["singlefile_sampleName"]]
listArguments[["singlefile_sampleName"]] <- NULL
}
# single file case
# @TODO: need to be refactoring
if (exists("singlefile_galaxyPath") && (singlefile_galaxyPath != "")) {
cwd <- getwd()
dir.create("raw")
setwd("raw")
for (singlefile_galaxyPath_i in seq(1:length(singlefile_galaxyPath))) {
if (!file.exists(singlefile_galaxyPath[singlefile_galaxyPath_i])) {
error_message <- paste("Cannot access the sample:", singlefile_sampleName[singlefile_galaxyPath_i], "located:", singlefile_galaxyPath[singlefile_galaxyPath_i], ". Please, contact your administrator ... if you have one!")
print(error_message)
stop(error_message)
}
file.symlink(singlefile_galaxyPath[singlefile_galaxyPath_i], singlefile_sampleName[singlefile_galaxyPath_i])
}
setwd(cwd)
directory <- "raw"
}
# We unzip automatically the chromatograms from the zip files.
if (exists("zipfile") && (zipfile != "")) {
if (!file.exists(zipfile)) {
error_message <- paste("Cannot access the Zip file:", zipfile, ". Please, contact your administrator ... if you have one!")
print(error_message)
stop(error_message)
}
# list all file in the zip file
# zip_files=unzip(zipfile,list=T)[,"Name"]
# Because IPO only want raw data in its working directory
if (!dir.exists("ipoworkingdir")) {
dir.create("ipoworkingdir")
}
setwd("ipoworkingdir")
# unzip
suppressWarnings(unzip(zipfile, unzip = getOption("unzip")))
# get the directory name
filesInZip <- unzip(zipfile, list = T)
directories <- unique(unlist(lapply(strsplit(filesInZip$Name, "/"), function(x) x[1])))
directories <- directories[!(directories %in% c("__MACOSX")) & file.info(directories)$isdir]
directory <- "."
if (length(directories) == 1) directory <- directories
cat("files_root_directory\t", directory, "\n")
}
# addition of the directory to the list of arguments in the first position
checkXmlStructure(directory)
checkFilesCompatibilityWithXcms(directory)
cat("\n\n")
# ----- MAIN PROCESSING INFO -----
cat("\tMAIN PROCESSING INFO\n")
ipo4retgroup(xset, sample.metadata.file, directory, parametersOutput, listArguments)
cat("\n\n")
cat("\tDONE\n")