Skip to content

Commit

Permalink
FEAT: added dummy code to start refactoring spectrum readers
Browse files Browse the repository at this point in the history
  • Loading branch information
sander-willems-bruker committed Jun 25, 2024
1 parent 45e37d1 commit 5717c6d
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/io/readers/spectrum_reader.rs
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;
}
32 changes: 32 additions & 0 deletions src/io/readers/spectrum_reader/minitdf.rs
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()
}
}
32 changes: 32 additions & 0 deletions src/io/readers/spectrum_reader/tdf.rs
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()
}
}

0 comments on commit 5717c6d

Please sign in to comment.