diff --git a/tools/matchms/matchms_remove_key.xml b/tools/matchms/matchms_remove_key.xml new file mode 100644 index 00000000..354fc916 --- /dev/null +++ b/tools/matchms/matchms_remove_key.xml @@ -0,0 +1,72 @@ + + Remove metadata entry for all spectra in a library + + + macros.xml + help.xml + + + + + + operation_3695 + + + + + matchms + + + + + + +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}") + + + + + + + + + + + + + + + + + + + + + + + + + + 10.5281/zenodo.6035335 + + diff --git a/tools/matchms/test-data/out_matchms_remove_key.msp b/tools/matchms/test-data/out_matchms_remove_key.msp new file mode 100644 index 00000000..6dc0f0fe --- /dev/null +++ b/tools/matchms/test-data/out_matchms_remove_key.msp @@ -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