# HG changeset patch # User recetox # Date 1717485048 0 # Node ID c24ebd41dd538405c5010f38a86c26254137a620 # Parent 80df426e7e475c5077fe25cb5a46f390db19f6d9 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 2abca9206b76bf42e6322d751ed3a31a6cc003a4 diff -r 80df426e7e47 -r c24ebd41dd53 matchms_remove_spectra.xml --- a/matchms_remove_spectra.xml Thu May 30 18:07:29 2024 +0000 +++ b/matchms_remove_spectra.xml Tue Jun 04 07:10:48 2024 +0000 @@ -1,4 +1,4 @@ - + Filters spectra based on metadata presence @@ -28,9 +28,8 @@ require_retention_time, require_retention_index, require_valid_annotation from matchms.importing import load_from_mgf, load_from_msp -#set metadata_fields = str("', '").join([str($f) for $f in $metadata_fields]) -required_metadata = "$metadata_fields" - +#set metadata_fields = [str($f) for $f in $metadata_fields] +required_metadata = [x for x in $metadata_fields] if "$spectra.ext" == "msp": spectra = list(load_from_msp("${spectra}")) elif "$spectra.ext" == 'mgf': @@ -40,57 +39,44 @@ filtered_spectra = [] removed_spectra = [] -keep = False for spectrum in spectra: + keep = True + if 'smiles' in required_metadata: - keep = is_valid_smiles(spectrum.get('smiles')) + keep = keep and is_valid_smiles(spectrum.get('smiles', '').strip()) if 'inchi' in required_metadata: - keep = is_valid_inchi(spectrum.get('inchi')) + keep = keep and is_valid_inchi(spectrum.get('inchi', '').strip()) if 'inchikey' in required_metadata: - keep = is_valid_inchikey(spectrum.get('inchikey')) + inchikey = spectrum.get('inchikey', '') + keep = keep and is_valid_inchikey(inchikey.strip()) if 'precursor_mz' in required_metadata: result = require_precursor_mz(spectrum) - if result is not None: - keep = True - else: - keep = False + keep = keep and result is not None if 'valid_annotation' in required_metadata: result = require_valid_annotation(spectrum) - if result is not None: - keep = True - else: - keep = False - + keep = keep and result is not None + if 'formula' in required_metadata: result = require_formula(spectrum) - if result is not None: - keep = True - else: - keep = False + keep = keep and result is not None if 'compound_name' in required_metadata: result = require_compound_name(spectrum) - if result is not None: - keep = True - else: - keep = False - + keep = keep and result is not None + if 'retention_time' in required_metadata: result = require_retention_time(spectrum) - if result is not None: - keep = True - else: - keep = False + keep = keep and result is not None if 'retention_index' in required_metadata: result = require_retention_index(spectrum) if result is not None: - keep = True + keep = keep and float(result.get('retention_index', 0)) > 0 else: keep = False diff -r 80df426e7e47 -r c24ebd41dd53 test-data/remove_spectra/require_filter.msp --- a/test-data/remove_spectra/require_filter.msp Thu May 30 18:07:29 2024 +0000 +++ b/test-data/remove_spectra/require_filter.msp Tue Jun 04 07:10:48 2024 +0000 @@ -4,6 +4,7 @@ PARENT_MASS: 347.930801 PUBCHEMID: 10970124 NOMINAL_MASS: 348 +RETENTION_INDEX: 0 SMILES: nan NUM PEAKS: 3 292.0 999.0 diff -r 80df426e7e47 -r c24ebd41dd53 test-data/remove_spectra/require_inchi_removed_spectra.msp --- a/test-data/remove_spectra/require_inchi_removed_spectra.msp Thu May 30 18:07:29 2024 +0000 +++ b/test-data/remove_spectra/require_inchi_removed_spectra.msp Tue Jun 04 07:10:48 2024 +0000 @@ -4,6 +4,7 @@ PARENT_MASS: 347.930801 PUBCHEMID: 10970124 NOMINAL_MASS: 348 +RETENTION_INDEX: 0.0 SMILES: nan NUM PEAKS: 3 292.0 999.0