示例#1
0
        /// <summary>
        /// Returns the mass spectrum for a specified LC ScanSet and a IMS ScanSet.
        /// </summary>
        /// <param name="lcScanSet"></param>
        /// <param name="imsScanSet"></param>
        /// <param name="minMZ"></param>
        /// <param name="maxMZ"></param>
        public override XYData GetMassSpectrum(ScanSet lcScanSet, ScanSet imsScanSet, double minMZ, double maxMZ)
        {
            Check.Require(imsScanSet.GetScanCount() > 0, string.Format(
                              "Cannot get spectrum. Number of scans in ScanSet ({0}) is 0", nameof(imsScanSet)));

            Check.Require(lcScanSet.GetScanCount() > 0, string.Format(
                              "Cannot get spectrum. Number of frames in FrameSet ({0}) is 0", nameof(lcScanSet)));

            var startFrameNumber = lcScanSet.GetLowestScanNumber();
            var endFrameNumber   = lcScanSet.GetHighestScanNumber();
            var startScanNumber  = imsScanSet.GetLowestScanNumber();
            var endScanNumber    = imsScanSet.GetHighestScanNumber();

            // TODO: If lowest and highest scan numbers are both 0, should we be summing the mass spectrum?

            var frameType = (UIMFData.FrameType)GetMSLevel(lcScanSet.PrimaryScanNumber);

            try
            {
                // Prior to January 2015 the SpectrumCache class in the UIMFReader used Dictionary<int, int> for ListOfIntensityDictionaries
                // This caused some datasets, e.g. EXP-Mix5_1um_pos_19Jan15_Columbia_DI, to run out of memory when caching 10 spectra
                // The UIMFLibrary now uses List<int, int>, which takes up less memory (at the expense having slower lookups by BinNumber, though this does not affect DeconTools' use of the UIMFLibrary)

                mReader.SpectraToCache           = 10;
                mReader.MaxSpectrumCacheMemoryMB = 750;

                mReader.GetSpectrum(
                    startFrameNumber, endFrameNumber, frameType,
                    startScanNumber, endScanNumber,
                    minMZ, maxMZ,
                    out var xVals, out var yVals);

                var xyData = new XYData();

                if (xVals == null || xVals.Length == 0)
                {
                    xyData.Xvalues = null;
                    xyData.Yvalues = null;
                    return(xyData);
                }

                xyData.Xvalues = xVals;
                xyData.Yvalues = yVals.Select <int, double>(i => i).ToArray();

                if (xyData.Xvalues[0] < minMZ || xyData.Xvalues[xyData.Xvalues.Length - 1] > maxMZ)
                {
                    xyData = xyData.TrimData(minMZ, maxMZ);
                }

                return(xyData);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error in UIMF GetMassSpectrum: " + ex.Message);
                throw;
            }
        }
