Esempio n. 1
0
 private static int? ValidateFormulaWithMz(SrmDocument document, ref string moleculeFormula, double mz, int? charge, out double monoMass, out double averageMass, out double? mzCalc)
 {
     // Is the ion's formula the old style where user expected us to add a hydrogen?
     var tolerance = document.Settings.TransitionSettings.Instrument.MzMatchTolerance;
     int massShift;
     var ion = new DocNodeCustomIon(moleculeFormula);
     monoMass = ion.GetMass(MassType.Monoisotopic);
     averageMass = ion.GetMass(MassType.Average);
     double mass = (document.Settings.TransitionSettings.Prediction.FragmentMassType == MassType.Monoisotopic)
         ? monoMass
         : averageMass;
     // Does given charge, if any, agree with mass and mz?
     mzCalc = charge.HasValue ? BioMassCalc.CalculateIonMz(mass, charge.Value) : (double?)null;
     if (mzCalc.HasValue && tolerance >= (Math.Abs(mzCalc.Value - mz)))
     {
         return charge;
     }
     int nearestCharge;
     charge = TransitionCalc.CalcCharge(mass, mz, tolerance, true, TransitionGroup.MIN_PRECURSOR_CHARGE,
         TransitionGroup.MAX_PRECURSOR_CHARGE, new int[0],
         TransitionCalc.MassShiftType.none, out massShift, out nearestCharge);
     if (!charge.HasValue)
     {
         // That formula and this mz don't yield a reasonable charge state - try adding an H
         var ion2 = new DocNodeCustomIon(BioMassCalc.AddH(ion.Formula));
         monoMass = ion2.GetMass(MassType.Monoisotopic);
         averageMass = ion2.GetMass(MassType.Average);
         mass = (document.Settings.TransitionSettings.Prediction.FragmentMassType == MassType.Monoisotopic)
             ? monoMass
             : averageMass;
         charge = TransitionCalc.CalcCharge(mass, mz, tolerance, true, TransitionGroup.MIN_PRECURSOR_CHARGE,
             TransitionGroup.MAX_PRECURSOR_CHARGE, new int[0], TransitionCalc.MassShiftType.none, out massShift, out nearestCharge);
         if (charge.HasValue)
         {
             moleculeFormula = ion2.Formula;
         }
         else
         {
             monoMass = 0;
             averageMass = 0;
         }
     }
     return charge;
 }
Esempio n. 2
0
 private double ValidateFormulaWithCharge(SrmDocument document, string moleculeFormula, int charge, out double monoMass, out double averageMass)
 {
     var massType = document.Settings.TransitionSettings.Prediction.PrecursorMassType;
     var ion = new DocNodeCustomIon(moleculeFormula);
     double mass = ion.GetMass(massType);
     monoMass = ion.GetMass(MassType.Monoisotopic);
     averageMass = ion.GetMass(MassType.Average);
     return BioMassCalc.CalculateIonMz(mass, charge);
 }