Esempio n. 1
0
        private bool ExtractScanInfoWork(
            XRawFileIO xcaliburAccessor,
            clsScanList scanList,
            clsSpectraCache spectraCache,
            clsDataOutput dataOutputHandler,
            clsSICOptions sicOptions,
            ThermoRawFileReader.clsScanInfo thermoScanInfo)
        {
            if (thermoScanInfo.ParentIonMZ > 0 && Math.Abs(mOptions.ParentIonDecoyMassDa) > 0)
            {
                thermoScanInfo.ParentIonMZ += mOptions.ParentIonDecoyMassDa;
            }

            bool success;

            // Determine if this was an MS/MS scan
            // If yes, determine the scan number of the survey scan
            if (thermoScanInfo.MSLevel <= 1)
            {
                // Survey Scan
                success = ExtractXcaliburSurveyScan(xcaliburAccessor, scanList, spectraCache, dataOutputHandler,
                                                    sicOptions, thermoScanInfo);
            }
            else
            {
                // Fragmentation Scan
                success = ExtractXcaliburFragmentationScan(xcaliburAccessor, scanList, spectraCache, dataOutputHandler,
                                                           sicOptions, mOptions.BinningOptions, thermoScanInfo);
            }

            return(success);
        }
Esempio n. 2
0
        private bool ExtractScanInfoCheckRange(
            XRawFileIO xcaliburAccessor,
            ThermoRawFileReader.clsScanInfo thermoScanInfo,
            clsScanList scanList,
            clsSpectraCache spectraCache,
            clsDataOutput dataOutputHandler,
            double percentComplete)
        {
            bool success;

            if (mScanTracking.CheckScanInRange(thermoScanInfo.ScanNumber, thermoScanInfo.RetentionTime, mOptions.SICOptions))
            {
                success = ExtractScanInfoWork(xcaliburAccessor, scanList, spectraCache, dataOutputHandler,
                                              mOptions.SICOptions, thermoScanInfo);
            }
            else
            {
                mScansOutOfRange += 1;
                success           = true;
            }

            UpdateProgress((short)Math.Round(percentComplete, 0));

            UpdateCacheStats(spectraCache);

            if (mOptions.AbortProcessing)
            {
                scanList.ProcessingIncomplete = true;
                return(false);
            }

            if (DateTime.UtcNow.Subtract(mLastLogTime).TotalSeconds >= 10 ||
                thermoScanInfo.ScanNumber % 500 == 0 && (
                    thermoScanInfo.ScanNumber >= mOptions.SICOptions.ScanRangeStart &&
                    thermoScanInfo.ScanNumber <= mOptions.SICOptions.ScanRangeEnd))
            {
                ReportMessage("Reading scan: " + thermoScanInfo.ScanNumber.ToString());
                Console.Write(".");
                mLastLogTime = DateTime.UtcNow;
            }


            return(success);
        }
        public void TestScanInfoCopyFromStruct(string rawFileName, int scanStart, int scanEnd)
        {
            var dataFile = GetRawDataFile(rawFileName);

            using (var reader = new XRawFileIO(dataFile.FullName))
            {

                Console.WriteLine("Checking clsScanInfo initializing from a struct using {0}", dataFile.Name);

                for (var scanNumber = scanStart; scanNumber <= scanEnd; scanNumber++)
                {
                    clsScanInfo scanInfo;
                    var success = reader.GetScanInfo(scanNumber, out scanInfo);

                    Assert.IsTrue(success, "GetScanInfo returned false for scan {0}", scanNumber);

            #pragma warning disable 618
                    var udtScanHeaderInfo = new udtScanHeaderInfoType
                    {
                        MSLevel = scanInfo.MSLevel,
                        EventNumber = scanInfo.EventNumber,
                        SIMScan = scanInfo.SIMScan,
                        MRMScanType = scanInfo.MRMScanType,
                        ZoomScan = scanInfo.ZoomScan,
                        NumPeaks = scanInfo.NumPeaks,
                        RetentionTime = scanInfo.RetentionTime,
                        LowMass = scanInfo.LowMass,
                        HighMass = scanInfo.HighMass,
                        TotalIonCurrent = scanInfo.TotalIonCurrent,
                        BasePeakMZ = scanInfo.BasePeakMZ,
                        BasePeakIntensity = scanInfo.BasePeakIntensity,
                        FilterText = scanInfo.FilterText,
                        ParentIonMZ = scanInfo.ParentIonMZ,
                        ActivationType = scanInfo.ActivationType,
                        CollisionMode = scanInfo.CollisionMode,
                        IonMode = scanInfo.IonMode,
                        MRMInfo = scanInfo.MRMInfo,
                        NumChannels = scanInfo.NumChannels,
                        UniformTime = scanInfo.UniformTime,
                        Frequency = scanInfo.Frequency,
                        IsCentroidScan = scanInfo.IsCentroided,
                        ScanEventNames = new string[scanInfo.ScanEvents.Count],
                        ScanEventValues = new string[scanInfo.ScanEvents.Count],
                        StatusLogNames = new string[scanInfo.StatusLog.Count],
                        StatusLogValues = new string[scanInfo.StatusLog.Count]
                    };
            #pragma warning restore 618

                    var targetIndex = 0;
                    foreach (var scanEvent in scanInfo.ScanEvents)
                    {
                        udtScanHeaderInfo.ScanEventNames[targetIndex] = scanEvent.Key;
                        udtScanHeaderInfo.ScanEventValues[targetIndex] = scanEvent.Value;
                        targetIndex++;
                    }

                    targetIndex = 0;
                    foreach (var scanEvent in scanInfo.StatusLog)
                    {
                        udtScanHeaderInfo.StatusLogNames[targetIndex] = scanEvent.Key;
                        udtScanHeaderInfo.StatusLogValues[targetIndex] = scanEvent.Value;
                        targetIndex++;
                    }

            #pragma warning disable 618
                    var scanInfoFromStruct = new clsScanInfo(scanInfo.ScanNumber, udtScanHeaderInfo);
            #pragma warning restore 618

                    Assert.AreEqual(scanInfoFromStruct.MSLevel, scanInfo.MSLevel);
                    Assert.AreEqual(scanInfoFromStruct.IsCentroided, scanInfo.IsCentroided);
                    Assert.AreEqual(scanInfoFromStruct.FilterText, scanInfo.FilterText);
                    Assert.AreEqual(scanInfoFromStruct.BasePeakIntensity, scanInfo.BasePeakIntensity, 0.0001);
                    Assert.AreEqual(scanInfoFromStruct.TotalIonCurrent, scanInfo.TotalIonCurrent, 0.0001);

                }
            }
        }
        private udtScanHeaderInfoType ScanInfoClassToStruct(clsScanInfo scanInfo)
        {
            var udtScanInfo = new udtScanHeaderInfoType
            {
                MSLevel = scanInfo.MSLevel,
                EventNumber = scanInfo.EventNumber,
                SIMScan = scanInfo.SIMScan,
                MRMScanType = scanInfo.MRMScanType,
                ZoomScan = scanInfo.ZoomScan,
                NumPeaks = scanInfo.NumPeaks,
                RetentionTime = scanInfo.RetentionTime,
                LowMass = scanInfo.LowMass,
                HighMass = scanInfo.HighMass,
                TotalIonCurrent = scanInfo.TotalIonCurrent,
                BasePeakMZ = scanInfo.BasePeakMZ,
                BasePeakIntensity = scanInfo.BasePeakIntensity,
                FilterText = scanInfo.FilterText,
                ParentIonMZ = scanInfo.ParentIonMZ,
                ActivationType = scanInfo.ActivationType,
                CollisionMode = scanInfo.CollisionMode,
                IonMode = scanInfo.IonMode,
                MRMInfo = scanInfo.MRMInfo,
                NumChannels = scanInfo.NumChannels,
                UniformTime = scanInfo.UniformTime,
                Frequency = scanInfo.Frequency,
                IsCentroidScan = scanInfo.IsCentroided,
                ScanEventNames = new string[scanInfo.ScanEvents.Count],
                ScanEventValues = new string[scanInfo.ScanEvents.Count]
            };

            for (var i = 0; i < scanInfo.ScanEvents.Count; i++)
            {
                udtScanInfo.ScanEventNames[i] = scanInfo.ScanEvents[i].Key;
                udtScanInfo.ScanEventValues[i] = scanInfo.ScanEvents[i].Value;
            }

            udtScanInfo.StatusLogNames = new string[scanInfo.StatusLog.Count];
            udtScanInfo.StatusLogValues = new string[scanInfo.StatusLog.Count];

            for (var i = 0; i < scanInfo.StatusLog.Count; i++)
            {
                udtScanInfo.StatusLogNames[i] = scanInfo.StatusLog[i].Key;
                udtScanInfo.StatusLogValues[i] = scanInfo.StatusLog[i].Value;
            }

            return udtScanInfo;
        }
        private void CacheScanInfo(int scan, clsScanInfo scanInfo)
        {
            if (mCachedScanInfo.Count > MAX_SCANS_TO_CACHE_INFO)
            {
                // Remove the oldest entry in mCachedScanInfo
                var minimumScanNumber = -1;
                var dtMinimumCacheDate = DateTime.UtcNow;

                foreach (var cachedInfo in mCachedScanInfo.Values)
                {
                    if (minimumScanNumber < 0 || cachedInfo.CacheDateUTC < dtMinimumCacheDate)
                    {
                        minimumScanNumber = cachedInfo.ScanNumber;
                        dtMinimumCacheDate = cachedInfo.CacheDateUTC;
                    }
                }

                if (mCachedScanInfo.ContainsKey(minimumScanNumber))
                {
                    mCachedScanInfo.Remove(minimumScanNumber);
                }
            }

            if (mCachedScanInfo.ContainsKey(scan))
            {
                mCachedScanInfo.Remove(scan);
            }

            mCachedScanInfo.Add(scan, scanInfo);
        }
        public bool GetScanInfo(int scan, out clsScanInfo scanInfo)
        {
            // Check for the scan in the cache
            if (mCachedScanInfo.TryGetValue(scan, out scanInfo))
            {
                return true;
            }

            if (scan < mFileInfo.ScanStart)
            {
                scan = mFileInfo.ScanStart;
            }
            else if (scan > mFileInfo.ScanEnd)
            {
                scan = mFileInfo.ScanEnd;
            }

            scanInfo = new clsScanInfo(scan);

            try
            {
                if (mXRawFile == null)
                    return false;

                // Make sure the MS controller is selected
                if (!SetMSController())
                    return false;

                // Initialize the values that will be populated using GetScanHeaderInfoForScanNum()
                scanInfo.NumPeaks = 0;
                scanInfo.TotalIonCurrent = 0;
                scanInfo.SIMScan = false;
                scanInfo.MRMScanType = MRMScanTypeConstants.NotMRM;
                scanInfo.ZoomScan = false;
                scanInfo.CollisionMode = string.Empty;
                scanInfo.FilterText = string.Empty;
                scanInfo.IonMode = IonModeConstants.Unknown;

                var numPeaks = 0;
                double retentionTime = 0;
                double lowMass = 0;
                double highMass = 0;
                double totalIonCurrent = 0;
                double basePeakMZ = 0;
                double basePeakIntensity = 0;
                var numChannels = 0;
                double frequency = 0;

                var booleanValue = 0;
                var errorCode = 0;

                mXRawFile.GetScanHeaderInfoForScanNum(
                    scan, ref numPeaks, ref retentionTime, ref lowMass, ref highMass,
                    ref totalIonCurrent, ref basePeakMZ, ref basePeakIntensity, ref numChannels, booleanValue, ref frequency);

                scanInfo.NumPeaks = numPeaks;
                scanInfo.RetentionTime = retentionTime;
                scanInfo.LowMass = lowMass;
                scanInfo.HighMass = highMass;
                scanInfo.TotalIonCurrent = totalIonCurrent;
                scanInfo.BasePeakMZ = basePeakMZ;
                scanInfo.BasePeakIntensity = basePeakIntensity;
                scanInfo.NumChannels = numChannels;
                scanInfo.Frequency = frequency;

                mXRawFile.IsError(ref errorCode);
                // Unfortunately, .IsError() always returns 0, even if an error occurred

                if (errorCode != 0)
                {
                    CacheScanInfo(scan, scanInfo);
                    return false;
                }

                scanInfo.UniformTime = Convert.ToBoolean(booleanValue);

                booleanValue = 0;
                mXRawFile.IsCentroidScanForScanNum(scan, ref booleanValue);

                scanInfo.IsCentroided = Convert.ToBoolean(booleanValue);

                var arrayCount = 0;
                object objLabels = null;
                object objValues = null;

                try
                {
                    if (!mCorruptMemoryEncountered)
                    {
                        // Retrieve the additional parameters for this scan (including Scan Event)
                        mXRawFile.GetTrailerExtraForScanNum(scan, ref objLabels, ref objValues, ref arrayCount);
                    }
                }
                catch (AccessViolationException ex)
                {
                    var msg = "Warning: Exception calling mXRawFile.GetTrailerExtraForScanNum for scan " + scan + ": " + ex.Message;
                    RaiseWarningMessage(msg);
                    arrayCount = 0;

                }
                catch (Exception ex)
                {
                    var msg = "Warning: Exception calling mXRawFile.GetTrailerExtraForScanNum for scan " + scan + ": " + ex.Message;
                    RaiseWarningMessage(msg);
                    arrayCount = 0;

                    if (ex.Message.ToLower().Contains("memory is corrupt"))
                    {
                        mCorruptMemoryEncountered = true;
                    }
                }

                scanInfo.EventNumber = 1;
                if (arrayCount > 0 && objLabels != null && objValues != null)
                {

                    var scanEventNames =
                        ((IEnumerable)objLabels).Cast<object>()
                            .Select(x => x.ToString())
                            .ToArray();

                    var scanEventValues =
                         ((IEnumerable)objValues).Cast<object>()
                            .Select(x => x.ToString())
                            .ToArray();

                    scanInfo.StoreScanEvents(scanEventNames, scanEventValues);

                    // Look for the entry in strLabels named "Scan Event:"
                    // Entries for the LCQ are:
                    //   Wideband Activation
                    //   Micro Scan Count
                    //   Ion Injection Time (ms)
                    //   Scan Segment
                    //   Scan Event
                    //   Elapsed Scan Time (sec)
                    //   API Source CID Energy
                    //   Resolution
                    //   Average Scan by Inst
                    //   BackGd Subtracted by Inst
                    //   Charge State

                    foreach (var scanEvent in from item in scanInfo.ScanEvents where item.Key.ToLower().StartsWith("scan event") select item)
                    {
                        try
                        {
                            scanInfo.EventNumber = Convert.ToInt32(scanEvent.Value);
                        }
                        catch (Exception)
                        {
                            // Ignore errors here
                        }
                        break;
                    }

                }

                // Lookup the filter text for this scan
                // Parse out the parent ion m/z for fragmentation scans
                // Must set filterText to Nothing prior to calling .GetFilterForScanNum()
                string filterText = null;
                mXRawFile.GetFilterForScanNum(scan, ref filterText);

                scanInfo.FilterText = string.Copy(filterText);

                scanInfo.IsFTMS = ScanIsFTMS(filterText);

                if (string.IsNullOrWhiteSpace(scanInfo.FilterText))
                    scanInfo.FilterText = string.Empty;

                if (scanInfo.EventNumber <= 1)
                {
                    int msLevel;

                    // XRaw periodically mislabels a scan as .EventNumber = 1 when it's really an MS/MS scan; check for this
                    string mzText;
                    if (ExtractMSLevel(scanInfo.FilterText, out msLevel, out mzText))
                    {
                        scanInfo.EventNumber = msLevel;
                    }
                }

                if (scanInfo.EventNumber > 1)
                {
                    // MS/MS data
                    scanInfo.MSLevel = 2;

                    if (string.IsNullOrWhiteSpace(scanInfo.FilterText))
                    {
                        // FilterText is empty; this indicates a problem with the .Raw file
                        // This is rare, but does happen (see scans 2 and 3 in QC_Shew_08_03_pt5_1_MAXPRO_27Oct08_Raptor_08-01-01.raw)
                        // We'll set the Parent Ion to 0 m/z and the collision mode to CID
                        scanInfo.ParentIonMZ = 0;
                        scanInfo.CollisionMode = "cid";
                        if (scanInfo.ActivationType == ActivationTypeConstants.Unknown)
                        {
                            scanInfo.ActivationType = ActivationTypeConstants.CID;
                        }
                        scanInfo.MRMScanType = MRMScanTypeConstants.NotMRM;
                    }
                    else
                    {
                        double parentIonMz;
                        int msLevel;
                        string collisionMode;

                        // Parse out the parent ion and collision energy from .FilterText
                        if (ExtractParentIonMZFromFilterText(scanInfo.FilterText, out parentIonMz, out msLevel, out collisionMode))
                        {
                            scanInfo.ParentIonMZ = parentIonMz;
                            scanInfo.CollisionMode = collisionMode;

                            if (msLevel > 2)
                            {
                                scanInfo.MSLevel = msLevel;
                            }

                            // Check whether this is an SRM MS2 scan
                            scanInfo.MRMScanType = DetermineMRMScanType(scanInfo.FilterText);
                        }
                        else
                        {
                            // Could not find "Full ms2" in .FilterText
                            // XRaw periodically mislabels a scan as .EventNumber > 1 when it's really an MS scan; check for this

                            bool simScan;
                            MRMScanTypeConstants eMRMScanType;
                            bool zoomScan;

                            if (ValidateMSScan(scanInfo.FilterText, out msLevel, out simScan, out eMRMScanType, out zoomScan))
                            {
                                // Yes, scan is an MS, SIM, or MRMQMS, or SRM scan
                                scanInfo.MSLevel = msLevel;
                                scanInfo.SIMScan = simScan;
                                scanInfo.MRMScanType = eMRMScanType;
                                scanInfo.ZoomScan = zoomScan;
                            }
                            else
                            {
                                // Unknown format for .FilterText; return an error
                                RaiseErrorMessage("Unknown format for Scan Filter: " + scanInfo.FilterText);
                                return false;
                            }
                        }
                    }
                }
                else
                {
                    // MS1 data
                    // Make sure .FilterText contains one of the known MS1, SIM or MRM tags

                    if (scanInfo.FilterText == string.Empty)
                    {
                        // FilterText is empty; this indicates a problem with the .Raw file
                        // This is rare, but does happen (see scans 2 and 3 in QC_Shew_08_03_pt5_1_MAXPRO_27Oct08_Raptor_08-01-01.raw)
                        scanInfo.MSLevel = 1;
                        scanInfo.SIMScan = false;
                        scanInfo.MRMScanType = MRMScanTypeConstants.NotMRM;

                    }
                    else
                    {

                        int msLevel;
                        bool simScan;
                        MRMScanTypeConstants eMRMScanType;
                        bool zoomScan;

                        if (ValidateMSScan(scanInfo.FilterText, out msLevel, out simScan, out eMRMScanType, out zoomScan))
                        {
                            // Yes, scan is an MS, SIM, or MRMQMS, or SRM scan
                            scanInfo.MSLevel = msLevel;
                            scanInfo.SIMScan = simScan;
                            scanInfo.MRMScanType = eMRMScanType;
                            scanInfo.ZoomScan = zoomScan;
                        }
                        else
                        {
                            // Unknown format for .FilterText; return an error
                            RaiseErrorMessage("Unknown format for Scan Filter: " + scanInfo.FilterText);
                            return false;
                        }
                    }

                }

                scanInfo.IonMode = DetermineIonizationMode(scanInfo.FilterText);

                // Now that we know MSLevel we can lookup the activation type (aka activation method)
                scanInfo.ActivationType = GetActivationType(scan, scanInfo.MSLevel);

                MRMInfo newMRMInfo;

                if (scanInfo.MRMScanType != MRMScanTypeConstants.NotMRM)
                {
                    // Parse out the MRM_QMS or SRM information for this scan
                    ExtractMRMMasses(scanInfo.FilterText, scanInfo.MRMScanType, out newMRMInfo);
                }
                else
                {
                    newMRMInfo = new MRMInfo();
                }

                scanInfo.MRMInfo = newMRMInfo;

                // Retrieve the Status Log for this scan using the following
                // The Status Log includes numerous instrument parameters, including voltages, temperatures, pressures, turbo pump speeds, etc.
                arrayCount = 0;
                objLabels = null;
                objValues = null;

                try
                {
                    if (!mCorruptMemoryEncountered)
                    {
                        double statusLogRT = 0;

                        mXRawFile.GetStatusLogForScanNum(scan, statusLogRT, ref objLabels, ref objValues, ref arrayCount);
                    }
                }
                catch (AccessViolationException ex)
                {
                    var msg = "Warning: Exception calling mXRawFile.GetStatusLogForScanNum for scan " + scan + ": " + ex.Message;
                    RaiseWarningMessage(msg);
                    arrayCount = 0;

                }
                catch (Exception ex)
                {
                    var msg = "Warning: Exception calling mXRawFile.GetStatusLogForScanNum for scan " + scan + ": " + ex.Message;
                    RaiseWarningMessage(msg);
                    arrayCount = 0;

                    if (ex.Message.ToLower().Contains("memory is corrupt"))
                    {
                        mCorruptMemoryEncountered = true;
                    }
                }

                if (arrayCount > 0)
                {
                    var logNames =
                        ((IEnumerable)objLabels).Cast<object>()
                            .Select(x => x.ToString())
                            .ToArray();

                    var logValues =
                         ((IEnumerable)objValues).Cast<object>()
                            .Select(x => x.ToString())
                            .ToArray();

                    scanInfo.StoreStatusLog(logNames, logValues);

                }

            }
            catch (Exception ex)
            {
                var msg = "Error: Exception in GetScanInfo: " + ex.Message;
                RaiseWarningMessage(msg);
                CacheScanInfo(scan, scanInfo);
                return false;
            }

            CacheScanInfo(scan, scanInfo);

            return true;
        }
