Skip to content

Commit

Permalink
Merge pull request #283 from workflow4metabolomics/pulsar-linting-fix
Browse files Browse the repository at this point in the history
Pulsar linting fix
  • Loading branch information
hechth authored Jan 21, 2025
2 parents 6551805 + 5a77047 commit d5cb3fe
Show file tree
Hide file tree
Showing 78 changed files with 8,154 additions and 40,504 deletions.
8 changes: 4 additions & 4 deletions tools/camera/CAMERA_annotateDiffreport.r
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ 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")

Expand Down Expand Up @@ -50,7 +50,7 @@ directory <- retrieveRawfileInTheWorkingDir(singlefile, zipfile)

# Because so far CAMERA isn't compatible with the new XCMSnExp object
if (exists("xdata")) {
xset <- getxcmsSetObject(xdata)
xset <- getxcmsSetObject(xdata)
}

cat("\n\n")
Expand Down
24 changes: 12 additions & 12 deletions tools/camera/CAMERA_combinexsAnnos.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# ----- PACKAGE -----
cat("\tSESSION INFO\n")

#Import the different functions
# 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")

Expand All @@ -18,7 +18,7 @@ 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
args <- parseCommandArgs(evaluate = FALSE) # interpretation of arguments given in command line as an R list of objects
write.table(as.matrix(args), col.names = FALSE, quote = FALSE, sep = "\t")

cat("\n\n")
Expand All @@ -27,7 +27,7 @@ cat("\n\n")
# ----- PROCESSING INFILE -----
cat("\tINFILE PROCESSING INFO\n")

#image is an .RData file necessary to use xset variable given by previous tools
# image is an .RData file necessary to use xset variable given by previous tools
load(args$image_pos)
xaP <- xa

Expand Down Expand Up @@ -58,16 +58,16 @@ cat("\n\n")
cat("\tMAIN PROCESSING INFO\n")

cAnnot <- combinexsAnnos_function(
xaP = xaP, xaN = xaN,
diffrepP = diffrepP, diffrepN = diffrepN,
pos = args$pos, tol = args$tol, ruleset = args$ruleset, keep_meta = args$keep_meta,
convertRTMinute = args$convertRTMinute, numDigitsMZ = args$numDigitsMZ, numDigitsRT = args$numDigitsRT,
variableMetadataOutput = "variableMetadata.tsv"
xaP = xaP, xaN = xaN,
diffrepP = diffrepP, diffrepN = diffrepN,
pos = args$pos, tol = args$tol, ruleset = args$ruleset, keep_meta = args$keep_meta,
convertRTMinute = args$convertRTMinute, numDigitsMZ = args$numDigitsMZ, numDigitsRT = args$numDigitsRT,
variableMetadataOutput = "variableMetadata.tsv"
)

# ----- EXPORT -----

#saving R data in .Rdata file to save the variables used in the present tool
# saving R data in .Rdata file to save the variables used in the present tool
objects2save <- c("xa", "variableMetadata", "diffrep", "cAnnot", "listOFargs", "zipfile", "singlefile")
save(list = objects2save[objects2save %in% ls()], file = "combinexsAnnos.RData")

Expand Down
128 changes: 64 additions & 64 deletions tools/camera/CAMERA_findAdducts.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ 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")

Expand All @@ -27,34 +27,34 @@ print(args)

# 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)
}

# Function to convert string to numeric lists
convert_psg_list <- function(x) {
# Check if x is NULL or has zero length before further processing
if (is.null(x) || length(x) == 0) {
return(NULL)
}

# Force conversion to character
x <- as.character(x)

if (grepl("^[0-9]+$", x)) {
# If the string represents a single numeric value
return(as.numeric(x))
} else {
# Convert string representation of a list to a numeric vector
# Use a regular expression to split by common separators
return(as.numeric(unlist(strsplit(x, "[,;\\s]+"))))
}
# Check if x is NULL or has zero length before further processing
if (is.null(x) || length(x) == 0) {
return(NULL)
}

# Force conversion to character
x <- as.character(x)

if (grepl("^[0-9]+$", x)) {
# If the string represents a single numeric value
return(as.numeric(x))
} else {
# Convert string representation of a list to a numeric vector
# Use a regular expression to split by common separators
return(as.numeric(unlist(strsplit(x, "[,;\\s]+"))))
}
}

for (arg in names(args)) {
args[[arg]] <- convertNullString(args[[arg]])
args[[arg]] <- convertNullString(args[[arg]])
}

# Convert only the 'psg_list' element in args
Expand All @@ -65,7 +65,7 @@ print(sapply(args, class))

# 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)
}

# ----- PROCESSING INFILE -----
Expand All @@ -88,41 +88,41 @@ args <- rawFilePath$args

print(paste("singlefile :", singlefile))
if (!is.null(singlefile)) {
directory <- retrieveRawfileInTheWorkingDir(singlefile, zipfile)
directory <- retrieveRawfileInTheWorkingDir(singlefile, zipfile)
}

