Skip to content

Commit

Permalink
updated matchms filtering tool
Browse files Browse the repository at this point in the history
  • Loading branch information
zargham-ahmad committed Jan 8, 2024
1 parent 98223db commit 06b5348
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 81 deletions.
4 changes: 2 additions & 2 deletions tools/matchms/matchms_filtering.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@
<test>
<param name="spectra" value="filtering/require_filter.msp" ftype="msp"/>
<param name="require_smiles_is_true" value="TRUE"/>
<output name="output" file="filtering/require_smiles_out.msp" ftype="msp"/>
<output name="output" file="filtering/require_out.msp" ftype="msp"/>
</test>
<test>
<param name="spectra" value="filtering/require_filter.msp" ftype="msp"/>
<param name="require_inchi_is_true" value="TRUE"/>
<output name="output" file="filtering/require_inchi_out.msp" ftype="msp"/>
<output name="output" file="filtering/require_out.msp" ftype="msp"/>
</test>
<test>
<param name="spectra" value="filtering/input.msp" ftype="msp"/>
Expand Down
10 changes: 6 additions & 4 deletions tools/matchms/matchms_filtering_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from matchms.filtering import default_filters, normalize_intensities, reduce_to_number_of_peaks, select_by_mz, \
select_by_relative_intensity
from matchms.filtering.filter_utils.derive_precursor_mz_and_parent_mass import derive_precursor_mz_from_parent_mass
from matchms.filtering.filter_utils.smile_inchi_inchikey_conversions import is_valid_inchi, is_valid_smiles
from matchms.importing import load_from_mgf, load_from_msp


def require_key(spectrum, key):
if spectrum.get(key):
def require_key(spectrum, key, function):
value = spectrum.get(key)
if function(value):
return spectrum

return None
Expand Down Expand Up @@ -95,10 +97,10 @@ def main(argv):
spectrum.set("precursor_mz", precursor_mz)

if args.require_smiles and spectrum is not None:
spectrum = require_key(spectrum, "smiles")
spectrum = require_key(spectrum, "smiles", is_valid_smiles)

if args.require_inchi and spectrum is not None:
spectrum = require_key(spectrum, "inchi")
spectrum = require_key(spectrum, "inchi", is_valid_inchi)

if spectrum is not None:
filtered_spectra.append(spectrum)
Expand Down
4 changes: 2 additions & 2 deletions tools/matchms/test-data/filtering/require_filter.msp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ COMPOUND_NAME: ((.eta.5-Cyclopentadienylironbiscarbonyl)(1,2-phenylenedioxysilyl
PARENT_MASS: 347.930801
PUBCHEMID: 10970124
NOMINAL_MASS: 348
SMILES: Cl[Si]1Oc2ccccc2O1.[C-]#[O+].[C-]#[O+].[CH]1C=CC=C1.[Fe]
SMILES: nan
NUM PEAKS: 3
292.0 999.0
314.0 118.89
Expand All @@ -21,7 +21,7 @@ PARENT_MASS: 186.1044655
RETENTION_INDEX: 1588.0
PUBCHEMID: 130762197
NOMINAL_MASS: 186
INCHI: InChI=1S/C13H14O/c1-13(10-14)9-12(13)8-7-11-5-3-2-4-6-11/h2-6,12,14H,9-10H2,1H3/t12-,13-/m0/s1
INCHI: nan
NUM PEAKS: 20
51.0 89.92
63.0 89.92
Expand Down
59 changes: 0 additions & 59 deletions tools/matchms/test-data/filtering/require_inchi_out.msp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
FORMULA: C13H9ClFeO4Si
CASNO: 2000570-99-8
ID: 2011
COMMENT: SpectrumID: 1519953; Source: C4-1998-38-3; Class: Benzenoids; CASRN not real!
COMPOUND_NAME: ((.eta.5-Cyclopentadienylironbiscarbonyl)(1,2-phenylenedioxysilyl)chloride complex
PARENT_MASS: 347.930801
PUBCHEMID: 10970124
NOMINAL_MASS: 348
SMILES: Cl[Si]1Oc2ccccc2O1.[C-]#[O+].[C-]#[O+].[CH]1C=CC=C1.[Fe]
NUM PEAKS: 3
292.0 999.0
314.0 118.89
348.0 734.24

FORMULA: C34H54O4
CASNO: 2000774-54-3
ID: 36905
Expand Down

0 comments on commit 06b5348

Please sign in to comment.