macpepdb 1.1.0

Large peptide database for mass spectrometry
Documentation
// std imports
use std::ops::Deref;

// 3rd party imports
use anyhow::{bail, Result};
use dihardts_omicstools::chemistry::amino_acid::*;

// internal imports
use crate::chemistry::molecule::WATER_MONO_MASS;

/// Internal representation of an amino acid
/// It basically wraps the omicstools amino acid and adds the mass as integer
/// to prevent floating point errors
///
pub struct InternalAminoAcid {
    inner_amino_acid: &'static dyn AminoAcid,
    mono_mass_int: i64,
}

impl InternalAminoAcid {
    /// Returns mass as MaCPepDBs integer representation
    ///
    pub fn get_mono_mass_int(&self) -> &i64 {
        &self.mono_mass_int
    }
}

impl Deref for InternalAminoAcid {
    type Target = dyn AminoAcid;

    fn deref(&self) -> &Self::Target {
        self.inner_amino_acid
    }
}

// This file is generated by build.rs
// Do not edit manually!
// It builds the internal amino acids with integer mass
// and the get_internal_amino_acid_by_one_letter_code function
include!(concat!(env!("OUT_DIR"), "/amino_acid.rs"));

/// Calculates the theoretical mass of a sequence in Dalton and returns in internal integer representation
///
/// # Arguments
/// * `sequence` - Amino acid sequence
///
pub fn calc_sequence_mass_int(sequence: &str) -> Result<i64> {
    let mut mass: i64 = *WATER_MONO_MASS;
    for c in sequence.chars() {
        mass += get_internal_amino_acid_by_one_letter_code(c)?.get_mono_mass_int();
    }
    Ok(mass)
}