comparison lib.r @ 0:b2032600d98f draft

planemo upload commit ddb46a9ade365cbe01b3ff9f50dffa0140136632
author lecorguille
date Tue, 24 May 2016 19:49:14 -0400
parents
children 508ab373b524
comparison
equal deleted inserted replaced
-1:000000000000 0:b2032600d98f
1
2 ##
3 ## This function launch IPO functions to get the best parameters for xcmsSet
4 ## A sample among the whole dataset is used to save time
5 ##
6 ipo4xcmsSet = function(directory, parametersOutput, listArguments, samplebyclass=4) {
7 setwd(directory)
8 files = list.files(".", recursive=T) # "KO/ko15.CDF" "KO/ko16.CDF" "WT/wt15.CDF" "WT/wt16.CDF"
9 files_classes = basename(dirname(files)) # "KO", "KO", "WT", "WT"
10
11 mzmlfile = files
12 if (samplebyclass > 0) {
13 #random selection of N files for IPO in each class
14 classes<-unique(basename(dirname(files)))
15 mzmlfile = NULL
16 for (class_i in classes){
17 files_class_i = files[files_classes==class_i]
18 if (samplebyclass > length(files_class_i)) {
19 mzmlfile = c(mzmlfile, files_class_i)
20 } else {
21 mzmlfile = c(mzmlfile,sample(files_class_i,samplebyclass))
22 }
23 }
24 }
25 #TODO: else, must we keep the RData to been use directly by group?
26
27 cat("\t\tSamples used:\n")
28 print(mzmlfile)
29
30 paramsPP <- getDefaultXcmsSetStartingParams(listArguments[["method"]]) #load default parameters of IPO
31
32 #user defined new parameters
33 paramsPP$ppm <- listArguments[["ppm"]]
34 paramsPP$min_peakwidth <- listArguments[["min_peakwidth"]]
35 paramsPP$max_peakwidth <- listArguments[["max_peakwidth"]]
36 paramsPP$nSlaves <- listArguments[["nSlaves"]]
37
38 #paramsPP$profparam <- list(step=0.005) #not yet used by IPO have to think of it for futur improvement
39 resultPPpos <- optimizeXcmsSet(mzmlfile, paramsPP, subdir="IPO_results") #some images generated by IPO
40 write.table(resultPPpos$best_settings$parameters, file=parametersOutput, sep="\t",row.names=FALSE) #can be read by user
41
42 }
43
44
45
46
47 ##
48 ## This function check if xcms will found all the files
49 ##
50 #@author Gildas Le Corguille lecorguille@sb-roscoff.fr ABiMS TEAM
51 checkFilesCompatibilityWithXcms <- function(directory) {
52 cat("Checking files filenames compatibilities with xmcs...\n")
53 # WHAT XCMS WILL FIND
54 filepattern <- c("[Cc][Dd][Ff]", "[Nn][Cc]", "([Mm][Zz])?[Xx][Mm][Ll]","[Mm][Zz][Dd][Aa][Tt][Aa]", "[Mm][Zz][Mm][Ll]")
55 filepattern <- paste(paste("\\.", filepattern, "$", sep = ""),collapse = "|")
56 info <- file.info(directory)
57 listed <- list.files(directory[info$isdir], pattern = filepattern,recursive = TRUE, full.names = TRUE)
58 files <- c(directory[!info$isdir], listed)
59 files_abs <- file.path(getwd(), files)
60 exists <- file.exists(files_abs)
61 files[exists] <- files_abs[exists]
62 files[exists] <- sub("//","/",files[exists])
63
64 # WHAT IS ON THE FILESYSTEM
65 filesystem_filepaths=system(paste("find $PWD/",directory," -not -name '\\.*' -not -path '*conda-env*' -type f -name \"*\"", sep=""), intern=T)
66 filesystem_filepaths=filesystem_filepaths[grep(filepattern, filesystem_filepaths, perl=T)]
67
68 # COMPARISON
69 if (!is.na(table(filesystem_filepaths %in% files)["FALSE"])) {
70 write("\n\nERROR: List of the files which will not be imported by xcmsSet",stderr())
71 write(filesystem_filepaths[!(filesystem_filepaths %in% files)],stderr())
72 stop("\n\nERROR: One or more of your files will not be import by xcmsSet. It may due to bad characters in their filenames.")
73
74 }
75 }
76
77
78
79 ##
80 ## This function check if XML contains special caracters. It also checks integrity and completness.
81 ##
82 #@author Misharl Monsoor misharl.monsoor@sb-roscoff.fr ABiMS TEAM
83 checkXmlStructure <- function (directory) {
84 cat("Checking XML structure...\n")
85
86 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;")
87 capture=system(cmd,intern=TRUE)
88
89 if (length(capture)>0){
90 #message=paste("The following mzXML or mzML file is incorrect, please check these files first:",capture)
91 write("\n\nERROR: The following mzXML or mzML file(s) are incorrect, please check these files first:", stderr())
92 write(capture, stderr())
93 stop("ERROR: xcmsSet cannot continue with incorrect mzXML or mzML files")
94 }
95
96 }