Mercurial > repos > lecorguille > ipo
comparison ipo4xcmsSet.r @ 0:ac5f2936575b draft
planemo upload commit 131562ad89c33a2f87754936ce3c8fe6899484c0
| author | lecorguille |
|---|---|
| date | Thu, 03 Aug 2017 06:00:00 -0400 |
| parents | |
| children | ae8de756dfcf |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:ac5f2936575b |
|---|---|
| 1 #!/usr/bin/env Rscript | |
| 2 #Authors Gildas Le Corguille and Yann Guitton | |
| 3 | |
| 4 | |
| 5 # ----- LOG FILE ----- | |
| 6 log_file=file("log.txt", open = "wt") | |
| 7 sink(log_file) | |
| 8 sink(log_file, type = "output") | |
| 9 | |
| 10 | |
| 11 # ----- PACKAGE ----- | |
| 12 options(bitmapType='cairo') | |
| 13 cat("\tPACKAGE INFO\n") | |
| 14 #pkgs=c("xcms","batch") | |
| 15 pkgs=c("parallel","BiocGenerics", "Biobase", "Rcpp", "mzR", "xcms","rsm","igraph","CAMERA","IPO","snow","batch") | |
| 16 for(pkg in pkgs) { | |
| 17 suppressWarnings( suppressPackageStartupMessages( stopifnot( library(pkg, quietly=TRUE, logical.return=TRUE, character.only=TRUE)))) | |
| 18 cat(pkg,"\t",as.character(packageVersion(pkg)),"\n",sep="") | |
| 19 } | |
| 20 source_local <- function(fname){ argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) } | |
| 21 cat("\n\n"); | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 # ----- ARGUMENTS ----- | |
| 28 cat("\tARGUMENTS INFO\n") | |
| 29 listArguments = parseCommandArgs(evaluate=FALSE) #interpretation of arguments given in command line as an R list of objects | |
| 30 write.table(as.matrix(listArguments), col.names=F, quote=F, sep='\t') | |
| 31 | |
| 32 cat("\n\n"); | |
| 33 | |
| 34 | |
| 35 # ----- ARGUMENTS PROCESSING ----- | |
| 36 cat("\tINFILE PROCESSING INFO\n") | |
| 37 | |
| 38 | |
| 39 #Import the different functions | |
| 40 source_local("lib.r") | |
| 41 | |
| 42 cat("\n\n") | |
| 43 | |
| 44 #Import the different functions | |
| 45 | |
| 46 # ----- PROCESSING INFILE ----- | |
| 47 cat("\tARGUMENTS PROCESSING INFO\n") | |
| 48 | |
| 49 xsetRdataOutput = paste("ipo4xcmsSet","RData",sep=".") | |
| 50 if (!is.null(listArguments[["xsetRdataOutput"]])){ | |
| 51 xsetRdataOutput = listArguments[["xsetRdataOutput"]]; listArguments[["xsetRdataOutput"]]=NULL | |
| 52 } | |
| 53 | |
| 54 parametersOutput = "parametersOutput.tsv" | |
| 55 if (!is.null(listArguments[["parametersOutput"]])){ | |
| 56 parametersOutput = listArguments[["parametersOutput"]]; listArguments[["parametersOutput"]]=NULL | |
| 57 } | |
| 58 | |
| 59 samplebyclass = 2 | |
| 60 if (!is.null(listArguments[["samplebyclass"]])){ | |
| 61 samplebyclass = listArguments[["samplebyclass"]]; listArguments[["samplebyclass"]]=NULL | |
| 62 } | |
| 63 | |
| 64 #necessary to unzip .zip file uploaded to Galaxy | |
| 65 #thanks to .zip file it's possible to upload many file as the same time conserving the tree hierarchy of directories | |
| 66 | |
| 67 | |
| 68 if (!is.null(listArguments[["zipfile"]])){ | |
| 69 zipfile= listArguments[["zipfile"]]; listArguments[["zipfile"]]=NULL | |
| 70 } | |
| 71 | |
| 72 | |
| 73 if (!is.null(listArguments[["singlefile_galaxyPath"]])){ | |
| 74 singlefile_galaxyPath = listArguments[["singlefile_galaxyPath"]]; listArguments[["singlefile_galaxyPath"]]=NULL | |
| 75 singlefile_sampleName = listArguments[["singlefile_sampleName"]]; listArguments[["singlefile_sampleName"]]=NULL | |
| 76 } | |
| 77 | |
| 78 # single file case | |
| 79 #@TODO: need to be refactoring | |
| 80 if(exists("singlefile_galaxyPath") && (singlefile_galaxyPath!="")) { | |
| 81 if(!file.exists(singlefile_galaxyPath)){ | |
| 82 error_message=paste("Cannot access the sample:",singlefile_sampleName,"located:",singlefile_galaxyPath,". Please, contact your administrator ... if you have one!") | |
| 83 print(error_message); stop(error_message) | |
| 84 } | |
| 85 | |
| 86 cwd=getwd() | |
| 87 dir.create("raw") | |
| 88 setwd("raw") | |
| 89 file.symlink(singlefile_galaxyPath,singlefile_sampleName) | |
| 90 setwd(cwd) | |
| 91 | |
| 92 directory = "raw" | |
| 93 | |
| 94 } | |
| 95 | |
| 96 # We unzip automatically the chromatograms from the zip files. | |
| 97 if(exists("zipfile") && (zipfile!="")) { | |
| 98 if(!file.exists(zipfile)){ | |
| 99 error_message=paste("Cannot access the Zip file:",zipfile,". Please, contact your administrator ... if you have one!") | |
| 100 print(error_message) | |
| 101 stop(error_message) | |
| 102 } | |
| 103 | |
| 104 #list all file in the zip file | |
| 105 #zip_files=unzip(zipfile,list=T)[,"Name"] | |
| 106 | |
| 107 # Because IPO only want raw data in its working directory | |
| 108 dir.create("ipoworkingdir") | |
| 109 setwd("ipoworkingdir") | |
| 110 | |
| 111 #unzip | |
| 112 suppressWarnings(unzip(zipfile, unzip="unzip")) | |
| 113 | |
| 114 #get the directory name | |
| 115 filesInZip=unzip(zipfile, list=T); | |
| 116 directories=unique(unlist(lapply(strsplit(filesInZip$Name,"/"), function(x) x[1]))); | |
| 117 directories=directories[!(directories %in% c("__MACOSX")) & file.info(directories)$isdir] | |
| 118 directory = "." | |
| 119 if (length(directories) == 1) directory = directories | |
| 120 | |
| 121 cat("files_root_directory\t",directory,"\n") | |
| 122 | |
| 123 | |
| 124 } | |
| 125 | |
| 126 #addition of the directory to the list of arguments in the first position | |
| 127 checkXmlStructure(directory) | |
| 128 checkFilesCompatibilityWithXcms(directory) | |
| 129 | |
| 130 cat("\n\n") | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 # ----- MAIN PROCESSING INFO ----- | |
| 138 cat("\tMAIN PROCESSING INFO\n") | |
| 139 | |
| 140 | |
| 141 xset = ipo4xcmsSet(directory, parametersOutput, listArguments, samplebyclass) | |
| 142 | |
| 143 | |
| 144 | |
| 145 cat("\n\n") | |
| 146 | |
| 147 | |
| 148 # ----- EXPORT ----- | |
| 149 | |
| 150 cat("\tXSET OBJECT INFO\n") | |
| 151 print(xset) | |
| 152 #delete the parameters to avoid the passage to the next tool in .RData image | |
| 153 | |
| 154 | |
| 155 #saving R data in .Rdata file to save the variables used in the present tool | |
| 156 objects2save = c("xset","zipfile") | |
| 157 save(list=objects2save[objects2save %in% ls()], file=xsetRdataOutput) | |
| 158 | |
| 159 cat("\n\n") | |
| 160 | |
| 161 | |
| 162 cat("\tDONE\n") | |
| 163 |
