Skip to content

Commit

Permalink
FEAT: added correct reading of compression type for frame reader
Browse files Browse the repository at this point in the history
  • Loading branch information
sander-willems-bruker committed Sep 18, 2024
1 parent 3538d5f commit 2a7f6bf
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/io/readers/frame_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use super::{
},
tdf_blob_reader::{TdfBlob, TdfBlobReader, TdfBlobReaderError},
},
QuadrupoleSettingsReader, QuadrupoleSettingsReaderError,
MetadataReader, MetadataReaderError, QuadrupoleSettingsReader,
QuadrupoleSettingsReaderError,
};

#[derive(Debug)]
Expand All @@ -30,13 +31,24 @@ pub struct FrameReader {
acquisition: AcquisitionType,
offsets: Vec<usize>,
dia_windows: Option<Vec<Arc<QuadrupoleSettings>>>,
compression_type: u8,
}

impl FrameReader {
pub fn new(path: impl AsRef<Path>) -> Result<Self, FrameReaderError> {
let sql_path = find_extension(&path, "analysis.tdf").ok_or(
FrameReaderError::FileNotFound("analysis.tdf".to_string()),
)?;
let compression_type =
match MetadataReader::new(&sql_path)?.compression_type {
2 => 2,
compression_type => {
return Err(FrameReaderError::CompressionTypeError(
compression_type,
))
},
};

let tdf_sql_reader = SqlReader::open(sql_path)?;
let sql_frames = SqlFrame::from_sql_reader(&tdf_sql_reader)?;
let bin_path = find_extension(&path, "analysis.tdf_bin").ok_or(
Expand Down Expand Up @@ -92,6 +104,7 @@ impl FrameReader {
AcquisitionType::DIAPASEF => Some(quadrupole_settings),
_ => None,
},
compression_type,
};
Ok(reader)
}
Expand All @@ -112,6 +125,18 @@ impl FrameReader {
}

pub fn get(&self, index: usize) -> Result<Frame, FrameReaderError> {
match self.compression_type {
2 => self.get_from_compression_type_2(index),
_ => Err(FrameReaderError::CompressionTypeError(
self.compression_type,
)),
}
}

pub fn get_from_compression_type_2(
&self,
index: usize,
) -> Result<Frame, FrameReaderError> {
// NOTE: get does it by 0-offsetting the vec, not by Frame index!!!
let mut frame = self.get_frame_without_coordinates(index)?;
let offset = self.offsets[index];
Expand Down

0 comments on commit 2a7f6bf

Please sign in to comment.