matchms.filtering.SpectrumProcessor module¶
- class matchms.filtering.SpectrumProcessor.ProcessingReport(filter_functions: List[Callable] | None = None)[source]¶
Bases:
object
Class to keep track of spectrum changes during filtering.
- class matchms.filtering.SpectrumProcessor.SpectrumProcessor(filters: Iterable[str | Callable | Tuple[Callable | str, Dict[str, any]]])[source]¶
Bases:
object
A class to process spectra using a series of filters.
The class enables a user to define a custom spectrum processing workflow by setting multiple flags and parameters.
- Parameters:
filters – A list of filter functions, see add_filter for all the allowed formats.
- parse_and_add_filter(filter_description: str | Callable | Tuple[Callable | str, Dict[str, any]], filter_position: int | None = None)[source]¶
Adds a filter, by parsing the different allowed inputs.
- filter:
Allowed formats: str (has to be a matchms function name) (str, {str, any} (has to be a matchms function name, followed by parameters) Callable (can be matchms filter or custom made filter) Callable, {str, any} (the dict should be parameters.
- filter_position:
If None: Matchms filters are automatically ordered. Custom filters will be added at the end of the filter list. If not None, the filter will be added to the given position in the filter order list.
- process_spectrum(spectrum, processing_report: ProcessingReport | None = None)[source]¶
Process the given spectrum with all filters in the processing pipeline.
- process_spectrums(spectrums: list, progress_bar: bool = True, cleaned_spectra_file=None)[source]¶
Process a list of spectrums with all filters in the processing pipeline.
- Parameters:
create_report (bool, optional) – Creates and outputs a report of the main changes during processing. The report will be returned as pandas DataFrame. Default is set to False.
progress_bar (bool, optional) – Displays progress bar if set to True. Default is True.
cleaned_spectra_file – Path to where the cleaned spectra should be saved.
- Returns:
Spectrums – List containing the processed spectrums.
processing_report – A ProcessingReport containing the effect of the filters.
- matchms.filtering.SpectrumProcessor.check_all_parameters_given(func: Callable)[source]¶
Asserts that all added parameters for a function are given (except spectrum_in)
- matchms.filtering.SpectrumProcessor.create_partial_function(filter_function: Callable, filter_params: Dict[str, any] | None)[source]¶
Adds the filter params to the filter function