Skip to content

Commit

Permalink
fix R linter errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bernt-matthias committed May 12, 2023
1 parent c41db76 commit 6706977
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 56 deletions.
6 changes: 4 additions & 2 deletions tools/xcms_export_samplemetadata/xcms_export_samplemetadata.r
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 5 additions & 3 deletions tools/xcms_fillpeaks/xcms_fillpeaks.r
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
8 changes: 5 additions & 3 deletions tools/xcms_group/xcms_group.r
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
57 changes: 34 additions & 23 deletions tools/xcms_macro/lib.r
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand All @@ -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))
Expand All @@ -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))
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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 <- "."
Expand Down
6 changes: 4 additions & 2 deletions tools/xcms_merge/xcms_merge.r
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 9 additions & 5 deletions tools/xcms_plot_chromatogram/xcms_plot_chromatogram.r
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tools/xcms_refine/xcms_refine.r
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
11 changes: 7 additions & 4 deletions tools/xcms_retcor/xcms_retcor.r
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions tools/xcms_summary/xcms_summary.r
Original file line number Diff line number Diff line change
Expand Up @@ -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 -----
Expand Down Expand Up @@ -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")) {
Expand Down
16 changes: 9 additions & 7 deletions tools/xcms_xcmsset/xcms_xcmsSet.r
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 6706977

Please sign in to comment.