view matchms_convert.xml @ 21:9e83636da9d3 draft default tip

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 129488bfd91735fc55fe32edb1079c24eee7b2d3
author recetox
date Thu, 14 Nov 2024 15:12:29 +0000
parents c5ed6bfcd806
children
line wrap: on
line source

<tool id="matchms_convert" name="matchms convert" version="@TOOL_VERSION@+galaxy0" profile="21.05">
    <description>convert between mass spectral library formats (.mgf/.msp/.json) using matchms</description>
    
    <macros>
        <import>macros.xml</import>
        <import>help.xml</import>
    </macros>

    <expand macro="creator"/>

    <edam_operations>
        <edam_operation>operation_3434</edam_operation>
    </edam_operations>
    <expand macro="bio.tools"/>

    <requirements>
        <requirement type="package" version="@TOOL_VERSION@">matchms</requirement>
    </requirements>

    <command detect_errors='aggressive'><![CDATA[
        python ${matchms_python_cli}
        #if $output_file.output_format == "msp":
        #if $output_file.export_style == "ms_lima":
        &&
        sh ${ms_lima_output}
        #end if
        #end if
    ]]></command>

<configfiles>
<configfile name="matchms_python_cli">
@init_logger@

from matchms.importing import load_from_msp, load_from_mgf, load_from_json
from matchms.exporting import save_as_msp, save_as_mgf, save_as_json
spectra = list(load_from_${spectral_library.ext}("${spectral_library}", ${harmonization_metadata}))
#if $output_file.output_format == "msp"
#if $output_file.export_style == "ms_lima"
save_as_msp(spectra, "${converted_library}", write_peak_comments = ${output_file.export_peak_comments}, style = "riken")
#else
save_as_msp(spectra, "${converted_library}", write_peak_comments = ${output_file.export_peak_comments}, style = "${output_file.export_style}")
#end if
#else
save_as_${output_file.output_format}(spectra, "${converted_library}")
#end if
</configfile>
<configfile name="ms_lima_output">
sed -E "s,[[:space:]]+, ,g" ${converted_library} > ${converted_library}.tmp

grep -rl 'IONMODE' . | xargs sed '/IONMODE/d' ${converted_library}.tmp > ${converted_library}.tmp1
grep -rl 'CHARGE' . | xargs sed '/CHARGE/d' ${converted_library}.tmp1 > ${converted_library}.tmp2
grep -rl 'COMPOUND_NAME' . | xargs sed 's/COMPOUND_NAME/NAME/g' ${converted_library}.tmp2 > ${converted_library}.tmp3

mv ${converted_library}.tmp3 ${converted_library}
rm -f ${converted_library}.tmp1 ${converted_library}.tmp2 ${converted_library}.tmp3 ${converted_library}.tmp
</configfile>
</configfiles>

    <inputs>
        <param label="Spectra file" name="spectral_library" type="data" format="msp,mgf,json"
            help="Mass spectral library file to convert." />

        <param label="Harmonization metadata" name="harmonization_metadata" type="boolean" truevalue="True" falsevalue="False"
            checked="true"
            help="Apply metadata harmonization, parsing certain keys required by additional filters or initializing other attributes. The default is True." />

        <conditional name="output_file">
            <param label="Spectral library format" name="output_format" type="select"
                help="Output format to convert the spectral library into.">
                <option value="msp" selected="true">msp</option>
                <option value="mgf">mgf</option>
                <option value="json">json</option>
            </param>
            <when value="msp">
                <param label="Export peak comments" name="export_peak_comments" type="boolean"
                    truevalue="True" falsevalue="False" checked="true"
                    help="Retain peak comments from individual peaks after the respective mz and intensity pairs when selected." />
                <param label="Export style" name="export_style" type="select"
                    help="Converts the keys to a specific style - see [1] for details.. One of ['matchms', 'massbank', 'nist', 'riken', 'gnps']. Default is 'matchms'.">
                    <option value="matchms" selected="true">matchms</option>
                    <option value="massbank">massbank</option>
                    <option value="nist">nist</option>
                    <option value="riken">riken</option>
                    <option value="gnps">gnps</option>
                    <option value="ms_lima">ms-lima</option>
                </param>
            </when>
            <when value="mgf" />
            <when value="json" />
        </conditional>
    </inputs>

    <outputs>
        <data label="${tool.name} from ${spectral_library.ext} to ${output_file.output_format} on ${on_string}" name="converted_library" format="msp">
            <change_format>
                <when input="output_file.output_format" value="mgf" format="mgf" />
                <when input="output_file.output_format" value="json" format="json" />
            </change_format>
        </data>
    </outputs>

    <tests>
        <test>
            <param name="spectral_library" value="similarity/RECETOX_Exposome_pesticides_HR_MS_20220323.msp" ftype="msp"/>
            <param name="harmonization_metadata" value="False"/>
            <param name="output_format" value="mgf"/>
            <output name="converted_library" file="convert/mgf_out.mgf" ftype="mgf"/>
        </test>
        <test>
            <param name="spectral_library" value="similarity/RECETOX_Exposome_pesticides_HR_MS_20220323.msp" ftype="msp"/>
            <param name="harmonization_metadata" value="False"/>
            <param name="output_format" value="json"/>
            <output name="converted_library" file="convert/json_out.json" ftype="json"/>
        </test>
        <test>
            <param name="spectral_library" value="convert/mgf_out.mgf" ftype="mgf"/>
            <param name="harmonization_metadata" value="False"/>
            <param name="export_peak_comments" value="False"/>
            <param name="output_format" value="msp"/>
            <param name="export_style" value="matchms"/>
            <output name="converted_library" file="convert/msp_out.msp" ftype="msp"/>
        </test>
        <test>
            <param name="spectral_library" value="convert/mgf_out.mgf" ftype="mgf"/>
            <param name="harmonization_metadata" value="True"/>
            <param name="export_peak_comments" value="False"/>
            <param name="output_format" value="msp"/>
            <param name="export_style" value="matchms"/>
            <output name="converted_library" file="convert/harmonized_msp_out.msp" ftype="msp"/>
        </test>
        <test>
            <param name="spectral_library" value="convert/mgf_out.mgf" ftype="mgf"/>
            <param name="harmonization_metadata" value="True"/>
            <param name="export_peak_comments" value="True"/>
            <param name="output_format" value="msp"/>
            <param name="export_style" value="matchms"/>
            <output name="converted_library" file="convert/harmonized_msp_peakcomments_out.msp" ftype="msp"/>
        </test>
        <test>
            <param name="spectral_library" value="convert/mgf_out.mgf" ftype="mgf"/>
            <param name="harmonization_metadata" value="True"/>
            <param name="export_peak_comments" value="False"/>
            <param name="output_format" value="msp"/>
            <param name="export_style" value="ms_lima"/>
            <output name="converted_library" file="convert/ms_lima_output.msp" ftype="msp"/>
        </test>
    </tests>


    <help><![CDATA[
        Description
            Mass spectral libraries are often stored in various formats, such as `msp`, `mgf` or `json`.
            This tool can be used to convert from one library format to another.
            Some of the metadata keywords might change during the conversion process, as they are harmonized internally with matchms.

            .. rubric:: **Footnotes**
            .. [1] Export styles - see this `table <https://github.com/matchms/matchms/blob/master/matchms/data/export_key_conversions.csv>`_ for supported key conversions and detailed description of the export styles.

            @HELP_matchms@
    ]]></help>


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