diff --git a/tools/camera/CAMERA_findAdducts.R b/tools/camera/CAMERA_findAdducts.R index 5eb62ef4c..20937d42e 100755 --- a/tools/camera/CAMERA_findAdducts.R +++ b/tools/camera/CAMERA_findAdducts.R @@ -12,39 +12,38 @@ print(args_vec) # Function to convert "NULL" strings to actual NULL values convertNullString <- function(x) { - if (x == "NULL") { - return(NULL) - } - return(x) + if (x == "NULL") { + return(NULL) + } + return(x) } args <- list( - image = args_vec[1], # the xsAnnotate object - ppm = as.numeric(args_vec[2]), # ppm error for the search - mzabs = as.numeric(args_vec[3]), # allowed variance for the search - multiplier = as.numeric(args_vec[4]), # highest number(n) of allowed clusterion [nM+ion] - polarity = args_vec[5], # Which polarity mode was used for measuring of the MS sample - rules = args_vec[6], # custom ruleset or NULL for default ruleset - max_peaks = as.numeric(args_vec[7]), # If run in parallel mode, this number defines how many peaks will be calculated in each thread - psg_list = convertNullString(args_vec[8]), # Vector of pseudospectra indices; correlation analysis will only be done for those groups - intval = args_vec[9], # choose intensity values. Allowed values are "into", "maxo", "intb" (string) - convertRTMinute = as.logical(args_vec[10]), # TRUE - FALSE - numDigitsMZ = as.numeric(args_vec[11]), # Number of digits MZ - numDigitsRT = as.numeric(args_vec[12]) # Number of digits RT + image = args_vec[1], # the xsAnnotate object + ppm = as.numeric(args_vec[2]), # ppm error for the search + mzabs = as.numeric(args_vec[3]), # allowed variance for the search + multiplier = as.numeric(args_vec[4]), # highest number(n) of allowed clusterion [nM+ion] + polarity = args_vec[5], # Which polarity mode was used for measuring of the MS sample + rules = args_vec[6], # custom ruleset or NULL for default ruleset + max_peaks = as.numeric(args_vec[7]), # If run in parallel mode, this number defines how many peaks will be calculated in each thread + psg_list = convertNullString(args_vec[8]), # Vector of pseudospectra indices; correlation analysis will only be done for those groups + intval = args_vec[9], # choose intensity values. Allowed values are "into", "maxo", "intb" (string) + convertRTMinute = as.logical(args_vec[10]), # TRUE - FALSE + numDigitsMZ = as.numeric(args_vec[11]), # Number of digits MZ + numDigitsRT = as.numeric(args_vec[12]) # Number of digits RT ) - # Convert "NULL" to actual NULL or convert to data frame if (args$rules == "NULL") { - args$rulset <- convertNullString(args$rules) # Return NULL + args$rulset <- convertNullString(args$rules) # Return NULL } else { args$rulset <- read.table(args$rules, h = TRUE, sep = ",") - if (ncol(args$rulset) < 4) rulset <- read.table(args$rules, h = TRUE, sep = "\t") - if (ncol(args$rulset) < 4) rulset <- read.table(args$rules, h = TRUE, sep = ",") - if (ncol(args$rulset) < 4) { - error_message <- "Your ruleset file seems not well formatted. The column separators accepted are ; , and tabulation" - print(error_message) - stop(error_message) - } + if (ncol(args$rulset) < 4) rulset <- read.table(args$rules, h = TRUE, sep = "\t") + if (ncol(args$rulset) < 4) rulset <- read.table(args$rules, h = TRUE, sep = ",") + if (ncol(args$rulset) < 4) { + error_message <- "Your ruleset file seems not well formatted. The column separators accepted are ; , and tabulation" + print(error_message) + stop(error_message) + } } print("Converted arguments:") @@ -55,7 +54,7 @@ print(sapply(args, class)) # Verify the arguments if (!file.exists(args$image)) { - stop("The provided RData file does not exist: ", args$image) + stop("The provided RData file does not exist: ", args$image) } # Load the RData file @@ -64,42 +63,42 @@ args$image <- NULL # Function to retrieve the raw file from the arguments getRawfilePathFromArguments <- function(singlefile, zipfile, args) { - if (!is.null(args$zipfile)) zipfile <- args$zipfile - if (!is.null(args$zipfilePositive)) zipfile <- args$zipfilePositive - if (!is.null(args$zipfileNegative)) zipfile <- args$zipfileNegative - - if (!is.null(args$singlefile_galaxyPath)) { - singlefile_galaxyPaths <- args$singlefile_galaxyPath - singlefile_sampleNames <- args$singlefile_sampleName - } - if (!is.null(args$singlefile_galaxyPathPositive)) { - singlefile_galaxyPaths <- args$singlefile_galaxyPathPositive - singlefile_sampleNames <- args$singlefile_sampleNamePositive - } - if (!is.null(args$singlefile_galaxyPathNegative)) { - singlefile_galaxyPaths <- args$singlefile_galaxyPathNegative - singlefile_sampleNames <- args$singlefile_sampleNameNegative - } - if (exists("singlefile_galaxyPaths")) { - singlefile_galaxyPaths <- unlist(strsplit(singlefile_galaxyPaths, ",")) - singlefile_sampleNames <- unlist(strsplit(singlefile_sampleNames, ",")) - - singlefile <- NULL - for (singlefile_galaxyPath_i in seq_len(length(singlefile_galaxyPaths))) { - singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i] - singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i] - singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath - } - } - for (argument in c( - "zipfile", "zipfilePositive", "zipfileNegative", - "singlefile_galaxyPath", "singlefile_sampleName", - "singlefile_galaxyPathPositive", "singlefile_sampleNamePositive", - "singlefile_galaxyPathNegative", "singlefile_sampleNameNegative" - )) { - args[[argument]] <- NULL - } - return(list(zipfile = zipfile, singlefile = singlefile, args = args)) + if (!is.null(args$zipfile)) zipfile <- args$zipfile + if (!is.null(args$zipfilePositive)) zipfile <- args$zipfilePositive + if (!is.null(args$zipfileNegative)) zipfile <- args$zipfileNegative + + if (!is.null(args$singlefile_galaxyPath)) { + singlefile_galaxyPaths <- args$singlefile_galaxyPath + singlefile_sampleNames <- args$singlefile_sampleName + } + if (!is.null(args$singlefile_galaxyPathPositive)) { + singlefile_galaxyPaths <- args$singlefile_galaxyPathPositive + singlefile_sampleNames <- args$singlefile_sampleNamePositive + } + if (!is.null(args$singlefile_galaxyPathNegative)) { + singlefile_galaxyPaths <- args$singlefile_galaxyPathNegative + singlefile_sampleNames <- args$singlefile_sampleNameNegative + } + if (exists("singlefile_galaxyPaths")) { + singlefile_galaxyPaths <- unlist(strsplit(singlefile_galaxyPaths, ",")) + singlefile_sampleNames <- unlist(strsplit(singlefile_sampleNames, ",")) + + singlefile <- NULL + for (singlefile_galaxyPath_i in seq_len(length(singlefile_galaxyPaths))) { + singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i] + singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i] + singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath + } + } + for (argument in c( + "zipfile", "zipfilePositive", "zipfileNegative", + "singlefile_galaxyPath", "singlefile_sampleName", + "singlefile_galaxyPathPositive", "singlefile_sampleNamePositive", + "singlefile_galaxyPathNegative", "singlefile_sampleNameNegative" + )) { + args[[argument]] <- NULL + } + return(list(zipfile = zipfile, singlefile = singlefile, args = args)) } # Save arguments for report generation @@ -114,33 +113,33 @@ args <- rawFilePath$args # Function to retrieve raw files in the working directory retrieveRawfileInTheWorkingDir <- function(singlefile, zipfile) { - if (!is.null(singlefile) && (length(singlefile) > 0)) { - for (singlefile_sampleName in names(singlefile)) { - singlefile_galaxyPath <- singlefile[[singlefile_sampleName]] - if (!file.exists(singlefile_galaxyPath)) { - error_message <- paste("Cannot access the sample:", singlefile_sampleName, "located at:", singlefile_galaxyPath) - print(error_message) - stop(error_message) - } - file.symlink(singlefile_galaxyPath, singlefile_sampleName) - } - directory <- "." - } - if (!is.null(zipfile) && (zipfile != "")) { - if (!file.exists(zipfile)) { - error_message <- paste("Cannot access the Zip file:", zipfile) - print(error_message) - stop(error_message) - } - suppressWarnings(unzip(zipfile, unzip = "unzip")) - 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 <- "." - if (length(directories) == 1) directory <- directories - cat("files_root_directory\t", directory, "\n") - } - return(directory) + if (!is.null(singlefile) && (length(singlefile) > 0)) { + for (singlefile_sampleName in names(singlefile)) { + singlefile_galaxyPath <- singlefile[[singlefile_sampleName]] + if (!file.exists(singlefile_galaxyPath)) { + error_message <- paste("Cannot access the sample:", singlefile_sampleName, "located at:", singlefile_galaxyPath) + print(error_message) + stop(error_message) + } + file.symlink(singlefile_galaxyPath, singlefile_sampleName) + } + directory <- "." + } + if (!is.null(zipfile) && (zipfile != "")) { + if (!file.exists(zipfile)) { + error_message <- paste("Cannot access the Zip file:", zipfile) + print(error_message) + stop(error_message) + } + suppressWarnings(unzip(zipfile, unzip = "unzip")) + 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 <- "." + if (length(directories) == 1) directory <- directories + cat("files_root_directory\t", directory, "\n") + } + return(directory) } # Retrieve the files @@ -161,7 +160,7 @@ RTSecondToMinute <- function(variableMetadata, convertRTMinute) { # Verify that the object xa is loaded if (!exists("xa")) { - stop("The object xa was not found in the RData file.") + stop("The object xa was not found in the RData file.") } print("Loaded xa object:") @@ -169,7 +168,7 @@ print(xa) # Apply the findAdducts function on the xsAnnotate object print("Calling findAdducts function:") -xa <- findAdducts(xa, ppm=args$ppm, mzabs=args$mzabs, multiplier=args$multiplier, polarity=args$polarity, rules=args$rulset, max_peaks=args$max_peaks, psg_list=args$psg_list, intval=args$intval) +xa <- findAdducts(xa, ppm = args$ppm, mzabs = args$mzabs, multiplier = args$multiplier, polarity = args$polarity, rules = args$rulset, max_peaks = args$max_peaks, psg_list = args$psg_list, intval = args$intval) print("Result of findAdducts function:") print(xa) @@ -178,17 +177,17 @@ print(xa) peakList <- getPeaklist(xa, intval = args$intval) # Generate group names with and without decimals for mz and rt -names_default <- groupnames(xa@xcmsSet, mzdec = 0, rtdec = 0) # Names without decimals -names_custom <- groupnames(xa@xcmsSet, mzdec = args$numDigitsMZ , rtdec = args$numDigitsRT) # Names with "x" decimals +names_default <- groupnames(xa@xcmsSet, mzdec = 0, rtdec = 0) # Names without decimals +names_custom <- groupnames(xa@xcmsSet, mzdec = args$numDigitsMZ, rtdec = args$numDigitsRT) # Names with "x" decimals # Calculate indices of the columns to include from peakList # Select all columns except the last sample-specific columns ncols <- length(colnames(peakList)) -sample_cols <- length(xa@sample) # Number of samples +sample_cols <- length(xa@sample) # Number of samples # Indices for the columns of interest -main_cols <- 1:(ncols - (3 + sample_cols)) # Main columns before sample columns -tail_cols <- (ncols - 2):ncols # The last 3 columns (adduct, isotope, pcgroup) +main_cols <- 1:(ncols - (3 + sample_cols)) # Main columns before sample columns +tail_cols <- (ncols - 2):ncols # The last 3 columns (adduct, isotope, pcgroup) # Combine the selected columns from matgrp with the group names variableMetadata <- cbind( @@ -200,13 +199,13 @@ variableMetadata <- cbind( if (!exists("RTinMinute")) RTinMinute <- FALSE if (args$convertRTMinute && RTinMinute == FALSE) { - RTinMinute <- TRUE - variableMetadata <- RTSecondToMinute(variableMetadata = variableMetadata, convertRTMinute = args$convertRTMinute) + RTinMinute <- TRUE + variableMetadata <- RTSecondToMinute(variableMetadata = variableMetadata, convertRTMinute = args$convertRTMinute) } # Save the extracted peak list as a TSV file named 'variableMetadata.tsv' output_file_tsv <- "variableMetadata.tsv" -write.table(variableMetadata, file=output_file_tsv, sep = "\t", row.names = FALSE, quote = FALSE) +write.table(variableMetadata, file = output_file_tsv, sep = "\t", row.names = FALSE, quote = FALSE) # Save the updated xsAnnotate object output_file_RData <- "camera_findAdducts.RData" @@ -214,4 +213,3 @@ objects2save <- c("xa", "variableMetadata", "listOFlistArguments", "zipfile", "s save(list = objects2save[objects2save %in% ls()], file = output_file_RData) cat("Output files generated:", output_file_tsv, "and", output_file_RData, "\n") - diff --git a/tools/camera/CAMERA_findIsotopes.R b/tools/camera/CAMERA_findIsotopes.R index 165f784ae..652a25267 100755 --- a/tools/camera/CAMERA_findIsotopes.R +++ b/tools/camera/CAMERA_findIsotopes.R @@ -11,17 +11,17 @@ print("Arguments retrieved from command line:") print(args_vec) args <- list( - image = args_vec[1], # the xsAnnotate object - maxcharge = as.numeric(args_vec[2]), # max. number of the isotope charge - maxiso = as.numeric(args_vec[3]), # max. number of the isotope peaks - ppm = as.numeric(args_vec[4]), # ppm error for the search - mzabs = as.numeric(args_vec[5]), # allowed variance for the search - intval = args_vec[6], # Intensity parameter ("into", "maxo", "intb") - minfrac = as.numeric(args_vec[7]), # In case of multiple samples, percentage value of samples, which must contain the correct C12/C13 ratio and are not NA - filter = as.logical(args_vec[8]), # Should C12/C13 filter be applied? - convertRTMinute = as.logical(args_vec[9]), # TRUE - FALSE - numDigitsMZ = as.numeric(args_vec[10]), # Number of digits MZ - numDigitsRT = as.numeric(args_vec[11]) # Number of digits RT + image = args_vec[1], # the xsAnnotate object + maxcharge = as.numeric(args_vec[2]), # max. number of the isotope charge + maxiso = as.numeric(args_vec[3]), # max. number of the isotope peaks + ppm = as.numeric(args_vec[4]), # ppm error for the search + mzabs = as.numeric(args_vec[5]), # allowed variance for the search + intval = args_vec[6], # Intensity parameter ("into", "maxo", "intb") + minfrac = as.numeric(args_vec[7]), # In case of multiple samples, percentage value of samples, which must contain the correct C12/C13 ratio and are not NA + filter = as.logical(args_vec[8]), # Should C12/C13 filter be applied? + convertRTMinute = as.logical(args_vec[9]), # TRUE - FALSE + numDigitsMZ = as.numeric(args_vec[10]), # Number of digits MZ + numDigitsRT = as.numeric(args_vec[11]) # Number of digits RT ) print("Converted arguments:") @@ -32,7 +32,7 @@ print(sapply(args, class)) # Argument validation if (!file.exists(args$image)) { - stop("The provided RData file does not exist: ", args$image) + stop("The provided RData file does not exist: ", args$image) } # Load the RData file @@ -41,42 +41,42 @@ args$image <- NULL # Function to retrieve the raw file from the arguments getRawfilePathFromArguments <- function(singlefile, zipfile, args) { - if (!is.null(args$zipfile)) zipfile <- args$zipfile - if (!is.null(args$zipfilePositive)) zipfile <- args$zipfilePositive - if (!is.null(args$zipfileNegative)) zipfile <- args$zipfileNegative - - if (!is.null(args$singlefile_galaxyPath)) { - singlefile_galaxyPaths <- args$singlefile_galaxyPath - singlefile_sampleNames <- args$singlefile_sampleName - } - if (!is.null(args$singlefile_galaxyPathPositive)) { - singlefile_galaxyPaths <- args$singlefile_galaxyPathPositive - singlefile_sampleNames <- args$singlefile_sampleNamePositive - } - if (!is.null(args$singlefile_galaxyPathNegative)) { - singlefile_galaxyPaths <- args$singlefile_galaxyPathNegative - singlefile_sampleNames <- args$singlefile_sampleNameNegative - } - if (exists("singlefile_galaxyPaths")) { - singlefile_galaxyPaths <- unlist(strsplit(singlefile_galaxyPaths, ",")) - singlefile_sampleNames <- unlist(strsplit(singlefile_sampleNames, ",")) - - singlefile <- NULL - for (singlefile_galaxyPath_i in seq_len(length(singlefile_galaxyPaths))) { - singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i] - singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i] - singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath - } - } - for (argument in c( - "zipfile", "zipfilePositive", "zipfileNegative", - "singlefile_galaxyPath", "singlefile_sampleName", - "singlefile_galaxyPathPositive", "singlefile_sampleNamePositive", - "singlefile_galaxyPathNegative", "singlefile_sampleNameNegative" - )) { - args[[argument]] <- NULL - } - return(list(zipfile = zipfile, singlefile = singlefile, args = args)) + if (!is.null(args$zipfile)) zipfile <- args$zipfile + if (!is.null(args$zipfilePositive)) zipfile <- args$zipfilePositive + if (!is.null(args$zipfileNegative)) zipfile <- args$zipfileNegative + + if (!is.null(args$singlefile_galaxyPath)) { + singlefile_galaxyPaths <- args$singlefile_galaxyPath + singlefile_sampleNames <- args$singlefile_sampleName + } + if (!is.null(args$singlefile_galaxyPathPositive)) { + singlefile_galaxyPaths <- args$singlefile_galaxyPathPositive + singlefile_sampleNames <- args$singlefile_sampleNamePositive + } + if (!is.null(args$singlefile_galaxyPathNegative)) { + singlefile_galaxyPaths <- args$singlefile_galaxyPathNegative + singlefile_sampleNames <- args$singlefile_sampleNameNegative + } + if (exists("singlefile_galaxyPaths")) { + singlefile_galaxyPaths <- unlist(strsplit(singlefile_galaxyPaths, ",")) + singlefile_sampleNames <- unlist(strsplit(singlefile_sampleNames, ",")) + + singlefile <- NULL + for (singlefile_galaxyPath_i in seq_len(length(singlefile_galaxyPaths))) { + singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i] + singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i] + singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath + } + } + for (argument in c( + "zipfile", "zipfilePositive", "zipfileNegative", + "singlefile_galaxyPath", "singlefile_sampleName", + "singlefile_galaxyPathPositive", "singlefile_sampleNamePositive", + "singlefile_galaxyPathNegative", "singlefile_sampleNameNegative" + )) { + args[[argument]] <- NULL + } + return(list(zipfile = zipfile, singlefile = singlefile, args = args)) } # Save arguments to generate a report @@ -91,33 +91,33 @@ args <- rawFilePath$args # Function to retrieve raw files in the working directory retrieveRawfileInTheWorkingDir <- function(singlefile, zipfile) { - if (!is.null(singlefile) && (length(singlefile) > 0)) { - for (singlefile_sampleName in names(singlefile)) { - singlefile_galaxyPath <- singlefile[[singlefile_sampleName]] - if (!file.exists(singlefile_galaxyPath)) { - error_message <- paste("Cannot access the sample:", singlefile_sampleName, "located:", singlefile_galaxyPath) - print(error_message) - stop(error_message) - } - file.symlink(singlefile_galaxyPath, singlefile_sampleName) - } - directory <- "." - } - if (!is.null(zipfile) && (zipfile != "")) { - if (!file.exists(zipfile)) { - error_message <- paste("Cannot access the Zip file:", zipfile) - print(error_message) - stop(error_message) - } - suppressWarnings(unzip(zipfile, unzip = "unzip")) - 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 <- "." - if (length(directories) == 1) directory <- directories - cat("files_root_directory\t", directory, "\n") - } - return(directory) + if (!is.null(singlefile) && (length(singlefile) > 0)) { + for (singlefile_sampleName in names(singlefile)) { + singlefile_galaxyPath <- singlefile[[singlefile_sampleName]] + if (!file.exists(singlefile_galaxyPath)) { + error_message <- paste("Cannot access the sample:", singlefile_sampleName, "located:", singlefile_galaxyPath) + print(error_message) + stop(error_message) + } + file.symlink(singlefile_galaxyPath, singlefile_sampleName) + } + directory <- "." + } + if (!is.null(zipfile) && (zipfile != "")) { + if (!file.exists(zipfile)) { + error_message <- paste("Cannot access the Zip file:", zipfile) + print(error_message) + stop(error_message) + } + suppressWarnings(unzip(zipfile, unzip = "unzip")) + 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 <- "." + if (length(directories) == 1) directory <- directories + cat("files_root_directory\t", directory, "\n") + } + return(directory) } # Retrieve files @@ -138,42 +138,43 @@ RTSecondToMinute <- function(variableMetadata, convertRTMinute) { # Verify if the xa object is loaded if (!exists("xa")) { - stop("The xa object was not found in the RData file.") + stop("The xa object was not found in the RData file.") } print("xa object loaded:") print(xa) print("calcIsotopeMatrix") -calcIsotopeMatrix <- function(maxiso = 4){ - - if(!is.numeric(maxiso)){ - stop("Parameter maxiso is not numeric!\n") - } else if(maxiso < 1 | maxiso > 8){ - stop(paste("Parameter maxiso must be between 1 and 8. ", - "Otherwise, use your own IsotopeMatrix.\n"),sep="") - } - - isotopeMatrix <- matrix(NA, 8, 4); - colnames(isotopeMatrix) <- c("mzmin", "mzmax", "intmin", "intmax") - - isotopeMatrix[1, ] <- c(1.000, 1.0040, 1.0, 150) - isotopeMatrix[2, ] <- c(0.997, 1.0040, 0.01, 200) - isotopeMatrix[3, ] <- c(1.000, 1.0040, 0.001, 200) - isotopeMatrix[4, ] <- c(1.000, 1.0040, 0.0001, 200) - isotopeMatrix[5, ] <- c(1.000, 1.0040, 0.00001, 200) - isotopeMatrix[6, ] <- c(1.000, 1.0040, 0.000001, 200) - isotopeMatrix[7, ] <- c(1.000, 1.0040, 0.0000001, 200) - isotopeMatrix[8, ] <- c(1.000, 1.0040, 0.00000001, 200) - - return(isotopeMatrix[1:maxiso, , drop=FALSE]) +calcIsotopeMatrix <- function(maxiso = 4) { + if (!is.numeric(maxiso)) { + stop("Parameter maxiso is not numeric!\n") + } else if (maxiso < 1 | maxiso > 8) { + stop(paste( + "Parameter maxiso must be between 1 and 8. ", + "Otherwise, use your own IsotopeMatrix.\n" + ), sep = "") + } + + isotopeMatrix <- matrix(NA, 8, 4) + colnames(isotopeMatrix) <- c("mzmin", "mzmax", "intmin", "intmax") + + isotopeMatrix[1, ] <- c(1.000, 1.0040, 1.0, 150) + isotopeMatrix[2, ] <- c(0.997, 1.0040, 0.01, 200) + isotopeMatrix[3, ] <- c(1.000, 1.0040, 0.001, 200) + isotopeMatrix[4, ] <- c(1.000, 1.0040, 0.0001, 200) + isotopeMatrix[5, ] <- c(1.000, 1.0040, 0.00001, 200) + isotopeMatrix[6, ] <- c(1.000, 1.0040, 0.000001, 200) + isotopeMatrix[7, ] <- c(1.000, 1.0040, 0.0000001, 200) + isotopeMatrix[8, ] <- c(1.000, 1.0040, 0.00000001, 200) + + return(isotopeMatrix[1:maxiso, , drop = FALSE]) } isotopeMatrix <- calcIsotopeMatrix(args$maxiso) # Apply the findIsotopes function on the xsAnnotate object print("Calling findIsotopes function:") -xa <- findIsotopes(xa, maxcharge=args$maxcharge, maxiso=args$maxiso, ppm=args$ppm, mzabs=args$mzabs, intval=args$intval, minfrac=args$minfrac, isotopeMatrix=isotopeMatrix, filter=args$filter) +xa <- findIsotopes(xa, maxcharge = args$maxcharge, maxiso = args$maxiso, ppm = args$ppm, mzabs = args$mzabs, intval = args$intval, minfrac = args$minfrac, isotopeMatrix = isotopeMatrix, filter = args$filter) print("Result of the findIsotopes function:") print(xa) @@ -182,17 +183,17 @@ print(xa) peakList <- getPeaklist(xa, intval = args$intval) # Generate group names with and without decimals for mz and rt -names_default <- groupnames(xa@xcmsSet, mzdec = 0, rtdec = 0) # Names without decimals -names_custom <- groupnames(xa@xcmsSet, mzdec = args$numDigitsMZ , rtdec = args$numDigitsRT) # Names with "x" decimals +names_default <- groupnames(xa@xcmsSet, mzdec = 0, rtdec = 0) # Names without decimals +names_custom <- groupnames(xa@xcmsSet, mzdec = args$numDigitsMZ, rtdec = args$numDigitsRT) # Names with "x" decimals # Calculate indices of the columns to include from peakList # Select all columns except the last sample-specific columns ncols <- length(colnames(peakList)) -sample_cols <- length(xa@sample) # Number of samples +sample_cols <- length(xa@sample) # Number of samples # Indices for the columns of interest -main_cols <- 1:(ncols - (3 + sample_cols)) # Main columns before sample columns -tail_cols <- (ncols - 2):ncols # The last 3 columns (adduct, isotope, pcgroup) +main_cols <- 1:(ncols - (3 + sample_cols)) # Main columns before sample columns +tail_cols <- (ncols - 2):ncols # The last 3 columns (adduct, isotope, pcgroup) # Combine the selected columns from matgrp with the group names variableMetadata <- cbind( @@ -204,18 +205,18 @@ variableMetadata <- cbind( if (!exists("RTinMinute")) RTinMinute <- FALSE if (args$convertRTMinute && RTinMinute == FALSE) { - RTinMinute <- TRUE - variableMetadata <- RTSecondToMinute(variableMetadata = variableMetadata, convertRTMinute = args$convertRTMinute) + RTinMinute <- TRUE + variableMetadata <- RTSecondToMinute(variableMetadata = variableMetadata, convertRTMinute = args$convertRTMinute) } # Saves the extracted peak list as a TSV file named 'variableMetadata.tsv' output_file_tsv <- "variableMetadata.tsv" -write.table(variableMetadata, file=output_file_tsv, sep = "\t", row.names = FALSE, quote = FALSE) +write.table(variableMetadata, file = output_file_tsv, sep = "\t", row.names = FALSE, quote = FALSE) # Save the updated xsAnnotate object output_file_RData <- "camera_findIsotopes.RData" + objects2save <- c("xa", "variableMetadata", "listOFlistArguments", "zipfile", "singlefile", "RTinMinute") save(list = objects2save[objects2save %in% ls()], file = output_file_RData) cat("Output files generated:", output_file_tsv, "and", output_file_RData, "\n") - diff --git a/tools/camera/CAMERA_groupCorr.R b/tools/camera/CAMERA_groupCorr.R index d55b85cd7..5832b71a0 100755 --- a/tools/camera/CAMERA_groupCorr.R +++ b/tools/camera/CAMERA_groupCorr.R @@ -11,18 +11,18 @@ print("Command-line arguments retrieved:") print(args_vec) args <- list( - image = args_vec[1], # the xsAnnotate object - cor_eic_th = as.numeric(args_vec[2]), # Correlation threshold for EIC correlation - pval = as.numeric(args_vec[3]), # p-value threshold for testing correlation significance - graphMethod = args_vec[4], # Clustering method for resulting correlation graph. See calcPC for more details. - calcIso = as.logical(args_vec[5]), # Include isotope detection information for graph clustering - calcCiS = as.logical(args_vec[6]), # Calculate correlation inside samples - calcCaS = as.logical(args_vec[7]), # Calculate correlation across samples - cor_exp_th = as.numeric(args_vec[8]), # Threshold for intensity correlations across samples - intval = args_vec[9], # Selection of the intensity values (such as "into") used in the correlation analysis. See getPeaklist for all allowed values. - numDigitsMZ = as.numeric(args_vec[10]), # Digits for MZ "customname" - numDigitsRT = as.numeric(args_vec[11]), # Digits for RT "customname" - convertRTMinute = as.logical(args_vec[12]) # TRUE - FALSE + image = args_vec[1], # the xsAnnotate object + cor_eic_th = as.numeric(args_vec[2]), # Correlation threshold for EIC correlation + pval = as.numeric(args_vec[3]), # p-value threshold for testing correlation significance + graphMethod = args_vec[4], # Clustering method for resulting correlation graph. See calcPC for more details. + calcIso = as.logical(args_vec[5]), # Include isotope detection information for graph clustering + calcCiS = as.logical(args_vec[6]), # Calculate correlation inside samples + calcCaS = as.logical(args_vec[7]), # Calculate correlation across samples + cor_exp_th = as.numeric(args_vec[8]), # Threshold for intensity correlations across samples + intval = args_vec[9], # Selection of the intensity values (such as "into") used in the correlation analysis. See getPeaklist for all allowed values. + numDigitsMZ = as.numeric(args_vec[10]), # Digits for MZ "customname" + numDigitsRT = as.numeric(args_vec[11]), # Digits for RT "customname" + convertRTMinute = as.logical(args_vec[12]) # TRUE - FALSE ) print("Converted arguments:") @@ -35,7 +35,7 @@ print(sapply(args, class)) # Verify if the arguments are correct if (!file.exists(args$image)) { - stop("The provided RData file does not exist: ", args$image) + stop("The provided RData file does not exist: ", args$image) } # Load the RData file @@ -44,42 +44,42 @@ args$image <- NULL # Function to retrieve the raw file from the arguments getRawfilePathFromArguments <- function(singlefile, zipfile, args) { - if (!is.null(args$zipfile)) zipfile <- args$zipfile - if (!is.null(args$zipfilePositive)) zipfile <- args$zipfilePositive - if (!is.null(args$zipfileNegative)) zipfile <- args$zipfileNegative - - if (!is.null(args$singlefile_galaxyPath)) { - singlefile_galaxyPaths <- args$singlefile_galaxyPath - singlefile_sampleNames <- args$singlefile_sampleName - } - if (!is.null(args$singlefile_galaxyPathPositive)) { - singlefile_galaxyPaths <- args$singlefile_galaxyPathPositive - singlefile_sampleNames <- args$singlefile_sampleNamePositive - } - if (!is.null(args$singlefile_galaxyPathNegative)) { - singlefile_galaxyPaths <- args$singlefile_galaxyPathNegative - singlefile_sampleNames <- args$singlefile_sampleNameNegative - } - if (exists("singlefile_galaxyPaths")) { - singlefile_galaxyPaths <- unlist(strsplit(singlefile_galaxyPaths, ",")) - singlefile_sampleNames <- unlist(strsplit(singlefile_sampleNames, ",")) - - singlefile <- NULL - for (singlefile_galaxyPath_i in seq_len(length(singlefile_galaxyPaths))) { - singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i] - singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i] - singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath - } - } - for (argument in c( - "zipfile", "zipfilePositive", "zipfileNegative", - "singlefile_galaxyPath", "singlefile_sampleName", - "singlefile_galaxyPathPositive", "singlefile_sampleNamePositive", - "singlefile_galaxyPathNegative", "singlefile_sampleNameNegative" - )) { - args[[argument]] <- NULL - } - return(list(zipfile = zipfile, singlefile = singlefile, args = args)) + if (!is.null(args$zipfile)) zipfile <- args$zipfile + if (!is.null(args$zipfilePositive)) zipfile <- args$zipfilePositive + if (!is.null(args$zipfileNegative)) zipfile <- args$zipfileNegative + + if (!is.null(args$singlefile_galaxyPath)) { + singlefile_galaxyPaths <- args$singlefile_galaxyPath + singlefile_sampleNames <- args$singlefile_sampleName + } + if (!is.null(args$singlefile_galaxyPathPositive)) { + singlefile_galaxyPaths <- args$singlefile_galaxyPathPositive + singlefile_sampleNames <- args$singlefile_sampleNamePositive + } + if (!is.null(args$singlefile_galaxyPathNegative)) { + singlefile_galaxyPaths <- args$singlefile_galaxyPathNegative + singlefile_sampleNames <- args$singlefile_sampleNameNegative + } + if (exists("singlefile_galaxyPaths")) { + singlefile_galaxyPaths <- unlist(strsplit(singlefile_galaxyPaths, ",")) + singlefile_sampleNames <- unlist(strsplit(singlefile_sampleNames, ",")) + + singlefile <- NULL + for (singlefile_galaxyPath_i in seq_len(length(singlefile_galaxyPaths))) { + singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i] + singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i] + singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath + } + } + for (argument in c( + "zipfile", "zipfilePositive", "zipfileNegative", + "singlefile_galaxyPath", "singlefile_sampleName", + "singlefile_galaxyPathPositive", "singlefile_sampleNamePositive", + "singlefile_galaxyPathNegative", "singlefile_sampleNameNegative" + )) { + args[[argument]] <- NULL + } + return(list(zipfile = zipfile, singlefile = singlefile, args = args)) } # Save arguments to generate a report @@ -94,33 +94,33 @@ args <- rawFilePath$args # Function to retrieve the raw file in the working directory retrieveRawfileInTheWorkingDir <- function(singlefile, zipfile) { - if (!is.null(singlefile) && (length(singlefile) > 0)) { - for (singlefile_sampleName in names(singlefile)) { - singlefile_galaxyPath <- singlefile[[singlefile_sampleName]] - if (!file.exists(singlefile_galaxyPath)) { - error_message <- paste("Cannot access the sample:", singlefile_sampleName, "located at:", singlefile_galaxyPath) - print(error_message) - stop(error_message) - } - file.symlink(singlefile_galaxyPath, singlefile_sampleName) - } - directory <- "." - } - if (!is.null(zipfile) && (zipfile != "")) { - if (!file.exists(zipfile)) { - error_message <- paste("Cannot access the Zip file:", zipfile) - print(error_message) - stop(error_message) - } - suppressWarnings(unzip(zipfile, unzip = "unzip")) - 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 <- "." - if (length(directories) == 1) directory <- directories - cat("files_root_directory\t", directory, "\n") - } - return(directory) + if (!is.null(singlefile) && (length(singlefile) > 0)) { + for (singlefile_sampleName in names(singlefile)) { + singlefile_galaxyPath <- singlefile[[singlefile_sampleName]] + if (!file.exists(singlefile_galaxyPath)) { + error_message <- paste("Cannot access the sample:", singlefile_sampleName, "located at:", singlefile_galaxyPath) + print(error_message) + stop(error_message) + } + file.symlink(singlefile_galaxyPath, singlefile_sampleName) + } + directory <- "." + } + if (!is.null(zipfile) && (zipfile != "")) { + if (!file.exists(zipfile)) { + error_message <- paste("Cannot access the Zip file:", zipfile) + print(error_message) + stop(error_message) + } + suppressWarnings(unzip(zipfile, unzip = "unzip")) + 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 <- "." + if (length(directories) == 1) directory <- directories + cat("files_root_directory\t", directory, "\n") + } + return(directory) } # Retrieve the files @@ -141,7 +141,7 @@ RTSecondToMinute <- function(variableMetadata, convertRTMinute) { # Ensure the xa object is loaded if (!exists("xa")) { - stop("The xa object was not found in the RData file.") + stop("The xa object was not found in the RData file.") } print("xa object loaded:") @@ -149,7 +149,7 @@ print(xa) # Apply the groupCorr function to the xsAnnotate object print("Calling groupCorr function:") -xa <- groupCorr(xa, cor_eic_th=args$cor_eic_th, pval=args$pval, graphMethod=args$graphMethod, calcIso=args$calcIso, calcCiS=args$calcCiS, calcCaS=args$calcCaS, cor_exp_th=args$cor_exp_th, intval=args$intval) +xa <- groupCorr(xa, cor_eic_th = args$cor_eic_th, pval = args$pval, graphMethod = args$graphMethod, calcIso = args$calcIso, calcCiS = args$calcCiS, calcCaS = args$calcCaS, cor_exp_th = args$cor_exp_th, intval = args$intval) print("Result of groupCorr function:") print(xa) @@ -158,17 +158,17 @@ print(xa) peakList <- getPeaklist(xa, intval = args$intval) # Generate group names with and without decimals for mz and rt -names_default <- groupnames(xa@xcmsSet, mzdec = 0, rtdec = 0) # Names without decimals -names_custom <- groupnames(xa@xcmsSet, mzdec = args$numDigitsMZ , rtdec = args$numDigitsRT) # Names with "x" decimals +names_default <- groupnames(xa@xcmsSet, mzdec = 0, rtdec = 0) # Names without decimals +names_custom <- groupnames(xa@xcmsSet, mzdec = args$numDigitsMZ, rtdec = args$numDigitsRT) # Names with "x" decimals # Calculate indices of the columns to include from peakList # Select all columns except the last sample-specific columns ncols <- length(colnames(peakList)) -sample_cols <- length(xa@sample) # Number of samples +sample_cols <- length(xa@sample) # Number of samples # Indices for the columns of interest -main_cols <- 1:(ncols - (3 + sample_cols)) # Main columns before sample columns -tail_cols <- (ncols - 2):ncols # The last 3 columns (adduct, isotope, pcgroup) +main_cols <- 1:(ncols - (3 + sample_cols)) # Main columns before sample columns +tail_cols <- (ncols - 2):ncols # The last 3 columns (adduct, isotope, pcgroup) # Combine the selected columns from matgrp with the group names variableMetadata <- cbind( @@ -180,13 +180,13 @@ variableMetadata <- cbind( if (!exists("RTinMinute")) RTinMinute <- FALSE if (args$convertRTMinute == TRUE && RTinMinute == FALSE) { - RTinMinute <- TRUE - variableMetadata <- RTSecondToMinute(variableMetadata = variableMetadata, convertRTMinute = args$convertRTMinute) + RTinMinute <- TRUE + variableMetadata <- RTSecondToMinute(variableMetadata = variableMetadata, convertRTMinute = args$convertRTMinute) } # Save the extracted peak list as a TSV file named 'variableMetadata.tsv' output_file_tsv <- "variableMetadata.tsv" -write.table(variableMetadata, file=output_file_tsv, sep = "\t", row.names = FALSE, quote = FALSE) +write.table(variableMetadata, file = output_file_tsv, sep = "\t", row.names = FALSE, quote = FALSE) # Save the updated xsAnnotate object output_file_RData <- "camera_groupCorr.RData" @@ -194,4 +194,3 @@ objects2save <- c("xa", "variableMetadata", "listOFlistArguments", "zipfile", "s save(list = objects2save[objects2save %in% ls()], file = output_file_RData) cat("Output files generated:", output_file_tsv, "and", output_file_RData, "\n") - diff --git a/tools/camera/CAMERA_groupFWHM.R b/tools/camera/CAMERA_groupFWHM.R index f3beea84d..cebc07865 100755 --- a/tools/camera/CAMERA_groupFWHM.R +++ b/tools/camera/CAMERA_groupFWHM.R @@ -12,18 +12,18 @@ print(args_vec) # Convert arguments to appropriate types args <- list( - image = args_vec[1], # RData input file - sigma = as.numeric(args_vec[2]), # Convert sigma to numeric - perfwhm = as.numeric(args_vec[3]), # Convert perfwhm to numeric - intval = args_vec[4], # intval parameter ("into", "maxo", "intb") - convertRTMinute = as.logical(args_vec[5]), # TRUE - FALSE - numDigitsMZ = as.numeric(args_vec[6]), # Number of digits MZ - numDigitsRT = as.numeric(args_vec[7]) # Number of digits RT + image = args_vec[1], # RData input file + sigma = as.numeric(args_vec[2]), # Convert sigma to numeric + perfwhm = as.numeric(args_vec[3]), # Convert perfwhm to numeric + intval = args_vec[4], # intval parameter ("into", "maxo", "intb") + convertRTMinute = as.logical(args_vec[5]), # TRUE - FALSE + numDigitsMZ = as.numeric(args_vec[6]), # Number of digits MZ + numDigitsRT = as.numeric(args_vec[7]) # Number of digits RT ) # Check if the image file exists if (!file.exists(args$image)) { - stop("The RData file does not exist: ", args$image) + stop("The RData file does not exist: ", args$image) } # Load the RData file (it should contain the xset object, typically an xcmsSet or XCMSnExp) @@ -32,73 +32,73 @@ args$image <- NULL # Function to get an xcmsSet or XCMSnExp object getxcmsSetObject <- function(xobject) { - # XCMS 1.x - if (class(xobject) == "xcmsSet") { - return(xobject) - } - # XCMS 3.x - if (class(xobject) == "XCMSnExp") { - suppressWarnings(xset <- as(xobject, "xcmsSet")) - if (is.null(xset@phenoData$sample_group)) { - sampclass(xset) <- "." - } else { - sampclass(xset) <- xset@phenoData$sample_group - } - if (!is.null(xset@phenoData$sample_name)) { - rownames(xset@phenoData) <- xset@phenoData$sample_name - } - return(xset) - } + # XCMS 1.x + if (class(xobject) == "xcmsSet") { + return(xobject) + } + # XCMS 3.x + if (class(xobject) == "XCMSnExp") { + suppressWarnings(xset <- as(xobject, "xcmsSet")) + if (is.null(xset@phenoData$sample_group)) { + sampclass(xset) <- "." + } else { + sampclass(xset) <- xset@phenoData$sample_group + } + if (!is.null(xset@phenoData$sample_name)) { + rownames(xset@phenoData) <- xset@phenoData$sample_name + } + return(xset) + } } # If the xdata object exists, convert it to xcmsSet if (exists("xdata")) { - xset <- getxcmsSetObject(xdata) + xset <- getxcmsSetObject(xdata) } # Function to retrieve the raw file from the arguments getRawfilePathFromArguments <- function(singlefile, zipfile, args) { - if (!is.null(args$zipfile)) zipfile <- args$zipfile - if (!is.null(args$zipfilePositive)) zipfile <- args$zipfilePositive - if (!is.null(args$zipfileNegative)) zipfile <- args$zipfileNegative - - if (!is.null(args$singlefile_galaxyPath)) { - singlefile_galaxyPaths <- args$singlefile_galaxyPath - singlefile_sampleNames <- args$singlefile_sampleName - } - if (!is.null(args$singlefile_galaxyPathPositive)) { - singlefile_galaxyPaths <- args$singlefile_galaxyPathPositive - singlefile_sampleNames <- args$singlefile_sampleNamePositive - } - if (!is.null(args$singlefile_galaxyPathNegative)) { - singlefile_galaxyPaths <- args$singlefile_galaxyPathNegative - singlefile_sampleNames <- args$singlefile_sampleNameNegative - } - if (exists("singlefile_galaxyPaths")) { - singlefile_galaxyPaths <- unlist(strsplit(singlefile_galaxyPaths, ",")) - singlefile_sampleNames <- unlist(strsplit(singlefile_sampleNames, ",")) - - singlefile <- NULL - for (singlefile_galaxyPath_i in seq_len(length(singlefile_galaxyPaths))) { - singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i] - singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i] - singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath - } - } - for (argument in c( - "zipfile", "zipfilePositive", "zipfileNegative", - "singlefile_galaxyPath", "singlefile_sampleName", - "singlefile_galaxyPathPositive", "singlefile_sampleNamePositive", - "singlefile_galaxyPathNegative", "singlefile_sampleNameNegative" - )) { - args[[argument]] <- NULL - } - return(list(zipfile = zipfile, singlefile = singlefile, args = args)) + if (!is.null(args$zipfile)) zipfile <- args$zipfile + if (!is.null(args$zipfilePositive)) zipfile <- args$zipfilePositive + if (!is.null(args$zipfileNegative)) zipfile <- args$zipfileNegative + + if (!is.null(args$singlefile_galaxyPath)) { + singlefile_galaxyPaths <- args$singlefile_galaxyPath + singlefile_sampleNames <- args$singlefile_sampleName + } + if (!is.null(args$singlefile_galaxyPathPositive)) { + singlefile_galaxyPaths <- args$singlefile_galaxyPathPositive + singlefile_sampleNames <- args$singlefile_sampleNamePositive + } + if (!is.null(args$singlefile_galaxyPathNegative)) { + singlefile_galaxyPaths <- args$singlefile_galaxyPathNegative + singlefile_sampleNames <- args$singlefile_sampleNameNegative + } + if (exists("singlefile_galaxyPaths")) { + singlefile_galaxyPaths <- unlist(strsplit(singlefile_galaxyPaths, ",")) + singlefile_sampleNames <- unlist(strsplit(singlefile_sampleNames, ",")) + + singlefile <- NULL + for (singlefile_galaxyPath_i in seq_len(length(singlefile_galaxyPaths))) { + singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i] + singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i] + singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath + } + } + for (argument in c( + "zipfile", "zipfilePositive", "zipfileNegative", + "singlefile_galaxyPath", "singlefile_sampleName", + "singlefile_galaxyPathPositive", "singlefile_sampleNamePositive", + "singlefile_galaxyPathNegative", "singlefile_sampleNameNegative" + )) { + args[[argument]] <- NULL + } + return(list(zipfile = zipfile, singlefile = singlefile, args = args)) } 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.*") -#Verification of a group step before doing the fillpeaks job. +# Verification of a group step before doing the fillpeaks job. if (!hasFeatures(xdata)) stop("You must always do a group step after a retcor. Otherwise it won't work for the groupFWHM step") # Save arguments to generate a report @@ -113,33 +113,33 @@ args <- rawFilePath$args # Function to retrieve the raw file in the working directory retrieveRawfileInTheWorkingDir <- function(singlefile, zipfile) { - if (!is.null(singlefile) && (length(singlefile) > 0)) { - for (singlefile_sampleName in names(singlefile)) { - singlefile_galaxyPath <- singlefile[[singlefile_sampleName]] - if (!file.exists(singlefile_galaxyPath)) { - error_message <- paste("Cannot access the sample:", singlefile_sampleName, "located:", singlefile_galaxyPath) - print(error_message) - stop(error_message) - } - file.symlink(singlefile_galaxyPath, singlefile_sampleName) - } - directory <- "." - } - if (!is.null(zipfile) && (zipfile != "")) { - if (!file.exists(zipfile)) { - error_message <- paste("Cannot access the Zip file:", zipfile) - print(error_message) - stop(error_message) - } - suppressWarnings(unzip(zipfile, unzip = "unzip")) - 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 <- "." - if (length(directories) == 1) directory <- directories - cat("files_root_directory\t", directory, "\n") - } - return(directory) + if (!is.null(singlefile) && (length(singlefile) > 0)) { + for (singlefile_sampleName in names(singlefile)) { + singlefile_galaxyPath <- singlefile[[singlefile_sampleName]] + if (!file.exists(singlefile_galaxyPath)) { + error_message <- paste("Cannot access the sample:", singlefile_sampleName, "located:", singlefile_galaxyPath) + print(error_message) + stop(error_message) + } + file.symlink(singlefile_galaxyPath, singlefile_sampleName) + } + directory <- "." + } + if (!is.null(zipfile) && (zipfile != "")) { + if (!file.exists(zipfile)) { + error_message <- paste("Cannot access the Zip file:", zipfile) + print(error_message) + stop(error_message) + } + suppressWarnings(unzip(zipfile, unzip = "unzip")) + 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 <- "." + if (length(directories) == 1) directory <- directories + cat("files_root_directory\t", directory, "\n") + } + return(directory) } # Retrieve files @@ -170,17 +170,17 @@ xa <- groupFWHM(xsa, sigma = as.numeric(args$sigma), perfwhm = as.numeric(args$p peakList <- getPeaklist(xa, intval = args$intval) # Generate group names with and without decimals for mz and rt -names_default <- groupnames(xa@xcmsSet, mzdec = 0, rtdec = 0) # Names without decimals -names_custom <- groupnames(xa@xcmsSet, mzdec = args$numDigitsMZ , rtdec = args$numDigitsRT) # Names with "x" decimals +names_default <- groupnames(xa@xcmsSet, mzdec = 0, rtdec = 0) # Names without decimals +names_custom <- groupnames(xa@xcmsSet, mzdec = args$numDigitsMZ, rtdec = args$numDigitsRT) # Names with "x" decimals # Calculate indices of the columns to include from peakList # Select all columns except the last sample-specific columns ncols <- length(colnames(peakList)) -sample_cols <- length(xa@sample) # Number of samples +sample_cols <- length(xa@sample) # Number of samples # Indices for the columns of interest -main_cols <- 1:(ncols - (3 + sample_cols)) # Main columns before sample columns -tail_cols <- (ncols - 2):ncols # The last 3 columns (adduct, isotope, pcgroup) +main_cols <- 1:(ncols - (3 + sample_cols)) # Main columns before sample columns +tail_cols <- (ncols - 2):ncols # The last 3 columns (adduct, isotope, pcgroup) # Combine the selected columns from matgrp with the group names variableMetadata <- cbind( @@ -192,8 +192,8 @@ variableMetadata <- cbind( if (!exists("RTinMinute")) RTinMinute <- FALSE if (args$convertRTMinute && RTinMinute == FALSE) { - RTinMinute <- TRUE - variableMetadata <- RTSecondToMinute(variableMetadata = variableMetadata, convertRTMinute = args$convertRTMinute) + RTinMinute <- TRUE + variableMetadata <- RTSecondToMinute(variableMetadata = variableMetadata, convertRTMinute = args$convertRTMinute) } # Save the peak list to a TSV file