-
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: added dummy code to start refactoring spectrum readers
- Loading branch information
1 parent
45e37d1
commit 5717c6d
Showing
3 changed files
with
114 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
pub mod minitdf; | ||
pub mod tdf; | ||
|
||
use core::fmt; | ||
use std::path::{Path, PathBuf}; | ||
|
||
use minitdf::MiniTDFSpectrumReader; | ||
use tdf::TDFSpectrumReader; | ||
|
||
use crate::ms_data::Spectrum; | ||
|
||
pub struct SpectrumReader { | ||
spectrum_reader: Box<dyn SpectrumReaderTrait>, | ||
} | ||
|
||
impl fmt::Debug for SpectrumReader { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "SpectrumReader {{ /* fields omitted */ }}") | ||
} | ||
} | ||
|
||
impl SpectrumReader { | ||
pub fn new(path: impl AsRef<Path>) -> Self { | ||
let spectrum_reader: Box<dyn SpectrumReaderTrait> = | ||
match path.as_ref().extension().and_then(|e| e.to_str()) { | ||
Some("parquet") => Box::new(MiniTDFSpectrumReader::new(path)), | ||
Some("tdf") => Box::new(TDFSpectrumReader::new(path)), | ||
_ => panic!(), | ||
}; | ||
Self { spectrum_reader } | ||
} | ||
|
||
pub fn get(&self, index: usize) -> Spectrum { | ||
self.spectrum_reader.get(index) | ||
} | ||
|
||
pub fn get_path(&self) -> PathBuf { | ||
self.spectrum_reader.get_path() | ||
} | ||
|
||
pub fn len(&self) -> usize { | ||
self.spectrum_reader.len() | ||
} | ||
} | ||
|
||
trait SpectrumReaderTrait: Sync { | ||
fn get(&self, index: usize) -> Spectrum; | ||
fn get_path(&self) -> PathBuf; | ||
fn len(&self) -> usize; | ||
} |
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,32 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
use crate::ms_data::Spectrum; | ||
|
||
use super::SpectrumReaderTrait; | ||
|
||
#[derive(Debug)] | ||
pub struct MiniTDFSpectrumReader { | ||
path: PathBuf, | ||
} | ||
|
||
impl MiniTDFSpectrumReader { | ||
pub fn new(path: impl AsRef<Path>) -> Self { | ||
Self { | ||
path: path.as_ref().to_path_buf(), | ||
} | ||
} | ||
} | ||
|
||
impl SpectrumReaderTrait for MiniTDFSpectrumReader { | ||
fn get(&self, index: usize) -> Spectrum { | ||
Spectrum::default() | ||
} | ||
|
||
fn len(&self) -> usize { | ||
0 //TODO | ||
} | ||
|
||
fn get_path(&self) -> PathBuf { | ||
self.path.clone() | ||
} | ||
} |
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,32 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
use crate::ms_data::Spectrum; | ||
|
||
use super::SpectrumReaderTrait; | ||
|
||
#[derive(Debug)] | ||
pub struct TDFSpectrumReader { | ||
path: PathBuf, | ||
} | ||
|
||
impl TDFSpectrumReader { | ||
pub fn new(path: impl AsRef<Path>) -> Self { | ||
Self { | ||
path: path.as_ref().to_path_buf(), | ||
} | ||
} | ||
} | ||
|
||
impl SpectrumReaderTrait for TDFSpectrumReader { | ||
fn get(&self, index: usize) -> Spectrum { | ||
Spectrum::default() | ||
} | ||
|
||
fn len(&self) -> usize { | ||
0 //TODO | ||
} | ||
|
||
fn get_path(&self) -> PathBuf { | ||
self.path.clone() | ||
} | ||
} |