diff --git a/tools/xcms_export_samplemetadata/xcms_export_samplemetadata.r b/tools/xcms_export_samplemetadata/xcms_export_samplemetadata.r index 31b36fcf6..7df323c8a 100755 --- a/tools/xcms_export_samplemetadata/xcms_export_samplemetadata.r +++ b/tools/xcms_export_samplemetadata/xcms_export_samplemetadata.r @@ -2,13 +2,15 @@ #Import the different functions source_local <- function(fname) { - argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep = "/")) + argv <- commandArgs(trailingOnly = FALSE) + base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) + source(paste(base_dir, fname, sep = "/")) } source_local("lib.r") pkgs <- c("xcms", "batch") loadAndDisplayPackages(pkgs) -cat("\n\n"); +cat("\n\n") args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects diff --git a/tools/xcms_fillpeaks/xcms_fillpeaks.r b/tools/xcms_fillpeaks/xcms_fillpeaks.r index 9414749be..56b678c9d 100755 --- a/tools/xcms_fillpeaks/xcms_fillpeaks.r +++ b/tools/xcms_fillpeaks/xcms_fillpeaks.r @@ -11,19 +11,21 @@ cat("\tSESSION INFO\n") #Import the different functions source_local <- function(fname) { - argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep = "/")) + argv <- commandArgs(trailingOnly = FALSE) + base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) + source(paste(base_dir, fname, sep = "/")) } source_local("lib.r") pkgs <- c("xcms", "batch") loadAndDisplayPackages(pkgs) -cat("\n\n"); +cat("\n\n") # ----- ARGUMENTS ----- cat("\tARGUMENTS INFO\n") args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects -write.table(as.matrix(args), col.names = F, quote = F, sep = "\t") +write.table(as.matrix(args), col.names = FALSE, quote = FALSE, sep = "\t") cat("\n\n") diff --git a/tools/xcms_group/xcms_group.r b/tools/xcms_group/xcms_group.r index 671366a51..35140bc20 100755 --- a/tools/xcms_group/xcms_group.r +++ b/tools/xcms_group/xcms_group.r @@ -11,19 +11,21 @@ cat("\tSESSION INFO\n") #Import the different functions source_local <- function(fname) { - argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep = "/")) + argv <- commandArgs(trailingOnly = FALSE) + base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) + source(paste(base_dir, fname, sep = "/")) } source_local("lib.r") pkgs <- c("xcms", "batch", "RColorBrewer") loadAndDisplayPackages(pkgs) -cat("\n\n"); +cat("\n\n") # ----- ARGUMENTS ----- cat("\tARGUMENTS INFO\n") args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects -write.table(as.matrix(args), col.names = F, quote = F, sep = "\t") +write.table(as.matrix(args), col.names = FALSE, quote = FALSE, sep = "\t") cat("\n\n") diff --git a/tools/xcms_macro/lib.r b/tools/xcms_macro/lib.r index 1654aae52..41704a3cd 100644 --- a/tools/xcms_macro/lib.r +++ b/tools/xcms_macro/lib.r @@ -89,15 +89,19 @@ mergeXData <- function(args) { } } rm(image) - xdata <- xdata_merged; rm(xdata_merged) - singlefile <- singlefile_merged; rm(singlefile_merged) - md5sumList <- md5sumList_merged; rm(md5sumList_merged) - sampleNamesList <- sampleNamesList_merged; rm(sampleNamesList_merged) + xdata <- xdata_merged + rm(xdata_merged) + singlefile <- singlefile_merged + rm(singlefile_merged) + md5sumList <- md5sumList_merged + rm(md5sumList_merged) + sampleNamesList <- sampleNamesList_merged + rm(sampleNamesList_merged) if (!is.null(args$sampleMetadata)) { cat("\tXSET PHENODATA SETTING...\n") sampleMetadataFile <- args$sampleMetadata - sampleMetadata <- getDataFrameFromFile(sampleMetadataFile, header = F) + sampleMetadata <- getDataFrameFromFile(sampleMetadataFile, header = FALSE) xdata@phenoData@data$sample_group <- sampleMetadata$V2[match(xdata@phenoData@data$sample_name, sampleMetadata$V1)] if (any(is.na(pData(xdata)$sample_group))) { @@ -109,16 +113,20 @@ mergeXData <- function(args) { } if (!is.null(chromTIC_merged)) { - chromTIC <- chromTIC_merged; chromTIC@phenoData <- xdata@phenoData + chromTIC <- chromTIC_merged + chromTIC@phenoData <- xdata@phenoData } if (!is.null(chromBPI_merged)) { - chromBPI <- chromBPI_merged; chromBPI@phenoData <- xdata@phenoData + chromBPI <- chromBPI_merged + chromBPI@phenoData <- xdata@phenoData } if (!is.null(chromTIC_adjusted_merged)) { - chromTIC_adjusted <- chromTIC_adjusted_merged; chromTIC_adjusted@phenoData <- xdata@phenoData + chromTIC_adjusted <- chromTIC_adjusted_merged + chromTIC_adjusted@phenoData <- xdata@phenoData } if (!is.null(chromBPI_adjusted_merged)) { - chromBPI_adjusted <- chromBPI_adjusted_merged; chromBPI_adjusted@phenoData <- xdata@phenoData + chromBPI_adjusted <- chromBPI_adjusted_merged + chromBPI_adjusted@phenoData <- xdata@phenoData } return(list("xdata" = xdata, "singlefile" = singlefile, "md5sumList" = md5sumList, "sampleNamesList" = sampleNamesList, "chromTIC" = chromTIC, "chromBPI" = chromBPI, "chromTIC_adjusted" = chromTIC_adjusted, "chromBPI_adjusted" = chromBPI_adjusted)) @@ -143,7 +151,8 @@ formatIonIdentifiers <- function(variableMetadata, numDigitsRT = 0, numDigitsMZ splitDeco <- strsplit(as.character(variableMetadata$name), "_") idsDeco <- sapply(splitDeco, function(x) { - deco <- unlist(x)[2]; if (is.na(deco)) return("") else return(paste0("_", deco)) + deco <- unlist(x)[2] + if (is.na(deco)) return("") else return(paste0("_", deco)) } ) namecustom <- make.unique(paste0("M", round(variableMetadata[, "mz"], numDigitsMZ), "T", round(variableMetadata[, "rt"], numDigitsRT), idsDeco)) @@ -169,7 +178,7 @@ getPlotChromPeakDensity <- function(xdata, param = NULL, mzdigit = 4) { if (length(unique(xdata$sample_group)) < 10) { group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1") - }else{ + } else { group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette = "Dark 3") } names(group_colors) <- unique(xdata$sample_group) @@ -216,12 +225,13 @@ getPlotAdjustedRtime <- function(xdata) { #@author G. Le Corguille # value: intensity values to be used into, maxo or intb -getPeaklistW4M <- function(xdata, intval = "into", convertRTMinute = F, numDigitsMZ = 4, numDigitsRT = 0, naTOzero = T, variableMetadataOutput, dataMatrixOutput, sampleNamesList) { +getPeaklistW4M <- function(xdata, intval = "into", convertRTMinute = FALSE, numDigitsMZ = 4, numDigitsRT = 0, naTOzero = TRUE, variableMetadataOutput, dataMatrixOutput, sampleNamesList) { dataMatrix <- featureValues(xdata, method = "medret", value = intval) colnames(dataMatrix) <- make.names(tools::file_path_sans_ext(colnames(dataMatrix))) dataMatrix <- cbind(name = groupnames(xdata), dataMatrix) variableMetadata <- featureDefinitions(xdata) - colnames(variableMetadata)[1] <- "mz"; colnames(variableMetadata)[4] <- "rt" + colnames(variableMetadata)[1] <- "mz" + colnames(variableMetadata)[4] <- "rt" variableMetadata <- data.frame(name = groupnames(xdata), variableMetadata) variableMetadata <- RTSecondToMinute(variableMetadata, convertRTMinute) @@ -231,17 +241,17 @@ getPeaklistW4M <- function(xdata, intval = "into", convertRTMinute = F, numDigit # FIX: issue when the vector at peakidx is too long and is written in a new line during the export variableMetadata[, "peakidx"] <- vapply(variableMetadata[, "peakidx"], FUN = paste, FUN.VALUE = character(1), collapse = ",") - write.table(variableMetadata, file = variableMetadataOutput, sep = "\t", quote = F, row.names = F) - write.table(dataMatrix, file = dataMatrixOutput, sep = "\t", quote = F, row.names = F) + write.table(variableMetadata, file = variableMetadataOutput, sep = "\t", quote = FALSE, row.names = FALSE) + write.table(dataMatrix, file = dataMatrixOutput, sep = "\t", quote = FALSE, row.names = FALSE) } #@author G. Le Corguille # It allow different of field separators -getDataFrameFromFile <- function(filename, header = T) { - myDataFrame <- read.table(filename, header = header, sep = ";", stringsAsFactors = F) - if (ncol(myDataFrame) < 2) myDataFrame <- read.table(filename, header = header, sep = "\t", stringsAsFactors = F) - if (ncol(myDataFrame) < 2) myDataFrame <- read.table(filename, header = header, sep = ",", stringsAsFactors = F) +getDataFrameFromFile <- function(filename, header = TRUE) { + myDataFrame <- read.table(filename, header = header, sep = ";", stringsAsFactors = FALSE) + if (ncol(myDataFrame) < 2) myDataFrame <- read.table(filename, header = header, sep = "\t", stringsAsFactors = FALSE) + if (ncol(myDataFrame) < 2) myDataFrame <- read.table(filename, header = header, sep = ",", stringsAsFactors = FALSE) if (ncol(myDataFrame) < 2) { error_message <- "Your tabular file seems not well formatted. The column separators accepted are ; , and tabulation" print(error_message) @@ -271,7 +281,7 @@ getPlotChromatogram <- function(chrom, xdata, pdfname = "Chromatogram.pdf", aggr # Color by group if (length(unique(xdata$sample_group)) < 10) { group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1") - }else{ + } else { group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette = "Dark 3") } if (length(group_colors) > 1) { @@ -392,10 +402,11 @@ retrieveRawfileInTheWorkingDir <- function(singlefile, zipfile, args, prefix = " singlefile_galaxyPath <- singlefile[[singlefile_sampleName]] if (!file.exists(singlefile_galaxyPath)) { error_message <- paste("Cannot access the sample:", singlefile_sampleName, "located:", singlefile_galaxyPath, ". Please, contact your administrator ... if you have one!") - print(error_message); stop(error_message) + print(error_message) + stop(error_message) } - if (!suppressWarnings(try(file.link(singlefile_galaxyPath, singlefile_sampleName), silent = T))) + if (!suppressWarnings(try(file.link(singlefile_galaxyPath, singlefile_sampleName), silent = TRUE))) file.copy(singlefile_galaxyPath, singlefile_sampleName) files <- c(files, singlefile_sampleName) } @@ -410,7 +421,7 @@ retrieveRawfileInTheWorkingDir <- function(singlefile, zipfile, args, prefix = " suppressWarnings(unzip(zipfile, unzip = "unzip")) #get the directory name - suppressWarnings(filesInZip <- unzip(zipfile, list = T)) + suppressWarnings(filesInZip <- unzip(zipfile, list = TRUE)) directories <- unique(unlist(lapply(strsplit(filesInZip$Name, "/"), function(x) x[1]))) directories <- directories[!(directories %in% c("__MACOSX")) & file.info(directories)$isdir] directory <- "." diff --git a/tools/xcms_merge/xcms_merge.r b/tools/xcms_merge/xcms_merge.r index 524429cb4..801b1aad5 100755 --- a/tools/xcms_merge/xcms_merge.r +++ b/tools/xcms_merge/xcms_merge.r @@ -2,13 +2,15 @@ #Import the different functions source_local <- function(fname) { - argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep = "/")) + argv <- commandArgs(trailingOnly = FALSE) + base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) + source(paste(base_dir, fname, sep = "/")) } source_local("lib.r") pkgs <- c("xcms", "batch") loadAndDisplayPackages(pkgs) -cat("\n\n"); +cat("\n\n") args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects diff --git a/tools/xcms_plot_chromatogram/xcms_plot_chromatogram.r b/tools/xcms_plot_chromatogram/xcms_plot_chromatogram.r index 3196472c0..9fed8689a 100755 --- a/tools/xcms_plot_chromatogram/xcms_plot_chromatogram.r +++ b/tools/xcms_plot_chromatogram/xcms_plot_chromatogram.r @@ -6,19 +6,21 @@ cat("\tSESSION INFO\n") #Import the different functions source_local <- function(fname) { - argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep = "/")) + argv <- commandArgs(trailingOnly = FALSE) + base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) + source(paste(base_dir, fname, sep = "/")) } source_local("lib.r") pkgs <- c("xcms", "batch", "RColorBrewer") loadAndDisplayPackages(pkgs) -cat("\n\n"); +cat("\n\n") # ----- ARGUMENTS ----- cat("\tARGUMENTS INFO\n") args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects -write.table(as.matrix(args), col.names = F, quote = F, sep = "\t") +write.table(as.matrix(args), col.names = FALSE, quote = FALSE, sep = "\t") cat("\n\n") @@ -52,10 +54,12 @@ cat("\t\tDRAW GRAPHICS\n") register(SerialParam()) if (!exists("chromTIC") || is.null(chromTIC)) { - cat("\t\t\tCompute TIC\n"); chromTIC <- chromatogram(xdata, aggregationFun = "sum") + cat("\t\t\tCompute TIC\n") + chromTIC <- chromatogram(xdata, aggregationFun = "sum") } if (!exists("chromBPI") || is.null(chromBPI)) { - cat("\t\t\tCompute BPI\n"); chromBPI <- chromatogram(xdata, aggregationFun = "max") + cat("\t\t\tCompute BPI\n") + chromBPI <- chromatogram(xdata, aggregationFun = "max") } if (!is.null(chromTIC_adjusted)) chromTIC <- chromTIC_adjusted diff --git a/tools/xcms_refine/xcms_refine.r b/tools/xcms_refine/xcms_refine.r index b95bd501a..cfdb370a0 100755 --- a/tools/xcms_refine/xcms_refine.r +++ b/tools/xcms_refine/xcms_refine.r @@ -19,13 +19,13 @@ source_local("lib.r") pkgs <- c("xcms", "batch", "RColorBrewer") loadAndDisplayPackages(pkgs) -cat("\n\n"); +cat("\n\n") # ----- ARGUMENTS ----- cat("\tARGUMENTS INFO\n") # interpretation of arguments given in command line as an R list of objects args <- parseCommandArgs(evaluate = FALSE) -write.table(as.matrix(args), col.names = F, quote = F, sep = "\t") +write.table(as.matrix(args), col.names = FALSE, quote = FALSE, sep = "\t") cat("\n\n") diff --git a/tools/xcms_retcor/xcms_retcor.r b/tools/xcms_retcor/xcms_retcor.r index 9d223bf2a..bec671793 100755 --- a/tools/xcms_retcor/xcms_retcor.r +++ b/tools/xcms_retcor/xcms_retcor.r @@ -11,19 +11,21 @@ cat("\tSESSION INFO\n") #Import the different functions source_local <- function(fname) { - argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep = "/")) + argv <- commandArgs(trailingOnly = FALSE) + base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) + source(paste(base_dir, fname, sep = "/")) } source_local("lib.r") pkgs <- c("xcms", "batch", "RColorBrewer") loadAndDisplayPackages(pkgs) -cat("\n\n"); +cat("\n\n") # ----- ARGUMENTS ----- cat("\tARGUMENTS INFO\n") args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects -write.table(as.matrix(args), col.names = F, quote = F, sep = "\t") +write.table(as.matrix(args), col.names = FALSE, quote = FALSE, sep = "\t") cat("\n\n") @@ -40,7 +42,8 @@ cat("\n\n") cat("\tINFILE PROCESSING INFO\n") #image is an .RData file necessary to use xset variable given by previous tools -load(args$image); args$image <- NULL +load(args$image) +args$image <- NULL if (!exists("xdata")) stop("\n\nERROR: The RData doesn't contain any object called 'xdata'. This RData should have been created by an old version of XMCS 2.*") # Handle infiles diff --git a/tools/xcms_summary/xcms_summary.r b/tools/xcms_summary/xcms_summary.r index 527c5fb6f..e8bfc0991 100755 --- a/tools/xcms_summary/xcms_summary.r +++ b/tools/xcms_summary/xcms_summary.r @@ -14,13 +14,15 @@ cat("\tSESSION INFO\n") #Import the different functions source_local <- function(fname) { - argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep = "/")) + argv <- commandArgs(trailingOnly = FALSE) + base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) + source(paste(base_dir, fname, sep = "/")) } source_local("lib.r") pkgs <- c("CAMERA", "batch") loadAndDisplayPackages(pkgs) -cat("\n\n"); +cat("\n\n") # ----- FUNCTION ----- @@ -62,13 +64,13 @@ args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in # ----- ARGUMENTS PROCESSING ----- #image is an .RData file necessary to use xset variable given by previous tools -load(args$image); +load(args$image) htmlOutput <- "summary.html" -if (!is.null(args$htmlOutput)) htmlOutput <- args$htmlOutput; +if (!is.null(args$htmlOutput)) htmlOutput <- args$htmlOutput user_email <- NULL -if (!is.null(args$user_email)) user_email <- args$user_email; +if (!is.null(args$user_email)) user_email <- args$user_email # if the RData come from XCMS 1.x if (exists("xset")) { diff --git a/tools/xcms_xcmsset/xcms_xcmsSet.r b/tools/xcms_xcmsset/xcms_xcmsSet.r index 1f63b8003..89961ac18 100755 --- a/tools/xcms_xcmsset/xcms_xcmsSet.r +++ b/tools/xcms_xcmsset/xcms_xcmsSet.r @@ -11,19 +11,21 @@ cat("\tSESSION INFO\n") #Import the different functions source_local <- function(fname) { - argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep = "/")) + argv <- commandArgs(trailingOnly = FALSE) + base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)) + source(paste(base_dir, fname, sep = "/")) } source_local("lib.r") pkgs <- c("xcms", "batch") loadAndDisplayPackages(pkgs) -cat("\n\n"); +cat("\n\n") # ----- ARGUMENTS ----- cat("\tARGUMENTS INFO\n") args <- parseCommandArgs(evaluate = FALSE) #interpretation of arguments given in command line as an R list of objects -write.table(as.matrix(args), col.names = F, quote = F, sep = "\t") +write.table(as.matrix(args), col.names = FALSE, quote = FALSE, sep = "\t") cat("\n\n") @@ -101,10 +103,10 @@ sampleNamesList <- getSampleMetadata(xdata = xdata, sampleMetadataOutput = "samp # Create a chromPeaks table if required if (exists("peaklistParam")) { - if (peaklistParam) { - cat("\nCreating the chromatographic peaks' table...\n") - write.table(chromPeaks(xdata), file = "chromPeak_table.tsv", sep = "\t", quote = F, row.names = F) - } + if (peaklistParam) { + cat("\nCreating the chromatographic peaks' table...\n") + write.table(chromPeaks(xdata), file = "chromPeak_table.tsv", sep = "\t", quote = FALSE, row.names = FALSE) + } } cat("\n\n")