Esempio n. 7
0
        private bool ExtractXcaliburFragmentationScan(
            XRawFileIO xcaliburAccessor,
            clsScanList scanList,
            clsSpectraCache spectraCache,
            clsDataOutput dataOutputHandler,
            clsSICOptions sicOptions,
            clsBinningOptions binningOptions,
            ThermoRawFileReader.clsScanInfo thermoScanInfo)
        {
            // Note that MinimumPositiveIntensity will be determined in LoadSpectraForThermoRawFile

            var scanInfo = new clsScanInfo(thermoScanInfo.ParentIonMZ)
            {
                ScanNumber               = thermoScanInfo.ScanNumber,
                ScanTime                 = (float)thermoScanInfo.RetentionTime,
                ScanHeaderText           = XRawFileIO.MakeGenericThermoScanFilter(thermoScanInfo.FilterText),
                ScanTypeName             = XRawFileIO.GetScanTypeNameFromThermoScanFilterText(thermoScanInfo.FilterText),
                BasePeakIonMZ            = thermoScanInfo.BasePeakMZ,
                BasePeakIonIntensity     = thermoScanInfo.BasePeakIntensity,
                TotalIonIntensity        = thermoScanInfo.TotalIonCurrent,
                MinimumPositiveIntensity = 0,
                ZoomScan                 = thermoScanInfo.ZoomScan,
                SIMScan     = thermoScanInfo.SIMScan,
                MRMScanType = thermoScanInfo.MRMScanType
            };

            // Typically .EventNumber is 1 for the parent-ion scan; 2 for 1st frag scan, 3 for 2nd frag scan, etc.
            // This resets for each new parent-ion scan
            scanInfo.FragScanInfo.FragScanNumber = thermoScanInfo.EventNumber - 1;

            // The .EventNumber value is sometimes wrong; need to check for this
            // For example, if the dataset only has MS2 scans and no parent-ion scan, .EventNumber will be 2 for every MS2 scan
            if (scanList.FragScans.Count > 0)
            {
                var prevFragScan = scanList.FragScans[scanList.FragScans.Count - 1];
                if (prevFragScan.ScanNumber == scanInfo.ScanNumber - 1)
                {
                    if (scanInfo.FragScanInfo.FragScanNumber <= prevFragScan.FragScanInfo.FragScanNumber)
                    {
                        scanInfo.FragScanInfo.FragScanNumber = prevFragScan.FragScanInfo.FragScanNumber + 1;
                    }
                }
            }

            scanInfo.FragScanInfo.MSLevel = thermoScanInfo.MSLevel;

            if (scanInfo.MRMScanType != MRMScanTypeConstants.NotMRM)
            {
                // This is an MRM scan
                scanList.MRMDataPresent = true;

                scanInfo.MRMScanInfo = clsMRMProcessing.DuplicateMRMInfo(thermoScanInfo.MRMInfo, thermoScanInfo.ParentIonMZ);

                if (scanList.SurveyScans.Count == 0)
                {
                    // Need to add a "fake" survey scan that we can map this parent ion to
                    mLastNonZoomSurveyScanIndex = scanList.AddFakeSurveyScan();
                }
            }
            else
            {
                scanInfo.MRMScanInfo.MRMMassCount = 0;
            }

            scanInfo.LowMass  = thermoScanInfo.LowMass;
            scanInfo.HighMass = thermoScanInfo.HighMass;
            scanInfo.IsFTMS   = thermoScanInfo.IsFTMS;

            // Store the ScanEvent values in .ExtendedHeaderInfo
            StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, thermoScanInfo.ScanEvents);

            // Store the collision mode and possibly the scan filter text
            scanInfo.FragScanInfo.CollisionMode = thermoScanInfo.CollisionMode;
            StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, clsExtendedStatsWriter.EXTENDED_STATS_HEADER_COLLISION_MODE, thermoScanInfo.CollisionMode);
            if (mOptions.WriteExtendedStatsIncludeScanFilterText)
            {
                StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, clsExtendedStatsWriter.EXTENDED_STATS_HEADER_SCAN_FILTER_TEXT, thermoScanInfo.FilterText);
            }

            if (mOptions.WriteExtendedStatsStatusLog)
            {
                // Store the StatusLog values in .ExtendedHeaderInfo
                StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, thermoScanInfo.StatusLog, mOptions.StatusLogKeyNameFilterList);
            }

            scanList.FragScans.Add(scanInfo);
            var fragScanIndex = scanList.FragScans.Count - 1;

            scanList.AddMasterScanEntry(clsScanList.eScanTypeConstants.FragScan, fragScanIndex);

            // Note: Even if keepRawSpectra = False, we still need to load the raw data so that we can compute the noise level for the spectrum
            var msDataResolution = binningOptions.BinSize / sicOptions.CompressToleranceDivisorForDa;

            var success = LoadSpectraForThermoRawFile(
                xcaliburAccessor,
                spectraCache,
                scanInfo,
                sicOptions.SICPeakFinderOptions.MassSpectraNoiseThresholdOptions,
                clsMASIC.DISCARD_LOW_INTENSITY_MSMS_DATA_ON_LOAD,
                sicOptions.CompressMSMSSpectraData,
                msDataResolution,
                mKeepRawSpectra && mKeepMSMSSpectra);

            if (!success)
            {
                return(false);
            }

            SaveScanStatEntry(dataOutputHandler.OutputFileHandles.ScanStats, clsScanList.eScanTypeConstants.FragScan, scanInfo, sicOptions.DatasetID);

            if (thermoScanInfo.MRMScanType == MRMScanTypeConstants.NotMRM)
            {
                // This is not an MRM scan
                mParentIonProcessor.AddUpdateParentIons(scanList, mLastNonZoomSurveyScanIndex, thermoScanInfo.ParentIonMZ,
                                                        fragScanIndex, spectraCache, sicOptions);
            }
            else
            {
                // This is an MRM scan
                mParentIonProcessor.AddUpdateParentIons(scanList, mLastNonZoomSurveyScanIndex, thermoScanInfo.ParentIonMZ,
                                                        scanInfo.MRMScanInfo, spectraCache, sicOptions);
            }

            if (mLastNonZoomSurveyScanIndex >= 0)
            {
                var precursorScanNumber = scanList.SurveyScans[mLastNonZoomSurveyScanIndex].ScanNumber;

                // Compute the interference of the parent ion in the MS1 spectrum for this frag scan
                scanInfo.FragScanInfo.InterferenceScore = ComputeInterference(xcaliburAccessor, thermoScanInfo, precursorScanNumber);
            }

            return(true);
        }
