-
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.
CHORE: reorganize specrum reader code
- Loading branch information
1 parent
3f49454
commit d4b71dd
Showing
7 changed files
with
132 additions
and
111 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
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
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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use crate::readers::{TimsTofFileType, TimsTofPath, TimsTofPathLike}; | ||
|
||
use super::{ | ||
errors::SpectrumReaderError, SpectrumReader, SpectrumReaderConfig, | ||
SpectrumReaderTrait, | ||
}; | ||
|
||
#[cfg(feature = "minitdf")] | ||
use super::minitdf::MiniTDFSpectrumReader; | ||
#[cfg(feature = "tdf")] | ||
use super::tdf::TDFSpectrumReader; | ||
|
||
#[derive(Debug, Default, Clone)] | ||
pub struct SpectrumReaderBuilder { | ||
path: Option<TimsTofPath>, | ||
config: SpectrumReaderConfig, | ||
} | ||
|
||
impl SpectrumReaderBuilder { | ||
pub fn with_path(&self, path: impl TimsTofPathLike) -> Self { | ||
// TODO | ||
let path = Some(path.to_timstof_path().unwrap()); | ||
Self { | ||
path, | ||
..self.clone() | ||
} | ||
} | ||
|
||
pub fn with_config(&self, config: SpectrumReaderConfig) -> Self { | ||
Self { | ||
config: config, | ||
..self.clone() | ||
} | ||
} | ||
|
||
pub fn finalize(self) -> Result<SpectrumReader, SpectrumReaderError> { | ||
let path = match self.path { | ||
None => return Err(SpectrumReaderError::NoPath), | ||
Some(path) => path, | ||
}; | ||
let spectrum_reader: Box<dyn SpectrumReaderTrait> = | ||
match path.file_type() { | ||
#[cfg(feature = "minitdf")] | ||
TimsTofFileType::MiniTDF => { | ||
Box::new(MiniTDFSpectrumReader::new(path)?) | ||
}, | ||
#[cfg(feature = "tdf")] | ||
TimsTofFileType::TDF => { | ||
Box::new(TDFSpectrumReader::new(path, self.config)?) | ||
}, | ||
}; | ||
let mut reader = SpectrumReader { spectrum_reader }; | ||
if self.config.spectrum_processing_params.calibrate { | ||
reader.calibrate(); | ||
} | ||
Ok(reader) | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#[cfg(feature = "tdf")] | ||
use super::super::FrameWindowSplittingConfiguration; | ||
|
||
#[cfg(feature = "serialize")] | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, Clone, Copy)] | ||
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] | ||
pub struct SpectrumProcessingParams { | ||
pub smoothing_window: u32, | ||
pub centroiding_window: u32, | ||
pub calibration_tolerance: f64, | ||
pub calibrate: bool, | ||
} | ||
|
||
impl Default for SpectrumProcessingParams { | ||
fn default() -> Self { | ||
Self { | ||
smoothing_window: 1, | ||
centroiding_window: 1, | ||
calibration_tolerance: 0.1, | ||
calibrate: false, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug, Default, Clone, Copy)] | ||
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))] | ||
pub struct SpectrumReaderConfig { | ||
pub spectrum_processing_params: SpectrumProcessingParams, | ||
#[cfg(feature = "tdf")] | ||
pub frame_splitting_params: FrameWindowSplittingConfiguration, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#[cfg(feature = "minitdf")] | ||
use super::minitdf::MiniTDFSpectrumReaderError; | ||
#[cfg(feature = "tdf")] | ||
use super::tdf::TDFSpectrumReaderError; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum SpectrumReaderError { | ||
#[cfg(feature = "minitdf")] | ||
#[error("{0}")] | ||
MiniTDFSpectrumReaderError(#[from] MiniTDFSpectrumReaderError), | ||
#[cfg(feature = "tdf")] | ||
#[error("{0}")] | ||
TDFSpectrumReaderError(#[from] TDFSpectrumReaderError), | ||
#[error("No path provided")] | ||
NoPath, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use crate::Spectrum; | ||
|
||
use super::errors::SpectrumReaderError; | ||
|
||
pub(crate) trait SpectrumReaderTrait: Sync + Send { | ||
fn get(&self, index: usize) -> Result<Spectrum, SpectrumReaderError>; | ||
fn len(&self) -> usize; | ||
fn calibrate(&mut self); | ||
} |