示例#2
0
        public override XYData GetMassSpectrum(ScanSet scanSet, double minMZ, double maxMZ)
        {
            Check.Require(scanSet != null, "Can't get mass spectrum; inputted set of scans is null");
            if (scanSet == null)
            {
                return(new XYData());
            }

            Check.Require(scanSet.IndexValues.Count > 0, "Can't get mass spectrum; no scan numbers inputted");

            // Unused: var totScans = GetNumMSScans();

            var xVals = new double[0];
            var yVals = new double[0];

            //if (scanSet.IndexValues.Count == 1)            //this is the case of only wanting one MS spectrum
            //{
            //    this.rawData.GetSpectrum(scanSet.IndexValues[0], ref xVals, ref yVals);
            //}
            //else
            //{
            //    int upperScan = Math.Min(scanSet.GetHighestScanNumber(), this.GetNumMSScans());
            //    int lowerScan = Math.Max(scanSet.GetLowestScanNumber(), 1);
            //    this.rawData.GetSummedSpectra(lowerScan, upperScan, minMZ, maxMZ, ref xVals, ref yVals);
            //}

            var upperScan = Math.Min(scanSet.GetHighestScanNumber(), GetNumMSScans());
            var lowerScan = Math.Max(scanSet.GetLowestScanNumber(), 1);

            //TODO:  Old DeconTools reference!! remove this
            RawData.GetSummedSpectra(lowerScan, upperScan, minMZ, maxMZ, ref xVals, ref yVals);

            var xydata = new XYData
            {
                Xvalues = xVals,
                Yvalues = yVals
            };

            return(xydata);
        }
        private void UpdateReportedSummedPeakIntensities(IsosResult profile, ScanSet lcScanSet, ScanSet imsScanSet)
        {
            var minFrame = lcScanSet.GetLowestScanNumber();
            var maxFrame = lcScanSet.GetHighestScanNumber();

            var minIMSScan = imsScanSet.GetLowestScanNumber();
            var maxIMSScan = imsScanSet.GetHighestScanNumber();

            var massTolerance = 0.2;

            var filteredUnsummedMSFeatures = (from n in _unsummedMSFeatures
                                              where n.ScanSet.PrimaryScanNumber >= minFrame &&
                                              n.ScanSet.PrimaryScanNumber <= maxFrame &&
                                              ((UIMFIsosResult)n).IMSScanSet.PrimaryScanNumber >= minIMSScan &&
                                              ((UIMFIsosResult)n).IMSScanSet.PrimaryScanNumber <= maxIMSScan &&
                                              n.IsotopicProfile.ChargeState == profile.IsotopicProfile.ChargeState &&
                                              Math.Abs(n.IsotopicProfile.MonoIsotopicMass -
                                                       profile.IsotopicProfile.MonoIsotopicMass) < massTolerance
                                              select n).ToList();

            var averageMonoMass = profile.IsotopicProfile.MonoIsotopicMass;     //initialize and assign original value
            var averageMonoMZ   = profile.IsotopicProfile.MonoPeakMZ;
            var averageMostAbundantPeakMonoMass = profile.IsotopicProfile.MostAbundantIsotopeMass;

            //if (filteredUnsummedMSFeatures.Count > 2)
            //{
            //    var higherAbundanceFeatures =
            //        (from n in filteredUnsummedMSFeatures where n.IntensityAggregate > 100000 select n).
            //            ToList();

            //    if (higherAbundanceFeatures.Count>0)
            //    {
            //        averageMonoMass = filteredUnsummedMSFeatures.Select(p => p.IsotopicProfile.MonoIsotopicMass).Average();
            //        averageMonoMZ = filteredUnsummedMSFeatures.Select(p => p.IsotopicProfile.MonoPeakMZ).Average();
            //        averageMostAbundantPeakMonoMass =
            //            filteredUnsummedMSFeatures.Select(p => p.IsotopicProfile.MostAbundantIsotopeMass).Average();
            //    }

            //}

            //var peaksToSum = (from n in Run.ResultCollection.MSPeakResultList
            //                  where n.Frame_num >= minFrame &&
            //                        n.Frame_num <= maxFrame &&
            //                        n.Scan_num >= minScan &&
            //                        n.Scan_num <= maxScan &&
            //                        n.XValue > minMZ &&
            //                        n.XValue < maxMZ
            //                  select n).ToList();

            //double adjustedIntensity = peaksToSum.Sum(p => p.Height);

            var unsummedAdjustedMSFeature = (from n in filteredUnsummedMSFeatures
                                             where
                                             n.ScanSet.PrimaryScanNumber == lcScanSet.PrimaryScanNumber &&
                                             ((UIMFIsosResult)n).IMSScanSet.PrimaryScanNumber == imsScanSet.PrimaryScanNumber
                                             select n).FirstOrDefault();

            profile.IsotopicProfile.OriginalIntensity = unsummedAdjustedMSFeature?.IntensityAggregate ?? 0;

            var adjustedIntensity = filteredUnsummedMSFeatures.Sum(p => p.IsotopicProfile.IntensityMostAbundant);

            // Uncomment to debug
            //if (unsummedAdjustedMSFeature == null)
            //{
            //    Console.WriteLine(profile.IsotopicProfile.MonoPeakMZ.ToString("0.000") + "\t" + profile.IsotopicProfile.ChargeState + "\t" + frameSet.PrimaryFrame + "\t" + scanSet.PrimaryScanNumber + "\t" + profile.IntensityAggregate + "\t" + adjustedIntensity + "\t" +  "0");
            //}
            //else
            //{
            //    Console.WriteLine(profile.IsotopicProfile.MonoPeakMZ.ToString("0.000") + "\t" + profile.IsotopicProfile.ChargeState + "\t" + frameSet.PrimaryFrame + "\t" + scanSet.PrimaryScanNumber + "\t" + profile.IntensityAggregate + "\t" + adjustedIntensity +"\t" + unsummedAdjustedMSFeature.IntensityAggregate);
            //}

            if (adjustedIntensity > profile.IntensityAggregate)
            {
                profile.IsotopicProfile.IsSaturated           = true;
                profile.IntensityAggregate                    = adjustedIntensity;
                profile.IsotopicProfile.IntensityMostAbundant = adjustedIntensity;

                if (filteredUnsummedMSFeatures.Count > 0)
                {
                    profile.IsotopicProfile.MonoIsotopicMass        = averageMonoMass;
                    profile.IsotopicProfile.MonoPeakMZ              = averageMonoMZ;
                    profile.IsotopicProfile.MostAbundantIsotopeMass = averageMostAbundantPeakMonoMass;
                }
            }
        }