Skip to content

Commit

Permalink
Ignore empty spectra
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfG committed Jul 1, 2024
1 parent bba02f7 commit 801b6fb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ms2pip/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,8 @@ def _process_spectra(
spectrum_id = match[1]
except (TypeError, IndexError):
raise exceptions.TitlePatternError(
"Spectrum title pattern could not be matched to spectrum IDs "
f"`{spectrum.identifier}`. "
f"Spectrum title pattern `{spectrum_id_pattern}` could not be matched to "
f"spectrum ID `{spectrum.identifier}`. "
" Are you sure that the regex contains a capturing group?"
)

Expand Down
10 changes: 9 additions & 1 deletion ms2pip/spectrum_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,22 @@ def read_spectrum_file(spectrum_file: str) -> Generator[ObservedSpectrum, None,
raise UnsupportedSpectrumFiletypeError(file_extension)

for spectrum in get_ms2_spectra(str(spectrum_file)):
yield ObservedSpectrum(
obs_spectrum = ObservedSpectrum(
mz=np.array(spectrum.mz, dtype=np.float32),
intensity=np.array(spectrum.intensity, dtype=np.float32),
identifier=str(spectrum.identifier),
precursor_mz=float(spectrum.precursor.mz),
precursor_charge=float(spectrum.precursor.charge),
retention_time=float(spectrum.precursor.rt),
)
# Workaround for mobiusklein/mzdata#3
if (
obs_spectrum.identifier == ""
or obs_spectrum.mz.shape[0] == 0
or obs_spectrum.intensity.shape[0] == 0
):
continue
yield obs_spectrum


def _is_minitdf(spectrum_file: str) -> bool:
Expand Down

0 comments on commit 801b6fb

Please sign in to comment.