-
Notifications
You must be signed in to change notification settings - Fork 11
Fix/minute division #100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/minute division #100
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| //! Handle converting [`Attribute`]s to and from [`SpectrumDescription`] | ||
| use std::borrow::Cow; | ||
| use std::{borrow::Cow, hint::black_box}; | ||
|
|
||
| use context_error::{BoxedError, Context, CreateError}; | ||
| use mzcv::{AccessionCode, Curie, Term, curie, term}; | ||
|
|
@@ -287,49 +287,66 @@ pub(crate) fn populate_spectrum_description_from_attributes<'a>( | |
|
|
||
| if let Some((Attribute { value, .. }, context)) = | ||
| group.iter().find(|a| a.0.name.accession == curie!(MS:1000894)) | ||
| && group.len() == 2 | ||
| && group.len() >= 2 | ||
| { | ||
| description.acquisition.scans[0].start_time = | ||
| f64::from(value.scalar().to_f32().map_err(|v| { | ||
| BoxedError::new( | ||
| MzSpecLibErrorKind::Attribute, | ||
| "Invalid attribute", | ||
| v.to_string(), | ||
| context.clone(), | ||
| ) | ||
| })?) / match unit.ok_or_else(|| { | ||
| BoxedError::new( | ||
| MzSpecLibErrorKind::MissingUnit, | ||
| "Invalid attribute", | ||
| "MS:1000894|retention time needs a unit", | ||
| context.clone(), | ||
| ) | ||
| })? { | ||
| Unit::Minute => 60.0, | ||
| _ => 1.0, // Assume seconds for anything else | ||
| }; | ||
| let enumerator = f64::from(value.scalar().to_f32().map_err(|v| { | ||
| BoxedError::new( | ||
| MzSpecLibErrorKind::Attribute, | ||
| "Invalid attribute", | ||
| v.to_string(), | ||
| context.clone(), | ||
| ) | ||
| })?); | ||
| let divisor = match unit.ok_or_else(|| { | ||
| BoxedError::new( | ||
| MzSpecLibErrorKind::MissingUnit, | ||
| "Invalid attribute", | ||
| "MS:1000894|retention time needs a unit", | ||
| context.clone(), | ||
| ) | ||
| })? { | ||
| Unit::Minute => 1.0, | ||
| Unit::Millisecond => 60.0 * (1000.0), | ||
| Unit::Second => 60.0, | ||
| _ => { | ||
| black_box(()); // We should probably warn here | ||
| 1.0 // Assume minutes for anything else | ||
| } | ||
| }; | ||
|
|
||
| // Start time is meant to be represented in "minutes" | ||
| description.acquisition.scans[0].start_time = enumerator / divisor; | ||
| } else if let Some((Attribute { value, .. }, context)) = | ||
| group.iter().find(|a| a.0.name.accession == curie!(MS:1000896)) | ||
| && group.len() == 2 | ||
| && group.len() >= 2 | ||
| { | ||
| let rt = f64::from(value.scalar().to_f32().map_err(|v| { | ||
| let enumerator = f64::from(value.scalar().to_f32().map_err(|v| { | ||
| BoxedError::new( | ||
| MzSpecLibErrorKind::Attribute, | ||
| "Invalid attribute", | ||
| v.to_string(), | ||
| context.clone(), | ||
| ) | ||
| })?) / match unit.ok_or_else(|| { | ||
| })?); | ||
|
|
||
| let denominator = match unit.ok_or_else(|| { | ||
| BoxedError::new( | ||
| MzSpecLibErrorKind::MissingUnit, | ||
| "Invalid attribute", | ||
| "MS:1000896|normalized retention time needs a unit", | ||
| context.clone(), | ||
| ) | ||
| })? { | ||
| Unit::Minute => 60.0, | ||
| _ => 1.0, // Assume seconds for anything else | ||
| Unit::Minute => 1.0, | ||
| Unit::Millisecond => 60.0 * (1000.0), | ||
| Unit::Second => 60.0, | ||
| _ => { | ||
| black_box(()); // We should probably warn here | ||
| 1.0 // Assume minutes for anything else | ||
| } | ||
| }; | ||
| let rt = enumerator / denominator; | ||
|
|
||
| // This is normalised time so if normal time is already set ignore this param | ||
| if description.acquisition.scans[0].start_time == 0.0 { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: This "sentinel value conditional" could introduce a bug if a library has both indexed and non-indexed retention times. since the indexed time CAN have values of 0.0. Imagine spectrum 1 defines iRT= -5, RT = 5 -> assigns -5 (bc the second pass does not over-write the 0.0) as the RT. then spectrum 2 defined iRT=0.0 and RT = 10 -> assigns 10 (because the second pass does over-write it) |
||
| description.acquisition.scans[0].start_time = rt; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I am struggling a bit on how to represent this in my libraries ... if my library is in "biognosys iRT scale"... it feels wrong to set minutes, when the values can be negative.