Skip to content

Commit

Permalink
Merge pull request #12 from vijay-gnanasambandan-bruker/adding_collis…
Browse files Browse the repository at this point in the history
…ion_energy_in_precursor

Adding collision energy in precursor.
  • Loading branch information
sander-willems-bruker authored Jan 3, 2024
2 parents c587617 + a987472 commit be40423
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/file_readers/common/sql_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ pub struct SqlReader {
}

impl SqlReader {
fn read_column_from_table<
T: rusqlite::types::FromSql + std::default::Default,
>(
fn read_column_from_table<T: rusqlite::types::FromSql + Default>(
&self,
column_name: &str,
table_name: &str,
) -> Vec<T> {
let connection: Connection = get_sql_connection(&self.path);
let column_names: Vec<String> =
self.get_table_columns(table_name).unwrap();
let order_by: String = column_names.join(", ");
let query: String = format!(
"SELECT {} FROM {} ORDER BY {}",
column_name, table_name, order_by
);

self.get_data_from_sql(&query)
}

pub fn get_data_from_sql<T: rusqlite::types::FromSql + Default>(
&self,
query: &String,
) -> Vec<T> {
let connection: Connection = get_sql_connection(&self.path);
let mut stmt: Statement = connection.prepare(&query).unwrap();
let rows = stmt
.query_map(
Expand Down
7 changes: 7 additions & 0 deletions src/file_readers/spectrum_readers/dda_reader/precursors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<f64> = 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<Precursor> = (0..precursor_table.mz.len())
.into_par_iter()
.map(|index| {
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/precursors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions tests/spectrum_readers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fn minitdf_reader() {
intensity: 0.0,
index: 1,
frame_index: 1,
collision_energy: 0.0,
}),
index: 0,
},
Expand All @@ -43,6 +44,7 @@ fn minitdf_reader() {
intensity: 0.0,
index: 2,
frame_index: 2,
collision_energy: 0.0,
}),
index: 1,
},
Expand Down Expand Up @@ -74,6 +76,7 @@ fn tdf_reader_dda() {
intensity: 10.0,
index: 1,
frame_index: 1,
collision_energy: 0.0,
}),
index: 0,
},
Expand All @@ -88,6 +91,7 @@ fn tdf_reader_dda() {
intensity: 10.0,
index: 2,
frame_index: 1,
collision_energy: 0.0,
}),
index: 1,
},
Expand All @@ -102,6 +106,7 @@ fn tdf_reader_dda() {
intensity: 10.0,
index: 3,
frame_index: 3,
collision_energy: 0.0,
}),
index: 2,
},
Expand Down

0 comments on commit be40423

Please sign in to comment.