Exemple #1
0
        /// <summary>
        /// Synchronizes the masses of an <see cref="IsotopeAbundances"/> object with
        /// the masses of this <see cref="BioMassCalc"/>, ensuring compatible mass calculations
        /// using the different classes.  This is only allowed with a monoisotopic mass calculator.
        /// </summary>
        /// <param name="abundances">An existing <see cref="IsotopeAbundances"/> object to be synchronized</param>
        /// <returns>An <see cref="IsotopeAbundances"/> object synchronized with this <see cref="BioMassCalc"/></returns>
        public IsotopeAbundances SynchMasses(IsotopeAbundances abundances)
        {
            if (MassType != MassType.Monoisotopic)
            {
                throw new InvalidOperationException(
                          Resources.
                          BioMassCalc_SynchMasses_Fixing_isotope_abundance_masses_requires_a_monoisotopic_mass_calculator);
            }

            var dictFixes = new Dictionary <string, MassDistribution>();

            foreach (var atomAbundance in abundances)
            {
                double monoMassCalc;
                if (!_atomicMasses.TryGetValue(atomAbundance.Key, out monoMassCalc))
                {
                    continue;
                }
                double secondMassCalc, thirdMassCalc;
                _atomicMasses.TryGetValue(atomAbundance.Key + "'", out secondMassCalc); // Not L10N
                _atomicMasses.TryGetValue(atomAbundance.Key + "\"", out thirdMassCalc); // Not L10N
                var massDist      = atomAbundance.Value;
                var massDistFixed = SynchDist(massDist, monoMassCalc, secondMassCalc, thirdMassCalc);
                if (!ReferenceEquals(massDist, massDistFixed))
                {
                    dictFixes.Add(atomAbundance.Key, massDistFixed);
                }
            }
            return(abundances.SetAbundances(dictFixes));
        }
Exemple #2
0
        /// <summary>
        /// Ensure that the entries for D and T are the same as the entries for H' and H".
        /// </summary>
        public static IsotopeAbundances AddHeavyNicknames(IsotopeAbundances isotopeAbundances)
        {
            var changes = new Dictionary <string, MassDistribution>();

            foreach (var kvp in DICT_HEAVYSYMBOL_NICKNAMES)
            {
                MassDistribution massDistribution;
                if (isotopeAbundances.TryGetValue(kvp.Value, out massDistribution))
                {
                    changes.Add(kvp.Key, massDistribution);
                }
            }

            return(isotopeAbundances.SetAbundances(changes));
        }
Exemple #3
0
        /// <summary>
        /// Synchronizes the masses of an <see cref="IsotopeAbundances"/> object with
        /// the masses of this <see cref="BioMassCalc"/>, ensuring compatible mass calculations
        /// using the different classes.  This is only allowed with a monoisotopic mass calculator.
        /// </summary>
        /// <param name="abundances">An existing <see cref="IsotopeAbundances"/> object to be synchronized</param>
        /// <returns>An <see cref="IsotopeAbundances"/> object synchronized with this <see cref="BioMassCalc"/></returns>
        public IsotopeAbundances SynchMasses(IsotopeAbundances abundances)
        {
            if (MassType != MassType.Monoisotopic)
                throw new InvalidOperationException(
                    Resources.
                        BioMassCalc_SynchMasses_Fixing_isotope_abundance_masses_requires_a_monoisotopic_mass_calculator);

            var dictFixes = new Dictionary<string, MassDistribution>();
            foreach (var atomAbundance in abundances)
            {
                double monoMassCalc;
                if (!_atomicMasses.TryGetValue(atomAbundance.Key, out monoMassCalc))
                    continue;
                double secondMassCalc, thirdMassCalc;
                _atomicMasses.TryGetValue(atomAbundance.Key + "'", out secondMassCalc); // Not L10N
                _atomicMasses.TryGetValue(atomAbundance.Key + "\"", out thirdMassCalc); // Not L10N
                var massDist = atomAbundance.Value;
                var massDistFixed = SynchDist(massDist, monoMassCalc, secondMassCalc, thirdMassCalc);
                if (!ReferenceEquals(massDist, massDistFixed))
                    dictFixes.Add(atomAbundance.Key, massDistFixed);
            }
            return abundances.SetAbundances(dictFixes);
        }