<tool id="Preprocess_DataSet" name="Preprocess MicroArrays DataSets" version="15">
    <description> Preprocessing microarrays datasets.Contains Background Correction, Normalization within arrays, between arrays (depending on the number of channels) and summarization. </description>  
    <macros>
        <import>citations.xml</import>
    </macros>  
    <requirements>
    	<requirement type="package">r-biocmanager</requirement>
		<requirement type="package">pandoc</requirement>
        <requirement type="package">r-base</requirement>
        <requirement type="package">r-batch</requirement>
        <requirement type="package">bioconductor-affyplm</requirement>
        <requirement type="package">bioconductor-affy</requirement>
        <requirement type="package">bioconductor-annotate</requirement>
        <requirement type="package">r-knitr</requirement>
        <requirement type="package">bioconductor-marray</requirement>
        <requirement type="package">r-idpmisc</requirement>
        <requirement type="package">r-kernsmooth</requirement>
        <requirement type="package">r-rmarkdown</requirement>
        <requirement type="package">r-markdown</requirement>
        <requirement type="package">bioconductor-limma</requirement>
        <requirement type="package">r-idpmisc</requirement>
    </requirements>
    <stdio>
        <exit_code range="1:" level="fatal" />
    </stdio>   
    <command>
    <![CDATA[
    Rscript
        #if $technologies.technology == "Affymetrix":
            '$__tool_directory__/Affymetrix_Preprocessing.R' 
            thefunctions "AffymetrixPreprocessingFunction" 
            image $image 
            backgroundcorrection_method $technologies.BackgroundCorrectionA 
            normalization_method $technologies.NormalizationA
            summary_method $technologies.SummarizationA
        #elif $technologies.technology == "Agilent":
	    #if $technologies.channelsA.channelA == "one":
            	'$__tool_directory__/Agilent_One_Color_Preprocessing.R'       
	    	thefunction "AgilentOneColorPreprocessingFunction" 
            	image $image 
            	methodBC $technologies.channelsA.BackgroundCorrectionAG
            	methodNBA $technologies.channelsA.methodNBAAG
	    #else: 
                '$__tool_directory__/Agilent_Two_Colors_Preprocessing.R' 
                thefunction "AgilentTwoChannelsPreprocessingFunction" 
                image $image 
                methodBC $technologies.channelsA.BackgroundCorrectionAGT 
                methodNWA $technologies.channelsA.methodNWAAGT 
                methodNBA $technologies.channelsA.methodNBAAGT 
            #end if 
        #else:
            #if $technologies.channelsG.channelG == "one"
                '$__tool_directory__/GenePix_One_Color_Preprocessing.R' 
	    	thefunction "GenePixOneColorPreprocessingFunction" 
            	image $image 
            	methodBC $technologies.channelsG.BackgroundCorrectionG  
            	methodNBA $technologies.channelsG.methodNBAG
	    #else:
                '$__tool_directory__/GenePix_Two_Colors_Preprocessing.R' 
                thefunction "GenePixTwoChannelsPreprocessingFunction" 
                image $image 
                methodBC $technologies.channelsG.BackgroundCorrectionGT 
                methodNWA $technologies.channelsG.methodNWAGT
                methodNBA $technologies.channelsG.methodNBAGT 
            #end if 
        #end if
        w $w
        h $h
    ]]>
    </command> 
    <inputs>
        <param name="image" type="data" format="rdata" label="Project microarray as a binary rdata" help="Last output from tool read dataset." >
            <validator type="expression" message="Please select output dataset from read dataset tool ">'Read.Project'  in value.name</validator>
        </param>
        <conditional name="technologies">
            <param name="technology" type="select" label="Select the technology">
                <option value="Affymetrix" selected="true">Affymetrix</option>
          	<option value="Agilent">Agilent</option>
          	<option value="GenePix">GenePix</option>
            </param>
            <when value="Affymetrix">
                <param name="BackgroundCorrectionA" type="select" label="Background correction method.">
          	    <option value="mas" selected="true">Mas</option>
                    <option value="rma">Rma</option>
          	    <option value="none">None</option>
    	        </param>
                <param name="NormalizationA" type="select" label="Normalization method.">
          	    <option value="quantiles" selected="true">Quantiles</option>
                    <option value="quantiles.robust">Quantiles robust</option>
		    <option value="quantiles.probeset">Quantiles Probeset</option>
                    <option value="constant">Constant</option>
          	    <option value="contrasts">Contrasts</option>
                    <option value="invariantset">Invariantset</option>
                    <option value="loess">Loess</option>
          	    <option value="qspline">QSPline</option>
                    <option value="scaling">Scaling</option>
		    <option value="vsn">VSN</option>
    	       </param> 
               <param name="SummarizationA" type="select" label="Summarization method.">
          	    <option value="median.polish" selected="true">Median.polish</option>
                    <option value="tukey.biweight">Tukey.biweight</option>
                    <option value="average.log">Average.log</option>
          	    <option value="log.average">Log.average</option>
                    <option value="rlm">Rlm</option>
                    <option value="lm">Lm</option>
                    <option value="log.median">Log.median</option>
                    <option value="median.log">Median.log</option>
          	    <option value="log.2nd.largest">Log.2nd.largest</option>
               </param> 
            </when>
            <when value="Agilent">
                <conditional name="channelsA">
            	    <param name="channelA" type="select" label="Select the number of channels">
                        <option value="one" selected="true">One</option>
          	        <option value="two">Two</option>
            	    </param>
                <when value="one">
               	    <param name="BackgroundCorrectionAG" type="select" label="Background correction method.">
          	        <option value="auto" selected="true">Auto</option>
                    	<option value="none">None</option>
          	    	<option value="subtract">Subtract</option>
		    	<option value="half">Half</option>
                    	<option value="minimum">Minimum</option>
          	    	<option value="movingmin">MovingMin</option>
		    	<option value="edwards">Edwards</option>
          	    	<option value="normexp">NormExp</option>
    	       	    </param>
               	    <param name="methodNBAAG" type="select" label="Normalization between arrays.">
          	        <option value="scale" selected="true">Scale</option>
                    	<option value="quantile">Quantile</option>
                    	<option value="cyclicloess">CyclicLoess</option>
    	       	    </param> 
            	</when>
            	<when value="two">
               	    <param name="BackgroundCorrectionAGT" type="select" label="Background correction method.">
          	        <option value="auto" selected="true">Auto</option>
                    	<option value="none">None</option>
          	    	<option value="subtract">Subtract</option>
		    	<option value="half">Half</option>
                    	<option value="minimum">Minimum</option>
          	    	<option value="movingmin">MovingMin</option>
		    	<option value="edwards">Edwards</option>
          	    	<option value="normexp">NormExp</option>
    	            </param>
               	    <param name="methodNWAAGT" type="select" label="Normalization within arrays.">
          	        <option value="median" selected="true">Median</option>
                    	<option value="loess">Loess</option>
                    	<option value="printtiploess">PrintTiploess</option>  
    	       	    </param> 
               	    <param name="methodNBAAGT" type="select" label="Normalization between arrays.">
          	        <option value="scale" selected="true">Scale</option>
                    	<option value="quantile">Quantile</option>
                    	<option value="Aquantile">AQuantile</option>  
                    	<option value="cyclicloess">CyclicLoess</option>
    	       	    </param> 
            	</when>
                </conditional>
            </when>
            <when value="GenePix">
                <conditional name="channelsG">
            	    <param name="channelG" type="select" label="Select the number of channels">
                        <option value="one" selected="true">One</option>
          		<option value="two">Two</option>
            	    </param>
            	    <when value="one">
               	        <param name="BackgroundCorrectionG" type="select" label="Background correction method.">
          	    	    <option value="auto" selected="true">Auto</option>
                    	    <option value="none">None</option>
          	    	    <option value="subtract">Subtract</option>
		    	    <option value="half">Half</option>
                    	    <option value="minimum">Minimum</option>
          	    	    <option value="movingmin">MovingMin</option>
		    	    <option value="edwards">Edwards</option>
          	    	    <option value="normexp">NormExp</option>
    	       		</param>
               		<param name="methodNBAG" type="select" label="Normalization between arrays.">
          	    		<!--<option value="scale" selected="true">Scale</option>-->
                    		<option value="quantile" selected="true">Quantile</option>
                                 <option value="scale">Scale</option>
                    		<option value="cyclicloess">CyclicLoess</option>
    	       		</param> 
            	    </when>
            	    <when value="two">
               	        <param name="BackgroundCorrectionGT" type="select" label="Background correction method.">
          	    	    <option value="auto" selected="true">Auto</option>
                    	    <option value="none">None</option>
          	    	    <option value="subtract">Subtract</option>
		    	    <option value="half">Half</option>
                    	    <option value="minimum">Minimum</option>
          	    	    <option value="movingmin">MovingMin</option>
		            <option value="edwards">Edwards</option>
          	    	    <option value="normexp">NormExp</option>
    	       		</param>
               		<param name="methodNWAGT" type="select" label="Normalization within arrays.">
          	    	    <option value="median" selected="true">Median</option>
                    	    <option value="loess">Loess</option>
                    	    <option value="printtiploess">PrintTiploess</option>  
    	       		</param> 
               		<param name="methodNBAGT" type="select" label="Normalization between arrays.">
          	    		<!--<option value="scale" >Scale</option>-->
                    	    <option value="quantile" selected="true">Quantile</option>
                            <option value="scale">Scale</option>
                            <option value="cyclicloess">CyclicLoess</option>
                    	    <option value="Aquantile">AQuantile</option>  
    	       		</param> 
            	    </when>
                </conditional>
            </when>
        </conditional>
        <param name="w" type="integer" value="1024" label="Plot's width" />
        <param name="h" type="integer" value="1024" label="Plot's height" />
    </inputs>
    <outputs>
        <data name="ProcessDataSetRData" format="rdata" from_work_dir="MicroArray.Preprocessing.RData" label="Preprocess.Project.Data.RData" />
        <data name="Matrix.Data" format="tabular" from_work_dir="Matrix.Data.tsv" label="Matrix.Data.tsv" />
        <data name="Preprocessing.Plots" format="html" from_work_dir="PreprocessingPlots.html" label="Preprocessing.Plots.html" />   
    </outputs>
     <tests>
        <test>
            <param name="image" ftype="rdata" value="Read.Project.Data.RData" />  
            <param name="technologies|technology" value="GenePix"/>
            <param name="technologies|channelsG|channelG" value="two"/>
            <param name="technologies|channelsG|BackgroundCorrectionGT" value="auto"/>
            <param name="technologies|channelsG|methodNWAGT" value="median"/>
            <param name="technologies|channelsG|methodNBAGT" value="quantile"/>
            <output name="ProcessDataSetRData"  ftype="rdata" file="Preprocess.Project.Data.RData" compare="sim_size" >
            </output>
            <output name="Matrix.Data"  ftype="tabular" file="Matrix.Data.tsv" >
            </output>
            <output name="Preprocessing.Plots"  ftype="html" file="Preprocessing.Plots.html" compare="sim_size">
            </output>
        </test>
    </tests>
    <help>
		
