diff xcms.r @ 22:411d2b9ea412 draft

planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 87dc789d7cd70a3733a1ad0b5a427f4d5905795d
author lecorguille
date Wed, 01 Mar 2017 16:57:27 -0500
parents 2faecb1270fe
children 38fa090ae98f
line wrap: on
line diff
--- a/xcms.r	Fri Feb 10 11:02:38 2017 -0500
+++ b/xcms.r	Wed Mar 01 16:57:27 2017 -0500
@@ -71,7 +71,7 @@
 }
 sampleMetadataOutput = "sampleMetadata.tsv"
 if (!is.null(listArguments[["sampleMetadataOutput"]])){
-  sampleMetadataOutput = listArguments[["sampleMetadataOutput"]]; listArguments[["sampleMetadataOutput"]]=NULL
+    sampleMetadataOutput = listArguments[["sampleMetadataOutput"]]; listArguments[["sampleMetadataOutput"]]=NULL
 }
 variableMetadataOutput = "variableMetadata.tsv"
 if (!is.null(listArguments[["variableMetadataOutput"]])){
@@ -99,67 +99,14 @@
     bicspdf = listArguments[["bicspdf"]]; listArguments[["bicspdf"]]=NULL
 }
 
-#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[["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("xcmsSet","retcor","fillPeaks"))  {
-    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)
-            }
-
-            file.symlink(singlefile_galaxyPath,singlefile_sampleName)
-        }
-        directory = "."
-
-        md5sumList=list("origin"=getMd5sum(directory))
-
-    }
-    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")
-
-        md5sumList=list("origin"=getMd5sum(directory))
-    }
+    rawFilePath = getRawfilePathFromArguments(listArguments)
+    zipfile = rawFilePath$zipfile
+    singlefile = rawFilePath$singlefile
+    listArguments = rawFilePath$listArguments
+    directory = retrieveRawfileInTheWorkingDirectory(singlefile, zipfile)
+    md5sumList=list("origin"=getMd5sum(directory))
 }
 
 #addition of the directory to the list of arguments in the first position
@@ -223,8 +170,8 @@
 
     #transform the files absolute pathways into relative pathways
     xset@filepaths<-sub(paste(getwd(),"/",sep="") ,"", xset@filepaths)
-
-    if(exists("zipfile") && (zipfile!="")) {
+    print(zipfile)
+    if(exists("zipfile") && !is.null(zipfile) && (zipfile!="")) {
 
         #Modify the samples names (erase the path)
         for(i in 1:length(sampnames(xset))){