diff CAMERA.r @ 25:230f0bc9e792 draft

planemo upload commit a634879c0e651eb0eb7b435a107ee40cf30524fa
author lecorguille
date Fri, 10 Feb 2017 11:11:27 -0500
parents 77a191e37af4
children 04e32b9a5486
line wrap: on
line diff
--- a/CAMERA.r	Wed Feb 01 12:23:07 2017 -0500
+++ b/CAMERA.r	Fri Feb 10 11:11:27 2017 -0500
@@ -11,12 +11,12 @@
 #pkgs=c("xcms","batch")
 pkgs=c("parallel","BiocGenerics", "Biobase", "Rcpp", "mzR", "xcms","snow","igraph","CAMERA","multtest","batch")
 for(p in pkgs) {
-  suppressPackageStartupMessages(suppressWarnings(library(p, quietly=TRUE, logical.return=TRUE, character.only=TRUE)))
-  cat(p,"\t",as.character(packageVersion(p)),"\n",sep="")
+    suppressPackageStartupMessages(suppressWarnings(library(p, quietly=TRUE, logical.return=TRUE, character.only=TRUE)))
+    cat(p,"\t",as.character(packageVersion(p)),"\n",sep="")
 }
 source_local <- function(fname){ argv <- commandArgs(trailingOnly = FALSE); base_dir <- dirname(substring(argv[grep("--file=", argv)], 8)); source(paste(base_dir, fname, sep="/")) }
 
-cat("\n\n"); 
+cat("\n\n");
 
 
 
@@ -34,25 +34,25 @@
 
 #image is an .RData file necessary to use xset variable given by previous tools
 if (!is.null(listArguments[["image"]])){
-  load(listArguments[["image"]]); listArguments[["image"]]=NULL
+    load(listArguments[["image"]]); listArguments[["image"]]=NULL
 }
 
 if (listArguments[["xfunction"]] %in% c("combinexsAnnos")) {
-  load(listArguments[["image_pos"]])
-  xaP=xa
-  listOFlistArgumentsP=listOFlistArguments
-  if (exists("xsAnnotate_object")) xaP=xsAnnotate_object
-  
-  diffrepP=NULL
-  if (exists("diffrep")) diffrepP=diffrep
+    load(listArguments[["image_pos"]])
+    xaP=xa
+    listOFlistArgumentsP=listOFlistArguments
+    if (exists("xsAnnotate_object")) xaP=xsAnnotate_object
+
+    diffrepP=NULL
+    if (exists("diffrep")) diffrepP=diffrep
 
-  load(listArguments[["image_neg"]])
-  xaN=xa
-  listOFlistArgumentsN=listOFlistArguments
-  if (exists("xsAnnotate_object")) xaN=xsAnnotate_object
+    load(listArguments[["image_neg"]])
+    xaN=xa
+    listOFlistArgumentsN=listOFlistArguments
+    if (exists("xsAnnotate_object")) xaN=xsAnnotate_object
 
-  diffrepN=NULL
-  if (exists("diffrep")) diffrepN=diffrep
+    diffrepN=NULL
+    if (exists("diffrep")) diffrepN=diffrep
 }
 
 
@@ -73,26 +73,26 @@
 
 xsetRdataOutput = paste(thefunction,"RData",sep=".")
 if (!is.null(listArguments[["xsetRdataOutput"]])){
-  xsetRdataOutput = listArguments[["xsetRdataOutput"]]; listArguments[["xsetRdataOutput"]]=NULL
+    xsetRdataOutput = listArguments[["xsetRdataOutput"]]; listArguments[["xsetRdataOutput"]]=NULL
 }
 
 rplotspdf = "Rplots.pdf"
 if (!is.null(listArguments[["rplotspdf"]])){
-  rplotspdf = listArguments[["rplotspdf"]]; listArguments[["rplotspdf"]]=NULL
+    rplotspdf = listArguments[["rplotspdf"]]; listArguments[["rplotspdf"]]=NULL
 }
 
 dataMatrixOutput = "dataMatrix.tsv"
 if (!is.null(listArguments[["dataMatrixOutput"]])){
-  dataMatrixOutput = listArguments[["dataMatrixOutput"]]; listArguments[["dataMatrixOutput"]]=NULL
+    dataMatrixOutput = listArguments[["dataMatrixOutput"]]; listArguments[["dataMatrixOutput"]]=NULL
 }
 
 variableMetadataOutput = "variableMetadata.tsv"
 if (!is.null(listArguments[["variableMetadataOutput"]])){
-  variableMetadataOutput = listArguments[["variableMetadataOutput"]]; listArguments[["variableMetadataOutput"]]=NULL
+    variableMetadataOutput = listArguments[["variableMetadataOutput"]]; listArguments[["variableMetadataOutput"]]=NULL
 }
 
 if (!is.null(listArguments[["new_file_path"]])){
-  new_file_path = listArguments[["new_file_path"]]; listArguments[["new_file_path"]]=NULL
+    new_file_path = listArguments[["new_file_path"]]; listArguments[["new_file_path"]]=NULL
 }
 
 #Import the different functions
