示例#1
0
        private void ComputeNoiseLevelForMassSpectrum(
            clsScanInfo scanInfo,
            clsMSSpectrum msSpectrum,
            clsBaselineNoiseOptions noiseThresholdOptions)
        {
            const bool IGNORE_NON_POSITIVE_DATA = true;

            scanInfo.BaselineNoiseStats = clsMASICPeakFinder.InitializeBaselineNoiseStats(0, noiseThresholdOptions.BaselineNoiseMode);

            if (noiseThresholdOptions.BaselineNoiseMode == clsMASICPeakFinder.eNoiseThresholdModes.AbsoluteThreshold)
            {
                scanInfo.BaselineNoiseStats.NoiseLevel = noiseThresholdOptions.BaselineNoiseLevelAbsolute;
                scanInfo.BaselineNoiseStats.PointsUsed = 1;
            }
            else if (msSpectrum.IonCount > 0)
            {
                mPeakFinder.ComputeTrimmedNoiseLevel(
                    msSpectrum.IonsIntensity, 0, msSpectrum.IonCount - 1,
                    noiseThresholdOptions, IGNORE_NON_POSITIVE_DATA,
                    out var newBaselineNoiseStats);

                scanInfo.BaselineNoiseStats = newBaselineNoiseStats;
            }
        }
示例#2
0
        private bool LoadSpectraForThermoRawFile(
            XRawFileIO xcaliburAccessor,
            clsSpectraCache spectraCache,
            clsScanInfo scanInfo,
            clsBaselineNoiseOptions noiseThresholdOptions,
            bool discardLowIntensityData,
            bool compressSpectraData,
            double msDataResolution,
            bool keepRawSpectrum)
        {
            var lastKnownLocation = "Start";

            try
            {
                // Load the ions for this scan

                lastKnownLocation = "xcaliburAccessor.GetScanData for scan " + scanInfo.ScanNumber;

                // Retrieve the m/z and intensity values for the given scan
                // We retrieve the profile-mode data, since that's required for determining spectrum noise
                scanInfo.IonCountRaw = xcaliburAccessor.GetScanData(scanInfo.ScanNumber, out var mzList, out var intensityList);

                if (scanInfo.IonCountRaw > 0)
                {
                    var ionCountVerified = VerifyDataSorted(scanInfo.ScanNumber, scanInfo.IonCountRaw, mzList, intensityList);
                    if (ionCountVerified != scanInfo.IonCountRaw)
                    {
                        scanInfo.IonCountRaw = ionCountVerified;
                    }
                }

                scanInfo.IonCount = scanInfo.IonCountRaw;

                lastKnownLocation = "Instantiate new clsMSSpectrum";

                var msSpectrum = new clsMSSpectrum(scanInfo.ScanNumber, mzList, intensityList, scanInfo.IonCountRaw);

                lastKnownLocation = "Manually determine the base peak m/z and base peak intensity";

                // ReSharper disable once CommentTypo

                // Regarding BPI, comparison of data read via the ThermoRawFileReader vs.
                // that read from the .mzML file for dataset QC_Shew_18_02-run1_02Mar19_Arwen_18-11-02
                // showed that 25% of the spectra had incorrect BPI values

                double totalIonIntensity = 0;
                double basePeakIntensity = 0;
                double basePeakMz        = 0;

                for (var ionIndex = 0; ionIndex < scanInfo.IonCountRaw; ionIndex++)
                {
                    totalIonIntensity += intensityList[ionIndex];
                    if (intensityList[ionIndex] > basePeakIntensity)
                    {
                        basePeakIntensity = intensityList[ionIndex];
                        basePeakMz        = mzList[ionIndex];
                    }
                }

                if (Math.Abs(scanInfo.BasePeakIonMZ - basePeakMz) > 0.1)
                {
                    mBpiUpdateCount += 1;

                    if (mBpiUpdateCount < 10)
                    {
                        ConsoleMsgUtils.ShowDebug("Updating BPI in scan {0} from {1:F3} m/z to {2:F3} m/z, and BPI Intensity from {3:F0} to {4:F0}",
                                                  scanInfo.ScanNumber, scanInfo.BasePeakIonMZ, basePeakMz, scanInfo.BasePeakIonIntensity, basePeakIntensity);
                    }

                    scanInfo.BasePeakIonMZ        = basePeakMz;
                    scanInfo.BasePeakIonIntensity = basePeakIntensity;
                }

                // Determine the minimum positive intensity in this scan
                lastKnownLocation = "Call mMASICPeakFinder.FindMinimumPositiveValue";
                scanInfo.MinimumPositiveIntensity = mPeakFinder.FindMinimumPositiveValue(msSpectrum.IonsIntensity, 0);

                if (msSpectrum.IonCount > 0)
                {
                    if (scanInfo.TotalIonIntensity < float.Epsilon)
                    {
                        scanInfo.TotalIonIntensity = totalIonIntensity;
                    }
                }
                else
                {
                    scanInfo.TotalIonIntensity = 0;
                }

                bool discardLowIntensityDataWork;
                bool compressSpectraDataWork;

                if (scanInfo.MRMScanType == MRMScanTypeConstants.NotMRM)
                {
                    discardLowIntensityDataWork = discardLowIntensityData;
                    compressSpectraDataWork     = compressSpectraData;
                }
                else
                {
                    discardLowIntensityDataWork = false;
                    compressSpectraDataWork     = false;
                }

                lastKnownLocation = "Call ProcessAndStoreSpectrum";
                mScanTracking.ProcessAndStoreSpectrum(
                    scanInfo, this,
                    spectraCache, msSpectrum,
                    noiseThresholdOptions,
                    discardLowIntensityDataWork,
                    compressSpectraDataWork,
                    msDataResolution,
                    keepRawSpectrum);
            }
            catch (Exception ex)
            {
                ReportError("Error in LoadSpectraForThermoRawFile (LastKnownLocation: " + lastKnownLocation + ")", ex, clsMASIC.eMasicErrorCodes.InputFileDataReadError);
                return(false);
            }

            return(true);
        }
