Beispiel #1
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");
            Check.Require(scanSet.IndexValues.Count > 0, "Can't get mass spectrum; no scan numbers inputted");

            var totScans = this.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(), this.GetNumMSScans());
            var lowerscan = Math.Max(scanSet.getLowestScanNumber(), 1);

            //TODO:  Old DeconTools reference!! remove this
            this.RawData.GetSummedSpectra(lowerscan, upperscan, minMZ, maxMZ, ref xvals, ref yvals);

            var xydata = new XYData();

            xydata.Xvalues = xvals;
            xydata.Yvalues = yvals;
            return(xydata);
        }
Beispiel #2
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, "Cannot get spectrum. Number of scans in ScanSet is 0");
            Check.Require(lcScanset.GetScanCount() > 0, "Cannot get spectrum. Number of frames in FrameSet is 0");

            var frameLower = lcScanset.getLowestScanNumber();
            var frameUpper = lcScanset.getHighestScanNumber();
            var scanLower  = imsScanset.getLowestScanNumber();
            var scanUpper  = imsScanset.getHighestScanNumber();

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

            var frameType = (DataReader.FrameType)GetMSLevel(lcScanset.PrimaryScanNumber);

            try
            {
                // Obtain an instance of the reader
                var uimfReader = UIMFLibraryAdapter.getInstance(Filename).Datareader;

                // 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 UIMFLibrry)

                uimfReader.SpectraToCache           = 10;
                uimfReader.MaxSpectrumCacheMemoryMB = 750;

                double[] xvals;
                int[]    yvals;
                var      nonZeroLength = uimfReader.GetSpectrum(frameLower,
                                                                frameUpper, frameType, scanLower, scanUpper, minMZ, maxMZ, out xvals, out 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;
            }
        }
        private void UpdateReportedSummedPeakIntensities(IsosResult profile, ScanSet lcScanSet, ScanSet imsScanSet)
        {
            var uimfIsosResult = (UIMFIsosResult)profile;

            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 == null
                                                            ? 0
                                                            : unsummedAdjustedMSFeature.IntensityAggregate;



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

            //TODO: remove this debug code later
            //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;
                }
            }
        }