changeset 24:d8915395681f draft

planemo upload for repository https://github.com/workflow4metabolomics/xcms commit 87dc789d7cd70a3733a1ad0b5a427f4d5905795d
author lecorguille
date Wed, 01 Mar 2017 16:56:01 -0500
parents 329cfa3d2be6
children dc4d3e2b9968
files abims_xcms_xcmsSet.xml lib.r macros.xml xcms.r
diffstat 4 files changed, 146 insertions(+), 122 deletions(-) [+]
line wrap: on
line diff
--- a/abims_xcms_xcmsSet.xml	Fri Feb 10 11:01:21 2017 -0500
+++ b/abims_xcms_xcmsSet.xml	Wed Mar 01 16:56:01 2017 -0500
@@ -11,10 +11,10 @@
     <command><![CDATA[
         @COMMAND_XCMS_SCRIPT@
 
-        #if $inputs.input == "zip_file":
-            zipfile '$inputs.zip_file'
-        #elif $inputs.input == "single_file":
-            singlefile_galaxyPath '$inputs.single_file' singlefile_sampleName '$inputs.single_file.name'
+        #if $input.is_of_type("mzxml") or $input.is_of_type("mzml") or $input.is_of_type("mzdata") or $input.is_of_type("netcdf"):
+            singlefile_galaxyPath '$input' singlefile_sampleName '$input.name'
+        #else
+            zipfile '$input'
         #end if
 
         xfunction xcmsSet
@@ -65,18 +65,7 @@
 
     <inputs>
 
-      <conditional name="inputs">
-            <param name="input" type="select" label="Choose your inputs method" >
-                <option value="zip_file" selected="true">Zip file from your history containing your chromatograms</option>
-                <option value="single_file">mzXML file from your history</option>
-            </param>
-            <when value="zip_file">
-                <param name="zip_file" type="data" format="no_unzip.zip,zip" label="Zip file" />
-            </when>
-            <when value="single_file">
-                <param name="single_file" type="data" format="mzxml,netcdf" label="Single file" />
-            </when>
-        </conditional>
+        <param name="input" type="data" format="mzxml,mzml,mzdata,netcdf,no_unzip.zip,zip" label="File(s) from your history containing your chromatograms" help="Single file mode for the format: mzxml, mzml, mzdata and netcdf. Zip file mode for the format: no_unzip.zip, zip. See the help section below." />
 
         <conditional name="options_scanrange">
             <param name="option" type="select" label="Scan range option " >
@@ -221,8 +210,7 @@
             </output>
         </test>-->
         <test>
-            <param name="inputs|input" value="zip_file" />
-            <param name="inputs|zip_file" value="faahKO_reduce.zip"  ftype="zip" />
+            <param name="input" value="faahKO_reduce.zip"  ftype="zip" />
             <param name="methods|method" value="centWave" />
             <param name="methods|ppm" value="25" />
             <param name="methods|peakwidth" value="20,50" />
@@ -307,8 +295,7 @@
             </output>
         </test>-->
         <test>
-            <param name="inputs|input" value="single_file" />
-            <param name="inputs|single_file" value="HU_neg_017.mzXML"  ftype="mzxml" />
+            <param name="input" value="HU_neg_017.mzXML"  ftype="mzxml" />
             <param name="methods|method" value="centWave" />
             <param name="methods|ppm" value="25" />
             <param name="methods|peakwidth" value="20,50" />
@@ -324,8 +311,7 @@
             </output>
         </test>
         <test>
-            <param name="inputs|input" value="single_file" />
-            <param name="inputs|single_file" value="MM14.mzML"  ftype="mzxml" />
+            <param name="input" value="MM14.mzML"  ftype="mzxml" />
             <param name="methods|method" value="centWave" />
             <param name="methods|ppm" value="56" />
             <param name="methods|peakwidth" value="5.275,13.5" />
@@ -405,20 +391,20 @@
 Input files
 -----------
 
-+---------------------------+--------------------+
-| Parameter : num + label   |   Format           |
-+===========================+====================+
-| OR : Zip file             |   zip              |
-+---------------------------+--------------------+
-| OR : Single file          |   mzXML, netCDF    |
-+---------------------------+--------------------+
++---------------------------+----------------------------------+
+| Parameter : num + label   |   Format                         |
++===========================+==================================+
+| OR : Zip file             |   zip                            |
++---------------------------+----------------------------------+
+| OR : Single file          |   mzXML, mzML, mzData, netCDF    |
++---------------------------+----------------------------------+
 
 **Choose your inputs**
 
 You have two methods for your inputs:
 
-    | Zip file (recommended): You can put a zip file containing your inputs: myinputs.zip (containing all your conditions as sub-directories).
-    | Single file: You can put a single file as input. That way, you will be able to launch several xcmsSet in parallel and use "xcms.xcmsSet Merger" before "xcms.group"
+    | Single file (recommended): You can put a single file as input. That way, you will be able to launch several xcmsSet in parallel and use "xcms.xcmsSet Merger" before "xcms.group"
+    | Zip file: You can put a zip file containing your inputs: myinputs.zip (containing all your conditions as sub-directories).
 
 Zip file: Steps for creating the zip file
 -----------------------------------------
--- a/lib.r	Fri Feb 10 11:01:21 2017 -0500
+++ b/lib.r	Wed Mar 01 16:56:01 2017 -0500
@@ -473,3 +473,85 @@
 
     return(as.matrix(md5sum(files)))
 }
+
+
+# This function get the raw file path from the arguments
+getRawfilePathFromArguments <- function(listArguments) {
+    zipfile = NULL
+    singlefile = NULL
+    if (!is.null(listArguments[["zipfile"]]))           zipfile = listArguments[["zipfile"]]
+    if (!is.null(listArguments[["zipfilePositive"]]))   zipfile = listArguments[["zipfilePositive"]]
+    if (!is.null(listArguments[["zipfileNegative"]]))   zipfile = listArguments[["zipfileNegative"]]
+
+    if (!is.null(listArguments[["singlefile_galaxyPath"]])) {
+        singlefile_galaxyPaths = listArguments[["singlefile_galaxyPath"]];
+        singlefile_sampleNames = listArguments[["singlefile_sampleName"]]
+    }
+    if (!is.null(listArguments[["singlefile_galaxyPathPositive"]])) {
+        singlefile_galaxyPaths = listArguments[["singlefile_galaxyPathPositive"]];
+        singlefile_sampleNames = listArguments[["singlefile_sampleNamePositive"]]
+    }
+    if (!is.null(listArguments[["singlefile_galaxyPathNegative"]])) {
+        singlefile_galaxyPaths = listArguments[["singlefile_galaxyPathNegative"]];
+        singlefile_sampleNames = listArguments[["singlefile_sampleNameNegative"]]
+    }
+    if (exists("singlefile_galaxyPaths")){
+        singlefile_galaxyPaths = unlist(strsplit(singlefile_galaxyPaths,","))
+        singlefile_sampleNames = unlist(strsplit(singlefile_sampleNames,","))
+
+        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
+        }
+    }
+    for (argument in c("zipfile","zipfilePositive","zipfileNegative","singlefile_galaxyPath","singlefile_sampleName","singlefile_galaxyPathPositive","singlefile_sampleNamePositive","singlefile_galaxyPathNegative","singlefile_sampleNameNegative")) {
+        listArguments[[argument]]=NULL
+    }
+    return(list(zipfile=zipfile, singlefile=singlefile, listArguments=listArguments))
+}
+
+
+# This function retrieve the raw file in the working directory
+#   - if zipfile: unzip the file with its directory tree
+#   - if singlefiles: set symlink with the good filename
+retrieveRawfileInTheWorkingDirectory <- function(singlefile, zipfile) {
+    if(!is.null(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 = "."
+
+    }
+    if(!is.null(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")
+
+    }
+    return (directory)
+}
--- a/macros.xml	Fri Feb 10 11:01:21 2017 -0500
+++ b/macros.xml	Wed Mar 01 16:56:01 2017 -0500
@@ -33,41 +33,50 @@
     <!-- zipfile load for planemo test -->
 
     <token name="@COMMAND_FILE_LOAD@">
-        #if $file_load_conditional.file_load_select == "yes":
-            #if $file_load_conditional.inputs.input == "zip_file":
-                zipfile '$file_load_conditional.inputs.zip_file'
-            #else
-                #set singlefile_galaxyPath = ','.join( [ str( $single_file ) for $single_file in $file_load_conditional.inputs.single_file ] )
-                #set singlefile_sampleName = ','.join( [ str( $single_file.name ) for $single_file in $file_load_conditional.inputs.single_file ] )
+        #if $file_load_section.file_load_conditional.file_load_select == "yes":
+            #if $file_load_section.file_load_conditional.input[0].is_of_type("mzxml") or $file_load_section.file_load_conditional.input[0].is_of_type("mzml") or $file_load_section.file_load_conditional.input[0].is_of_type("mzdata") or $file_load_section.file_load_conditional.input[0].is_of_type("netcdf"):
+                #set singlefile_galaxyPath = ','.join( [ str( $single_file ) for $single_file in $file_load_section.file_load_conditional.input ] )
+                #set singlefile_sampleName = ','.join( [ str( $single_file.name ) for $single_file in $file_load_section.file_load_conditional.input ] )
 
                 singlefile_galaxyPath '$singlefile_galaxyPath' singlefile_sampleName '$singlefile_sampleName'
+            #else
+                zipfile '$file_load_section.file_load_conditional.input'
             #end if
         #end if
     </token>
 
-    <xml name="file_load">
-        <conditional name="file_load_conditional">
-            <param name="file_load_select" type="select" label="Resubmit your dataset or your zip file" help="Use only if you get a message which say that your original dataset or zip file have been deleted on the server." >
-                <option value="no" >no need</option>
-                <option value="yes" >yes</option>
-            </param>
-            <when value="no">
-            </when>
-            <when value="yes">
-                <conditional name="inputs">
-                    <param name="input" type="select" label="Choose your inputs method" >
-                        <option value="zip_file" selected="true">Zip file from your history containing your chromatograms</option>
-                        <option value="single_file">A mzXML or netCDF file from your history</option>
-                    </param>
-                    <when value="zip_file">
-                        <param name="zip_file" type="data" format="no_unzip.zip,zip" label="Zip file" />
-                    </when>
-                    <when value="single_file">
-                        <param name="single_file" type="data" format="mzxml,netcdf" label="Single file"  multiple="true"/>
-                    </when>
-                </conditional>
-            </when>
-        </conditional>
+    <xml name="input_file_load">
+        <section name="file_load_section" title="Resubmit your raw dataset or your zip file">
+            <conditional name="file_load_conditional">
+                <param name="file_load_select" type="select" label="Resubmit your dataset or your zip file" help="Use only if you get a message which say that your original dataset or zip file have been deleted on the server." >
+                    <option value="no" >no need</option>
+                    <option value="yes" >yes</option>
+                </param>
+                <when value="no">
+                </when>
+                <when value="yes">
+                    <param name="input" type="data" format="mzxml,mzml,mzdata,netcdf,no_unzip.zip,zip" multiple="true" label="File(s) from your history containing your chromatograms" help="Single file mode for the format: mzxml, mzml, mzdata and netcdf. Zip file mode for the format: no_unzip.zip, zip. See the help section below." />
+                </when>
+            </conditional>
+        </section>
+    </xml>
+
+    <xml name="test_file_load_zip">
+        <section name="file_load_section">
+            <conditional name="file_load_conditional">
+                <param name="file_load_select" value="yes" />
+                <param name="input" value="faahKO_reduce.zip" ftype="zip" />
+            </conditional>
+        </section>
+    </xml>
+
+    <xml name="test_file_load_single">
+        <section name="file_load_section">
+            <conditional name="file_load_conditional">
+                <param name="file_load_select" value="yes" />
+                <param name="input" value="wt15.CDF,ko16.CDF,ko15.CDF,wt16.CDF" ftype="netcdf" />
+            </conditional>
+        </section>
     </xml>
 
     <token name="@COMMAND_PEAKLIST@">
--- a/xcms.r	Fri Feb 10 11:01:21 2017 -0500
+++ b/xcms.r	Wed Mar 01 16:56:01 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))){