view matchms_formatter.xml @ 31:a5a5b147da70 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:08:43 +0000
parents 8bd942dcf1ad
children
line wrap: on
line source

<tool id="matchms_formatter" name="matchms scores formatter" version="@TOOL_VERSION@+galaxy0" profile="21.09">
    <description>reformat scores object of matchms to long format table</description>

    <macros>
        <import>macros.xml</import>
        <import>help.xml</import>
    </macros>
    <expand macro="creator"/>
    <edam_operations>
        <edam_operation>operation_0335</edam_operation>
    </edam_operations>
    <expand macro="bio.tools"/>

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

    <command detect_errors="aggressive"><![CDATA[
        python3 '${formatter}'
    ]]></command>
    
    <environment_variables>
        <environment_variable name="MPLCONFIGDIR">\$_GALAXY_JOB_TMP_DIR</environment_variable>
        <environment_variable name="XDG_CACHE_HOME">\$_GALAXY_JOB_TMP_DIR</environment_variable>
        <environment_variable name="OPENBLAS_NUM_THREADS">4</environment_variable>
        <environment_variable name="RLIMIT_NPROC">4</environment_variable>        
    </environment_variables>

    <configfiles>
        <configfile name="formatter">
from matchms.importing import scores_from_json
from pandas import DataFrame

scores = scores_from_json('$scores')
data = []

for i, (row, col) in enumerate(zip(scores.scores.row, scores.scores.col)):
        data.append([scores.queries[col].metadata['$key'], scores.references[row].metadata['$key'], *scores.scores.data[i]])

result = DataFrame(data, columns=['query', 'reference', *scores.scores.score_names])

result.to_csv('$output', sep="\t", index=False)

        </configfile>
    </configfiles>

    <inputs>
        <param label="Scores object" name="scores" type="data" format="json" help="matchms Scores json file." />
        <param label="Key" name="key" type="text" value="compound_name" help="Name of the key to use. Default is 'compound_name'." />
    </inputs>
    <outputs>
        <data label="${tool.name} on ${on_string}" name="output" format="tsv"/>
    </outputs>

    <tests>
        <test>
            <param name="scores" value="formatter/fill2_trunc_scores_with_metadata_match.json" ftype="json"/>
            <param name="key" value="compound_name"/>
            <output name="output" value="formatter/fill2_formatted.tsv" ftype="tsv"
                checksum="md5$4f0d83da381b8a403d807d26a9dd0f34"/>
        </test>
        <test>
            <param name="scores" value="similarity/scores_test4_out.json" ftype="json"/>
            <param name="key" value="compound_name"/>
            <output name="output" file="formatter/test4_formatted.tsv" ftype="tsv"/>
        </test>
    </tests>

    <help>
        @HELP_formatter@
        @HELP_matchms@
    </help>

    <citations>
        <citation type="doi">https://doi.org/10.5281/zenodo.6035335</citation>
    </citations>
</tool>