예제 #1
0
        public static MRMInfo InitializeMRMInfo()
        {
            var udtMRMInfo = new MRMInfo();

            udtMRMInfo.Clear();

            return(udtMRMInfo);
        }
        public static MRMInfo InitializeMRMInfo()
        {
            var mrmInfo = new MRMInfo();

            mrmInfo.Clear();

            return(mrmInfo);
        }
        /// <summary>
        /// Duplicate the MRM info
        /// </summary>
        /// <param name="source"></param>
        /// <param name="target"></param>
        public static void DuplicateMRMInfo(MRMInfo source, out MRMInfo target)
        {
            target = new MRMInfo();
            target.Clear();

            foreach (var item in source.MRMMassList)
            {
                target.MRMMassList.Add(item);
            }
        }
예제 #4
0
        /// <summary>
        /// Duplicate the MRM info
        /// </summary>
        /// <param name="udtSource"></param>
        /// <param name="udtTarget"></param>
        public static void DuplicateMRMInfo(MRMInfo udtSource, out MRMInfo udtTarget)
        {
            udtTarget = new MRMInfo();
            udtTarget.Clear();

            foreach (var item in udtSource.MRMMassList)
            {
                udtTarget.MRMMassList.Add(item);
            }
        }
 public static void InitializeMRMInfo(out MRMInfo mrmInfo, int initialMassCountCapacity)
 {
     mrmInfo = InitializeMRMInfo();
 }
 public static void InitializeMRMInfo(out MRMInfo udtMRMInfo, int intInitialMassCountCapacity)
 {
     udtMRMInfo = InitializeMRMInfo();
 }
        public static MRMInfo InitializeMRMInfo()
        {
            var udtMRMInfo = new MRMInfo();
            udtMRMInfo.Clear();

            return udtMRMInfo;
        }
        /// <summary>
        /// Duplicate the MRM info
        /// </summary>
        /// <param name="udtSource"></param>
        /// <param name="udtTarget"></param>
        public static void DuplicateMRMInfo(MRMInfo udtSource, out MRMInfo udtTarget)
        {
            udtTarget = new MRMInfo();
            udtTarget.Clear();

            foreach (var item in udtSource.MRMMassList)
            {
                udtTarget.MRMMassList.Add(item);
            }
        }
        /// <summary>
        /// Parse out the MRM_QMS or SRM mass info from filterText
        /// </summary>
        /// <param name="filterText"></param>
        /// <param name="mrmScanType"></param>
        /// <param name="mrmInfo">Output: MRM info class</param>
        /// <remarks>We do not parse mass information out for Full Neutral Loss scans</remarks>
        public static void ExtractMRMMasses(string filterText, MRMScanTypeConstants mrmScanType, out MRMInfo mrmInfo)
        {
            // Parse out the MRM_QMS or SRM mass info from filterText
            // It should be of the form

            // SIM:              p NSI SIM ms [330.00-380.00]
            // or
            // MRM_Q1MS_TEXT:    p NSI Q1MS [179.652-184.582, 505.778-510.708, 994.968-999.898]
            // or
            // MRM_Q3MS_TEXT:    p NSI Q3MS [150.070-1500.000]
            // or
            // MRM_SRM_TEXT:     c NSI SRM ms2 [email protected] [397.209-392.211, 579.289-579.291]

            // Note: we do not parse mass information out for Full Neutral Loss scans
            // MRM_FullNL_TEXT: c NSI Full cnl 162.053 [300.000-1200.000]

            mrmInfo = new MRMInfo();

            if (string.IsNullOrWhiteSpace(filterText))
            {
                return;
            }

            if (!(mrmScanType == MRMScanTypeConstants.SIM |
                  mrmScanType == MRMScanTypeConstants.MRMQMS |
                  mrmScanType == MRMScanTypeConstants.SRM))
            {
                // Unsupported MRM type
                return;
            }

            // Parse out the text between the square brackets
            var reMatch = mMassList.Match(filterText);

            if (!reMatch.Success)
            {
                return;
            }

            reMatch = mMassRanges.Match(reMatch.Value);

            while (reMatch.Success)
            {
                try
                {
                    // Note that group 0 is the full mass range (two mass values, separated by a dash)
                    // Group 1 is the first mass value
                    // Group 2 is the second mass value

                    var mrmMassRange = new udtMRMMassRangeType
                    {
                        StartMass = double.Parse(reMatch.Groups["StartMass"].Value),
                        EndMass = double.Parse(reMatch.Groups["EndMass"].Value)
                    };

                    var centralMass = mrmMassRange.StartMass + (mrmMassRange.EndMass - mrmMassRange.StartMass) / 2;
                    mrmMassRange.CentralMass = Math.Round(centralMass, 6);

                    mrmInfo.MRMMassList.Add(mrmMassRange);

                }
                catch (Exception)
                {
                    // Error parsing out the mass values; skip this group
                }

                reMatch = reMatch.NextMatch();
            }
        }
        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;
        }