示例#3
0
        public bool ProcessAndStoreSpectrum(
            clsScanInfo scanInfo,
            DataInput.clsDataImport dataImportUtilities,
            clsSpectraCache spectraCache,
            clsMSSpectrum msSpectrum,
            clsBaselineNoiseOptions noiseThresholdOptions,
            bool discardLowIntensityData,
            bool compressData,
            double msDataResolution,
            bool keepRawSpectrum)
        {
            var lastKnownLocation = "Start";

            try
            {
                // Determine the noise threshold intensity for this spectrum
                // Stored in scanInfo.BaselineNoiseStats
                lastKnownLocation = "Call ComputeNoiseLevelForMassSpectrum";
                ComputeNoiseLevelForMassSpectrum(scanInfo, msSpectrum, noiseThresholdOptions);

                if (!keepRawSpectrum)
                {
                    return(true);
                }

                // Discard low intensity data, but not for MRM scans
                if (discardLowIntensityData && scanInfo.MRMScanType == ThermoRawFileReader.MRMScanTypeConstants.NotMRM)
                {
                    // Discard data below the noise level or below the minimum S/N level
                    // If we are searching for Reporter ions, then it is important to not discard any of the ions in the region of the reporter ion m/z values
                    lastKnownLocation = "Call DiscardDataBelowNoiseThreshold";
                    dataImportUtilities.DiscardDataBelowNoiseThreshold(msSpectrum,
                                                                       scanInfo.BaselineNoiseStats.NoiseLevel,
                                                                       mReporterIons.MZIntensityFilterIgnoreRangeStart,
                                                                       mReporterIons.MZIntensityFilterIgnoreRangeEnd,
                                                                       noiseThresholdOptions);

                    scanInfo.IonCount = msSpectrum.IonCount;
                }

                if (compressData)
                {
                    lastKnownLocation = "Call CompressSpectraData";
                    // Again, if we are searching for Reporter ions, then it is important to not discard any of the ions in the region of the reporter ion m/z values
                    CompressSpectraData(msSpectrum, msDataResolution,
                                        mReporterIons.MZIntensityFilterIgnoreRangeStart,
                                        mReporterIons.MZIntensityFilterIgnoreRangeEnd);
                }

                if (msSpectrum.IonCount > MAX_ALLOWABLE_ION_COUNT)
                {
                    // Do not keep more than 50,000 ions
                    lastKnownLocation = "Call DiscardDataToLimitIonCount";
                    mSpectraFoundExceedingMaxIonCount += 1;

                    // Display a message at the console the first 10 times we encounter spectra with over MAX_ALLOWABLE_ION_COUNT ions
                    // In addition, display a new message every time a new max value is encountered
                    if (mSpectraFoundExceedingMaxIonCount <= 10 || msSpectrum.IonCount > mMaxIonCountReported)
                    {
                        Console.WriteLine();
                        Console.WriteLine(
                            "Note: Scan " + scanInfo.ScanNumber + " has " + msSpectrum.IonCount + " ions; " +
                            "will only retain " + MAX_ALLOWABLE_ION_COUNT + " (trimmed " +
                            mSpectraFoundExceedingMaxIonCount.ToString() + " spectra)");

                        mMaxIonCountReported = msSpectrum.IonCount;
                    }

                    dataImportUtilities.DiscardDataToLimitIonCount(msSpectrum,
                                                                   mReporterIons.MZIntensityFilterIgnoreRangeStart,
                                                                   mReporterIons.MZIntensityFilterIgnoreRangeEnd,
                                                                   MAX_ALLOWABLE_ION_COUNT);

                    scanInfo.IonCount = msSpectrum.IonCount;
                }

                lastKnownLocation = "Call AddSpectrumToPool";
                var success = spectraCache.AddSpectrumToPool(msSpectrum, scanInfo.ScanNumber);

                return(success);
            }
            catch (Exception ex)
            {
                ReportError("Error in ProcessAndStoreSpectrum (LastKnownLocation: " + lastKnownLocation + ")", ex, clsMASIC.eMasicErrorCodes.InputFileDataReadError);
                return(false);
            }
        }