@@ -44,8 +44,8 @@ def read_mgf(spectrum_file: str) -> Generator[ObservedSpectrum, None, None]:
4444 precursor_mz = None
4545 spectrum = ObservedSpectrum (
4646 identifier = spectrum ["params" ]["title" ],
47- mz = spectrum ["m/z array" ],
48- intensity = spectrum ["intensity array" ],
47+ mz = spectrum ["m/z array" ]. astype ( np . float32 ) ,
48+ intensity = spectrum ["intensity array" ]. astype ( np . float32 ) ,
4949 precursor_mz = precursor_mz ,
5050 precursor_charge = precursor_charge ,
5151 )
@@ -80,8 +80,8 @@ def read_mzml(spectrum_file: str) -> Generator[ObservedSpectrum, None, None]:
8080 precursor_charge = None
8181 spectrum = ObservedSpectrum (
8282 identifier = spectrum ["id" ],
83- mz = spectrum ["m/z array" ],
84- intensity = spectrum ["intensity array" ],
83+ mz = spectrum ["m/z array" ]. astype ( np . float32 ) ,
84+ intensity = spectrum ["intensity array" ]. astype ( np . float32 ) ,
8585 precursor_mz = precursor ["selected ion m/z" ],
8686 precursor_charge = precursor_charge ,
8787 )
@@ -99,13 +99,16 @@ def read_tdf(spectrum_file: str) -> Generator[ObservedSpectrum, None, None]:
9999
100100 """
101101 if not _has_timsrust :
102- raise ImportError ("Optional dependency timsrust_pyo3 required for .d spectrum file support." )
102+ raise ImportError (
103+ "Optional dependency timsrust_pyo3 required for .d spectrum file support. Reinstall "
104+ "ms2pip with `pip install ms2pip[tdf]` and try again."
105+ )
103106 reader = timsrust .TimsReader (spectrum_file )
104107 for spectrum in reader .read_all_spectra ():
105108 spectrum = ObservedSpectrum (
106109 identifier = spectrum .index ,
107- mz = np .asarray (spectrum .mz_values ),
108- intensity = np .asarray (spectrum .intensities ),
110+ mz = np .asarray (spectrum .mz_values , dtype = np . float32 ),
111+ intensity = np .asarray (spectrum .intensities , dtype = np . float32 ),
109112 precursor_mz = spectrum .precursor .mz ,
110113 precursor_charge = spectrum .precursor .charge
111114 )
0 commit comments