-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: updated TdfReader to use frameReader instead
- Loading branch information
1 parent
c2aada8
commit 02bc4e5
Showing
2 changed files
with
46 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,124 +1,54 @@ | ||
use { | ||
crate::{ | ||
domain_converters::{ | ||
ConvertableDomain, Frame2RtConverter, Scan2ImConverter, | ||
Tof2MzConverter, | ||
}, | ||
file_readers::{ | ||
common::{ | ||
ms_data_blobs::ReadableFromBinFile, | ||
sql_reader::{FrameTable, ReadableFromSql, SqlReader}, | ||
}, | ||
ReadableFrames, | ||
}, | ||
io::readers::common::tdf_blobs::TdfBlobReader, | ||
ms_data::{AcquisitionType, Frame, MSLevel, QuadrupoleSettings}, | ||
use crate::{ | ||
domain_converters::{Frame2RtConverter, Scan2ImConverter, Tof2MzConverter}, | ||
file_readers::{ | ||
common::sql_reader::{ReadableFromSql, SqlReader}, | ||
ReadableFrames, | ||
}, | ||
rayon::prelude::*, | ||
std::{path::Path, sync::Arc}, | ||
io::readers::frame_reader::FrameReader, | ||
ms_data::Frame, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct TDFReader { | ||
pub path: String, | ||
frame_reader: FrameReader, | ||
pub tdf_sql_reader: SqlReader, | ||
tdf_bin_reader: TdfBlobReader, | ||
pub rt_converter: Frame2RtConverter, | ||
pub im_converter: Scan2ImConverter, | ||
pub mz_converter: Tof2MzConverter, | ||
pub frame_table: FrameTable, | ||
pub acquisition: AcquisitionType, | ||
ms_levels: Vec<MSLevel>, | ||
} | ||
|
||
impl TDFReader { | ||
pub fn new(path: &String) -> Self { | ||
let tdf_sql_reader: SqlReader = SqlReader { | ||
path: String::from(path), | ||
}; | ||
let frame_table: FrameTable = FrameTable::from_sql(&tdf_sql_reader); | ||
let file_name: String = Path::new(&path) | ||
.join("analysis.tdf_bin") | ||
.to_string_lossy() | ||
.to_string(); | ||
let tdf_bin_reader: TdfBlobReader = TdfBlobReader::new( | ||
String::from(&file_name), | ||
frame_table.offsets.iter().map(|x| *x as usize).collect(), | ||
) | ||
.unwrap(); | ||
let ms_levels: Vec<MSLevel> = frame_table | ||
.msms_type | ||
.iter() | ||
.map(|msms_type| match msms_type { | ||
0 => MSLevel::MS1, | ||
8 => MSLevel::MS2, | ||
9 => MSLevel::MS2, | ||
_ => MSLevel::Unknown, | ||
}) | ||
.collect(); | ||
let mut acquisition = AcquisitionType::Unknown; | ||
if frame_table.msms_type.contains(&8) { | ||
acquisition = AcquisitionType::DDAPASEF; | ||
} else if frame_table.msms_type.contains(&9) { | ||
acquisition = AcquisitionType::DIAPASEF; | ||
} | ||
let frame_reader: FrameReader = FrameReader::new(&path); | ||
Self { | ||
path: path.to_string(), | ||
tdf_bin_reader: tdf_bin_reader, | ||
rt_converter: Self::get_rt_converter(&frame_table), | ||
rt_converter: Frame2RtConverter::from_values( | ||
frame_reader.sql_frames.iter().map(|x| x.rt).collect(), | ||
), | ||
im_converter: Scan2ImConverter::from_sql(&tdf_sql_reader), | ||
mz_converter: Tof2MzConverter::from_sql(&tdf_sql_reader), | ||
frame_table: frame_table, | ||
tdf_sql_reader: tdf_sql_reader, | ||
ms_levels: ms_levels, | ||
acquisition: acquisition, | ||
frame_reader: frame_reader, | ||
} | ||
} | ||
|
||
fn get_rt_converter(frame_table: &FrameTable) -> Frame2RtConverter { | ||
let retention_times: Vec<f64> = frame_table.rt.clone(); | ||
Frame2RtConverter::from_values(retention_times) | ||
} | ||
} | ||
|
||
impl ReadableFrames for TDFReader { | ||
fn read_single_frame(&self, index: usize) -> Frame { | ||
let mut frame: Frame = | ||
Frame::read_from_file(&self.tdf_bin_reader, index); | ||
frame.rt = self.rt_converter.convert(index as u32); | ||
frame.index = self.frame_table.id[index]; | ||
frame.ms_level = self.ms_levels[index]; | ||
frame.acquisition_type = self.acquisition; | ||
if frame.ms_level == MSLevel::MS2 { | ||
frame.quadrupole_settings = Arc::new(QuadrupoleSettings::default()); | ||
} | ||
frame | ||
self.frame_reader.get(index) | ||
} | ||
|
||
fn read_all_frames(&self) -> Vec<Frame> { | ||
(0..self.tdf_bin_reader.len()) | ||
.into_par_iter() | ||
.map(|index| self.read_single_frame(index)) | ||
.collect() | ||
self.frame_reader.collect(|_| true) | ||
} | ||
|
||
fn read_all_ms1_frames(&self) -> Vec<Frame> { | ||
(0..self.tdf_bin_reader.len()) | ||
.into_par_iter() | ||
.map(|index| match self.ms_levels[index] { | ||
MSLevel::MS1 => self.read_single_frame(index), | ||
_ => Frame::default(), | ||
}) | ||
.collect() | ||
self.frame_reader.collect(|x| x.msms_type == 0) | ||
} | ||
|
||
fn read_all_ms2_frames(&self) -> Vec<Frame> { | ||
(0..self.tdf_bin_reader.len()) | ||
.into_par_iter() | ||
.map(|index| match self.ms_levels[index] { | ||
MSLevel::MS2 => self.read_single_frame(index), | ||
_ => Frame::default(), | ||
}) | ||
.collect() | ||
self.frame_reader.collect(|x| x.msms_type != 0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters