Beispiel #1
0
        public static SpectrumPeakAnnotation Create(SmallMoleculeLibraryAttributes mol, Adduct adduct, string comment, double?mzTheoretical)
        {
            double?massTheoretical = mzTheoretical.HasValue ? adduct.MassFromMz(mzTheoretical.Value, MassType.Monoisotopic).Value : (double?)null;
            var    ion             = new CustomIon(mol, adduct, massTheoretical);

            if ((mzTheoretical ?? 0.0) > 0)
            {
                if (Equals(ion.MonoisotopicMassMz, 0.0))
                {
                    // We didn't have enough info to calculate mz, use the provided theoretical value
                    var massMono    = adduct.MassFromMz(mzTheoretical.Value, MassType.Monoisotopic);
                    var massAverage = adduct.MassFromMz(mzTheoretical.Value, MassType.Average);
                    ion = new CustomIon(ion.GetSmallMoleculeLibraryAttributes(), ion.Adduct, massMono, massAverage);
                }
                else
                {
                    // Check our calculated value against provided theoretical value, allowing quite a lot of wiggle (not everybody is using the same precision out there)
                    var delta = .5; // Generous error for sanity check
                    if (Math.Abs(ion.MonoisotopicMassMz - mzTheoretical.Value) > delta)
                    {
                        Assume.Fail(string.Format(@"SpectrumPeakAnnotation: mzTheoretical {0} and mzActual {1} disagree by more than {2} in {3} {4}",
                                                  mzTheoretical, ion.MonoisotopicMassMz, delta, ion, comment ?? string.Empty));
                    }
                }
            }
            return(ion.IsEmpty && string.IsNullOrEmpty(comment) ?
                   EMPTY :
                   new SpectrumPeakAnnotation(ion, comment));
        }
Beispiel #2
0
        // Cannot find a way to use anything but a file with SQLite
        // public const string _bibliospecLiteLibPath = @"C:\Libraries\yeast.blib";

        private List <SpectrumPeakAnnotation> MakeTestPeakAnnotation(Adduct adduct, float mz, string name, string note)
        {
            var ion = new CustomIon(null, adduct,
                                    adduct.MassFromMz(mz, MassType.Monoisotopic),
                                    adduct.MassFromMz(mz, MassType.Average),
                                    name);
            var annot = SpectrumPeakAnnotation.Create(ion, note);

            return(new List <SpectrumPeakAnnotation> {
                annot
            });
        }
Beispiel #3
0
 /// <summary>
 /// Get a mass value from the text string, treating the string as m/z info if we have a charge state
 /// </summary>
 private double?GetMassFromText(string text, MassType massType)
 {
     try
     {
         if (String.IsNullOrEmpty(text))
         {
             return(null);
         }
         else
         {
             double parsed = double.Parse(text);
             if (!Adduct.IsEmpty)
             {
                 // Convert from m/z to mass
                 return(Adduct.MassFromMz(parsed, massType));
             }
             return(parsed);
         }
     }
     catch (Exception)
     {
         return(null);
     }
 }