Esempio n. 8
0
        private double ComputeInterference(
            XRawFileIO xcaliburAccessor,
            ThermoRawFileReader.clsScanInfo scanInfo,
            int precursorScanNumber)
        {
            if (precursorScanNumber != mCachedPrecursorScan)
            {
                xcaliburAccessor.GetScanData(precursorScanNumber, out var centroidedIonsMz, out var centroidedIonsIntensity, 0, true);

                UpdateCachedPrecursorScan(precursorScanNumber, centroidedIonsMz, centroidedIonsIntensity);
            }

            var chargeState = 0;

            scanInfo.TryGetScanEvent(SCAN_EVENT_CHARGE_STATE, out var chargeStateText, true);
            if (!string.IsNullOrWhiteSpace(chargeStateText))
            {
                if (!int.TryParse(chargeStateText, out chargeState))
                {
                    chargeState = 0;
                }
            }

            if (!scanInfo.TryGetScanEvent(SCAN_EVENT_MS2_ISOLATION_WIDTH, out var isolationWidthText, true))
            {
                if (scanInfo.MRMScanType == MRMScanTypeConstants.SRM)
                {
                    // SRM data files don't have the MS2 Isolation Width event
                    return(0);
                }

                WarnIsolationWidthNotFound(
                    scanInfo.ScanNumber,
                    "Could not determine the MS2 isolation width (" + SCAN_EVENT_MS2_ISOLATION_WIDTH + ")");

                return(0);
            }

            if (!double.TryParse(isolationWidthText, out var isolationWidth))
            {
                ReportWarning("MS2 isolation width (" + SCAN_EVENT_MS2_ISOLATION_WIDTH + ") was non-numeric (" + isolationWidthText + "); " +
                              "cannot compute interference for scan " + scanInfo.ScanNumber);
                return(0);
            }

            double parentIonMz;

            if (Math.Abs(scanInfo.ParentIonMZ) > 0)
            {
                parentIonMz = scanInfo.ParentIonMZ;
            }
            else
            {
                // ThermoRawFileReader could not determine the parent ion m/z value (this is highly unlikely)
                // Use scan event "Monoisotopic M/Z" instead
                if (!scanInfo.TryGetScanEvent(SCAN_EVENT_MONOISOTOPIC_MZ, out var monoMzText, true))
                {
                    ReportWarning("Could not determine the parent ion m/z value (" + SCAN_EVENT_MONOISOTOPIC_MZ + "); " +
                                  "cannot compute interference for scan " + scanInfo.ScanNumber);
                    return(0);
                }

                if (!double.TryParse(monoMzText, out var mz))
                {
                    OnWarningEvent(string.Format("Skipping scan {0} since scan event {1} was not a number: {2}",
                                                 scanInfo.ScanNumber, SCAN_EVENT_MONOISOTOPIC_MZ, monoMzText));
                    return(0);
                }

                parentIonMz = mz;
            }

            if (Math.Abs(parentIonMz) < float.Epsilon)
            {
                ReportWarning("Parent ion m/z is 0; cannot compute interference for scan " + scanInfo.ScanNumber);
                return(0);
            }

            var precursorInterference = ComputePrecursorInterference(
                scanInfo.ScanNumber,
                precursorScanNumber, parentIonMz, isolationWidth, chargeState);

            return(precursorInterference);
        }
Esempio n. 9
0
        private bool ExtractXcaliburSurveyScan(
            XRawFileIO xcaliburAccessor,
            clsScanList scanList,
            clsSpectraCache spectraCache,
            clsDataOutput dataOutputHandler,
            clsSICOptions sicOptions,
            ThermoRawFileReader.clsScanInfo thermoScanInfo)
        {
            var scanInfo = new clsScanInfo()
            {
                ScanNumber               = thermoScanInfo.ScanNumber,
                ScanTime                 = (float)thermoScanInfo.RetentionTime,
                ScanHeaderText           = XRawFileIO.MakeGenericThermoScanFilter(thermoScanInfo.FilterText),
                ScanTypeName             = XRawFileIO.GetScanTypeNameFromThermoScanFilterText(thermoScanInfo.FilterText),
                BasePeakIonMZ            = thermoScanInfo.BasePeakMZ,
                BasePeakIonIntensity     = thermoScanInfo.BasePeakIntensity,
                TotalIonIntensity        = thermoScanInfo.TotalIonCurrent,
                MinimumPositiveIntensity = 0,        // This will be determined in LoadSpectraForThermoRawFile
                ZoomScan                 = thermoScanInfo.ZoomScan,
                SIMScan     = thermoScanInfo.SIMScan,
                MRMScanType = thermoScanInfo.MRMScanType,
                LowMass     = thermoScanInfo.LowMass,
                HighMass    = thermoScanInfo.HighMass,
                IsFTMS      = thermoScanInfo.IsFTMS
            };

            // Survey scans typically lead to multiple parent ions; we do not record them here
            scanInfo.FragScanInfo.ParentIonInfoIndex = -1;

            if (scanInfo.MRMScanType != MRMScanTypeConstants.NotMRM)
            {
                // This is an MRM scan
                scanList.MRMDataPresent = true;
            }

            if (scanInfo.SIMScan)
            {
                scanList.SIMDataPresent = true;
                var simKey = scanInfo.LowMass + "_" + scanInfo.HighMass;

                if (mSIMScanMapping.TryGetValue(simKey, out var simIndex))
                {
                    scanInfo.SIMIndex = simIndex;
                }
                else
                {
                    scanInfo.SIMIndex = mSIMScanMapping.Count;
                    mSIMScanMapping.Add(simKey, mSIMScanMapping.Count);
                }
            }

            // Store the ScanEvent values in .ExtendedHeaderInfo
            StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, thermoScanInfo.ScanEvents);

            // Store the collision mode and possibly the scan filter text
            scanInfo.FragScanInfo.CollisionMode = thermoScanInfo.CollisionMode;
            StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, clsExtendedStatsWriter.EXTENDED_STATS_HEADER_COLLISION_MODE, thermoScanInfo.CollisionMode);
            if (mOptions.WriteExtendedStatsIncludeScanFilterText)
            {
                StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, clsExtendedStatsWriter.EXTENDED_STATS_HEADER_SCAN_FILTER_TEXT, thermoScanInfo.FilterText);
            }

            if (mOptions.WriteExtendedStatsStatusLog)
            {
                // Store the StatusLog values in .ExtendedHeaderInfo
                StoreExtendedHeaderInfo(dataOutputHandler, scanInfo, thermoScanInfo.StatusLog, mOptions.StatusLogKeyNameFilterList);
            }

            scanList.SurveyScans.Add(scanInfo);

            if (!scanInfo.ZoomScan)
            {
                mLastNonZoomSurveyScanIndex = scanList.SurveyScans.Count - 1;
            }

            scanList.AddMasterScanEntry(clsScanList.eScanTypeConstants.SurveyScan, scanList.SurveyScans.Count - 1);

            double msDataResolution;

            if (sicOptions.SICToleranceIsPPM)
            {
                // Define MSDataResolution based on the tolerance value that will be used at the lowest m/z in this spectrum, divided by sicOptions.CompressToleranceDivisorForPPM
                // However, if the lowest m/z value is < 100, then use 100 m/z
                if (thermoScanInfo.LowMass < 100)
                {
                    msDataResolution = clsParentIonProcessing.GetParentIonToleranceDa(sicOptions, 100) /
                                       sicOptions.CompressToleranceDivisorForPPM;
                }
                else
                {
                    msDataResolution = clsParentIonProcessing.GetParentIonToleranceDa(sicOptions, thermoScanInfo.LowMass) /
                                       sicOptions.CompressToleranceDivisorForPPM;
                }
            }
            else
            {
                msDataResolution = sicOptions.SICTolerance / sicOptions.CompressToleranceDivisorForDa;
            }

            // Note: Even if mKeepRawSpectra = False, we still need to load the raw data so that we can compute the noise level for the spectrum
            var success = LoadSpectraForThermoRawFile(
                xcaliburAccessor,
                spectraCache,
                scanInfo,
                sicOptions.SICPeakFinderOptions.MassSpectraNoiseThresholdOptions,
                clsMASIC.DISCARD_LOW_INTENSITY_MS_DATA_ON_LOAD,
                sicOptions.CompressMSSpectraData,
                msDataResolution,
                mKeepRawSpectra);

            if (!success)
            {
                return(false);
            }

            SaveScanStatEntry(dataOutputHandler.OutputFileHandles.ScanStats, clsScanList.eScanTypeConstants.SurveyScan, scanInfo, sicOptions.DatasetID);

            return(true);
        }