From cda1a5dd86938f6d62c1d16a84dc3c914d7319cc Mon Sep 17 00:00:00 2001 From: Vijayaraja G Date: Tue, 19 Dec 2023 17:22:21 -0600 Subject: [PATCH 1/4] Adding collision energy in precursor. --- src/file_readers/common/sql_reader.rs | 14 ++++++++++---- .../common/sql_reader/tables/pasef_frame_msms.rs | 2 ++ .../spectrum_readers/dda_reader/precursors.rs | 3 +++ src/precursors.rs | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/file_readers/common/sql_reader.rs b/src/file_readers/common/sql_reader.rs index ac7e993..5c54db7 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) + } + + 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/common/sql_reader/tables/pasef_frame_msms.rs b/src/file_readers/common/sql_reader/tables/pasef_frame_msms.rs index 49332e8..9947bce 100644 --- a/src/file_readers/common/sql_reader/tables/pasef_frame_msms.rs +++ b/src/file_readers/common/sql_reader/tables/pasef_frame_msms.rs @@ -9,6 +9,7 @@ pub struct PasefFrameMsMsTable { pub mz_width: Vec, pub collision_energy: Vec, pub precursor: Vec, + pub collision_energy_by_precursor: Vec, } impl ReadableFromSql for PasefFrameMsMsTable { @@ -28,6 +29,7 @@ impl ReadableFromSql for PasefFrameMsMsTable { .read_column_from_table("CollisionEnergy", table_name), precursor: sql_reader .read_column_from_table("Precursor", table_name), + collision_energy_by_precursor: sql_reader.get_data_from_sql(&"select CollisionEnergy,Precursor from PasefFrameMsMsInfo group by Precursor".to_string()), } } } diff --git a/src/file_readers/spectrum_readers/dda_reader/precursors.rs b/src/file_readers/spectrum_readers/dda_reader/precursors.rs index f0b1753..81b7249 100644 --- a/src/file_readers/spectrum_readers/dda_reader/precursors.rs +++ b/src/file_readers/spectrum_readers/dda_reader/precursors.rs @@ -29,10 +29,12 @@ impl PrecursorReader { let precursor_table: PrecursorTable = PrecursorTable::from_sql(&tdf_reader.tdf_sql_reader); let retention_times: Vec = tdf_reader.frame_table.rt.clone(); + let collision_energy = &pasef_frames.collision_energy_by_precursor; let precursors: Vec = (0..precursor_table.mz.len()) .into_par_iter() .map(|index| { let frame_id: usize = precursor_table.precursor_frame[index]; + let precursor_id: usize = precursor_table.id[index]; let scan_id: f64 = precursor_table.scan_average[index]; Precursor { mz: precursor_table.mz[index], @@ -42,6 +44,7 @@ impl PrecursorReader { intensity: precursor_table.intensity[index], index: index + 1, //TODO? frame_index: frame_id, + collision_energy: collision_energy[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. From 08cc65413d6f466f0453f9b4def21ca284cf957b Mon Sep 17 00:00:00 2001 From: Vijayaraja G Date: Tue, 19 Dec 2023 17:35:23 -0600 Subject: [PATCH 2/4] fix: removed unused variable and fixed typo mistake. --- src/file_readers/common/sql_reader/tables/pasef_frame_msms.rs | 2 +- src/file_readers/spectrum_readers/dda_reader/precursors.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/file_readers/common/sql_reader/tables/pasef_frame_msms.rs b/src/file_readers/common/sql_reader/tables/pasef_frame_msms.rs index 9947bce..eb68420 100644 --- a/src/file_readers/common/sql_reader/tables/pasef_frame_msms.rs +++ b/src/file_readers/common/sql_reader/tables/pasef_frame_msms.rs @@ -29,7 +29,7 @@ impl ReadableFromSql for PasefFrameMsMsTable { .read_column_from_table("CollisionEnergy", table_name), precursor: sql_reader .read_column_from_table("Precursor", table_name), - collision_energy_by_precursor: sql_reader.get_data_from_sql(&"select CollisionEnergy,Precursor from PasefFrameMsMsInfo group by Precursor".to_string()), + collision_energy_by_precursor: sql_reader.get_data_from_sql(&"select CollisionEnergy from PasefFrameMsMsInfo group by Precursor".to_string()), } } } diff --git a/src/file_readers/spectrum_readers/dda_reader/precursors.rs b/src/file_readers/spectrum_readers/dda_reader/precursors.rs index 81b7249..fb164ed 100644 --- a/src/file_readers/spectrum_readers/dda_reader/precursors.rs +++ b/src/file_readers/spectrum_readers/dda_reader/precursors.rs @@ -34,7 +34,6 @@ impl PrecursorReader { .into_par_iter() .map(|index| { let frame_id: usize = precursor_table.precursor_frame[index]; - let precursor_id: usize = precursor_table.id[index]; let scan_id: f64 = precursor_table.scan_average[index]; Precursor { mz: precursor_table.mz[index], From fbbbdd3533524ac07f66f053c3fe397130435292 Mon Sep 17 00:00:00 2001 From: Vijayaraja G Date: Thu, 21 Dec 2023 11:33:06 -0600 Subject: [PATCH 3/4] fix: review comment updates --- src/file_readers/common/sql_reader.rs | 2 +- .../common/sql_reader/tables/pasef_frame_msms.rs | 2 -- .../spectrum_readers/dda_reader/precursors.rs | 9 +++++++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/file_readers/common/sql_reader.rs b/src/file_readers/common/sql_reader.rs index 5c54db7..a5e10f0 100644 --- a/src/file_readers/common/sql_reader.rs +++ b/src/file_readers/common/sql_reader.rs @@ -28,7 +28,7 @@ impl SqlReader { self.get_data_from_sql(&query) } - fn get_data_from_sql( + pub fn get_data_from_sql( &self, query: &String, ) -> Vec { diff --git a/src/file_readers/common/sql_reader/tables/pasef_frame_msms.rs b/src/file_readers/common/sql_reader/tables/pasef_frame_msms.rs index eb68420..49332e8 100644 --- a/src/file_readers/common/sql_reader/tables/pasef_frame_msms.rs +++ b/src/file_readers/common/sql_reader/tables/pasef_frame_msms.rs @@ -9,7 +9,6 @@ pub struct PasefFrameMsMsTable { pub mz_width: Vec, pub collision_energy: Vec, pub precursor: Vec, - pub collision_energy_by_precursor: Vec, } impl ReadableFromSql for PasefFrameMsMsTable { @@ -29,7 +28,6 @@ impl ReadableFromSql for PasefFrameMsMsTable { .read_column_from_table("CollisionEnergy", table_name), precursor: sql_reader .read_column_from_table("Precursor", table_name), - collision_energy_by_precursor: sql_reader.get_data_from_sql(&"select CollisionEnergy from PasefFrameMsMsInfo group by Precursor".to_string()), } } } diff --git a/src/file_readers/spectrum_readers/dda_reader/precursors.rs b/src/file_readers/spectrum_readers/dda_reader/precursors.rs index fb164ed..482ede4 100644 --- a/src/file_readers/spectrum_readers/dda_reader/precursors.rs +++ b/src/file_readers/spectrum_readers/dda_reader/precursors.rs @@ -23,13 +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_energy = &pasef_frames.collision_energy_by_precursor; + 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| { @@ -43,7 +48,7 @@ impl PrecursorReader { intensity: precursor_table.intensity[index], index: index + 1, //TODO? frame_index: frame_id, - collision_energy: collision_energy[index], + collision_energy: collision_energies[index], } }) .collect(); From a987472afcbda5e7fbb4902532809f62b27bd4ea Mon Sep 17 00:00:00 2001 From: Vijayaraja G Date: Fri, 22 Dec 2023 09:28:40 -0600 Subject: [PATCH 4/4] tests: added default value in precursor object. --- tests/spectrum_readers.rs | 5 +++++ 1 file changed, 5 insertions(+) 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, },