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