@@ -101,39 +101,67 @@
 #necessary to unzip .zip file uploaded to Galaxy
 #thanks to .zip file it's possible to upload many file as the same time conserving the tree hierarchy of directories
 
+if (!is.null(listArguments[["zipfile"]])){
+    zipfile= listArguments[["zipfile"]]; listArguments[["zipfile"]]=NULL
+}
 
-if (!is.null(listArguments[["zipfile"]])){
-  zipfile= listArguments[["zipfile"]]; listArguments[["zipfile"]]=NULL
+if (!is.null(listArguments[["singlefile_galaxyPath"]])){
+    singlefile_galaxyPaths = unlist(strsplit(listArguments[["singlefile_galaxyPath"]],",")); listArguments[["singlefile_galaxyPath"]]=NULL
+    singlefile_sampleNames = unlist(strsplit(listArguments[["singlefile_sampleName"]],",")); listArguments[["singlefile_sampleName"]]=NULL
+
+    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
+    }
 }
 
 # We unzip automatically the chromatograms from the zip files.
 if (thefunction %in% c("annotatediff"))  {
-  if(exists("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)
-    }
+    if(exists("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)
+            }
 
-    #unzip
-    suppressWarnings(unzip(zipfile, unzip="unzip"))
+            file.symlink(singlefile_galaxyPath,singlefile_sampleName)
+        }
+        directory = "."
+
 
-    #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")
-  }
+    }
+    if(exists("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")
+
+    }
 }
 
 
-
 #addition of xset object to the list of arguments in the first position
 if (exists("xset") != 0){
-  listArguments=append(list(xset), listArguments)
+    listArguments=append(list(xset), listArguments)
 }
 
 cat("\n\n")
@@ -149,18 +177,25 @@
 
 
 if (thefunction %in% c("annotatediff")) {
-  results_list=annotatediff(xset=xset,listArguments=listArguments,variableMetadataOutput=variableMetadataOutput,dataMatrixOutput=dataMatrixOutput,new_file_path=new_file_path)
-  xa=results_list[["xa"]]
-  diffrep=results_list[["diffrep"]]
-  variableMetadata=results_list[["variableMetadata"]]
+    results_list=annotatediff(xset=xset,listArguments=listArguments,variableMetadataOutput=variableMetadataOutput,dataMatrixOutput=dataMatrixOutput,new_file_path=new_file_path)
+    xa=results_list[["xa"]]
+    diffrep=results_list[["diffrep"]]
+    variableMetadata=results_list[["variableMetadata"]]
 
-  cat("\n\n")
-  cat("\tXSET OBJECT INFO\n")
-  print(xa)
+    cat("\n\n")
+    cat("\tXSET OBJECT INFO\n")
+    print(xa)
 }
 
 if (thefunction %in% c("combinexsAnnos")) {
-  cAnnot=combinexsAnnos_function(xaP=xaP,xaN=xaN,listOFlistArgumentsP=listOFlistArgumentsP,listOFlistArgumentsN=listOFlistArgumentsN,diffrepP=diffrepP,diffrepN=diffrepN,convert_param=listArguments[["convert_param"]],pos=listArguments[["pos"]],tol=listArguments[["tol"]],ruleset=listArguments[["ruleset"]],keep_meta=listArguments[["keep_meta"]],variableMetadataOutput=variableMetadataOutput)
+    cAnnot=combinexsAnnos_function(
+        xaP=xaP,xaN=xaN,
+        listOFlistArgumentsP=listOFlistArgumentsP,listOFlistArgumentsN=listOFlistArgumentsN,
+        diffrepP=diffrepP,diffrepN=diffrepN,
+        pos=listArguments[["pos"]],tol=listArguments[["tol"]],ruleset=listArguments[["ruleset"]],keep_meta=listArguments[["keep_meta"]],
+        intval=listArguments[["intval"]], convertRTMinute=listArguments[["convertRTMinute"]], numDigitsMZ=listArguments[["numDigitsMZ"]], numDigitsRT=listArguments[["numDigitsRT"]],
+        variableMetadataOutput=variableMetadataOutput
+    )
 }
 
 dev.off()