# Check if the 'rules' argument in 'args' is NULL
if (is.null(args$rules)) {
# If 'args$rules' is NULL, set 'rulset' to NULL
args$rulset <- NULL
# If 'args$rules' is NULL, set 'rulset' to NULL
args$rulset <- NULL
} else {
# Try to read the rules file with different delimiters
delimiters <- c(";", "\t", ",") # List of possible delimiters
success <- FALSE # Flag to check if reading was successful

for (sep in delimiters) {
# Attempt to read the rules file with the current separator
args$rulset <- read.table(args$rules, header = TRUE, sep = sep)

# Check if the number of columns is at least 4
if (ncol(args$rulset) >= 4) {
success <- TRUE # Mark success if the format is correct
break # Exit the loop if the file was read successfully
# Try to read the rules file with different delimiters
delimiters <- c(";", "\t", ",") # List of possible delimiters
success <- FALSE # Flag to check if reading was successful

for (sep in delimiters) {
# Attempt to read the rules file with the current separator
args$rulset <- read.table(args$rules, header = TRUE, sep = sep)

# Check if the number of columns is at least 4
if (ncol(args$rulset) >= 4) {
success <- TRUE # Mark success if the format is correct
break # Exit the loop if the file was read successfully
}
}

# If reading the rules file failed for all delimiters
if (!success) {
# Display an error message if the file is not well formatted
error_message <- "The rules file appears to be improperly formatted. Accepted column separators are ;, tab, and ,."
print(error_message)
stop(error_message) # Stop execution with an error
}
}

# If reading the rules file failed for all delimiters
if (!success) {
# Display an error message if the file is not well formatted
error_message <- "The rules file appears to be improperly formatted. Accepted column separators are ;, tab, and ,."
print(error_message)
stop(error_message) # Stop execution with an error
}
}

# 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:")
Expand All @@ -139,26 +139,26 @@ print(xa)
peakList <- getPeaklist(xa, intval = args$intval)

if (length(phenoData@data$sample_name) == 1) {
peakList$name <- make.unique(paste0("M", round(peakList[, "mz"], 0), "T", round(peakList[, "rt"], 0)), "_")
variableMetadata <- peakList[, c("name", setdiff(names(peakList), "name"))]
variableMetadata <- formatIonIdentifiers(variableMetadata, numDigitsRT = args$numDigitsRT, numDigitsMZ = args$numDigitsMZ)
peakList$name <- make.unique(paste0("M", round(peakList[, "mz"], 0), "T", round(peakList[, "rt"], 0)), "_")
variableMetadata <- peakList[, c("name", setdiff(names(peakList), "name"))]
variableMetadata <- formatIonIdentifiers(variableMetadata, numDigitsRT = args$numDigitsRT, numDigitsMZ = args$numDigitsMZ)
} else {
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

variableMetadata <- data.frame(
name = names_default,
name_custom = names_custom,
stringsAsFactors = FALSE
)
variableMetadata <- cbind(variableMetadata, peakList[, !(make.names(colnames(peakList)) %in% c(make.names(sampnames(xa@xcmsSet))))])
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

variableMetadata <- data.frame(
name = names_default,
name_custom = names_custom,
stringsAsFactors = FALSE
)
variableMetadata <- cbind(variableMetadata, peakList[, !(make.names(colnames(peakList)) %in% c(make.names(sampnames(xa@xcmsSet))))])
}

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'
Expand Down
84 changes: 42 additions & 42 deletions tools/camera/CAMERA_findIsotopes.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ 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")

Expand All @@ -30,7 +30,7 @@ print(sapply(args, class))

# 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)
}

# ----- PROCESSING INFILE -----
Expand All @@ -53,41 +53,41 @@ args <- rawFilePath$args

print(paste("singlefile :", singlefile))
if (!is.null(singlefile)) {
directory <- retrieveRawfileInTheWorkingDir(singlefile, zipfile)
directory <- retrieveRawfileInTheWorkingDir(singlefile, zipfile)
}

# 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])
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)
Expand All @@ -103,26 +103,26 @@ print(xa)
peakList <- getPeaklist(xa, intval = args$intval)

if (length(phenoData@data$sample_name) == 1) {
peakList$name <- make.unique(paste0("M", round(peakList[, "mz"], 0), "T", round(peakList[, "rt"], 0)), "_")
variableMetadata <- peakList[, c("name", setdiff(names(peakList), "name"))]
variableMetadata <- formatIonIdentifiers(variableMetadata, numDigitsRT = args$numDigitsRT, numDigitsMZ = args$numDigitsMZ)
peakList$name <- make.unique(paste0("M", round(peakList[, "mz"], 0), "T", round(peakList[, "rt"], 0)), "_")
variableMetadata <- peakList[, c("name", setdiff(names(peakList), "name"))]
variableMetadata <- formatIonIdentifiers(variableMetadata, numDigitsRT = args$numDigitsRT, numDigitsMZ = args$numDigitsMZ)
} else {
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

variableMetadata <- data.frame(
name = names_default,
name_custom = names_custom,
stringsAsFactors = FALSE
)
variableMetadata <- cbind(variableMetadata, peakList[, !(make.names(colnames(peakList)) %in% c(make.names(sampnames(xa@xcmsSet))))])
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

variableMetadata <- data.frame(
name = names_default,
name_custom = names_custom,
stringsAsFactors = FALSE
)
variableMetadata <- cbind(variableMetadata, peakList[, !(make.names(colnames(peakList)) %in% c(make.names(sampnames(xa@xcmsSet))))])
}

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'
Expand Down
Loading

0 comments on commit d5cb3fe

Please sign in to comment.