@@ -3,8 +3,8 @@ use std::collections::HashMap;
33use crate :: ms2_spectrum:: MS2Spectrum ;
44use crate :: precursor:: Precursor ;
55
6- impl From < timsrust:: ms_data :: Precursor > for Precursor {
7- fn from ( precursor : timsrust:: ms_data :: Precursor ) -> Self {
6+ impl From < timsrust:: Precursor > for Precursor {
7+ fn from ( precursor : timsrust:: Precursor ) -> Self {
88 Precursor {
99 mz : precursor. mz ,
1010 rt : precursor. rt ,
@@ -15,8 +15,8 @@ impl From<timsrust::ms_data::Precursor> for Precursor {
1515 }
1616}
1717
18- impl From < timsrust:: ms_data :: Spectrum > for MS2Spectrum {
19- fn from ( spectrum : timsrust:: ms_data :: Spectrum ) -> Self {
18+ impl From < timsrust:: Spectrum > for MS2Spectrum {
19+ fn from ( spectrum : timsrust:: Spectrum ) -> Self {
2020 MS2Spectrum :: new (
2121 spectrum. index . to_string ( ) ,
2222 spectrum. mz_values . iter ( ) . map ( |mz| * mz as f32 ) . collect ( ) ,
@@ -25,7 +25,7 @@ impl From<timsrust::ms_data::Spectrum> for MS2Spectrum {
2525 . iter ( )
2626 . map ( |intensity| * intensity as f32 )
2727 . collect ( ) ,
28- Some ( Precursor :: from ( spectrum . precursor ) ) ,
28+ spectrum . precursor . map ( Precursor :: from) ,
2929 )
3030 }
3131}
@@ -34,35 +34,36 @@ impl From<timsrust::ms_data::Spectrum> for MS2Spectrum {
3434pub fn parse_precursor_info (
3535 spectrum_path : & str ,
3636) -> Result < HashMap < String , Precursor > , std:: io:: Error > {
37- let reader = timsrust:: FileReader :: new ( spectrum_path)
37+ let reader = timsrust:: readers :: SpectrumReader :: new ( spectrum_path)
3838 . map_err ( |e| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , e. to_string ( ) ) ) ?;
3939
40- Ok ( reader
41- . read_all_spectra ( )
40+ let spectra = reader
41+ . get_all ( )
4242 . into_iter ( )
43- . filter ( |spectrum| {
44- matches ! (
45- spectrum. precursor,
46- timsrust:: ms_data:: Precursor { .. }
47- )
48- } )
49- . map ( |spectrum| {
50- (
51- spectrum. index . to_string ( ) ,
52- Precursor :: from ( spectrum. precursor ) ,
53- )
43+ . collect :: < Result < Vec < _ > , _ > > ( )
44+ . map_err ( |e| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , e. to_string ( ) ) ) ?;
45+
46+ let precursor_info = spectra
47+ . into_iter ( )
48+ . filter_map ( |spectrum| match spectrum. precursor {
49+ Some ( precursor) => Some ( ( spectrum. index . to_string ( ) , Precursor :: from ( precursor) ) ) ,
50+ None => None ,
5451 } )
55- . collect :: < HashMap < String , Precursor > > ( ) )
52+ . collect :: < HashMap < _ , _ > > ( ) ;
53+
54+ Ok ( precursor_info)
5655}
5756
5857/// Read MS2 spectra from spectrum files with timsrust
5958pub fn read_ms2_spectra ( spectrum_path : & str ) -> Result < Vec < MS2Spectrum > , std:: io:: Error > {
60- let reader = timsrust:: FileReader :: new ( spectrum_path)
59+ let reader = timsrust:: readers :: SpectrumReader :: new ( spectrum_path)
6160 . map_err ( |e| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , e. to_string ( ) ) ) ?;
6261
63- Ok ( reader
64- . read_all_spectra ( )
62+ let spectra = reader
63+ . get_all ( )
6564 . into_iter ( )
66- . map ( MS2Spectrum :: from)
67- . collect ( ) )
65+ . collect :: < Result < Vec < _ > , _ > > ( )
66+ . map_err ( |e| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , e. to_string ( ) ) ) ?;
67+
68+ Ok ( spectra. into_iter ( ) . map ( MS2Spectrum :: from) . collect ( ) )
6869}
0 commit comments