Mercurial > repos > recetox > matchms_remove_spectra
comparison matchms_remove_spectra.xml @ 0:80df426e7e47 draft
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 113433b8b9790405c2c5d054aee4a29a21b77dc7
author | recetox |
---|---|
date | Thu, 30 May 2024 18:07:29 +0000 |
parents | |
children | c24ebd41dd53 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:80df426e7e47 |
---|---|
1 <tool id="matchms_remove_spectra" name="matchms remove spectra" version="@TOOL_VERSION@+galaxy0" profile="21.09"> | |
2 <description>Filters spectra based on metadata presence</description> | |
3 | |
4 <macros> | |
5 <import>macros.xml</import> | |
6 </macros> | |
7 | |
8 <expand macro="creator"/> | |
9 | |
10 <edam_operations> | |
11 <edam_operation>operation_3695</edam_operation> | |
12 </edam_operations> | |
13 | |
14 <expand macro="bio.tools"/> | |
15 | |
16 <requirements> | |
17 <requirement type="package" version="@TOOL_VERSION@">matchms</requirement> | |
18 </requirements> | |
19 <command detect_errors="exit_code"><![CDATA[ | |
20 python3 '${filter_spectra}' | |
21 ]]></command> | |
22 | |
23 <configfiles> | |
24 <configfile name="filter_spectra"> | |
25 from matchms.exporting import save_as_mgf, save_as_msp | |
26 from matchms.filtering.filter_utils.smile_inchi_inchikey_conversions import is_valid_inchi, is_valid_smiles, is_valid_inchikey | |
27 from matchms.filtering import require_compound_name, require_formula, require_precursor_mz, \ | |
28 require_retention_time, require_retention_index, require_valid_annotation | |
29 from matchms.importing import load_from_mgf, load_from_msp | |
30 | |
31 #set metadata_fields = str("', '").join([str($f) for $f in $metadata_fields]) | |
32 required_metadata = "$metadata_fields" | |
33 | |
34 if "$spectra.ext" == "msp": | |
35 spectra = list(load_from_msp("${spectra}")) | |
36 elif "$spectra.ext" == 'mgf': | |
37 spectra = list(load_from_mgf("${spectra}")) | |
38 else: | |
39 raise ValueError(f'File format {$spectra.ext} not supported for mass spectra file.') | |
40 | |
41 filtered_spectra = [] | |
42 removed_spectra = [] | |
43 keep = False | |
44 | |
45 for spectrum in spectra: | |
46 if 'smiles' in required_metadata: | |
47 keep = is_valid_smiles(spectrum.get('smiles')) | |
48 | |
49 if 'inchi' in required_metadata: | |
50 keep = is_valid_inchi(spectrum.get('inchi')) | |
51 | |
52 if 'inchikey' in required_metadata: | |
53 keep = is_valid_inchikey(spectrum.get('inchikey')) | |
54 | |
55 if 'precursor_mz' in required_metadata: | |
56 result = require_precursor_mz(spectrum) | |
57 if result is not None: | |
58 keep = True | |
59 else: | |
60 keep = False | |
61 | |
62 if 'valid_annotation' in required_metadata: | |
63 result = require_valid_annotation(spectrum) | |
64 if result is not None: | |
65 keep = True | |
66 else: | |
67 keep = False | |
68 | |
69 if 'formula' in required_metadata: | |
70 result = require_formula(spectrum) | |
71 if result is not None: | |
72 keep = True | |
73 else: | |
74 keep = False | |
75 | |
76 if 'compound_name' in required_metadata: | |
77 result = require_compound_name(spectrum) | |
78 if result is not None: | |
79 keep = True | |
80 else: | |
81 keep = False | |
82 | |
83 if 'retention_time' in required_metadata: | |
84 result = require_retention_time(spectrum) | |
85 if result is not None: | |
86 keep = True | |
87 else: | |
88 keep = False | |
89 | |
90 if 'retention_index' in required_metadata: | |
91 result = require_retention_index(spectrum) | |
92 if result is not None: | |
93 keep = True | |
94 else: | |
95 keep = False | |
96 | |
97 if keep: | |
98 filtered_spectra.append(spectrum) | |
99 | |
100 if "$spectra_removed" == "TRUE" and keep == False: | |
101 removed_spectra.append(spectrum) | |
102 | |
103 | |
104 if "$spectra.ext" == "msp": | |
105 save_as_msp(filtered_spectra, "${output_filtered}") | |
106 save_as_msp(removed_spectra, "${output_removed}") | |
107 else: | |
108 save_as_mgf(filtered_spectra, "${output_filtered}") | |
109 save_as_mgf(removed_spectra, "${output_removed}") | |
110 | |
111 </configfile> | |
112 </configfiles> | |
113 | |
114 <inputs> | |
115 <param name="spectra" type="data" format="msp,mgf" label="Input Spectra File" help="Input file containing mass spectra"/> | |
116 <param name="metadata_fields" type="select" multiple="true" label="Metadata Fields" help="Select metadata fields required in the spectra"> | |
117 <option value="smiles">SMILES</option> | |
118 <option value="inchi">InChI</option> | |
119 <option value="inchikey">InChIKey</option> | |
120 <option value="formula">Formula</option> | |
121 <option value="retention_time">Retention Time</option> | |
122 <option value="retention_index">Retention Index</option> | |
123 <option value="precursor_mz">Precursor MZ</option> | |
124 <option value="valid_annotation">Valid Annotation</option> | |
125 <option value="compound_name">Compound Name</option> | |
126 </param> | |
127 <param name="spectra_removed" type="boolean" truevalue="TRUE" falsevalue="FALSE" checked="false" label="Output Removed Spectra" help="Output spectra that were removed due to missing metadata"/> | |
128 </inputs> | |
129 | |
130 <outputs> | |
131 <data name="output_filtered" format_source="spectra" label="${tool.name} on ${on_string}: Filtered Spectra"/> | |
132 <data name="output_removed" format_source="spectra" label="${tool.name} on ${on_string}: Removed Spectra"> | |
133 <filter>spectra_removed</filter> | |
134 </data> | |
135 </outputs> | |
136 | |
137 <tests> | |
138 <test expect_num_outputs="1"> | |
139 <param name="spectra" value="remove_spectra/require_filter.msp" ftype="msp"/> | |
140 <param name="metadata_fields" value="smiles"/> | |
141 <output name="output_filtered" file="remove_spectra/require_smiles.msp" ftype="msp"/> | |
142 </test> | |
143 <test expect_num_outputs="2"> | |
144 <param name="spectra" value="remove_spectra/require_filter.msp" ftype="msp"/> | |
145 <param name="metadata_fields" value="inchi"/> | |
146 <param name="spectra_removed" value="TRUE"/> | |
147 <output name="output_filtered" file="remove_spectra/require_inchi.msp" ftype="msp"/> | |
148 <output name="output_removed" file="remove_spectra/require_inchi_removed_spectra.msp" ftype="msp"/> | |
149 </test> | |
150 <test expect_num_outputs="1"> | |
151 <param name="spectra" value="remove_spectra/require_filter.msp" ftype="msp"/> | |
152 <param name="metadata_fields" value="inchikey"/> | |
153 <output name="output_filtered" file="remove_spectra/require_inchikey.msp" ftype="msp"/> | |
154 </test> | |
155 <test expect_num_outputs="1"> | |
156 <param name="spectra" value="remove_spectra/require_filter.msp" ftype="msp"/> | |
157 <param name="metadata_fields" value="formula"/> | |
158 <output name="output_filtered" file="remove_spectra/require_formula.msp" ftype="msp"/> | |
159 </test> | |
160 <test expect_num_outputs="1"> | |
161 <param name="spectra" value="remove_spectra/require_filter.msp" ftype="msp"/> | |
162 <param name="metadata_fields" value="retention_time"/> | |
163 <output name="output_filtered" file="remove_spectra/require_retention_time.msp" ftype="msp"/> | |
164 </test> | |
165 <test expect_num_outputs="1"> | |
166 <param name="spectra" value="remove_spectra/require_filter.msp" ftype="msp"/> | |
167 <param name="metadata_fields" value="retention_index"/> | |
168 <output name="output_filtered" file="remove_spectra/require_retention_index.msp" ftype="msp"/> | |
169 </test> | |
170 <test expect_num_outputs="1"> | |
171 <param name="spectra" value="remove_spectra/require_filter.msp" ftype="msp"/> | |
172 <param name="metadata_fields" value="precursor_mz"/> | |
173 <output name="output_filtered" file="remove_spectra/require_precursor_mz.msp" ftype="msp"/> | |
174 </test> | |
175 <test expect_num_outputs="1"> | |
176 <param name="spectra" value="remove_spectra/require_filter.msp" ftype="msp"/> | |
177 <param name="metadata_fields" value="compound_name"/> | |
178 <output name="output_filtered" file="remove_spectra/require_compound_name.msp" ftype="msp"/> | |
179 </test> | |
180 <test expect_num_outputs="1"> | |
181 <param name="spectra" value="remove_spectra/require_filter.msp" ftype="msp"/> | |
182 <param name="metadata_fields" value="valid_annotation"/> | |
183 <output name="output_filtered"> | |
184 <assert_contents> | |
185 <has_n_lines n="0"/> | |
186 </assert_contents> | |
187 </output> | |
188 </test> | |
189 </tests> | |
190 | |
191 <help><![CDATA[ | |
192 This tool filters input mass spectra based on the presence of specified metadata fields. Spectra missing any of the selected metadata fields are optionally logged and output separately. | |
193 Valid Annotation filter removes spectra that are not fully annotated (correct and matching, smiles, inchi and inchikey) | |
194 ]]></help> | |
195 | |
196 <expand macro="citations"/> | |
197 </tool> |