.. class:: infomark

**Authors**  T.Bensellak, B.Ettetuani.

---------------------------------------------------

==================================
Preprocessing Microarray DataSet
==================================

-----------
Description
-----------

This tool is used as first phase of the global workflow, the preprocessing .

-----------------
Workflow position
-----------------

**Upstream tools**

+-------------------------------+------------------------------+---------+
| Name                          | output file                  |format   |
+===============================+==============================+=========+
| Read.DataSet.Microarray       |  MicroArrayObject.RData      | Rdat    |			
+-------------------------------+------------------------------+---------+


**Downstream tools**

+-----------------------------------------------+----------------------------------------------+---------+
| Name                                          | Output file                                  | Format  |
+===============================================+==============================================+=========+
|Tests and Selection                            | Test.results.tsv                             | Tabular |
+-----------------------------------------------+----------------------------------------------+---------+

-----------
Input files
-----------

+---------------------------+------------+
| Parameter : num + label   |   Format   |
+===========================+============+
| Image                     |   Rdata    |
+---------------------------+------------+
| Methods parmeters         |   Numeric  |
+---------------------------+------------+

------------
Output files
------------

**Microarray.Preprocessing.RData**

**Matrix.Data.tsv**

------------------------------
General schema of the workflow
------------------------------

https://bensellak.github.io/microarrays-galaxy/workflow.png


   </help>
   <expand macro="R_citation">
   </expand>
</tool>
