comparison lib.r @ 31:281786a7b9a2 draft

planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 7b226c3ba91a3cf654ec1c14b3ef85090968bb0f
author lecorguille
date Mon, 05 Mar 2018 04:17:36 -0500
parents 4d6f4cd7c3ef
children 69b5a006fca1
comparison
equal deleted inserted replaced
30:4d6f4cd7c3ef 31:281786a7b9a2
50 return(variableMetadata) 50 return(variableMetadata)
51 } 51 }
52 52
53 #@author G. Le Corguille 53 #@author G. Le Corguille
54 # Draw the plotChromPeakDensity 3 per page in a pdf file 54 # Draw the plotChromPeakDensity 3 per page in a pdf file
55 getPlotChromPeakDensity <- function(xdata) { 55 getPlotChromPeakDensity <- function(xdata, mzdigit=4) {
56 pdf(file="plotChromPeakDensity.pdf", width=16, height=12) 56 pdf(file="plotChromPeakDensity.pdf", width=16, height=12)
57 57
58 par(mfrow = c(3, 1), mar = c(4, 4, 1, 0.5)) 58 par(mfrow = c(3, 1), mar = c(4, 4, 1, 0.5))
59 59
60 group_colors <- brewer.pal(3, "Set1")[1:length(unique(xdata$sample_group))] 60 group_colors <- brewer.pal(3, "Set1")[1:length(unique(xdata$sample_group))]
61 names(group_colors) <- unique(xdata$sample_group) 61 names(group_colors) <- unique(xdata$sample_group)
62 62
63 xlim <- c(min(featureDefinitions(xdata)$rtmin), max(featureDefinitions(xdata)$rtmax)) 63 xlim <- c(min(featureDefinitions(xdata)$rtmin), max(featureDefinitions(xdata)$rtmax))
64 for (i in 1:nrow(featureDefinitions(xdata))) { 64 for (i in 1:nrow(featureDefinitions(xdata))) {
65 plotChromPeakDensity(xdata, mz=c(featureDefinitions(xdata)[i,]$mzmin,featureDefinitions(xdata)[i,]$mzmax), col=group_colors, pch=16, xlim=xlim) 65 mzmin = featureDefinitions(xdata)[i,]$mzmin
66 mzmax = featureDefinitions(xdata)[i,]$mzmax
67 plotChromPeakDensity(xdata, mz=c(mzmin,mzmax), col=group_colors, pch=16, xlim=xlim, main=paste(round(mzmin,mzdigit),round(mzmax,mzdigit)))
66 legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1) 68 legend("topright", legend=names(group_colors), col=group_colors, cex=0.8, lty=1)
67 } 69 }
68 70
69 dev.off() 71 dev.off()
70 } 72 }
429 exists <- file.exists(files_abs) 431 exists <- file.exists(files_abs)
430 files[exists] <- files_abs[exists] 432 files[exists] <- files_abs[exists]
431 files[exists] <- sub("//","/",files[exists]) 433 files[exists] <- sub("//","/",files[exists])
432 434
433 # WHAT IS ON THE FILESYSTEM 435 # WHAT IS ON THE FILESYSTEM
434 filesystem_filepaths <- system(paste("find $PWD/",directory," -not -name '\\.*' -not -path '*conda-env*' -type f -name \"*\"", sep=""), intern=T) 436 filesystem_filepaths <- system(paste0("find \"$PWD/",directory,"\" -not -name '\\.*' -not -path '*conda-env*' -type f -name \"*\""), intern=T)
435 filesystem_filepaths <- filesystem_filepaths[grep(filepattern, filesystem_filepaths, perl=T)] 437 filesystem_filepaths <- filesystem_filepaths[grep(filepattern, filesystem_filepaths, perl=T)]
436 438
437 # COMPARISON 439 # COMPARISON
438 if (!is.na(table(filesystem_filepaths %in% files)["FALSE"])) { 440 if (!is.na(table(filesystem_filepaths %in% files)["FALSE"])) {
439 write("\n\nERROR: List of the files which will not be imported by xcmsSet",stderr()) 441 write("\n\nERROR: List of the files which will not be imported by xcmsSet",stderr())
459 # This function check if XML contains special caracters. It also checks integrity and completness. 461 # This function check if XML contains special caracters. It also checks integrity and completness.
460 #@author Misharl Monsoor misharl.monsoor@sb-roscoff.fr ABiMS TEAM 462 #@author Misharl Monsoor misharl.monsoor@sb-roscoff.fr ABiMS TEAM
461 checkXmlStructure <- function (directory) { 463 checkXmlStructure <- function (directory) {
462 cat("Checking XML structure...\n") 464 cat("Checking XML structure...\n")
463 465
464 cmd <- paste("IFS=$'\n'; for xml in $(find",directory,"-not -name '\\.*' -not -path '*conda-env*' -type f -iname '*.*ml*'); do if [ $(xmllint --nonet --noout \"$xml\" 2> /dev/null; echo $?) -gt 0 ]; then echo $xml;fi; done;") 466 cmd <- paste0("IFS=$'\n'; for xml in $(find '",directory,"' -not -name '\\.*' -not -path '*conda-env*' -type f -iname '*.*ml*'); do if [ $(xmllint --nonet --noout \"$xml\" 2> /dev/null; echo $?) -gt 0 ]; then echo $xml;fi; done;")
465 capture <- system(cmd, intern=TRUE) 467 capture <- system(cmd, intern=TRUE)
466 468
467 if (length(capture)>0){ 469 if (length(capture)>0){
468 #message=paste("The following mzXML or mzML file is incorrect, please check these files first:",capture) 470 #message=paste("The following mzXML or mzML file is incorrect, please check these files first:",capture)
469 write("\n\nERROR: The following mzXML or mzML file(s) are incorrect, please check these files first:", stderr()) 471 write("\n\nERROR: The following mzXML or mzML file(s) are incorrect, please check these files first:", stderr())
478 #@author Misharl Monsoor misharl.monsoor@sb-roscoff.fr ABiMS TEAM 480 #@author Misharl Monsoor misharl.monsoor@sb-roscoff.fr ABiMS TEAM
479 deleteXmlBadCharacters<- function (directory) { 481 deleteXmlBadCharacters<- function (directory) {
480 cat("Checking Non ASCII characters in the XML...\n") 482 cat("Checking Non ASCII characters in the XML...\n")
481 483
482 processed <- F 484 processed <- F
483 l <- system( paste("find",directory, "-not -name '\\.*' -not -path '*conda-env*' -type f -iname '*.*ml*'"), intern=TRUE) 485 l <- system( paste0("find '",directory, "' -not -name '\\.*' -not -path '*conda-env*' -type f -iname '*.*ml*'"), intern=TRUE)
484 for (i in l){ 486 for (i in l){
485 cmd <- paste("LC_ALL=C grep '[^ -~]' \"", i, "\"", sep="") 487 cmd <- paste("LC_ALL=C grep '[^ -~]' \"", i, "\"", sep="")
486 capture <- suppressWarnings(system(cmd, intern=TRUE)) 488 capture <- suppressWarnings(system(cmd, intern=TRUE))
487 if (length(capture)>0){ 489 if (length(capture)>0){
488 cmd <- paste("perl -i -pe 's/[^[:ascii:]]//g;'",i) 490 cmd <- paste("perl -i -pe 's/[^[:ascii:]]//g;'",i)
536 if (!is.null(args$singlefile_galaxyPathNegative)) { 538 if (!is.null(args$singlefile_galaxyPathNegative)) {
537 singlefile_galaxyPaths <- args$singlefile_galaxyPathNegative; 539 singlefile_galaxyPaths <- args$singlefile_galaxyPathNegative;
538 singlefile_sampleNames <- args$singlefile_sampleNameNegative 540 singlefile_sampleNames <- args$singlefile_sampleNameNegative
539 } 541 }
540 if (exists("singlefile_galaxyPaths")){ 542 if (exists("singlefile_galaxyPaths")){
541 singlefile_galaxyPaths <- unlist(strsplit(singlefile_galaxyPaths,",")) 543 singlefile_galaxyPaths <- unlist(strsplit(singlefile_galaxyPaths,"\\|"))
542 singlefile_sampleNames <- unlist(strsplit(singlefile_sampleNames,",")) 544 singlefile_sampleNames <- unlist(strsplit(singlefile_sampleNames,"\\|"))
543 545
544 singlefile <- NULL 546 singlefile <- NULL
545 for (singlefile_galaxyPath_i in seq(1:length(singlefile_galaxyPaths))) { 547 for (singlefile_galaxyPath_i in seq(1:length(singlefile_galaxyPaths))) {
546 singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i] 548 singlefile_galaxyPath <- singlefile_galaxyPaths[singlefile_galaxyPath_i]
547 singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i] 549 singlefile_sampleName <- singlefile_sampleNames[singlefile_galaxyPath_i]