Mercurial > repos > recetox > matchms_subsetting
comparison matchms_subsetting.xml @ 0:2b61ec493df6 draft
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit a0565620150b69e0ca87aa686709c25356436f71
author | recetox |
---|---|
date | Wed, 22 Nov 2023 14:44:19 +0000 |
parents | |
children | d2996f624507 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2b61ec493df6 |
---|---|
1 <tool id="matchms_subsetting" name="matchms subsetting" version="@TOOL_VERSION@+galaxy0" profile="21.09"> | |
2 <description>Extract spectra from a library given unique metadata identifier</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 if "$list_of_identifiers.ext" == "csv": | |
36 identifiers_table = pandas.read_csv('${list_of_identifiers}', dtype=object) | |
37 else: | |
38 identifiers_table = pandas.read_csv('${list_of_identifiers}', dtype=object, sep='\t') | |
39 | |
40 identifiers_table.columns = map(str.lower, identifiers_table.columns) | |
41 | |
42 spectra_arr = np.asarray(spectra, dtype=object) | |
43 | |
44 def filter_spectra(spectra, identifiers, mode): | |
45 identifier_column = identifiers.columns[0] | |
46 | |
47 indices = [] | |
48 for i, spectrum in enumerate(spectra): | |
49 if spectrum.get(identifier_column) in identifiers.values: | |
50 indices.append(i) | |
51 | |
52 if mode == "include": | |
53 spectra_filtered = spectra[indices] | |
54 else: | |
55 spectra_filtered = np.delete(spectra, indices) | |
56 | |
57 return spectra_filtered | |
58 | |
59 filtered_spectra = filter_spectra(spectra_arr, identifiers_table, "${mode}") | |
60 | |
61 matchms.exporting.save_as_msp(filtered_spectra.tolist(), '${output}') | |
62 </configfile> | |
63 </configfiles> | |
64 | |
65 <inputs> | |
66 <param label="Spectra file" name="spectral_library" type="data" format="msp" | |
67 help="Mass spectral library file." /> | |
68 <param label="Select mode" name="mode" type="select" | |
69 help="Include/Exclude the spectra matching the identifiers in the file. The default is include."> | |
70 <option value="include" selected="true">include</option> | |
71 <option value="exclude">exclude</option> | |
72 </param> | |
73 <param label="list of identifiers" name="list_of_identifiers" type="data" format="csv,tsv,tabular" | |
74 help="file containing list of identifiers in tsv or csv." /> | |
75 | |
76 </inputs> | |
77 | |
78 <outputs> | |
79 <data label="${tool.name} on ${on_string}" name="output" format="msp"> | |
80 </data> | |
81 </outputs> | |
82 | |
83 <tests> | |
84 <test> | |
85 <param name="spectral_library" value="out_matchms_add_key.msp" ftype="msp"/> | |
86 <param name="mode" value="include"/> | |
87 <param name="list_of_identifiers" value="subsetting/identifier.csv" ftype="csv"/> | |
88 <output name="output" file="subsetting/subsetting_output.msp" ftype="msp"/> | |
89 </test> | |
90 <test> | |
91 <param name="spectral_library" value="out_matchms_add_key.msp" ftype="msp"/> | |
92 <param name="mode" value="exclude"/> | |
93 <param name="list_of_identifiers" value="subsetting/identifier.csv" ftype="csv"/> | |
94 <output name="output" file="subsetting/subsetting_output2.msp" ftype="msp"/> | |
95 </test> | |
96 </tests> | |
97 | |
98 <help> | |
99 **Description** | |
100 The tool takes an msp file and a csv/tsv file containing list of identifier and | |
101 extract spectra from a library based on the provided list of identifiers. | |
102 </help> | |
103 | |
104 <citations> | |
105 <citation type="doi">https://doi.org/10.5281/zenodo.8083373</citation> | |
106 </citations> | |
107 </tool> |