diff --git a/src/file_readers/common/sql_reader.rs b/src/file_readers/common/sql_reader.rs index ac7e993..a5e10f0 100644 --- a/src/file_readers/common/sql_reader.rs +++ b/src/file_readers/common/sql_reader.rs @@ -12,14 +12,11 @@ pub struct SqlReader { } impl SqlReader { - fn read_column_from_table< - T: rusqlite::types::FromSql + std::default::Default, - >( + fn read_column_from_table( &self, column_name: &str, table_name: &str, ) -> Vec { - let connection: Connection = get_sql_connection(&self.path); let column_names: Vec = self.get_table_columns(table_name).unwrap(); let order_by: String = column_names.join(", "); @@ -27,6 +24,15 @@ impl SqlReader { "SELECT {} FROM {} ORDER BY {}", column_name, table_name, order_by ); + + self.get_data_from_sql(&query) + } + + pub fn get_data_from_sql( + &self, + query: &String, + ) -> Vec { + let connection: Connection = get_sql_connection(&self.path); let mut stmt: Statement = connection.prepare(&query).unwrap(); let rows = stmt .query_map( diff --git a/src/file_readers/spectrum_readers/dda_reader/precursors.rs b/src/file_readers/spectrum_readers/dda_reader/precursors.rs index f0b1753..482ede4 100644 --- a/src/file_readers/spectrum_readers/dda_reader/precursors.rs +++ b/src/file_readers/spectrum_readers/dda_reader/precursors.rs @@ -23,12 +23,18 @@ pub struct PrecursorReader { impl PrecursorReader { pub fn new(tdf_reader: &TDFReader) -> Self { + let select_collision_energy_sql = String::from( + "SELECT CollisionEnergy FROM PasefFrameMsMsInfo GROUP BY Precursor", + ); let pasef_frames: PasefFrameMsMsTable = PasefFrameMsMsTable::from_sql(&tdf_reader.tdf_sql_reader); let im_reader: Scan2ImConverter = tdf_reader.im_converter; let precursor_table: PrecursorTable = PrecursorTable::from_sql(&tdf_reader.tdf_sql_reader); let retention_times: Vec = tdf_reader.frame_table.rt.clone(); + let collision_energies = tdf_reader + .tdf_sql_reader + .get_data_from_sql(&select_collision_energy_sql); let precursors: Vec = (0..precursor_table.mz.len()) .into_par_iter() .map(|index| { @@ -42,6 +48,7 @@ impl PrecursorReader { intensity: precursor_table.intensity[index], index: index + 1, //TODO? frame_index: frame_id, + collision_energy: collision_energies[index], } }) .collect(); diff --git a/src/precursors.rs b/src/precursors.rs index 544dc56..195beb3 100644 --- a/src/precursors.rs +++ b/src/precursors.rs @@ -8,6 +8,7 @@ pub struct Precursor { pub intensity: f64, pub index: usize, pub frame_index: usize, + pub collision_energy: f64, } /// A type of quadrupole selection. diff --git a/tests/spectrum_readers.rs b/tests/spectrum_readers.rs index bff4c43..6da7dec 100644 --- a/tests/spectrum_readers.rs +++ b/tests/spectrum_readers.rs @@ -29,6 +29,7 @@ fn minitdf_reader() { intensity: 0.0, index: 1, frame_index: 1, + collision_energy: 0.0, }), index: 0, }, @@ -43,6 +44,7 @@ fn minitdf_reader() { intensity: 0.0, index: 2, frame_index: 2, + collision_energy: 0.0, }), index: 1, }, @@ -74,6 +76,7 @@ fn tdf_reader_dda() { intensity: 10.0, index: 1, frame_index: 1, + collision_energy: 0.0, }), index: 0, }, @@ -88,6 +91,7 @@ fn tdf_reader_dda() { intensity: 10.0, index: 2, frame_index: 1, + collision_energy: 0.0, }), index: 1, }, @@ -102,6 +106,7 @@ fn tdf_reader_dda() { intensity: 10.0, index: 3, frame_index: 3, + collision_energy: 0.0, }), index: 2, },