Skip to content

Commit

Permalink
adding meta data extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
theGreatHerrLebert committed Nov 9, 2023
1 parent f2b33e8 commit 54d7f65
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 41 deletions.
80 changes: 78 additions & 2 deletions rustdf/src/data/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,36 @@ extern crate rusqlite;
use rusqlite::{Connection, Result};
use std::path::Path;

#[derive(Debug, Clone)]
pub struct PasefMsMsMeta {
pub frame_id: i64,
pub scan_num_begin: i64,
pub scan_num_end: i64,
pub isolation_mz: f64,
pub isolation_width: f64,
pub collision_energy: f64,
pub precursor_id: i64,
}

#[derive(Debug, Clone)]
pub struct DDAPrecursorMeta {
pub precursor_id: i64,
pub precursor_mz_highest_intensity: f64,
pub precursor_mz_average: f64,
pub precursor_mz_monoisotopic: Option<f64>,
pub precursor_charge: Option<u32>,
pub precursor_average_scan_number: f64,
pub precursor_total_intensity: f64,
pub precursor_frame_id: i64,
}

#[derive(Debug, Clone)]
pub struct DDAPrecursorInfo {
pub precursor_id: i64,
pub precursor_mz_highest_intensity: f64,
pub precursor_mz_average: f64,
pub precursor_mz_monoisotopic: f64,
pub precursor_charge: i64,
pub precursor_mz_monoisotopic: Option<f64>,
pub precursor_charge: Option<i64>,
pub precursor_average_scan_number: f64,
pub precursor_total_intensity: f64,
pub precursor_frame_id: i64,
Expand Down Expand Up @@ -75,6 +99,58 @@ struct GlobalMetaInternal {
value: String,
}

pub fn read_dda_precursor_info(bruker_d_folder_name: &str) -> Result<Vec<DDAPrecursorInfo>, Box<dyn std::error::Error>> {
// Connect to the database
let db_path = Path::new(bruker_d_folder_name).join("analysis.tdf");
let conn = Connection::open(db_path)?;

// prepare the query
let rows: Vec<&str> = vec!["Id", "LargestPeakMz", "AverageMz", "MonoisotopicMz", "Charge", "ScanNumber", "Intensity", "Parent"];
let query = format!("SELECT {} FROM Precursors", rows.join(", "));

// execute the query
let frames_rows: Result<Vec<DDAPrecursorInfo>, _> = conn.prepare(&query)?.query_map([], |row| {
Ok(DDAPrecursorInfo {
precursor_id: row.get(0)?,
precursor_mz_highest_intensity: row.get(1)?,
precursor_mz_average: row.get(2)?,
precursor_mz_monoisotopic: row.get(3)?, // Now using Option<f64>
precursor_charge: row.get(4)?, // Now using Option<i64>
precursor_average_scan_number: row.get(5)?,
precursor_total_intensity: row.get(6)?,
precursor_frame_id: row.get(7)?,
})
})?.collect();

// return the frames
Ok(frames_rows?)
}

pub fn read_pasef_frame_ms_ms_info(bruker_d_folder_name: &str) -> Result<Vec<PasefMsMsMeta>, Box<dyn std::error::Error>> {
// Connect to the database
let db_path = Path::new(bruker_d_folder_name).join("analysis.tdf");
let conn = Connection::open(db_path)?;

// prepare the query
let rows: Vec<&str> = vec!["Frame", "ScanNumBegin", "ScanNumEnd", "IsolationMz", "IsolationWidth", "CollisionEnergy", "Precursor"];
let query = format!("SELECT {} FROM PasefFrameMsMsInfo", rows.join(", "));

// execute the query
let frames_rows: Result<Vec<PasefMsMsMeta>, _> = conn.prepare(&query)?.query_map([], |row| {
Ok(PasefMsMsMeta {
frame_id: row.get(0)?,
scan_num_begin: row.get(1)?,
scan_num_end: row.get(2)?,
isolation_mz: row.get(3)?,
isolation_width: row.get(4)?,
collision_energy: row.get(5)?,
precursor_id: row.get(6)?, })
})?.collect();

// return the frames
Ok(frames_rows?)
}

// Read the global meta data from the analysis.tdf file
pub fn read_global_meta_sql(bruker_d_folder_name: &str) -> Result<GlobalMetaData, Box<dyn std::error::Error>> {

Expand Down
50 changes: 11 additions & 39 deletions rustdf/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,49 +1,21 @@
// use rustdf::data::handle::TimsDataHandle;
use std::env;
use std::path::Path;
use rusqlite::{Connection, Result};
use rustdf::data::meta::{FrameMeta};
use rustdf::data::meta::{read_dda_precursor_info};

fn main() -> Result<()> {

fn main() {
let _args: Vec<String> = env::args().collect();

let data_path = "/media/hd01/CCSPred/M210115_001_Slot1-1_1_850.d";
// Connect to the database
let db_path = Path::new(data_path).join("analysis.tdf");
let conn = Connection::open(db_path)?;

// prepare the query
let rows: Vec<&str> = vec!["Id", "Time", "ScanMode", "Polarity", "MsMsType", "TimsId", "MaxIntensity", "SummedIntensities",
"NumScans", "NumPeaks", "MzCalibration", "T1", "T2", "TimsCalibration", "PropertyGroup", "AccumulationTime", "RampTime"];
let query = format!("SELECT {} FROM Frames", rows.join(", "));

// execute the query
let frames_rows: Result<Vec<FrameMeta>, _> = conn.prepare(&query)?.query_map([], |row| {
Ok(FrameMeta {
id: row.get(0)?,
time: row.get(1)?,
scan_mode: row.get(2)?,
polarity: row.get(3)?,
ms_ms_type: row.get(4)?,
tims_id: row.get(5)?,
max_intensity: row.get(6)?,
sum_intensity: row.get(7)?,
num_scans: row.get(8)?,
num_peaks: row.get(9)?,
mz_calibration: row.get(10)?,
t_1: row.get(11)?,
t_2: row.get(12)?,
tims_calibration: row.get(13)?,
property_group: row.get(14)?,
accumulation_time: row.get(15)?,
ramp_time: row.get(16)?,
})
})?.collect();
let result = read_dda_precursor_info(data_path);

for row in frames_rows? {
println!("FrameMeta: {:?}", row);
match result {
Ok(precursors) => {
println!("Precursors: {:?}", precursors);
},
Err(e) => {
println!("Error: {:?}", e);
}
}

// return the frames
Ok(())
}

0 comments on commit 54d7f65

Please sign in to comment.