Skip to content

Commit

Permalink
Start on isotope matching #21
Browse files Browse the repository at this point in the history
Signed-off-by: Douwe Schulte <[email protected]>
  • Loading branch information
douweschulte committed Apr 10, 2024
1 parent c42a20d commit eea011f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"Cargoxy",
"centroiding",
"consts",
"daltons",
"deamidated",
"Deamidation",
"Decose",
Expand Down
31 changes: 23 additions & 8 deletions rustyms/src/spectrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl RawSpectrum {
{
annotated.spectrum[closest.0]
.annotation
.push(fragment.clone());
.push((fragment.clone(), Vec::new()));
}
}

Expand Down Expand Up @@ -444,7 +444,7 @@ impl AnnotatedSpectrum {
let number = p
.annotation
.iter()
.filter(|a| {
.filter(|(a, _)| {
peptide_index.map_or(true, |i| a.peptide_index == i)
&& ion.map_or(true, |kind| a.ion.kind() == kind)
})
Expand Down Expand Up @@ -481,11 +481,11 @@ impl AnnotatedSpectrum {
.flat_map(|p| {
p.annotation
.iter()
.filter(|a| {
.filter(|(a, _)| {
a.peptide_index == peptide_index
&& ion.map_or(true, |kind| a.ion.kind() == kind)
})
.filter_map(|a| a.ion.position())
.filter_map(|(a, _)| a.ion.position())
})
.map(|pos| pos.sequence_index)
.unique()
Expand All @@ -500,12 +500,12 @@ impl AnnotatedSpectrum {
let num_annotated = spectrum
.iter()
.flat_map(|p| {
p.annotation.iter().filter(|a| {
p.annotation.iter().filter(|(a, _)| {
peptide_index.map_or(true, |i| a.peptide_index == i)
&& ion.map_or(true, |kind| a.ion.kind() == kind)
})
})
.map(|f| f.formula.clone())
.map(|(f, _)| f.formula.clone())
.unique()
.count() as u32;
let total_fragments = fragments
Expand Down Expand Up @@ -863,6 +863,17 @@ impl RawPeak {
}
}

/// An isotope annotation.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub struct MatchedIsotopeDistribution {
/// The index of the matched peak in the spectrum, if found
pub peak_index: Option<usize>,
/// The isotope offset in whole daltons from the monoisotopic peak
pub isotope_offset: usize,
/// The theoretical abundance of this isotope (normalised to 1 for the whole distribution)
pub theoretical_isotope_abundance: OrderedFloat<f64>,
}

/// An annotated peak
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct AnnotatedPeak {
Expand All @@ -873,7 +884,9 @@ pub struct AnnotatedPeak {
/// The charge
pub charge: Charge, // TODO: Is this item needed? (mgf has it, not used in rustyms)
/// The annotation, if present
pub annotation: Vec<Fragment>,
pub annotation: Vec<(Fragment, Vec<MatchedIsotopeDistribution>)>,
/// Any annotation as isotope from a given fragment
pub isotope_annotation: Vec<(usize, usize)>,
}

impl AnnotatedPeak {
Expand All @@ -883,7 +896,8 @@ impl AnnotatedPeak {
experimental_mz: peak.mz,
intensity: peak.intensity,
charge: peak.charge,
annotation: vec![annotation],
annotation: vec![(annotation, Vec::new())],
isotope_annotation: Vec::new(),
}
}

Expand All @@ -894,6 +908,7 @@ impl AnnotatedPeak {
intensity: peak.intensity,
charge: peak.charge,
annotation: Vec::new(),
isotope_annotation: Vec::new(),
}
}
}
Expand Down

0 comments on commit eea011f

Please sign in to comment.