<tool id="create_sqlite_db" name="create_sqlite_db" version="0.0.4">
    <description>
        Create SQLite database of an XCMS-CAMERA dataset
    </description>


    <macros>
        <import>macros.xml</import>
    </macros>

    <expand macro="requirements">
      
    </expand>


 <stdio>
        <exit_code range="1:" />
    </stdio>
    <command interpreter="Rscript"><![CDATA[
        create_sqlite_db.R
            --out_dir=.
            --xset_xa=$xset_xa
	    --pa=$pa
            --xcms_camera_option=$camera_xcms
            --cores=\${GALAXY_SLOTS:-4}
            #if $file_load_conditional.file_load_select=="yes"
                --mzML_files='
                #for $i in $file_load_conditional.input
                    $i,
                #end for
                '
                --galaxy_names='
                #for $i in $file_load_conditional.input
                    $i.name,
                #end for
                '
            #end if

            #if $eic
                --eic
            #end if
            #if $raw_rt_columns
                --raw_rt_columns
            #end if
            #if $grp_peaklist_opt.grp_peaklist_opt=="yes"
                --grp_peaklist=$grp_peaklist
            #end if

    ]]></command>
    <inputs>


        <param type="data" name="xset_xa" label="xcmsSet or CAMERA object"
               help="Either xcmsSet object saved as 'xset' or CAMERA 'xa' object in an RData file. Please
                     specify which to use below" format="rdata.xcms.raw,rdata.xcms.group,rdata.xcms.retcor,rdata.xcms.fillpeaks,rdata.camera.quick,rdata.camera.positive,rdata.camera.negative,rdata"/>
        <expand macro="camera_xcms" />

        <param type="data" name="pa" label="purityA object" format="rdata"
               help="purityA object saved as 'pa' in a RData file (output from assess_purity_msms)"/>

	<param name="eic" type="boolean" label="Include EIC data?"
               help="The Extracted Ion Chromatogram can be calculated for each peak and stored in
                     the database. Note, this will take considerable time for large datasets and
                     the resulting SQLite database can be large"/>
	
	<param name="raw_rt_columns" type="boolean" label="Use user defined Raw RT columns?"
               help="Only use if the track_rt_raw tool has been used"/>


        <expand macro="grp_peaklist" />


        <expand macro="fileload" />

    </inputs>
    <outputs>
        <data name="lcms_data_sqlite" format="sqlite" label="${tool.name} on ${on_string}: LC-MS(/MS) data SQLite db"
              from_work_dir="lcms_data.sqlite" />
        <data name="cpeakgroup_msms" format="tsv" label="${tool.name} on ${on_string}: c-peak-group-msms"
              from_work_dir="cpeakgroup_msms.tsv" />

    </outputs>
    <tests>
        <test>
            <conditional name="file_load_conditional">
                <param name="file_load_select" value="yes"/>
                <param name="input" >
                    <collection type="list">
                        <element name="LCMS_1.mzML" value="LCMS_1.mzML"/>
                        <element name="LCMS_2.mzML" value="LCMS_2.mzML"/>
                        <element name="LCMSMS_1.mzML" value="LCMSMS_1.mzML"/>
                        <element name="LCMSMS_2.mzML" value="LCMSMS_2.mzML"/>
                    </collection>
                </param>
            </conditional>
	    <param name="camera_xcms" value="xcms"/>
            <param name="xset_xa" value="LCMS_1_LCMS_2_LCMSMS_1_LCMSMS_2.xset.group.rdata"/>
            <param name="pa" value="frag4feature.rdata"/>
            <output name="cpeakgroup_msms" value="cpeakgroup_msms.tsv" >
                 
            </output>
        </test>
    </tests>
    
    <help><![CDATA[
=============================================================
Create SQLite database for LC-MS(/MS) dataset
=============================================================
Create an SQLite database for the msPurity and XCMS (CAMERA) outputs. The SQLite database created can 
be used as input to the spectral_matching tool. 

Please note that getting the extracted ion chromatograms can take a long time if the dataset has a large number of files and peaks.

-----------
Output
-----------
* lcms_sqlite: An SQLite database of the LC-MS(/MS) data (including fragmentation scans)
* cpeakgroup_msms: A csv file for all grouped features that have associated fragmentation spectra

    ]]></help>
<expand macro="citations" />
</tool>
