# HG changeset patch # User lecorguille # Date 1487177126 18000 # Node ID f24b9c360a60ff35ae9a73727627ea212a9aa64a # Parent 9541ba588de1529a5abbbdacd8fd2df09a2fa937 planemo upload commit dc4b1363a3fe83f195167f1f0b25c9728006e364 diff -r 9541ba588de1 -r f24b9c360a60 ProbMetab.xml --- a/ProbMetab.xml Mon Jul 04 11:58:12 2016 -0400 +++ b/ProbMetab.xml Wed Feb 15 11:45:26 2017 -0500 @@ -1,4 +1,4 @@ - + Wrapper function for ProbMetab R package. @@ -12,186 +12,214 @@ @COMMAND_CAMERA_SCRIPT@ #if $acquisition_options.mode == "one": - mode_acquisition $acquisition_options.mode xa $acquisition_options.xa + mode_acquisition $acquisition_options.mode + image '$acquisition_options.image' ##if $acquisition_options.xsetnofill_options.option == "show": - ##xsetnofill $acquisition_options.xsetnofill_options.xsetnofill - ##end if + ##xsetnofill $acquisition_options.xsetnofill_options.xsetnofill + ##end if + + @COMMAND_FILE_LOAD_ONE@ + #else - mode_acquisition $acquisition_options.mode inputs_mode $acquisition_options.input_mode.option + mode_acquisition $acquisition_options.mode + inputs_mode $acquisition_options.input_mode.option #if $acquisition_options.input_mode.option== "two": - image_pos $acquisition_options.input_mode.image_pos image_neg $acquisition_options.input_mode.image_neg - ##if $acquisition_options.input_mode.xsetnofill_options.option == "show": - ##xsetPnofill $acquisition_options.input_mode.xsetnofill_options.xsetPnofill xsetNnofill $acquisition_options.input_mode.xsetnofill_options.xsetNnofill - ##end if + image_pos '$acquisition_options.input_mode.image_pos' + image_neg '$acquisition_options.input_mode.image_neg' + ##if $acquisition_options.input_mode.xsetnofill_options.option == "show": + ##xsetPnofill $acquisition_options.input_mode.xsetnofill_options.xsetPnofill + ##xsetNnofill $acquisition_options.input_mode.xsetnofill_options.xsetNnofill + ##end if + + @COMMAND_FILE_LOAD_POSITIVE@ + @COMMAND_FILE_LOAD_NEGATIVE@ ##else - ##image_combinexsannos $acquisition_options.input_mode.image_combinexsannos image_pos $acquisition_options.input_mode.image_pos + ##image_combinexsannos $acquisition_options.input_mode.image_combinexsannos + ##image_pos $acquisition_options.input_mode.image_pos #end if #end if #if $option_toexclude.option == "show": - toexclude $option_toexclude.toexclude + toexclude $option_toexclude.toexclude #end if - allowMiss $allowMiss html $html kegg_db $kegg_db ppm_tol $ppm_tol - opt $opt corths $corths corprob $corprob pcorprob $pcorprob prob $prob - - @COMMAND_ZIPFILE_LOAD@ + allowMiss $allowMiss + html $html + kegg_db $kegg_db + ppm_tol $ppm_tol + opt $opt + corths $corths + corprob $corprob + pcorprob $pcorprob + prob $prob + + @COMMAND_LOG_EXIT@ - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - + - - - - - - - + + + + + + + - + - + - - - + + - - - + - - + + - --> - - + + + - (html) + (html) (html) - + - (acquisition_options['mode'] == 'one') + (acquisition_options['mode'] == 'one') - (acquisition_options['mode'] == 'two') + (acquisition_options['mode'] == 'two') - (acquisition_options['mode'] == 'two') + (acquisition_options['mode'] == 'two') - (acquisition_options['mode'] == 'two') + (acquisition_options['mode'] == 'two') - - - - + + + + + + + + + + + + + + + + + + + + + @@ -206,7 +234,7 @@ - + @HELP_AUTHORS@ ========= @@ -225,7 +253,7 @@ **Details** ProbMetab assumes peak detection, retention time correction and peak grouping [4, 5] in order to -perform mass peak to compound assignment. +perform mass peak to compound assignment. Once the initial annotation for different forms of the same ion (adducts and isotopes), is defined, one can seek for a non-redundant set of putative molecules (after charge and possible adduct @@ -235,7 +263,7 @@ experimental condition. In order to address this issue, a flexible workflow, which allows users to integrate different methods, would improve true molecular ions recovery. -The ion annotation table has the following core information: exact mass of putative molecule with experimental error; isotopic pattern associated; adduct form associated, and the original reference to raw data. +The ion annotation table has the following core information: exact mass of putative molecule with experimental error; isotopic pattern associated; adduct form associated, and the original reference to raw data. @@ -250,9 +278,9 @@ ========================= ========================================== ======= ========== Name Output file Format Parameter ========================= ========================================== ======= ========== -xcms.annotate xset.annotate_POS (or NEG).RData RData RData file +xcms.annotate xset.annotate_POS (or NEG).RData RData RData file ========================= ========================================== ======= ========== - + **General schema of the metabolomic workflow** @@ -295,7 +323,7 @@ **Calculate** -**intervals** +**intervals** A vector of SNR numerical intervals, to which different carbon offset should be added to predicted C-number. **offset** @@ -309,7 +337,7 @@ Which noise model to use, "erfc" to complementary error function, or "gaussian" to standard gaussian with two sd corresponding to the given p.p.m precision. -**precision** +**precision** Equipment mass accuracy, usually the same used in exact mass search. @@ -384,6 +412,10 @@ Changelog/News -------------- +**Version 1.1.0 - 15/02/2017** + +- IMPROVEMENT: Probmetab is now compatible with merged individual data from xcms.xcmsSet + **Version 1.0.1 - 16/05/2016** - TEST: refactoring to pass planemo test using conda dependencies @@ -393,10 +425,8 @@ - NEW: ProbMetab first version - + - - diff -r 9541ba588de1 -r f24b9c360a60 README.txt --- a/README.txt Mon Jul 04 11:58:12 2016 -0400 +++ b/README.txt Wed Feb 15 11:45:26 2017 -0500 @@ -1,19 +1,15 @@ Changelog/News -------------- +**Version 1.1.0 - 15/02/2017** + +- IMPROVEMENT: Probmetab is now compatible with merged individual data from xcms.xcmsSet + **Version 1.0.1 - 16/05/2016** - TEST: refactoring to pass planemo test using conda dependencies - **Version 1.0.0 - 10/06/2015** - NEW: ProbMetab first version - -Test Status ------------ - -Planemo test using conda: passed - -Planemo shed_test : passed diff -r 9541ba588de1 -r f24b9c360a60 lib.r --- a/lib.r Mon Jul 04 11:58:12 2016 -0400 +++ b/lib.r Wed Feb 15 11:45:26 2017 -0500 @@ -5,204 +5,204 @@ ##Main probmetab function launch by the Galaxy ProbMetab wrapper probmetab = function(xa, xaP, xaN, variableMetadata, variableMetadataP, variableMetadataN, listArguments){ - ##ONE MODE ACQUISITION## - if(listArguments[["mode_acquisition"]]=="one") { - comb=NULL + ##ONE MODE ACQUISITION## + if(listArguments[["mode_acquisition"]]=="one") { + comb=NULL - #Get the polarity from xa object - polarity=xa@polarity - #SNR option - if ("xsetnofill" %in% names(listArguments)) { - load(listArguments[["xsetnofill"]]) - xsetnofill=xset - } - else{ - xsetnofill=NULL - } - #Exclude samples - if ("toexclude" %in% names(listArguments)) { - toexclude=listArguments[["toexclude"]] - } - else { - toexclude=NULL - } - ionAnnot=get.annot(xa, polarity=polarity, allowMiss=listArguments[["allowMiss"]],xset=xsetnofill,toexclude=toexclude) - comb=NULL - } + #Get the polarity from xa object + polarity=xa@polarity + #SNR option + if ("xsetnofill" %in% names(listArguments)) { + load(listArguments[["xsetnofill"]]) + xsetnofill=xset + } + else{ + xsetnofill=NULL + } + #Exclude samples + if ("toexclude" %in% names(listArguments)) { + toexclude=listArguments[["toexclude"]] + } + else { + toexclude=NULL + } + ionAnnot=get.annot(xa, polarity=polarity, allowMiss=listArguments[["allowMiss"]],xset=xsetnofill,toexclude=toexclude) + comb=NULL + } - ##TWO MODES ACQUISITION## - #Mode annotatediffreport - else if(listArguments[["inputs_mode"]]=="two"){ - ##Prepare the objects that will be used for the get.annot function - comb=1 - + ##TWO MODES ACQUISITION## + #Mode annotatediffreport + else if(listArguments[["inputs_mode"]]=="two"){ + ##Prepare the objects that will be used for the get.annot function + comb=1 + - xsetPnofill=NULL - xsetNnofill=NULL - # TODO: a reactiver - #if ("xsetPnofill" %in% names(listArguments)) { - # load(listArguments[["xsetPnofill"]]) - # xsetPnofill=xset - #} - #if ("xsetNnofill" %in% names(listArguments)) { - # load(listArguments[["xsetNnofill"]]) - # xsetNnofill=xset - #} - # include CAMERA non-annotated compounds, and snr retrieval - # comb 2+ - used on Table 1 - ionAnnotP2plus = get.annot(axP, allowMiss=listArguments[["allowMiss"]], xset=xsetPnofill,toexclude=listArguments[["toexclude"]]) - ionAnnotN2plus = get.annot(axN, polarity="negative", allowMiss=listArguments[["allowMiss"]], xset=xsetNnofill,toexclude=listArguments[["toexclude"]]) - ionAnnot = combineMolIon(ionAnnotP2plus, ionAnnotN2plus) - print(sum(ionAnnot$molIon[,3]==1)) - print(sum(ionAnnot$molIon[,3]==0)) - write.table(ionAnnot[1], sep="\t", quote=FALSE, row.names=FALSE, file="CombineMolIon.tsv") - #Merge variableMetadata Negative and positive acquisitions mode - + xsetPnofill=NULL + xsetNnofill=NULL + # TODO: a reactiver + #if ("xsetPnofill" %in% names(listArguments)) { + # load(listArguments[["xsetPnofill"]]) + # xsetPnofill=xset + #} + #if ("xsetNnofill" %in% names(listArguments)) { + # load(listArguments[["xsetNnofill"]]) + # xsetNnofill=xset + #} + # include CAMERA non-annotated compounds, and snr retrieval + # comb 2+ - used on Table 1 + ionAnnotP2plus = get.annot(axP, allowMiss=listArguments[["allowMiss"]], xset=xsetPnofill,toexclude=listArguments[["toexclude"]]) + ionAnnotN2plus = get.annot(axN, polarity="negative", allowMiss=listArguments[["allowMiss"]], xset=xsetNnofill,toexclude=listArguments[["toexclude"]]) + ionAnnot = combineMolIon(ionAnnotP2plus, ionAnnotN2plus) + print(sum(ionAnnot$molIon[,3]==1)) + print(sum(ionAnnot$molIon[,3]==0)) + write.table(ionAnnot[1], sep="\t", quote=FALSE, row.names=FALSE, file="CombineMolIon.tsv") + #Merge variableMetadata Negative and positive acquisitions mode - #Mode combinexsannos TODO bug avec tableau issus de combinexsannos - #else { - #load(listArguments[["image_combinexsannos"]]) - #image_combinexsannos=cAnnot - ##Prepare the objects that will be used for the combineMolIon function - #load(listArguments[["image_pos"]]) - #image_pos=xa - #ionAnnot=combineMolIon(peaklist=cAnnot, cameraobj=image_pos, polarity="pos") - #} - - } + + #Mode combinexsannos TODO bug avec tableau issus de combinexsannos + #else { + #load(listArguments[["image_combinexsannos"]]) + #image_combinexsannos=cAnnot + ##Prepare the objects that will be used for the combineMolIon function + #load(listArguments[["image_pos"]]) + #image_pos=xa + #ionAnnot=combineMolIon(peaklist=cAnnot, cameraobj=image_pos, polarity="pos") + #} + + } - ##DATABASE MATCHING## - if (listArguments[["kegg_db"]]=="KEGG"){ - DB=build.database.kegg(orgID = NULL) - } - else{ - table_list <<- NULL - ids=strsplit(listArguments[["kegg_db"]],",") - ids=ids[[1]] - if(length(ids)>1){ - for(i in 1:length(ids)){ - table_list[[i]] <- build.database.kegg(ids[i]) - } - db_table=do.call("rbind",table_list) - DB=unique(db_table) - } - else{ - DB=build.database.kegg(listArguments[["kegg_db"]]) - } - } - #Matching des mass exactes mesurees avec les masses des compounds KEGG (pas M+H ou M-H) - reactionM = create.reactionM(DB, ionAnnot, ppm.tol=listArguments[["ppm_tol"]]) - ##PROBABILITY RANKING## - # number of masses with candidates inside the fixed mass window - # and masses with more than one candidate - length(unique(reactionM[reactionM[,"id"]!="unknown",1])) - sum(table(reactionM[reactionM[,"id"]!="unknown",1])>1) - #if (listArguments[["useIso"]]){ - #BUG TODO - # Calculate the ratio between observed and theoretical isotopic patterns. - # If you don't have an assessment of carbon offset to carbon number prediction - # skip this step and use the reactionM as input to weigthM function. - #isoPatt < incorporate.isotopes(comb2plus, reactionM, , samp=12:23, DB=DB) - # calculate the likelihood of each mass to compound assignment using mass accuracy,and isotopic pattern, when present - #wl < weightM(isoPatt,intervals=seq(0,1000,by=500), offset=c(3.115712, 3.434146, 2.350798)) - - #isoPatt=incorporate.isotopes(ionAnnot, reactionM,comb=comb,var=listArguments[["var"]],DB=DB) + ##DATABASE MATCHING## + if (listArguments[["kegg_db"]]=="KEGG"){ + DB=build.database.kegg(orgID = NULL) + } + else{ + table_list <<- NULL + ids=strsplit(listArguments[["kegg_db"]],",") + ids=ids[[1]] + if(length(ids)>1){ + for(i in 1:length(ids)){ + table_list[[i]] <- build.database.kegg(ids[i]) + } + db_table=do.call("rbind",table_list) + DB=unique(db_table) + } + else{ + DB=build.database.kegg(listArguments[["kegg_db"]]) + } + } + #Matching des mass exactes mesurees avec les masses des compounds KEGG (pas M+H ou M-H) + reactionM = create.reactionM(DB, ionAnnot, ppm.tol=listArguments[["ppm_tol"]]) + ##PROBABILITY RANKING## + # number of masses with candidates inside the fixed mass window + # and masses with more than one candidate + length(unique(reactionM[reactionM[,"id"]!="unknown",1])) + sum(table(reactionM[reactionM[,"id"]!="unknown",1])>1) + #if (listArguments[["useIso"]]){ + #BUG TODO + # Calculate the ratio between observed and theoretical isotopic patterns. + # If you don't have an assessment of carbon offset to carbon number prediction + # skip this step and use the reactionM as input to weigthM function. + #isoPatt < incorporate.isotopes(comb2plus, reactionM, , samp=12:23, DB=DB) + # calculate the likelihood of each mass to compound assignment using mass accuracy,and isotopic pattern, when present + #wl < weightM(isoPatt,intervals=seq(0,1000,by=500), offset=c(3.115712, 3.434146, 2.350798)) - #wl = weightM(reactionM, useIso=true) - #} - #else { - #wl = weightM(reactionM, useIso=FALSE) - #} - wl =weightM(reactionM, useIso=FALSE) - w = design.connection(reactionM) - # Probability calculations - x = 1:ncol(wl$wm) - y = 1:nrow(wl$wm) - conn = gibbs.samp(x, y, 5000, w, wl$wm) - ansConn = export.class.table(conn, reactionM, ionAnnot, DB=DB,html=listArguments[["html"]],filename="AnalysisExample",prob=listArguments[["prob"]]) - if(listArguments[["html"]]){ - #Zip the EICS plot - system(paste('zip -r "Analysis_Report.zip" "AnalysisExample_fig"')) - } - - # calculate the correlations and partial correlations and cross reference then with reactions - mw=which(w==1,arr.ind=TRUE) - #reac2cor function : Use the intensity of putative molecules in repeated samples to calculate correlations and partial - #correlation in a user defined threshold of false discovery rate for significance testing. After the - #correlation test the function also overlay significant correlations with all putative reactions between - #two masses. - #It generates a list of estimated correlations and reactions. - corList=reac2cor(mw,ansConn$classTable,listArguments[["opt"]],listArguments[["corths"]],listArguments[["corprob"]],listArguments[["pcorprob"]]) - ans=list("ansConn"=ansConn,"corList"=corList) - #Generate the siff table for CytoScape - cytoscape_output(corList,ansConn) + #isoPatt=incorporate.isotopes(ionAnnot, reactionM,comb=comb,var=listArguments[["var"]],DB=DB) + + #wl = weightM(reactionM, useIso=true) + #} + #else { + #wl = weightM(reactionM, useIso=FALSE) + #} + wl =weightM(reactionM, useIso=FALSE) + w = design.connection(reactionM) + # Probability calculations + x = 1:ncol(wl$wm) + y = 1:nrow(wl$wm) + conn = gibbs.samp(x, y, 5000, w, wl$wm) + ansConn = export.class.table(conn, reactionM, ionAnnot, DB=DB,html=listArguments[["html"]],filename="AnalysisExample",prob=listArguments[["prob"]]) + if(listArguments[["html"]]){ + #Zip the EICS plot + system(paste('zip -r "Analysis_Report.zip" "AnalysisExample_fig"')) + } + + # calculate the correlations and partial correlations and cross reference then with reactions + mw=which(w==1,arr.ind=TRUE) + #reac2cor function : Use the intensity of putative molecules in repeated samples to calculate correlations and partial + #correlation in a user defined threshold of false discovery rate for significance testing. After the + #correlation test the function also overlay significant correlations with all putative reactions between + #two masses. + #It generates a list of estimated correlations and reactions. + corList=reac2cor(mw,ansConn$classTable,listArguments[["opt"]],listArguments[["corths"]],listArguments[["corprob"]],listArguments[["pcorprob"]]) + ans=list("ansConn"=ansConn,"corList"=corList) + #Generate the siff table for CytoScape + cytoscape_output(corList,ansConn) - #Execute the merge_probmetab function to merge the variableMetadata table and annotations from ProbMetab results - - if(listArguments[["mode_acquisition"]]=="one") { - #Retrocompatibility with previous annotateDiffreport variableMetadata dataframe (must replace mzmed column by mz, and rtmed by rt) - names(variableMetadata)[names(variableMetadata)=="mzmed"] <- "mz" - names(variableMetadata)[names(variableMetadata)=="rtmed"] <- "rt" - variableM=merge_probmetab(variableMetadata, ansConn) - write.table(variableM, sep="\t", quote=FALSE, row.names=FALSE, file="variableMetadata.tsv") - } else if (listArguments[["mode_acquisition"]]=="two") { - #Retrocompatibility with previous annotateDiffreport variableMetadata dataframe (must replace mzmed column by mz, and rtmed by rt) - names(variableMetadataP)[names(variableMetadata)=="mzmed"] <- "mz" - names(variableMetadataP)[names(variableMetadata)=="rtmed"] <- "rt" - names(variableMetadataN)[names(variableMetadata)=="mzmed"] <- "mz" - names(variableMetadataN)[names(variableMetadata)=="rtmed"] <- "rt" - variableMP=merge_probmetab(variableMetadataP, ansConn) - write.table(variableMP, sep="\t", quote=FALSE, row.names=FALSE, file="variableMetadata_Positive.tsv") - variableMN=merge_probmetab(variableMetadataN, ansConn) - write.table(variableMN, sep="\t", quote=FALSE, row.names=FALSE, file="variableMetadata_Negative.tsv") - } + #Execute the merge_probmetab function to merge the variableMetadata table and annotations from ProbMetab results + + if(listArguments[["mode_acquisition"]]=="one") { + #Retrocompatibility with previous annotateDiffreport variableMetadata dataframe (must replace mzmed column by mz, and rtmed by rt) + names(variableMetadata)[names(variableMetadata)=="mzmed"] <- "mz" + names(variableMetadata)[names(variableMetadata)=="rtmed"] <- "rt" + variableM=merge_probmetab(variableMetadata, ansConn) + write.table(variableM, sep="\t", quote=FALSE, row.names=FALSE, file="variableMetadata.tsv") + } else if (listArguments[["mode_acquisition"]]=="two") { + #Retrocompatibility with previous annotateDiffreport variableMetadata dataframe (must replace mzmed column by mz, and rtmed by rt) + names(variableMetadataP)[names(variableMetadata)=="mzmed"] <- "mz" + names(variableMetadataP)[names(variableMetadata)=="rtmed"] <- "rt" + names(variableMetadataN)[names(variableMetadata)=="mzmed"] <- "mz" + names(variableMetadataN)[names(variableMetadata)=="rtmed"] <- "rt" + variableMP=merge_probmetab(variableMetadataP, ansConn) + write.table(variableMP, sep="\t", quote=FALSE, row.names=FALSE, file="variableMetadata_Positive.tsv") + variableMN=merge_probmetab(variableMetadataN, ansConn) + write.table(variableMN, sep="\t", quote=FALSE, row.names=FALSE, file="variableMetadata_Negative.tsv") + } - return(ans) + return(ans) } ##Function that generates a siff table for CytoScape cytoscape_output=function(corList,ansConn){ - signif_cor=as.data.frame(corList$signif.cor) - classTable=as.data.frame(ansConn$classTable) - #Siff table - siff_table=cbind(signif_cor["node1"],signif_cor["cor"],signif_cor["node2"]) - #attribute table output for Cytoscape + signif_cor=as.data.frame(corList$signif.cor) + classTable=as.data.frame(ansConn$classTable) + #Siff table + siff_table=cbind(signif_cor["node1"],signif_cor["cor"],signif_cor["node2"]) + #attribute table output for Cytoscape - ## START Code part from the export2cytoscape function of ProbMetab written by Ricardo R. Silva - for (i in 1:nrow(classTable)) if (classTable[i, 1] == ""){ - classTable[i, c(1, 4, 6, 7)] <- classTable[i - 1, c(1, 4, 6, 7)] - } - msel <- as.matrix(classTable[, 1:7]) - msel <- cbind(msel[, 6], msel[,-6]) - colnames(msel)[1] <- "Id" - msel[, 1] <- sub("^\\s+", "", msel[, 1]) - colnames(msel)[1] <- "Id" - ids <- unique(msel[, 1]) - attrMatrix <- matrix("", nrow = length(ids), ncol = ncol(msel)-1) - for (i in 1:length(ids)) { - attrMatrix[i, 1] <- unique(msel[msel[, 1] == ids[i], - 2]) - attrMatrix[i, 2] <- paste("[", paste(msel[msel[, - 1] == ids[i], 3], collapse = ", "), "]", sep = "") - attrMatrix[i, 3] <- paste("[", paste(msel[msel[, - 1] == ids[i], 4], collapse = ", "), "]", sep = "") - attrMatrix[i, 4] <- unique(msel[msel[, 1] == ids[i], - 5]) - attrMatrix[i, 5] <- paste("[", paste(msel[msel[, - 1] == ids[i], 6], collapse = ", "), "]", sep = "") - attrMatrix[i, 6] <- unique(msel[msel[, 1] == ids[i], - 7]) + ## START Code part from the export2cytoscape function of ProbMetab written by Ricardo R. Silva + for (i in 1:nrow(classTable)) if (classTable[i, 1] == ""){ + classTable[i, c(1, 4, 6, 7)] <- classTable[i - 1, c(1, 4, 6, 7)] + } + msel <- as.matrix(classTable[, 1:7]) + msel <- cbind(msel[, 6], msel[,-6]) + colnames(msel)[1] <- "Id" + msel[, 1] <- sub("^\\s+", "", msel[, 1]) + colnames(msel)[1] <- "Id" + ids <- unique(msel[, 1]) + attrMatrix <- matrix("", nrow = length(ids), ncol = ncol(msel)-1) + for (i in 1:length(ids)) { + attrMatrix[i, 1] <- unique(msel[msel[, 1] == ids[i], + 2]) + attrMatrix[i, 2] <- paste("[", paste(msel[msel[, + 1] == ids[i], 3], collapse = ", "), "]", sep = "") + attrMatrix[i, 3] <- paste("[", paste(msel[msel[, + 1] == ids[i], 4], collapse = ", "), "]", sep = "") + attrMatrix[i, 4] <- unique(msel[msel[, 1] == ids[i], + 5]) + attrMatrix[i, 5] <- paste("[", paste(msel[msel[, + 1] == ids[i], 6], collapse = ", "), "]", sep = "") + attrMatrix[i, 6] <- unique(msel[msel[, 1] == ids[i], + 7]) } - ids <- as.numeric(unique(msel[, 1])) - attrMatrix <- cbind(ids, attrMatrix) - colnames(attrMatrix) <- colnames(msel) - ## END Code part from the export2cytoscape function of ProbMetab writieen by Ricardo R. Silva - write.table(attrMatrix, sep="\t", quote=FALSE, row.names=FALSE, file="Analysis_Report.tsv") - write.table(siff_table, sep="\t", quote=FALSE, row.names=FALSE, file="sif.tsv") + ids <- as.numeric(unique(msel[, 1])) + attrMatrix <- cbind(ids, attrMatrix) + colnames(attrMatrix) <- colnames(msel) + ## END Code part from the export2cytoscape function of ProbMetab writieen by Ricardo R. Silva + write.table(attrMatrix, sep="\t", quote=FALSE, row.names=FALSE, file="Analysis_Report.tsv") + write.table(siff_table, sep="\t", quote=FALSE, row.names=FALSE, file="sif.tsv") - return(attrMatrix) + return(attrMatrix) } ##Functions written by Jean-Francois Martin @@ -211,55 +211,55 @@ { # determine ionisation in ProbMetab result file, used in function merge_probmetab # input : for 1 ion, aninfo = string with m/z rt and CAMERA annotation from ProbMetab result file - # if the difference between m/z and the probmetab proposed mass is ~1 we use the sign (positive or negative) of this diference + # if the difference between m/z and the probmetab proposed mass is ~1 we use the sign (positive or negative) of this diference # to define the type of ionisation - # If adduct or fragment was detected, therefore diff >>1 and so, we search for substring "+" ou "2+" ou "3+" ou "-"... + # If adduct or fragment was detected, therefore diff >>1 and so, we search for substring "+" ou "2+" ou "3+" ou "-"... # to define the type of ionisation # aninfo : vecteur of character resulting of the parsing(sep="#") of the probmetab annotation if (round(abs(as.numeric(aninfo[1]) - pm),0) ==1) { if (as.numeric(aninfo[1]) - pm <0) {esi <- "n"} else {esi <- "p"} - } else + } else if (!is.na(aninfo[4])) { anstr <- aninfo[4] # cat(anstr) if ((grepl("]+",anstr,fixed=T)==T) || (grepl("]2+",anstr,fixed=T)==T) || (grepl("]3+",anstr,fixed=T)==T)) { esi <- "p"} - else + else if ((grepl("]-",anstr,fixed=T)==T) || (grepl("]2-",anstr,fixed=T)==T) || (grepl("]3-",anstr,fixed=T)==T)) { esi <- "n"} # cat(" ioni ",esi,"\n") } else - { esi <- "u"} - + { esi <- "u"} + return(esi) } merge_probmetab <- function(metaVar,ansConn) { ## Parse ProbMetab information result file and merge in variable_metaData initial file - ## inputs : + ## inputs : ## metaVar : data.frame of metadataVariable input of probmetab function ## ansConn : data.frame of ProbMetab result ## output : dataframe with Probmetab results merge with variableMetadata ## Constante ## iannot : indice de la colonne annotation dans le resultat de probMetab iannot <- 4 - - ## definition of an unique identification of ions mz with 3 decimals and rt(sec) with 1 decimal to avoid + + ## definition of an unique identification of ions mz with 3 decimals and rt(sec) with 1 decimal to avoid ## duplicate ions name in the diffreport result file ions <- paste ("M",round(metaVar$mz,3),"T",round(metaVar$rt,1),sep="") metaVar <- data.frame(ions,metaVar) - + ###### Result data.frame from ProbMetab result list an_ini <- ansConn$classTable - + ## Suppression of rows without mz and rt or unknown and columns of intensities - ## COLUMNS SUBSCRIPTS HAVE TO BE CHECKED WITh DIFFERENT RESULTS FILES + ## COLUMNS SUBSCRIPTS HAVE TO BE CHECKED WITh DIFFERENT RESULTS FILES an <- an_ini[(an_ini[,2]!="unknown"),c(1,2,3,7)] - ## initialisation of vectors receiving the result of the parse of the column annotation (subscrip iannot) + ## initialisation of vectors receiving the result of the parse of the column annotation (subscrip iannot) mz <- rep(0,dim(an)[1]) rt <- rep(0,dim(an)[1]) propmz <- rep(0,dim(an)[1]) ioni <- rep("u",dim(an)[1]) - + ## parse the column annotation and define ionisation mode for (i in 1:dim(an)[1]) { if (an[i,1] != "") { @@ -276,12 +276,12 @@ ioni[i] <- ioni[i-1] } } - + ## definition of an unique identification of ions : mz with 3 decimals and rt(sec) with 1 decimal ## The same as for the metadataVariable data.frame to match with. ions <- paste ("M",round(mz,3),"T",round(rt,1),sep="") an <- data.frame(ions,ioni,propmz,mz,rt,an) - + ## transposition of the different probmetab annotations which are in different rows in the initial result data.frame ## on only 1 row separated with a ";" li <- as.matrix(table(an$propmz)) @@ -298,26 +298,105 @@ ions[c] <- as.character(suban[1,1]) propmz[c] <- as.numeric(suban[1,3]) mpc[c] <- paste(suban[,7],collapse=";") - proba[c] <- paste(as.character(suban[,8]),collapse=";") + proba[c] <- paste(as.character(suban[,8]),collapse=";") } - + ## Creation of the data.frame with 1 row per ions anc <- data.frame(ions,propmz,mpc,proba) anc <- anc[order(anc[,1]),] - + metaVarFinal <- merge(metaVar, anc, by.x=1, by.y=1, all.x=T, all.y=T) metaVarFinal <- metaVarFinal[,-1] #write.table(metaVarFinal,file="res.txt", sep="\t", row.names=F, quote=F) - + return (metaVarFinal) } # RETROCOMPATIBILITE avec ancienne version de annotate getVariableMetadata = function(xa) { - # --- variableMetadata --- - peakList=getPeaklist(xa) - peakList=cbind(groupnames(xa@xcmsSet),peakList); colnames(peakList)[1] = c("name"); - variableMetadata=peakList[,!(colnames(peakList) %in% c(sampnames(xa@xcmsSet)))] - variableMetadata$name= paste("M",round(variableMetadata$mz),"T",round(variableMetadata$rt),sep="") - return (variableMetadata) + # --- variableMetadata --- + peakList=getPeaklist(xa) + peakList=cbind(groupnames(xa@xcmsSet),peakList); colnames(peakList)[1] = c("name"); + variableMetadata=peakList[,!(colnames(peakList) %in% c(sampnames(xa@xcmsSet)))] + variableMetadata$name= groupnames(xa@xcmsSet) + return (variableMetadata) +} + + +# This function get the raw file path from the arguments +getRawfilePathFromArguments <- function(listArguments) { + zipfile = NULL + singlefile = NULL + if (!is.null(listArguments[["zipfile"]])) zipfile = listArguments[["zipfile"]] + if (!is.null(listArguments[["zipfilePositive"]])) zipfile = listArguments[["zipfilePositive"]] + if (!is.null(listArguments[["zipfileNegative"]])) zipfile = listArguments[["zipfileNegative"]] + + if (!is.null(listArguments[["singlefile_galaxyPath"]])) { + singlefile_galaxyPaths = listArguments[["singlefile_galaxyPath"]]; + singlefile_sampleNames = listArguments[["singlefile_sampleName"]] + } + if (!is.null(listArguments[["singlefile_galaxyPathPositive"]])) { + singlefile_galaxyPaths = listArguments[["singlefile_galaxyPathPositive"]]; + singlefile_sampleNames = listArguments[["singlefile_sampleNamePositive"]] + } + if (!is.null(listArguments[["singlefile_galaxyPathNegative"]])) { + singlefile_galaxyPaths = listArguments[["singlefile_galaxyPathNegative"]]; + singlefile_sampleNames = listArguments[["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(1:length(singlefile_galaxyPaths))) { + singlefile_galaxyPath=singlefile_galaxyPaths[singlefile_galaxyPath_i] + singlefile_sampleName=singlefile_sampleNames[singlefile_galaxyPath_i] + singlefile[[singlefile_sampleName]] = singlefile_galaxyPath + } + } + return(list(zipfile=zipfile, singlefile=singlefile)) } + + +# This function retrieve the raw file in the working directory +# - if zipfile: unzip the file with its directory tree +# - if singlefiles: set symlink with the good filename +retrieveRawfileInTheWorkingDirectory <- 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,". Please, contact your administrator ... if you have one!") + 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,". Please, contact your administrator ... if you have one!") + print(error_message) + stop(error_message) + } + + #list all file in the zip file + #zip_files=unzip(zipfile,list=T)[,"Name"] + + #unzip + suppressWarnings(unzip(zipfile, unzip="unzip")) + + #get the directory name + 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") + + } +} diff -r 9541ba588de1 -r f24b9c360a60 macros.xml --- a/macros.xml Mon Jul 04 11:58:12 2016 -0400 +++ b/macros.xml Wed Feb 15 11:45:26 2017 -0500 @@ -16,29 +16,99 @@ LANG=C Rscript $__tool_directory__/probmetab.r - - - - #if $zipfile_load_conditional.zipfile_load_select == "yes": - #if $zipfile_load_conditional.zip_file: - zipfile $zipfile_load_conditional.zip_file + + + ; + return=\$?; + mv log.txt '$log'; + cat '$log'; + sh -c "exit \$return" + + + + + #if $file_load_section_selected.file_load_conditional.file_load_select == "yes": + #if $file_load_section_selected.file_load_conditional.inputs.input == "zip_file": + zipfile$polarity '$file_load_section_selected.file_load_conditional.inputs.zip_file' + #else + #set singlefile_galaxyPath = ','.join( [ str( $single_file ) for $single_file in $file_load_section_selected.file_load_conditional.inputs.single_file ] ) + #set singlefile_sampleName = ','.join( [ str( $single_file.name ) for $single_file in $file_load_section_selected.file_load_conditional.inputs.single_file ] ) + + singlefile_galaxyPath$polarity '$singlefile_galaxyPath' + singlefile_sampleName$polarity '$singlefile_sampleName' #end if - #end if + #end if + + + + #set file_load_section_selected = $file_load_section + #set polarity="" + @COMMAND_FILE_LOAD_NEUTRAL@ + + + + #set file_load_section_selected = $file_load_sectionPositive + #set polarity="Positive" + @COMMAND_FILE_LOAD_NEUTRAL@ + + + + #set file_load_section_selected = $file_load_sectionNegative + #set polarity="Negative" + @COMMAND_FILE_LOAD_NEUTRAL@ - - - - - - - - - - - - + + +
+ + + + + + + + + + + + + + + + + + + + + + +
- + + +
+ + + + + + + +
+
+ + > +
+ + + + + + + +
+
+ .. class:: infomark diff -r 9541ba588de1 -r f24b9c360a60 probmetab.r --- a/probmetab.r Mon Jul 04 11:58:12 2016 -0400 +++ b/probmetab.r Wed Feb 15 11:45:26 2017 -0500 @@ -4,7 +4,7 @@ # ----- LOG ----- -log_file=file("probmetab.log", open = "wt") +log_file=file("log.txt", open = "wt") sink(log_file) sink(log_file, type = "out") @@ -12,8 +12,8 @@ cat("\tPACKAGE INFO\n") pkgs=c("parallel","BiocGenerics", "Biobase", "Rcpp", "mzR", "igraph", "xcms","snow","CAMERA","batch","ProbMetab") for(p in pkgs) { - suppressWarnings( suppressPackageStartupMessages( stopifnot( library(p, quietly=TRUE, logical.return=TRUE, character.only=TRUE)))) - cat(p,"\t",as.character(packageVersion(p)),"\n",sep="") + suppressWarnings( suppressPackageStartupMessages( stopifnot( library(p, quietly=TRUE, logical.return=TRUE, character.only=TRUE)))) + cat(p,"\t",as.character(packageVersion(p)),"\n",sep="") } source_local <- function(fname){ @@ -22,8 +22,10 @@ source(paste(base_dir, fname, sep="/")) } cat("\n\n") + + # ----- ARGUMENTS ----- -cat("\tARGUMENTS INFO\n") +cat("\tARGUMENTS INFO\n") listArguments = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects write.table(as.matrix(listArguments), col.names=F, quote=F, sep='\t') @@ -35,68 +37,53 @@ # ----- INFILE PROCESSING ----- if(listArguments[["mode_acquisition"]]=="one") { - load(listArguments[["xa"]]) - - if (!is.null(listArguments[["zipfile"]])){ - zipfile= listArguments[["zipfile"]]; listArguments[["zipfile"]]=NULL - } - - #Unzip the chromatograms file for plotting EIC pour the HTML file - if(exists("zipfile")) - { - if (zipfile!=""){ - directory=unzip(zipfile) - } - } - if (!exists("xa")) { - xa=xsAnnotate_object - } - source_local("lib.r") - if (!exists("variableMetadata")) variableMetadata= getVariableMetadata(xa); - + load(listArguments[["image"]]) + cat("\t\tXA OBJECT INFO\n") + print(xa) + + source_local("lib.r") + rawFilePath = getRawfilePathFromArguments(listArguments) + zipfile = rawFilePath$zipfile + singlefile = rawFilePath$singlefile + retrieveRawfileInTheWorkingDirectory(singlefile, zipfile) + + if (!exists("variableMetadata")) variableMetadata= getVariableMetadata(xa); + } else if(listArguments[["inputs_mode"]]=="two"){ - load(listArguments[["image_pos"]]) - - if (!is.null(listArguments[["zipfile"]])){ - zipfile= listArguments[["zipfile"]]; listArguments[["zipfile"]]=NULL - } - - #Unzip the chromatograms file for plotting EIC pour the HTML file - if(exists("zipfile")) { - if (zipfile!=""){ - directory=unzip(zipfile) - } - } - if (!exists("xa")) { - xa=xsAnnotate_object - } - xaP=xa - source_local("lib.r") - if (!exists("variableMetadata")) variableMetadataP= getVariableMetadata(xa) - else variableMetadataP=variableMetadata + + # POSITIVE + load(listArguments[["image_pos"]]) + if (!exists("xa")) xaP=xsAnnotate_object + else xaP=xa + cat("\t\tXA-POSITIVE OBJECT INFO\n") + print(xaP) + + if (!exists("variableMetadata")) variableMetadataP = getVariableMetadata(xa) + else variableMetadataP = variableMetadata - load(listArguments[["image_neg"]]) - - if (!is.null(listArguments[["zipfile"]])){ - zipfile= listArguments[["zipfile"]]; listArguments[["zipfile"]]=NULL - } - - #Unzip the chromatograms file for plotting EIC pour the HTML file - if(exists("zipfile")) { - - if (zipfile!=""){ - directory=unzip(zipfile) - } - } - if (!exists("xa")) { - xa=xsAnnotate_object - } - xaN=xa - source_local("lib.r") - - if (!exists("variableMetadata")) variableMetadataN= getVariableMetadata(xa) - else variableMetadataN=variableMetadata + source_local("lib.r") + rawFilePath = getRawfilePathFromArguments(listArguments) + zipfilePos = rawFilePath$zipfile + singlefilePos = rawFilePath$singlefile + retrieveRawfileInTheWorkingDirectory(singlefilePos, zipfilePos) + + # NEGATIVE + load(listArguments[["image_neg"]]) + + if (!exists("xa")) xaN=xsAnnotate_object + else xaN=xa + cat("\t\tXA-NEGATIVE OBJECT INFO\n") + print(xaP) + + if (!exists("variableMetadata")) variableMetadataN = getVariableMetadata(xa) + else variableMetadataN = variableMetadata + + source_local("lib.r") + rawFilePath = getRawfilePathFromArguments(listArguments) + zipfileNeg = rawFilePath$zipfile + singlefileNeg = rawFilePath$singlefile + retrieveRawfileInTheWorkingDirectory(singlefileNeg, zipfileNeg) } #Import the different functions @@ -107,13 +94,12 @@ cat("\tMAIN PROCESSING INFO\n") if(listArguments[["mode_acquisition"]]=="one") { - results=probmetab(xa=xa, variableMetadata=variableMetadata,listArguments=listArguments) + results=probmetab(xa=xa, variableMetadata=variableMetadata,listArguments=listArguments) } else if(listArguments[["inputs_mode"]]=="two"){ - results=probmetab(xaP=xaP, xaN=xaN,variableMetadataP=variableMetadataP, variableMetadataN=variableMetadataN, listArguments=listArguments) + results=probmetab(xaP=xaP, xaN=xaN,variableMetadataP=variableMetadataP, variableMetadataN=variableMetadataN, listArguments=listArguments) } #delete the parameters to avoid the passage to the next tool in .RData image #rm(listArguments) cat("\tDONE\n") #saving R data in .Rdata file to save the variables used in the present tool #save.image(paste("probmetab","RData",sep=".")) - diff -r 9541ba588de1 -r f24b9c360a60 test-data/faahOK-single.xset.merged.group.retcor.group.fillPeaks.annotate.negative.Rdata Binary file test-data/faahOK-single.xset.merged.group.retcor.group.fillPeaks.annotate.negative.Rdata has changed diff -r 9541ba588de1 -r f24b9c360a60 test-data/ko15.CDF Binary file test-data/ko15.CDF has changed diff -r 9541ba588de1 -r f24b9c360a60 test-data/ko16.CDF Binary file test-data/ko16.CDF has changed diff -r 9541ba588de1 -r f24b9c360a60 test-data/wt15.CDF Binary file test-data/wt15.CDF has changed diff -r 9541ba588de1 -r f24b9c360a60 test-data/wt16.CDF Binary file test-data/wt16.CDF has changed