<tool id="create_msp" name="Create MSP Files from msPurity" version="0.1.3">
    <description> </description>
     <macros>
        <import>macros.xml</import>
    </macros>
    <expand macro="requirements">
    </expand>


    <command interpreter="Rscript" ><![CDATA[
	create_msp.R
	--purity "$purity"
	--mode "$mode"
	--ppm "$ppm"
    ]]></command>
    <inputs>
        <param name="purity" type="data" format="rdata" label="msPurity frag4feature dataset" argument="--purity"/>
        <param name="mode" type="select" label="Spectra use mode (if precursor was fragmented in >1 scans)" help='WARNING: The averaging and max options are still being developed and will likely fail' argument="--mode">
            <option value="max" >Max Intensity</option>
            <option value="average">Weighted Average</option>
            <option value="all" selected="true">All</option>
        </param>
        <param name="ppm" optional="true" type="float" label="Allowed mass deviation between fragment MZs for spectra averaging (in ppm)" argument="--ppm"/>
    </inputs>
    <outputs>
        <data name="output" format="txt" label="log" />
        <data name="msp_out" format="msp" from_work_dir="outfile.msp" label="${purity.name} MSP file"/>
    </outputs>
    <tests>
        <test>
            <param name="mode" value="all"/>
            <param name="purity" value="lightpurity.RData"/>
            <output name="msp_out" file="input.msp"/>
        </test>
      
    </tests>
	<help><![CDATA[
------------------------------
Create MSP Files from msPurity
------------------------------

* TO-DO: Averaging functionality
* TO-DO: Add citation for MSP
* TO-DO: Add PRECURSORTYPE if adducts available
* TO-DO: Create MSP from xcms/mzml files

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

| This tool will extract the MSMS spectra data from an msPurity-frag4feature object into a file with MSP data format.
| Linking each precursor with its corresponding fragmentation spectra and associating the index within the msPurity object as the name UID.
| Currently, there are three different methods for extracting the data in case that more than one MSMS scan was acquired for the same precursor m/z. See Parameters.

Parameters
----------

**\1. msPurity frag4feature dataset** 

Result object from msPurity purityA-frag4feature functions.

**\2. Spectra use mode (if precursor was fragmented in >1 scans)**

* "Max Intensity" will only use the scan where the precursor m/z signal was maximal.

* "Weighted Average" will merge all the scans, group fragment m/z using a PPM deviation (see 3.) and weight the intensities based on the precursor intensity of that scan. 

* "All" will generate a single entry in the MSP file for each MSMS scan independently.  

**\3. PPM deviation for fragmentation spectra averaging**

Set the value only if you selected "Weighted Average" above, the PPM value is used to define the limits for m/z grouping into a single fragment. 
The weighting is based on the precursor intensity, meaning that the more intense the precursor signal was, the more intensity will its fragments contribute to the averaged spectra.

		
Developers and contributors
---------------------------

- **Jordi Capellades (j.capellades.to@gmail.com) - Universitat Rovira i Virgili (SP)**
- **Ralf Weber (r.j.weber@bham.ac.uk) - University of Birmingham (UK)**

	]]></help>

<expand macro="citations" >
       <citation type="doi">10.1186/s13321-016-0115-9</citation>
</expand>
  
</tool>
