annotate matchms_metadata_merge.xml @ 0:107186a6fcec draft

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
author recetox
date Thu, 23 Nov 2023 09:56:32 +0000
parents
children 8e18dcf410ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
1 <tool id="matchms_metadata_merge" name="matchms metadata merge" version="@TOOL_VERSION@+galaxy0" profile="21.09">
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
2 <description>Merge metadata csv into MSP by a specified column</description>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
3
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
4 <macros>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
5 <import>macros.xml</import>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
6 <import>help.xml</import>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
7 </macros>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
8
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
9 <expand macro="creator"/>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
10
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
11 <edam_operations>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
12 <edam_operation>operation_2409</edam_operation>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
13 </edam_operations>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
14 <expand macro="bio.tools"/>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
15
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
16 <requirements>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
17 <requirement type="package" version="@TOOL_VERSION@">matchms</requirement>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
18 </requirements>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
19
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
20 <command detect_errors='aggressive'><![CDATA[
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
21 python '${matchms_python_cli}'
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
22 ]]></command>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
23
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
24 <configfiles>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
25 <configfile name="matchms_python_cli">
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
26 import pandas
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
27 import matchms
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
28 import numpy as np
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
29
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
30 matchms.set_matchms_logger_level('ERROR')
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
31 matchms.Metadata.set_key_replacements({})
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
32
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
33 spectra = list(matchms.importing.load_from_msp('${spectral_library}', False))
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
34
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
35 metadata_table = pandas.read_csv('${metadata_table_file}', dtype=object)
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
36 metadata_table.columns = map(str.lower, metadata_table.columns)
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
37
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
38 metadata_table.drop_duplicates(subset='${user_specified_column}'.lower(), inplace=True)
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
39
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
40 spectra_metadata= pandas.DataFrame.from_dict([x.metadata for x in spectra])
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
41 spectra_metadata.dropna(axis=1, inplace=True)
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
42
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
43 merged = metadata_table.merge(spectra_metadata, on='${user_specified_column}'.lower(), how='right')
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
44
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
45 spectra_arr = np.asarray(spectra, dtype=object)
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
46
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
47 def update_metadata(spectrum: matchms.Spectrum, row):
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
48 metadata = spectrum.metadata
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
49 metadata.update(row)
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
50 spectrum.metadata = metadata
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
51 return spectrum
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
52
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
53 vec_update_metadata = np.vectorize(update_metadata)
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
54 merged_array = vec_update_metadata(spectra_arr, merged.to_dict(orient='records'))
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
55
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
56 matchms.exporting.save_as_msp(merged_array.tolist(), '${output}')
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
57 </configfile>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
58 </configfiles>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
59
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
60 <inputs>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
61 <param label="Spectra file" name="spectral_library" type="data" format="msp"
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
62 help="Mass spectral library file." />
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
63 <param label="Metadata csv file" name="metadata_table_file" type="data" format="csv"
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
64 help="csv file containing the metadata." />
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
65
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
66 <param label="specify column/metadata key" name="user_specified_column" type="text" value="compound_name" help="Name of the user specified column to merge the data on." />
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
67 </inputs>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
68
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
69 <outputs>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
70 <data label="${tool.name} on ${on_string}" name="output" format="msp">
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
71 </data>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
72 </outputs>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
73
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
74 <tests>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
75 <test>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
76 <param name="spectral_library" value="metadata_merge/input.msp" ftype="msp"/>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
77 <param name="metadata_table_file" value="metadata_merge/metadata.csv" ftype="csv"/>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
78 <param name="user_specified_column" value="name"/>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
79 <output name="output" file="metadata_merge/output.msp" ftype="msp"/>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
80 </test>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
81 </tests>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
82
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
83 <help>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
84 **Description**
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
85 The tool takes an msp file and a metadata csv file and merges the metadata in the csv
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
86 file with the metadata in the MSP file on a user specified column.
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
87 </help>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
88
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
89 <citations>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
90 <citation type="doi">https://doi.org/10.5281/zenodo.8083373</citation>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
91 </citations>
107186a6fcec planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f5f5a8eff32c9b5de792dce99bc3c63dc971e82c
recetox
parents:
diff changeset
92 </tool>