Skip to content

Commit

Permalink
Merge pull request #460 from RECETOX/hechth/issue458
Browse files Browse the repository at this point in the history
Implemented `matchms remove key` tool
  • Loading branch information
hechth authored Dec 4, 2023
2 parents 19994ff + 24e1cac commit 970c7dc
Show file tree
Hide file tree
Showing 2 changed files with 260 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tools/matchms/matchms_remove_key.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<tool id="matchms_remove_key" name="matchms remove key" version="@TOOL_VERSION@+galaxy0" profile="21.09">
<description>Remove metadata entry for all spectra in a library</description>

<macros>
<import>macros.xml</import>
<import>help.xml</import>
</macros>

<expand macro="creator"/>

<edam_operations>
<edam_operation>operation_3695</edam_operation>
</edam_operations>
<expand macro="bio.tools"/>

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

<command detect_errors='aggressive'><![CDATA[
python3 '${matchms_python_cli}'
]]></command>

<configfiles>
<configfile name="matchms_python_cli">
import matchms
@init_logger@

matchms.Metadata.set_key_replacements({})
key = "${key}".lower()
spectra = list(matchms.importing.load_from_msp("${spectral_library}", metadata_harmonization = "False"))
new_spectra = []
for spectrum in spectra:
if spectrum.get(key) is not None:
metadata = spectrum.metadata
del metadata[key]
spectrum.metadata = metadata
new_spectra.append(spectrum)
matchms.exporting.save_as_msp(new_spectra, "${output}")
</configfile>
</configfiles>

<inputs>
<param label="Spectra file" name="spectral_library" type="data" format="msp"
help="Mass spectral library file to add key." />

<param label="Attribute Name" name="key" type="text" value="" help="Name of the attribute which will be removed from all spectra records in the MSP." />
</inputs>

<outputs>
<data label="${tool.name} on ${on_string}" name="output" format="msp">
</data>
</outputs>

<tests>
<test>
<param name="spectral_library" value="filtering/input.msp" ftype="msp"/>
<param name="key" value="ionmode"/>
<output name="output" file="out_matchms_remove_key.msp" ftype="msp" compare="sim_size"/>
</test>
</tests>

<help><![CDATA[
Description
The tool take MSP file as an input and take as parameters the name of the
attribute which will be removed from all spectra records in the MSP.
]]></help>

<citations>
<citation type="doi">10.5281/zenodo.6035335</citation>
</citations>
</tool>
188 changes: 188 additions & 0 deletions tools/matchms/test-data/out_matchms_remove_key.msp
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
NAME:C001
RETENTIONTIME:38.74
RETENTIONINDEX: -1
SPECTRUMTYPE:Centroid
Num Peaks:57
216.9205 32607700
256.8215 31377637
175.0641 26780143
206.9034 26130980
254.8252 23747536
198.8647 21688594
196.8658 21390430
372.7383 19374863
258.8237 15532799
382.8218 12815572
488.6825 12267966
392.7685 10913351
316.7777 10734168
440.7322 10603010
138.9121 10186226
312.7841 10051801
434.7287 9943329
266.8652 9805546
370.7418 9765463
450.7016 8762673
324.9549 8619910
428.7834 8554675
384.8177 8311500
442.7401 8271752
200.8848 7742528
492.744 7662344
494.8953 7188793
546.6093 7177067
498.8794 6811405
500.8484 6520691
322.8157 6317648
350.9875 6150799
550.6949 6104789
426.7772 5431633
566.5977 5171811
510.763 4989757
486.7743 4886062
460.7076 4528973
484.7242 4273989
518.7415 4243468
334.849 4178412
413.2664 3965867
436.8161 3705247
502.7832 3567833
342.8093 3285552
366.8281 3253770
306.9914 3169316
268.8537 3090354
800.4451 2792137
186.1095 2675456
234.0134 2550129
462.7862 2123666
349.9455 2050695
612.6927 2005587
676.6436 1982714
351.941 1965882
148.9337 1008656

NAME:C002
RETENTIONTIME:520.25
RETENTIONINDEX: 1234.5
SPECTRUMTYPE:Centroid
Num Peaks:35
525.375 1073323842
310.1623 295359836
526.3783 181668883
1047.7378 150394804
551.3321 111616808
1048.7399 90978863
289.6491 46498377
312.0296 38757284
1075.1968 33352763
1049.7432 29946438
552.3348 28340614
813.5403 25060147
527.3812 23642795
309.1649 18045974
301.1565 15185412
311.1658 13124727
330.6757 12666597
624.296 11790213
1076.2004 10417953
578.2905 7578406
562.3269 7538206
1050.7453 6807767
267.2688 6103973
814.5336 5865975
1069.7158 5074652
619.3008 4742103
1216.8041 4439324
1206.3127 3738816
1217.807 3565334
1074.1979 3402288
553.3314 2609936
955.1171 2322927
1101.6535 2023916
131.1733 1971789
279.0196 1946255

NAME:C003
RETENTIONTIME:483.67
SPECTRUMTYPE:Centroid
Num Peaks:26
522.3565 4089569222
523.354 1201714423
288.6414 202172046
1043.7028 144351468
1044.7068 83271854
549.3267 63300808
279.6362 29849749
1045.706 27998321
1058.1594 20718345
1071.1639 15461047
378.2093 15309961
796.9808 13576738
809.9883 12596682
265.2529 11366224
280.6546 8848921
576.2749 7386007
1059.1626 6608764
810.9916 6601055
1046.7131 6505178
797.9841 6368973
1072.1671 5096642
625.4543 4040374
379.1966 2902366
577.3074 2354251
617.2778 2323470
266.2564 1420444

NAME:C004
RETENTIONTIME:473.48
SPECTRUMTYPE:Centroid
Num Peaks:24
496.34 12577588056
497.3442 3337125302
991.6726 1420557258
992.6749 763118028
498.3462 532285213
993.6787 239161906
296.147 190395687
1017.6897 168186952
482.3247 145772322
1018.6656 120599518
499.3493 68176083
1019.6555 57647644
994.6801 53549573
770.964 49250157
483.3283 36245876
275.6336 28001849
771.9675 22666873
1020.6591 12469103
783.9721 9839299
949.6233 8009033
124.1405 6517662
950.6274 3674694
784.9749 3622908
170.2437 1237313

NAME:C005
RETENTIONTIME:41.72
SPECTRUMTYPE:Centroid
Num Peaks:20
337.0623 88672453
359.0443 48435582
353.0361 37061354
375.018 29159485
218.1386 14009249
417.0027 13822994
381.0261 13522755
438.9851 11307111
396.9999 10317665
454.9592 9820452
432.9764 9779399
338.0654 8770055
360.0459 5025128
418.9966 4386311
512.8989 4072570
456.9603 3774845
470.9263 3632486
572.871 3485486
440.9796 3364168
376.0216 2740193

0 comments on commit 970c7dc

Please sign in to comment.