Skip to content

Commit

Permalink
Solves problem of creating variableMetadata with 1 sample
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienCode404 committed Nov 8, 2024
1 parent 4e17f51 commit 38cc94e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 88 deletions.
36 changes: 15 additions & 21 deletions tools/camera/CAMERA_findAdducts.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,27 +138,21 @@ print(xa)
# Extract the list of annotated peaks
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

# 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(rownames(phenoData)) # Number of samples

# Indices for the columns of interest
main_cols <- 1:(ncols - sample_cols - 3) # 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 <- data.frame(
name = names_default,
name_custom = names_custom,
stringsAsFactors = FALSE
)

variableMetadata <- cbind(variableMetadata, peakList[, c(main_cols, tail_cols)])
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)
} 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))))])
}

if (!exists("RTinMinute")) RTinMinute <- FALSE

Expand Down
36 changes: 15 additions & 21 deletions tools/camera/CAMERA_findIsotopes.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,21 @@ print(xa)
# Extract the list of annotated peaks
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

# 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(rownames(phenoData)) # Number of samples

# Indices for the columns of interest
main_cols <- 1:(ncols - sample_cols - 3) # 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 <- data.frame(
name = names_default,
name_custom = names_custom,
stringsAsFactors = FALSE
)

variableMetadata <- cbind(variableMetadata, peakList[, c(main_cols, tail_cols)])
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)
} 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))))])
}

if (!exists("RTinMinute")) RTinMinute <- FALSE

Expand Down
36 changes: 15 additions & 21 deletions tools/camera/CAMERA_groupCorr.R
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,21 @@ print(xa)
# Extract the list of annotated peaks
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

# 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(rownames(phenoData)) # Number of samples

# Indices for the columns of interest
main_cols <- 1:(ncols - sample_cols - 3) # 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 <- data.frame(
name = names_default,
name_custom = names_custom,
stringsAsFactors = FALSE
)

variableMetadata <- cbind(variableMetadata, peakList[, c(main_cols, tail_cols)])
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)
} 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))))])
}

if (!exists("RTinMinute")) RTinMinute <- FALSE

Expand Down
44 changes: 19 additions & 25 deletions tools/camera/CAMERA_groupFWHM.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ if (!hasFeatures(xdata)) stop("You must always do a group step after a retcor. O
cat("Converting xset object to xsAnnotate...\n")
xsa <- xsAnnotate(xset, sample = args$sample, nSlaves = as.numeric(args$nSlaves), polarity = args$polarity)

print(paste0("All samples in xset object:", paste(seq_along(xset@filepaths), collapse = ", ")))
print(paste0("Selected samples:", paste(xsa@sample, collapse = ", ")))
print(paste0("Run in parallel mode (0 = disabled):", paste(xsa@runParallel)))
print(paste0("Polarity:", xsa@polarity))
print(paste0("All samples in xset object: ", paste(seq_along(xset@filepaths), collapse = ", ")))
print(paste0("Selected samples: ", paste(xsa@sample, collapse = ", ")))
print(paste0("Run in parallel mode (0 = disabled): ", paste(xsa@runParallel)))
print(paste0("Polarity: ", xsa@polarity))

# Apply the groupFWHM function with the parameters
cat("Applying groupFWHM...\n")
Expand All @@ -103,27 +103,21 @@ xa <- groupFWHM(xsa, sigma = as.numeric(args$sigma), perfwhm = as.numeric(args$p
# Extract the list of annotated peaks
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

# 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(rownames(xdata@phenoData)) # Number of samples

# Indices for the columns of interest
main_cols <- 1:(ncols - sample_cols - 3) # 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 <- data.frame(
name = names_default,
name_custom = names_custom,
stringsAsFactors = FALSE
)

variableMetadata <- cbind(variableMetadata, peakList[, c(main_cols, tail_cols)])
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)
} 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))))])
}

if (!exists("RTinMinute")) RTinMinute <- FALSE

Expand Down

0 comments on commit 38cc94e

Please sign in to comment.