Mercurial > repos > lecorguille > xcms_summary
changeset 28:018a9771de28 draft
"planemo upload for repository https://github.com/workflow4metabolomics/xcms commit dcc90f9cf76e6980c0a7d9698c89fab826e7adae"
author | workflow4metabolomics |
---|---|
date | Wed, 07 Apr 2021 16:46:50 +0000 |
parents | bed23aa27b4b |
children | 2a2850fdf29e |
files | README.rst abims_xcms_summary.xml lib.r macros_xcms.xml test-data/faahKO-single.xset.merged.group.retcor.group.fillpeaks.summary.html xcms_summary.r |
diffstat | 6 files changed, 192 insertions(+), 158 deletions(-) [+] |
line wrap: on
line diff
--- a/README.rst Thu Sep 24 08:09:02 2020 +0000 +++ b/README.rst Wed Apr 07 16:46:50 2021 +0000 @@ -4,6 +4,10 @@ .. _News: https://bioconductor.org/packages/release/bioc/news/xcms/NEWS +**Version 3.12.0+galaxy* - 03/03/2020** + +- UPGRADE: upgrade the xcms version from 3.6.1 to 3.12.0 (see XCMS News_) + **Version 3.6.1+galaxy1 - 05/04/2020** - UPGRADE: upgrade the CAMERA version from 1.38.0 to 1.42.0
--- a/abims_xcms_summary.xml Thu Sep 24 08:09:02 2020 +0000 +++ b/abims_xcms_summary.xml Wed Apr 07 16:46:50 2021 +0000 @@ -1,4 +1,4 @@ -<tool id="abims_xcms_summary" name="xcms process history" version="@TOOL_VERSION@+galaxy2"> +<tool id="abims_xcms_summary" name="xcms process history" version="@TOOL_VERSION@+galaxy0"> <description>Create a summary of XCMS analysis</description> @@ -8,8 +8,8 @@ </macros> <requirements> - <requirement type="package" version="@TOOL_VERSION@">bioconductor-xcms</requirement> - <requirement type="package" version="1.40.0">bioconductor-camera</requirement> + <requirement type="package" version="@TOOL_VERSION@">bioconductor-xcms</requirement> + <requirement type="package" version="1.46.0">bioconductor-camera</requirement> <requirement type="package" version="1.1_5">r-batch</requirement> </requirements> @@ -87,12 +87,12 @@ Changelog/News -------------- +@HELP_XCMS_NEWVERSION_31200@ + **Version 3.6.1+galaxy2 - 23/09/2020** - BUGFIX: "Error: object 'sampleNamesList' not found" in case of .RData input from CAMERA -.. _News: https://bioconductor.org/packages/release/bioc/news/xcms/NEWS - **Version 3.6.1+galaxy1 - 05/04/2020** - UPGRADE: upgrade the CAMERA version from 1.38.0 to 1.42.0
--- a/lib.r Thu Sep 24 08:09:02 2020 +0000 +++ b/lib.r Wed Apr 07 16:46:50 2021 +0000 @@ -6,8 +6,8 @@ parseCommandArgs <- function(...) { args <- batch::parseCommandArgs(...) for (key in names(args)) { - if (args[key] %in% c("TRUE","FALSE")) - args[key] = as.logical(args[key]) + if (args[key] %in% c("TRUE", "FALSE")) + args[key] <- as.logical(args[key]) } return(args) } @@ -17,14 +17,20 @@ # - load the packages # - display the sessionInfo loadAndDisplayPackages <- function(pkgs) { - for(pkg in pkgs) suppressPackageStartupMessages( stopifnot( library(pkg, quietly=TRUE, logical.return=TRUE, character.only=TRUE))) + for (pkg in pkgs) suppressPackageStartupMessages(stopifnot(library(pkg, quietly = TRUE, logical.return = TRUE, character.only = TRUE))) - sessioninfo = sessionInfo() - cat(sessioninfo$R.version$version.string,"\n") + sessioninfo <- sessionInfo() + cat(sessioninfo$R.version$version.string, "\n") cat("Main packages:\n") - for (pkg in names(sessioninfo$otherPkgs)) { cat(paste(pkg,packageVersion(pkg)),"\t") }; cat("\n") + for (pkg in names(sessioninfo$otherPkgs)) { + cat(paste(pkg, packageVersion(pkg)), "\t") + } + cat("\n") cat("Other loaded packages:\n") - for (pkg in names(sessioninfo$loadedOnly)) { cat(paste(pkg,packageVersion(pkg)),"\t") }; cat("\n") + for (pkg in names(sessioninfo$loadedOnly)) { + cat(paste(pkg, packageVersion(pkg)), "\t") + } + cat("\n") } #@author G. Le Corguille @@ -43,20 +49,20 @@ chromTIC_adjusted <- NULL chromBPI_adjusted <- NULL md5sumList <- NULL - for(image in args$images) { + for (image in args$images) { load(image) # Handle infiles if (!exists("singlefile")) singlefile <- NULL if (!exists("zipfile")) zipfile <- NULL - rawFilePath <- retrieveRawfileInTheWorkingDirectory(singlefile, zipfile, args) + rawFilePath <- retrieveRawfileInTheWorkingDir(singlefile, zipfile, args) zipfile <- rawFilePath$zipfile singlefile <- rawFilePath$singlefile if (exists("raw_data")) xdata <- raw_data 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.*") - cat(sampleNamesList$sampleNamesOrigin,"\n") + cat(sampleNamesList$sampleNamesOrigin, "\n") if (!exists("xdata_merged")) { xdata_merged <- xdata @@ -68,14 +74,14 @@ chromTIC_adjusted_merged <- chromTIC_adjusted chromBPI_adjusted_merged <- chromBPI_adjusted } else { - if (is(xdata, "XCMSnExp")) xdata_merged <- c(xdata_merged,xdata) - else if (is(xdata, "OnDiskMSnExp")) xdata_merged <- xcms:::.concatenate_OnDiskMSnExp(xdata_merged,xdata) + if (is(xdata, "XCMSnExp")) xdata_merged <- c(xdata_merged, xdata) + else if (is(xdata, "OnDiskMSnExp")) xdata_merged <- xcms:::.concatenate_OnDiskMSnExp(xdata_merged, xdata) else stop("\n\nERROR: The RData either a OnDiskMSnExp object called raw_data or a XCMSnExp object called xdata") - singlefile_merged <- c(singlefile_merged,singlefile) - md5sumList_merged$origin <- rbind(md5sumList_merged$origin,md5sumList$origin) - sampleNamesList_merged$sampleNamesOrigin <- c(sampleNamesList_merged$sampleNamesOrigin,sampleNamesList$sampleNamesOrigin) - sampleNamesList_merged$sampleNamesMakeNames <- c(sampleNamesList_merged$sampleNamesMakeNames,sampleNamesList$sampleNamesMakeNames) + singlefile_merged <- c(singlefile_merged, singlefile) + md5sumList_merged$origin <- rbind(md5sumList_merged$origin, md5sumList$origin) + sampleNamesList_merged$sampleNamesOrigin <- c(sampleNamesList_merged$sampleNamesOrigin, sampleNamesList$sampleNamesOrigin) + sampleNamesList_merged$sampleNamesMakeNames <- c(sampleNamesList_merged$sampleNamesMakeNames, sampleNamesList$sampleNamesMakeNames) chromTIC_merged <- mergeChrom(chromTIC_merged, chromTIC) chromBPI_merged <- mergeChrom(chromBPI_merged, chromBPI) chromTIC_adjusted_merged <- mergeChrom(chromTIC_adjusted_merged, chromTIC_adjusted) @@ -91,79 +97,93 @@ if (!is.null(args$sampleMetadata)) { cat("\tXSET PHENODATA SETTING...\n") sampleMetadataFile <- args$sampleMetadata - sampleMetadata <- getDataFrameFromFile(sampleMetadataFile, header=F) - xdata@phenoData@data$sample_group=sampleMetadata$V2[match(xdata@phenoData@data$sample_name,sampleMetadata$V1)] + sampleMetadata <- getDataFrameFromFile(sampleMetadataFile, header = F) + xdata@phenoData@data$sample_group <- sampleMetadata$V2[match(xdata@phenoData@data$sample_name, sampleMetadata$V1)] if (any(is.na(pData(xdata)$sample_group))) { sample_missing <- pData(xdata)$sample_name[is.na(pData(xdata)$sample_group)] - error_message <- paste("Those samples are missing in your sampleMetadata:", paste(sample_missing, collapse=" ")) + error_message <- paste("Those samples are missing in your sampleMetadata:", paste(sample_missing, collapse = " ")) print(error_message) stop(error_message) } } - if (!is.null(chromTIC_merged)) { chromTIC <- chromTIC_merged; chromTIC@phenoData <- xdata@phenoData } - if (!is.null(chromBPI_merged)) { chromBPI <- chromBPI_merged; chromBPI@phenoData <- xdata@phenoData } - if (!is.null(chromTIC_adjusted_merged)) { 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 } + if (!is.null(chromTIC_merged)) { + chromTIC <- chromTIC_merged; chromTIC@phenoData <- xdata@phenoData + } + if (!is.null(chromBPI_merged)) { + chromBPI <- chromBPI_merged; chromBPI@phenoData <- xdata@phenoData + } + if (!is.null(chromTIC_adjusted_merged)) { + 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 + } - return(list("xdata"=xdata, "singlefile"=singlefile, "md5sumList"=md5sumList,"sampleNamesList"=sampleNamesList, "chromTIC"=chromTIC, "chromBPI"=chromBPI, "chromTIC_adjusted"=chromTIC_adjusted, "chromBPI_adjusted"=chromBPI_adjusted)) + return(list("xdata" = xdata, "singlefile" = singlefile, "md5sumList" = md5sumList, "sampleNamesList" = sampleNamesList, "chromTIC" = chromTIC, "chromBPI" = chromBPI, "chromTIC_adjusted" = chromTIC_adjusted, "chromBPI_adjusted" = chromBPI_adjusted)) } #@author G. Le Corguille # This function convert if it is required the Retention Time in minutes RTSecondToMinute <- function(variableMetadata, convertRTMinute) { - if (convertRTMinute){ + if (convertRTMinute) { #converting the retention times (seconds) into minutes print("converting the retention times into minutes in the variableMetadata") - variableMetadata[,"rt"] <- variableMetadata[,"rt"]/60 - variableMetadata[,"rtmin"] <- variableMetadata[,"rtmin"]/60 - variableMetadata[,"rtmax"] <- variableMetadata[,"rtmax"]/60 + variableMetadata[, "rt"] <- variableMetadata[, "rt"] / 60 + variableMetadata[, "rtmin"] <- variableMetadata[, "rtmin"] / 60 + variableMetadata[, "rtmax"] <- variableMetadata[, "rtmax"] / 60 } - return (variableMetadata) + return(variableMetadata) } #@author G. Le Corguille # This function format ions identifiers -formatIonIdentifiers <- function(variableMetadata, numDigitsRT=0, numDigitsMZ=0) { - splitDeco <- strsplit(as.character(variableMetadata$name),"_") - idsDeco <- sapply(splitDeco, function(x) { 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)) - variableMetadata <- cbind(name=variableMetadata$name, namecustom=namecustom, variableMetadata[,!(colnames(variableMetadata) %in% c("name"))]) +formatIonIdentifiers <- function(variableMetadata, numDigitsRT = 0, numDigitsMZ = 0) { + splitDeco <- strsplit(as.character(variableMetadata$name), "_") + idsDeco <- sapply(splitDeco, + function(x) { + 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)) + variableMetadata <- cbind(name = variableMetadata$name, namecustom = namecustom, variableMetadata[, !(colnames(variableMetadata) %in% c("name"))]) return(variableMetadata) } #@author G. Le Corguille # This function convert the remain NA to 0 in the dataMatrix naTOzeroDataMatrix <- function(dataMatrix, naTOzero) { - if (naTOzero){ + if (naTOzero) { dataMatrix[is.na(dataMatrix)] <- 0 } - return (dataMatrix) + return(dataMatrix) } #@author G. Le Corguille # Draw the plotChromPeakDensity 3 per page in a pdf file -getPlotChromPeakDensity <- function(xdata, param = NULL, mzdigit=4) { - pdf(file="plotChromPeakDensity.pdf", width=16, height=12) +getPlotChromPeakDensity <- function(xdata, param = NULL, mzdigit = 4) { + pdf(file = "plotChromPeakDensity.pdf", width = 16, height = 12) par(mfrow = c(3, 1), mar = c(4, 4, 1, 0.5)) - if(length(unique(xdata$sample_group))<10){ + if (length(unique(xdata$sample_group)) < 10) { group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1") }else{ - group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette="Dark 3") + group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette = "Dark 3") } names(group_colors) <- unique(xdata$sample_group) col_per_samp <- as.character(xdata$sample_group) - for(i in 1:length(group_colors)){col_per_samp[col_per_samp==(names(group_colors)[i])]<-group_colors[i]} + for (i in seq_len(length(group_colors))) { + col_per_samp[col_per_samp == (names(group_colors)[i])] <- group_colors[i] + } xlim <- c(min(featureDefinitions(xdata)$rtmin), max(featureDefinitions(xdata)$rtmax)) - for (i in 1:nrow(featureDefinitions(xdata))) { - mzmin = featureDefinitions(xdata)[i,]$mzmin - mzmax = featureDefinitions(xdata)[i,]$mzmax - plotChromPeakDensity(xdata, param = param, mz=c(mzmin,mzmax), col=col_per_samp, pch=16, xlim=xlim, main=paste(round(mzmin,mzdigit),round(mzmax,mzdigit))) - legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1) + for (i in seq_len(nrow(featureDefinitions(xdata)))) { + mzmin <- featureDefinitions(xdata)[i, ]$mzmin + mzmax <- featureDefinitions(xdata)[i, ]$mzmax + plotChromPeakDensity(xdata, param = param, mz = c(mzmin, mzmax), col = col_per_samp, pch = 16, xlim = xlim, main = paste(round(mzmin, mzdigit), round(mzmax, mzdigit))) + legend("topright", legend = names(group_colors), col = group_colors, cex = 0.8, lty = 1) } dev.off() @@ -173,57 +193,57 @@ # Draw the plotChromPeakDensity 3 per page in a pdf file getPlotAdjustedRtime <- function(xdata) { - pdf(file="raw_vs_adjusted_rt.pdf", width=16, height=12) + pdf(file = "raw_vs_adjusted_rt.pdf", width = 16, height = 12) # Color by group - if(length(unique(xdata$sample_group))<10){ + if (length(unique(xdata$sample_group)) < 10) { group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1") - }else{ - group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette="Dark 3") + } else { + group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette = "Dark 3") } if (length(group_colors) > 1) { names(group_colors) <- unique(xdata$sample_group) plotAdjustedRtime(xdata, col = group_colors[xdata$sample_group]) - legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1) + legend("topright", legend = names(group_colors), col = group_colors, cex = 0.8, lty = 1) } # Color by sample plotAdjustedRtime(xdata, col = rainbow(length(xdata@phenoData@data$sample_name))) - legend("topright", legend=xdata@phenoData@data$sample_name, col=rainbow(length(xdata@phenoData@data$sample_name)), cex=0.8, lty=1) + legend("topright", legend = xdata@phenoData@data$sample_name, col = rainbow(length(xdata@phenoData@data$sample_name)), cex = 0.8, lty = 1) dev.off() } #@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) { - dataMatrix <- featureValues(xdata, method="medret", value=intval) +getPeaklistW4M <- function(xdata, intval = "into", convertRTMinute = F, numDigitsMZ = 4, numDigitsRT = 0, naTOzero = T, 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) + dataMatrix <- cbind(name = groupnames(xdata), dataMatrix) variableMetadata <- featureDefinitions(xdata) - colnames(variableMetadata)[1] = "mz"; colnames(variableMetadata)[4] = "rt" - variableMetadata = data.frame(name=groupnames(xdata), variableMetadata) + colnames(variableMetadata)[1] <- "mz"; colnames(variableMetadata)[4] <- "rt" + variableMetadata <- data.frame(name = groupnames(xdata), variableMetadata) variableMetadata <- RTSecondToMinute(variableMetadata, convertRTMinute) - variableMetadata <- formatIonIdentifiers(variableMetadata, numDigitsRT=numDigitsRT, numDigitsMZ=numDigitsMZ) + variableMetadata <- formatIonIdentifiers(variableMetadata, numDigitsRT = numDigitsRT, numDigitsMZ = numDigitsMZ) dataMatrix <- naTOzeroDataMatrix(dataMatrix, naTOzero) # 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 = ",") + 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 = F, row.names = F) + write.table(dataMatrix, file = dataMatrixOutput, sep = "\t", quote = F, row.names = F) } #@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 = 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) if (ncol(myDataFrame) < 2) { - error_message="Your tabular file seems not well formatted. The column separators accepted are ; , and tabulation" + error_message <- "Your tabular file seems not well formatted. The column separators accepted are ; , and tabulation" print(error_message) stop(error_message) } @@ -233,36 +253,36 @@ #@author G. Le Corguille # Draw the BPI and TIC graphics # colored by sample names or class names -getPlotChromatogram <- function(chrom, xdata, pdfname="Chromatogram.pdf", aggregationFun = "max") { +getPlotChromatogram <- function(chrom, xdata, pdfname = "Chromatogram.pdf", aggregationFun = "max") { if (aggregationFun == "sum") - type="Total Ion Chromatograms" + type <- "Total Ion Chromatograms" else - type="Base Peak Intensity Chromatograms" + type <- "Base Peak Intensity Chromatograms" - adjusted="Raw" + adjusted <- "Raw" if (hasAdjustedRtime(xdata)) - adjusted="Adjusted" + adjusted <- "Adjusted" - main <- paste(type,":",adjusted,"data") + main <- paste(type, ":", adjusted, "data") - pdf(pdfname, width=16, height=10) + pdf(pdfname, width = 16, height = 10) # Color by group - if(length(unique(xdata$sample_group))<10){ + if (length(unique(xdata$sample_group)) < 10) { group_colors <- brewer.pal(length(unique(xdata$sample_group)), "Set1") }else{ - group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette="Dark 3") + group_colors <- hcl.colors(length(unique(xdata$sample_group)), palette = "Dark 3") } if (length(group_colors) > 1) { names(group_colors) <- unique(xdata$sample_group) - plot(chrom, col = group_colors[chrom$sample_group], main=main, peakType = "none") - legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1) + plot(chrom, col = group_colors[chrom$sample_group], main = main, peakType = "none") + legend("topright", legend = names(group_colors), col = group_colors, cex = 0.8, lty = 1) } # Color by sample - plot(chrom, col = rainbow(length(xdata@phenoData@data$sample_name)), main=main, peakType = "none") - legend("topright", legend=xdata@phenoData@data$sample_name, col=rainbow(length(xdata@phenoData@data$sample_name)), cex=0.8, lty=1) + plot(chrom, col = rainbow(length(xdata@phenoData@data$sample_name)), main = main, peakType = "none") + legend("topright", legend = xdata@phenoData@data$sample_name, col = rainbow(length(xdata@phenoData@data$sample_name)), cex = 0.8, lty = 1) dev.off() } @@ -271,7 +291,7 @@ # Get the polarities from all the samples of a condition #@author Misharl Monsoor misharl.monsoor@sb-roscoff.fr ABiMS TEAM #@author Gildas Le Corguille lecorguille@sb-roscoff.fr ABiMS TEAM -getSampleMetadata <- function(xdata=NULL, sampleMetadataOutput="sampleMetadata.tsv") { +getSampleMetadata <- function(xdata = NULL, sampleMetadataOutput = "sampleMetadata.tsv") { cat("Creating the sampleMetadata file...\n") #Create the sampleMetada dataframe @@ -285,7 +305,7 @@ if (any(duplicated(sampleNamesMakeNames))) { write("\n\nERROR: Usually, R has trouble to deal with special characters in its column names, so it rename them using make.names().\nIn your case, at least two columns after the renaming obtain the same name, thus XCMS will collapse those columns per name.", stderr()) for (sampleName in sampleNamesOrigin) { - write(paste(sampleName,"\t->\t",make.names(sampleName)),stderr()) + write(paste(sampleName, "\t->\t", make.names(sampleName)), stderr()) } stop("\n\nERROR: One or more of your files will not be import by xcmsSet. It may due to bad characters in their filenames.") } @@ -293,7 +313,7 @@ if (!all(sampleNamesOrigin == sampleNamesMakeNames)) { cat("\n\nWARNING: Usually, R has trouble to deal with special characters in its column names, so it rename them using make.names()\nIn your case, one or more sample names will be renamed in the sampleMetadata and dataMatrix files:\n") for (sampleName in sampleNamesOrigin) { - cat(paste(sampleName,"\t->\t",make.names(sampleName),"\n")) + cat(paste(sampleName, "\t->\t", make.names(sampleName), "\n")) } } @@ -301,7 +321,7 @@ #For each sample file, the following actions are done - for (fileIdx in 1:length(fileNames(xdata))) { + for (fileIdx in seq_len(length(fileNames(xdata)))) { #Check if the file is in the CDF format if (!mzR:::netCDFIsFile(fileNames(xdata))) { @@ -309,10 +329,10 @@ if (is.null(sampleMetadata$polarity)) sampleMetadata$polarity <- NA #Extract the polarity (a list of polarities) - polarity <- fData(xdata)[fData(xdata)$fileIdx == fileIdx,"polarity"] + polarity <- fData(xdata)[fData(xdata)$fileIdx == fileIdx, "polarity"] #Verify if all the scans have the same polarity uniq_list <- unique(polarity) - if (length(uniq_list)>1){ + if (length(uniq_list) > 1) { polarity <- "mixed" } else { polarity <- as.character(uniq_list) @@ -324,16 +344,16 @@ } - write.table(sampleMetadata, sep="\t", quote=FALSE, row.names=FALSE, file=sampleMetadataOutput) + write.table(sampleMetadata, sep = "\t", quote = FALSE, row.names = FALSE, file = sampleMetadataOutput) - return(list("sampleNamesOrigin"=sampleNamesOrigin, "sampleNamesMakeNames"=sampleNamesMakeNames)) + return(list("sampleNamesOrigin" = sampleNamesOrigin, "sampleNamesMakeNames" = sampleNamesMakeNames)) } # This function will compute MD5 checksum to check the data integrity #@author Gildas Le Corguille lecorguille@sb-roscoff.fr -getMd5sum <- function (files) { +getMd5sum <- function(files) { cat("Compute md5 checksum...\n") library(tools) return(as.matrix(md5sum(files))) @@ -343,71 +363,71 @@ # - if zipfile: unzip the file with its directory tree # - if singlefiles: set symlink with the good filename #@author Gildas Le Corguille lecorguille@sb-roscoff.fr -retrieveRawfileInTheWorkingDirectory <- function(singlefile, zipfile, args, prefix="") { +retrieveRawfileInTheWorkingDir <- function(singlefile, zipfile, args, prefix = "") { - if (!(prefix %in% c("","Positive","Negative","MS1","MS2"))) stop("prefix must be either '', 'Positive', 'Negative', 'MS1' or 'MS2'") + if (!(prefix %in% c("", "Positive", "Negative", "MS1", "MS2"))) stop("prefix must be either '', 'Positive', 'Negative', 'MS1' or 'MS2'") # single - if the file are passed in the command arguments -> refresh singlefile - if (!is.null(args[[paste0("singlefile_galaxyPath",prefix)]])) { - singlefile_galaxyPaths <- unlist(strsplit(args[[paste0("singlefile_galaxyPath",prefix)]],"\\|")) - singlefile_sampleNames <- unlist(strsplit(args[[paste0("singlefile_sampleName",prefix)]],"\\|")) + if (!is.null(args[[paste0("singlefile_galaxyPath", prefix)]])) { + singlefile_galaxyPaths <- unlist(strsplit(args[[paste0("singlefile_galaxyPath", prefix)]], "\\|")) + singlefile_sampleNames <- unlist(strsplit(args[[paste0("singlefile_sampleName", prefix)]], "\\|")) singlefile <- NULL - for (singlefile_galaxyPath_i in seq(1:length(singlefile_galaxyPaths))) { + for (singlefile_galaxyPath_i in seq_len(length(singlefile_galaxyPaths))) { singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i] singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i] # In case, an url is used to import data within Galaxy - singlefile_sampleName <- tail(unlist(strsplit(singlefile_sampleName,"/")), n=1) + singlefile_sampleName <- tail(unlist(strsplit(singlefile_sampleName, "/")), n = 1) singlefile[[singlefile_sampleName]] <- singlefile_galaxyPath } } # zipfile - if the file are passed in the command arguments -> refresh zipfile - if (!is.null(args[[paste0("zipfile",prefix)]])) - zipfile <- args[[paste0("zipfile",prefix)]] + if (!is.null(args[[paste0("zipfile", prefix)]])) + zipfile <- args[[paste0("zipfile", prefix)]] # single - if(!is.null(singlefile) && (length("singlefile")>0)) { + if (!is.null(singlefile) && (length("singlefile") > 0)) { files <- vector() 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,". Please, contact your administrator ... if you have one!") + 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) } - if (!suppressWarnings( try (file.link(singlefile_galaxyPath, singlefile_sampleName), silent=T))) + if (!suppressWarnings(try(file.link(singlefile_galaxyPath, singlefile_sampleName), silent = T))) file.copy(singlefile_galaxyPath, singlefile_sampleName) files <- c(files, singlefile_sampleName) } } # zipfile - if(!is.null(zipfile) && (zipfile != "")) { - if(!file.exists(zipfile)){ - error_message <- paste("Cannot access the Zip file:",zipfile,". Please, contact your administrator ... if you have one!") + if (!is.null(zipfile) && (zipfile != "")) { + if (!file.exists(zipfile)) { + error_message <- paste("Cannot access the Zip file:", zipfile, ". Please, contact your administrator ... if you have one!") print(error_message) stop(error_message) } - suppressWarnings(unzip(zipfile, unzip="unzip")) + suppressWarnings(unzip(zipfile, unzip = "unzip")) #get the directory name - suppressWarnings(filesInZip <- unzip(zipfile, list=T)) - directories <- unique(unlist(lapply(strsplit(filesInZip$Name,"/"), function(x) x[1]))) + suppressWarnings(filesInZip <- unzip(zipfile, list = T)) + 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") + cat("files_root_directory\t", directory, "\n") - filepattern <- c("[Cc][Dd][Ff]", "[Nn][Cc]", "([Mm][Zz])?[Xx][Mm][Ll]","[Mm][Zz][Dd][Aa][Tt][Aa]", "[Mm][Zz][Mm][Ll]") - filepattern <- paste(paste("\\.", filepattern, "$", sep=""),collapse="|") + filepattern <- c("[Cc][Dd][Ff]", "[Nn][Cc]", "([Mm][Zz])?[Xx][Mm][Ll]", "[Mm][Zz][Dd][Aa][Tt][Aa]", "[Mm][Zz][Mm][Ll]") + filepattern <- paste(paste("\\.", filepattern, "$", sep = ""), collapse = "|") info <- file.info(directory) - listed <- list.files(directory[info$isdir], pattern=filepattern,recursive=TRUE, full.names=TRUE) + listed <- list.files(directory[info$isdir], pattern = filepattern, recursive = TRUE, full.names = TRUE) files <- c(directory[!info$isdir], listed) exists <- file.exists(files) files <- files[exists] } - return(list(zipfile=zipfile, singlefile=singlefile, files=files)) + return(list(zipfile = zipfile, singlefile = singlefile, files = files)) } @@ -417,15 +437,15 @@ getxcmsSetObject <- function(xobject) { # XCMS 1.x if (class(xobject) == "xcmsSet") - return (xobject) + return(xobject) # XCMS 3.x if (class(xobject) == "XCMSnExp") { # Get the legacy xcmsSet object - suppressWarnings(xset <- as(xobject, 'xcmsSet')) + suppressWarnings(xset <- as(xobject, "xcmsSet")) if (!is.null(xset@phenoData$sample_group)) sampclass(xset) <- xset@phenoData$sample_group else sampclass(xset) <- "." - return (xset) + return(xset) } }
--- a/macros_xcms.xml Thu Sep 24 08:09:02 2020 +0000 +++ b/macros_xcms.xml Wed Apr 07 16:46:50 2021 +0000 @@ -1,7 +1,7 @@ <?xml version="1.0"?> <macros> - <token name="@TOOL_VERSION@">3.6.1</token> + <token name="@TOOL_VERSION@">3.12.0</token> <xml name="requirements"> <requirements> <requirement type="package" version="@TOOL_VERSION@">bioconductor-xcms</requirement> @@ -243,6 +243,7 @@ .. _xcms: https://bioconductor.org/packages/release/bioc/html/xcms.html .. _manual: http://www.bioconductor.org/packages/release/bioc/manuals/xcms/man/xcms.pdf .. _example: https://bioconductor.org/packages/release/bioc/vignettes/xcms/inst/doc/xcms.html +.. _News: https://bioconductor.org/packages/release/bioc/news/xcms/NEWS </token> @@ -256,6 +257,11 @@ - UPGRADE: upgrade the xcms version from 3.4.4 to 3.6.1 (see XCMS News_) </token> + <token name="@HELP_XCMS_NEWVERSION_31200@"> +**Version 3.12.0+galaxy* - 03/03/2020** + +- UPGRADE: upgrade the xcms version from 3.6.1 to 3.12.0 (see XCMS News_) + </token> <xml name="citation"> <citations>
--- a/test-data/faahKO-single.xset.merged.group.retcor.group.fillpeaks.summary.html Thu Sep 24 08:09:02 2020 +0000 +++ b/test-data/faahKO-single.xset.merged.group.retcor.group.fillpeaks.summary.html Wed Apr 07 16:46:50 2021 +0000 @@ -5,7 +5,7 @@ <title>[W4M] XCMS analysis summary</title> <style> table, tr, td, th { border: 1px solid #000000; border-collapse:collapse; } -td,th { padding: 5px; padding-right: 12px; } +td, th { padding: 5px; padding-right: 12px; } th { background: #898989; text-align:left;color: white;} h2 { color: #FFA212; } ul li { margin-bottom:10px; }
--- a/xcms_summary.r Thu Sep 24 08:09:02 2020 +0000 +++ b/xcms_summary.r Wed Apr 07 16:46:50 2021 +0000 @@ -13,17 +13,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="/")) } +source_local <- function(fname) { + 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") +pkgs <- c("CAMERA", "batch") loadAndDisplayPackages(pkgs) cat("\n\n"); # ----- FUNCTION ----- -writehtml <- function(...) { cat(...,"\n", file=htmlOutput,append = TRUE,sep="") } -writeraw <- function(htmlOutput, object, open="at") { +writehtml <- function(...) { + cat(..., "\n", file = htmlOutput, append = TRUE, sep = "") +} +writeraw <- function(htmlOutput, object, open = "at") { log_file <- file(htmlOutput, open = open) sink(log_file) sink(log_file, type = "output") @@ -33,26 +37,26 @@ } getSampleNames <- function(xobject) { if (class(xobject) == "xcmsSet") - return (sampnames(xobject)) + return(sampnames(xobject)) if (class(xobject) == "XCMSnExp") - return (xobject@phenoData@data$sample_name) + return(xobject@phenoData@data$sample_name) } getFilePaths <- function(xobject) { if (class(xobject) == "xcmsSet") - return (xobject@filepaths) + return(xobject@filepaths) if (class(xobject) == "XCMSnExp") - return (fileNames(xobject)) + return(fileNames(xobject)) } equalParams <- function(param1, param2) { - writeraw("param1.txt", param1, open="wt") - writeraw("param2.txt", param2, open="wt") + writeraw("param1.txt", param1, open = "wt") + writeraw("param2.txt", param2, open = "wt") return(tools::md5sum("param1.txt") == tools::md5sum("param2.txt")) } # ----- ARGUMENTS ----- -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 # ----- ARGUMENTS PROCESSING ----- @@ -61,26 +65,26 @@ 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")) { xobject <- xset # retrocompatability - if (!exists("sampleNamesList")) sampleNamesList <- list("sampleNamesMakeNames"=make.names(sampnames(xobject))) + if (!exists("sampleNamesList")) sampleNamesList <- list("sampleNamesMakeNames" = make.names(sampnames(xobject))) } # if the RData come from CAMERA if (exists("xa")) { xobject <- xa@xcmsSet - if (!exists("sampleNamesList")) sampleNamesList <- list("sampleNamesMakeNames"=make.names(xa@xcmsSet@phenoData$sample_name)) + if (!exists("sampleNamesList")) sampleNamesList <- list("sampleNamesMakeNames" = make.names(xa@xcmsSet@phenoData$sample_name)) } # if the RData come from XCMS 3.x if (exists("xdata")) { xobject <- xdata - if (!exists("sampleNamesList")) sampleNamesList <- list("sampleNamesMakeNames"=make.names(xdata@phenoData@data$sample_name)) + if (!exists("sampleNamesList")) sampleNamesList <- list("sampleNamesMakeNames" = make.names(xdata@phenoData@data$sample_name)) } if (!exists("xobject")) stop("You need at least a xdata, a xset or a xa object.") @@ -97,7 +101,7 @@ writehtml("<style>") writehtml("table, tr, td, th { border: 1px solid #000000; border-collapse:collapse; }") - writehtml("td,th { padding: 5px; padding-right: 12px; }") + writehtml("td, th { padding: 5px; padding-right: 12px; }") writehtml("th { background: #898989; text-align:left;color: white;}") writehtml("h2 { color: #FFA212; }") writehtml("ul li { margin-bottom:10px; }") @@ -108,7 +112,7 @@ writehtml("<div><h1>___ XCMS analysis summary using Workflow4Metabolomics ___</h1>") # to pass the planemo shed_test if (user_email != "test@bx.psu.edu") { - if (!is.null(user_email)) writehtml("By: ", user_email," - ") + if (!is.null(user_email)) writehtml("By: ", user_email, " - ") writehtml("Date: ", format(Sys.time(), "%y%m%d-%H:%M:%S")) } writehtml("</div>") @@ -117,10 +121,10 @@ writehtml("<div><table>") if (all(getSampleNames(xobject) == sampleNamesList$sampleNamesMakeNames)) { sampleNameHeaderHtml <- paste0("<th>sample</th>") - sampleNameHtml <- paste0("<td>",getSampleNames(xobject),"</td>") + sampleNameHtml <- paste0("<td>", getSampleNames(xobject), "</td>") } else { sampleNameHeaderHtml <- paste0("<th>sample</th><th>sample renamed</th>") - sampleNameHtml <- paste0("<td>",getSampleNames(xobject),"</td><td>",sampleNamesList$sampleNamesMakeNames,"</td>") + sampleNameHtml <- paste0("<td>", getSampleNames(xobject), "</td><td>", sampleNamesList$sampleNamesMakeNames, "</td>") } if (!exists("md5sumList")) { @@ -129,16 +133,16 @@ md5sumLegend <- "" } else if (is.null(md5sumList$removalBadCharacters)) { md5sumHeaderHtml <- paste0("<th>md5sum<sup>*</sup></th>") - md5sumHtml <- paste0("<td>",md5sumList$origin,"</td>") + md5sumHtml <- paste0("<td>", md5sumList$origin, "</td>") md5sumLegend <- "<br/><sup>*</sup>The program md5sum is designed to verify data integrity. So you can check if the data were uploaded correctly or if the data were changed during the process." } else { md5sumHeaderHtml <- paste0("<th>md5sum<sup>*</sup></th><th>md5sum<sup>**</sup> after bad characters removal</th>") - md5sumHtml <- paste0("<td>",md5sumList$origin,"</td><td>",md5sumList$removalBadCharacters,"</td>") + md5sumHtml <- paste0("<td>", md5sumList$origin, "</td><td>", md5sumList$removalBadCharacters, "</td>") md5sumLegend <- "<br/><sup>*</sup>The program md5sum is designed to verify data integrity. So you can check if the data were uploaded correctly or if the data were changed during the process.<br/><sup>**</sup>Because some bad characters (eg: accent) were removed from your original file, the checksum have changed too.<br/>" } - writehtml("<tr>",sampleNameHeaderHtml,"<th>filename</th>",md5sumHeaderHtml,"</tr>") - writehtml(paste0("<tr>",sampleNameHtml,"<td>",getFilePaths(xobject),"</td>",md5sumHtml,"</tr>")) + writehtml("<tr>", sampleNameHeaderHtml, "<th>filename</th>", md5sumHeaderHtml, "</tr>") + writehtml(paste0("<tr>", sampleNameHtml, "<td>", getFilePaths(xobject), "</td>", md5sumHtml, "</tr>")) writehtml("</table>") writehtml(md5sumLegend) @@ -157,22 +161,22 @@ timestamp <- processDate(processHistoryItem) xcmsFunction <- processType(processHistoryItem) params <- processParam(processHistoryItem) - writehtml("<tr><td>",timestamp,"</td><td>",xcmsFunction,"</td><td colspan='2'><pre>") + writehtml("<tr><td>", timestamp, "</td><td>", xcmsFunction, "</td><td colspan='2'><pre>") writeraw(htmlOutput, params) writehtml("</pre></td></tr>") } } # CAMERA and retrocompatability XCMS 1.x if (exists("listOFlistArguments")) { - for(tool in names(listOFlistArguments)) { + for (tool in names(listOFlistArguments)) { listOFlistArgumentsDisplay <- listOFlistArguments[[tool]][!(names(listOFlistArguments[[tool]]) %in% argBlacklist)] - timestamp <- strsplit(tool,"_")[[1]][1] - xcmsFunction <- strsplit(tool,"_")[[1]][2] - writehtml("<tr><td rowspan='",length(listOFlistArgumentsDisplay),"'>",timestamp,"</td><td rowspan='",length(listOFlistArgumentsDisplay),"'>",xcmsFunction,"</td>") + timestamp <- strsplit(tool, "_")[[1]][1] + xcmsFunction <- strsplit(tool, "_")[[1]][2] + writehtml("<tr><td rowspan='", length(listOFlistArgumentsDisplay), "'>", timestamp, "</td><td rowspan='", length(listOFlistArgumentsDisplay), "'>", xcmsFunction, "</td>") line_begin <- "" for (arg in names(listOFlistArgumentsDisplay)) { - writehtml(line_begin,"<td>",arg,"</td><td>",unlist(listOFlistArgumentsDisplay[arg][1]),"</td></tr>") + writehtml(line_begin, "<td>", arg, "</td><td>", unlist(listOFlistArgumentsDisplay[arg][1]), "</td></tr>") line_begin <- "<tr>" } } @@ -202,7 +206,7 @@ writehtml("<h2>Informations about the CAMERA object:</h2>") writehtml("<div>") - writehtml("Number of pcgroup: ",length(xa@pspectra)) + writehtml("Number of pcgroup: ", length(xa@pspectra)) writehtml("</div>") } @@ -210,21 +214,21 @@ writehtml("<div><ul>") writehtml("<li>To cite the <b>XCMS</b> package in publications use:") writehtml("<ul>") - writehtml("<li>","Smith, C.A. and Want, E.J. and O'Maille, G. and Abagyan,R. and Siuzdak, G.XCMS: Processing mass spectrometry data for metabolite profiling using nonlinear peak alignment, matching and identification, Analytical Chemistry, 78:779-787 (2006)","</li>") - writehtml("<li>","Ralf Tautenhahn, Christoph Boettcher, Steffen Neumann: Highly sensitive feature detection for high resolution LC/MS BMC Bioinformatics, 9:504 (2008)","</li>") - writehtml("<li>","H. Paul Benton, Elizabeth J. Want and Timothy M. D. Ebbels Correction of mass calibration gaps in liquid chromatography-mass spectrometry metabolomics data Bioinformatics, 26:2488 (2010)","</li>") + writehtml("<li>", "Smith, C.A. and Want, E.J. and O'Maille, G. and Abagyan,R. and Siuzdak, G.XCMS: Processing mass spectrometry data for metabolite profiling using nonlinear peak alignment, matching and identification, Analytical Chemistry, 78:779-787 (2006)", "</li>") + writehtml("<li>", "Ralf Tautenhahn, Christoph Boettcher, Steffen Neumann: Highly sensitive feature detection for high resolution LC/MS BMC Bioinformatics, 9:504 (2008)", "</li>") + writehtml("<li>", "H. Paul Benton, Elizabeth J. Want and Timothy M. D. Ebbels Correction of mass calibration gaps in liquid chromatography-mass spectrometry metabolomics data Bioinformatics, 26:2488 (2010)", "</li>") writehtml("</ul>") writehtml("</li>") writehtml("<li>To cite the <b>CAMERA</b> package in publications use:") writehtml("<ul>") - writehtml("<li>","Kuhl, C., Tautenhahn, R., Boettcher, C., Larson, T. R. and Neumann,S. CAMERA: an integrated strategy for compound spectra extraction and annotation of liquid chromatography/mass spectrometry data sets. Analytical Chemistry, 84:283-289 (2012)","</li>") + writehtml("<li>", "Kuhl, C., Tautenhahn, R., Boettcher, C., Larson, T. R. and Neumann,S. CAMERA: an integrated strategy for compound spectra extraction and annotation of liquid chromatography/mass spectrometry data sets. Analytical Chemistry, 84:283-289 (2012)", "</li>") writehtml("</ul>") writehtml("</li>") writehtml("<li>To cite the <b>Workflow4Metabolimics (W4M)</b> project in publications use:") writehtml("<ul>") - writehtml("<li>","Franck Giacomoni, Gildas Le Corguillé, Misharl Monsoor, Marion Landi, Pierre Pericard, Mélanie Pétéra, Christophe Duperier, Marie Tremblay-Franco, Jean-François Martin, Daniel Jacob, Sophie Goulitquer, Etienne A. Thévenot and Christophe Caron (2014). Workflow4Metabolomics: A collaborative research infrastructure for computational metabolomics. Bioinformatics doi:10.1093/bioinformatics/btu813","</li>") + writehtml("<li>", "Franck Giacomoni, Gildas Le Corguillé, Misharl Monsoor, Marion Landi, Pierre Pericard, Mélanie Pétéra, Christophe Duperier, Marie Tremblay-Franco, Jean-François Martin, Daniel Jacob, Sophie Goulitquer, Etienne A. Thévenot and Christophe Caron (2014). Workflow4Metabolomics: A collaborative research infrastructure for computational metabolomics. Bioinformatics doi:10.1093/bioinformatics/btu813", "</li>") writehtml("</ul>") writehtml("</li>") writehtml("</ul></div>")