-
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.
Merge pull request #19 from MannLabs/develop
Develop
- Loading branch information
Showing
78 changed files
with
2,385 additions
and
1,639 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 |
---|---|---|
|
@@ -12,9 +12,7 @@ env: | |
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Build | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
//! Allows conversions between domains (e.g. Time of Flight and m/z) | ||
mod frame_to_rt; | ||
mod scan_to_im; | ||
mod tof_to_mz; | ||
|
||
pub use frame_to_rt::Frame2RtConverter; | ||
pub use scan_to_im::Scan2ImConverter; | ||
pub use tof_to_mz::Tof2MzConverter; | ||
|
||
/// Convert from one domain (e.g. Time of Flight) to another (m/z). | ||
pub trait ConvertableDomain { | ||
fn convert<T: Into<f64> + Copy>(&self, value: T) -> f64; | ||
} |
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,19 @@ | ||
/// A converter from Frame -> retention time. | ||
#[derive(Debug, Clone)] | ||
pub struct Frame2RtConverter { | ||
rt_values: Vec<f64>, | ||
} | ||
|
||
impl Frame2RtConverter { | ||
pub fn from_values(rt_values: Vec<f64>) -> Self { | ||
Self { rt_values } | ||
} | ||
} | ||
|
||
impl super::ConvertableDomain for Frame2RtConverter { | ||
fn convert<T: Into<f64> + Copy>(&self, value: T) -> f64 { | ||
let lower_value: f64 = self.rt_values[value.into().floor() as usize]; | ||
let upper_value: f64 = self.rt_values[value.into().ceil() as usize]; | ||
(lower_value + upper_value) / 2. | ||
} | ||
} |
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,28 @@ | ||
/// A converter from Scan -> (inversed) ion mobility. | ||
#[derive(Debug, Clone)] | ||
pub struct Scan2ImConverter { | ||
scan_intercept: f64, | ||
scan_slope: f64, | ||
} | ||
|
||
impl Scan2ImConverter { | ||
pub fn from_boundaries( | ||
im_min: f64, | ||
im_max: f64, | ||
scan_max_index: u32, | ||
) -> Self { | ||
let scan_intercept: f64 = im_max; | ||
let scan_slope: f64 = (im_min - scan_intercept) / scan_max_index as f64; | ||
Self { | ||
scan_intercept, | ||
scan_slope, | ||
} | ||
} | ||
} | ||
|
||
impl super::ConvertableDomain for Scan2ImConverter { | ||
fn convert<T: Into<f64> + Copy>(&self, value: T) -> f64 { | ||
let scan_index_f64: f64 = value.into(); | ||
self.scan_intercept + self.scan_slope * scan_index_f64 | ||
} | ||
} |
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,42 @@ | ||
use linreg::linear_regression; | ||
|
||
/// A converter from TOF -> m/z. | ||
#[derive(Debug, Clone)] | ||
pub struct Tof2MzConverter { | ||
tof_intercept: f64, | ||
tof_slope: f64, | ||
} | ||
|
||
impl Tof2MzConverter { | ||
pub fn from_boundaries( | ||
mz_min: f64, | ||
mz_max: f64, | ||
tof_max_index: u32, | ||
) -> Self { | ||
let tof_intercept: f64 = mz_min.sqrt(); | ||
let tof_slope: f64 = | ||
(mz_max.sqrt() - tof_intercept) / tof_max_index as f64; | ||
Self { | ||
tof_intercept, | ||
tof_slope, | ||
} | ||
} | ||
|
||
pub fn from_pairs(data: &Vec<(f64, u32)>) -> Self { | ||
let x: Vec<u32> = data.iter().map(|(_, x_val)| *x_val).collect(); | ||
let y: Vec<f64> = | ||
data.iter().map(|(y_val, _)| (*y_val).sqrt()).collect(); | ||
let (tof_slope, tof_intercept) = linear_regression(&x, &y).unwrap(); | ||
Self { | ||
tof_intercept, | ||
tof_slope, | ||
} | ||
} | ||
} | ||
|
||
impl super::ConvertableDomain for Tof2MzConverter { | ||
fn convert<T: Into<f64> + Copy>(&self, value: T) -> f64 { | ||
let tof_index_f64: f64 = value.into(); | ||
(self.tof_intercept + self.tof_slope * tof_index_f64).powi(2) | ||
} | ||
} |
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,9 +1,16 @@ | ||
use crate::file_readers; | ||
use crate::{ | ||
file_readers, | ||
// io::readers::common::{sql_reader::SqlError, tdf_blobs::TdfBlobError}, | ||
}; | ||
|
||
/// An error that is produced by timsrust (uses [thiserror]). | ||
#[derive(thiserror::Error, Debug)] | ||
pub enum Error { | ||
/// An error to indicate a path is not a Bruker File Format. | ||
#[error("FileFormatError: {0}")] | ||
FileFormatError(#[from] file_readers::FileFormatError), | ||
// #[error("SqlError: {0}")] | ||
// SqlError(#[from] SqlError), | ||
// #[error("BinError: {0}")] | ||
// BinError(#[from] TdfBlobError), | ||
} |
Oops, something went wrong.