Exemple #1
0
        public void TestGetScanCountsByScanType(
            string uimfFileName,
            int frameStart,
            int frameEnd,
            int expectedMS1,
            int expectedMS2,
            int expectedTotalScanCount)
        {
            var dataFile = GetUimfDataFile(uimfFileName);

            using (var reader = new MSDataFileReader(dataFile.FullName))
            {
                Console.WriteLine("Parsing scan headers for {0}", dataFile.Name);

                var scanCount = reader.SpectrumCount;
                Console.WriteLine("Total scans: {0}", scanCount);
                Assert.AreEqual(expectedTotalScanCount, scanCount, "Total scan count mismatch");
                Console.WriteLine();

                var frameScanPairToIndexMap = reader.GetUimfFrameScanPairToIndexMapping();

                var scanCountMS1 = 0;
                var scanCountMS2 = 0;

                foreach (var frame in frameScanPairToIndexMap)
                {
                    var frameNumber   = frame.Key.Key;
                    var scanNumber    = frame.Key.Value;
                    var spectrumIndex = frame.Value;

                    if (frameNumber < frameStart || frameNumber > frameEnd)
                    {
                        continue;
                    }

                    var spectrum = reader.GetSpectrum(spectrumIndex, false);

                    if (spectrum.Level > 1)
                    {
                        scanCountMS2++;
                    }
                    else
                    {
                        scanCountMS1++;
                    }
                }

                Console.WriteLine("scanCountMS1={0}", scanCountMS1);
                Console.WriteLine("scanCountMS2={0}", scanCountMS2);

                Assert.AreEqual(expectedMS1, scanCountMS1, "MS1 scan count mismatch");
                Assert.AreEqual(expectedMS2, scanCountMS2, "MS2 scan count mismatch");
            }
        }
Exemple #2
0
        public void TestGetScanCountsByScanType(
            string dotDFolderName,
            int scanStart,
            int scanEnd,
            int expectedMS1,
            int expectedMS2,
            int expectedTotalScanCount)
        {
            var dataFolder = GetBrukerDataFolder(dotDFolderName);

            using (var reader = new MSDataFileReader(dataFolder.FullName))
            {
                Console.WriteLine("Parsing scan headers for {0}", dataFolder.Name);

                var scanCount = reader.SpectrumCount;
                Console.WriteLine("Total scans: {0}", scanCount);
                Assert.AreEqual(expectedTotalScanCount, scanCount, "Total scan count mismatch");
                Console.WriteLine();

                var scanNumberToIndexMap = reader.GetScanToIndexMapping();

                var scanCountMS1 = 0;
                var scanCountMS2 = 0;

                foreach (var scan in scanNumberToIndexMap.Where(x => x.Key >= scanStart && x.Key <= scanEnd))
                {
                    // var scanNumber = scan.Key;
                    var spectrumIndex = scan.Value;

                    var spectrum = reader.GetSpectrum(spectrumIndex, false);

                    if (spectrum.Level > 1)
                    {
                        scanCountMS2++;
                    }
                    else
                    {
                        scanCountMS1++;
                    }
                }

                Console.WriteLine("scanCountMS1={0}", scanCountMS1);
                Console.WriteLine("scanCountMS2={0}", scanCountMS2);

                Assert.AreEqual(expectedMS1, scanCountMS1, "MS1 scan count mismatch");
                Assert.AreEqual(expectedMS2, scanCountMS2, "MS2 scan count mismatch");
            }
        }
Exemple #3
0
        public MzRun(string fileName)
            : this()
        {
            var fileInfo = new FileInfo(fileName);

            if (!fileInfo.Exists)
            {
                throw new FileNotFoundException("Cannot initialize Run. File not found: " + fileName);
            }

            var fileExtension = Path.GetExtension(fileName).ToLower();

            switch (fileExtension)
            {
            case ".mzxml":
                MSFileType = Globals.MSFileType.MZXML_Rawdata;
                break;

            case ".mzml":
                MSFileType = Globals.MSFileType.MZML;
                break;

            case ".mz5":
                MSFileType = Globals.MSFileType.MZ5;
                break;

            default:
                throw new IOException("Cannot initialize Run. File extension " + fileExtension + " isn't supported. The following file extensions are supported: mzXML, mzML, and mz5");
            }

            Filename = fileName;
            var baseFilename = Path.GetFileName(Filename);

            DatasetName = baseFilename.Substring(0, baseFilename.LastIndexOf('.'));
            DataSetPath = Path.GetDirectoryName(Filename);

            _reader = new MSDataFileReader(fileName);

            MinLCScan = GetMinPossibleLCScanNum();
            MaxLCScan = GetMaxPossibleLCScanNum();
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="pWiz"></param>
        /// <param name="datasetStatsSummarizer"></param>
        /// <param name="ticAndBPIPlot"></param>
        /// <param name="lcms2DPlot"></param>
        /// <param name="saveLCMS2DPlots"></param>
        /// <param name="saveTICAndBPI"></param>
        /// <param name="checkCentroidingStatus"></param>
        public clsProteoWizardDataParser(
            MSDataFileReader pWiz,
            DatasetStatsSummarizer datasetStatsSummarizer,
            clsTICandBPIPlotter ticAndBPIPlot,
            clsLCMSDataPlotter lcms2DPlot,
            bool saveLCMS2DPlots,
            bool saveTICAndBPI,
            bool checkCentroidingStatus)
        {
            mPWiz = pWiz;
            mDatasetStatsSummarizer = datasetStatsSummarizer;
            mTICAndBPIPlot          = ticAndBPIPlot;
            mLCMS2DPlot             = lcms2DPlot;

            mSaveLCMS2DPlots        = saveLCMS2DPlots;
            mSaveTICAndBPI          = saveTICAndBPI;
            mCheckCentroidingStatus = checkCentroidingStatus;

            mGetQ1MZ = new Regex("Q[0-9]=([0-9.]+)", RegexOptions.Compiled);

            mGetQ3MZ = new Regex("Q1=[0-9.]+ Q3=([0-9.]+)", RegexOptions.Compiled);

            mWarnedAccessViolationException = false;
        }
        public void TestPWiz(
            string fileOrDirectoryName,
            bool isDirectory,
            int expectedSpectraInFile,
            int expectedSpectraLoaded,
            int expectedTotalDataPoints,
            double expectedMedianTIC,
            double expectedMedianBPI)
        {
            try
            {
                if (!InstrumentDataUtilities.FindInstrumentData(fileOrDirectoryName, isDirectory, out var instrumentDataFileOrDirectory))
                {
                    Assert.Fail("File or directory not found");
                    return;
                }

                using (var reader = new MSDataFileReader(instrumentDataFileOrDirectory.FullName))
                {
                    Console.WriteLine("Chromatogram count: " + reader.ChromatogramCount);
                    Console.WriteLine();

                    var ticIntensities = new Dictionary <int, float>();

                    for (var chromatogramIndex = 0; chromatogramIndex < reader.ChromatogramCount; chromatogramIndex++)
                    {
                        // Note that even for a small .Wiff file (1.5 MB), obtaining the Chromatogram list will take some time (20 to 60 seconds)
                        // The chromatogram at index 0 should be the TIC
                        // The chromatogram at index >=1 will be each SRM

                        reader.GetChromatogram(chromatogramIndex, out var chromatogramID, out var timeArray, out var intensityArray);

                        // Determine the chromatogram type

                        if (chromatogramID == null)
                        {
                            chromatogramID = string.Empty;
                        }

                        var cvParams = reader.GetChromatogramCVParams(chromatogramIndex);

                        if (MSDataFileReader.TryGetCVParamDouble(cvParams, pwiz.CLI.cv.CVID.MS_TIC_chromatogram, out _))
                        {
                            // This chromatogram is the TIC
                            Console.WriteLine("TIC has id {0} and {1} data points", chromatogramID, timeArray.Length);

                            for (var i = 0; i < intensityArray.Length; i++)
                            {
                                ticIntensities.Add(i, intensityArray[i]);
                            }
                        }

                        if (MSDataFileReader.TryGetCVParamDouble(cvParams, pwiz.CLI.cv.CVID.MS_selected_reaction_monitoring_chromatogram, out _))
                        {
                            // This chromatogram is an SRM scan
                            Console.WriteLine("SRM scan has id {0} and {1} data points", chromatogramID, timeArray.Length);
                        }
                    }

                    Console.WriteLine("Spectrum count: " + reader.SpectrumCount);

                    var    spectraLoaded    = 0;
                    long   totalPointsRead  = 0;
                    double ticSumAllSpectra = 0;
                    double bpiSumAllSpectra = 0;

                    var spectrumIndex = 0;
                    while (spectrumIndex < reader.SpectrumCount)
                    {
                        var spectrum = reader.GetSpectrum(spectrumIndex, getBinaryData: true);
                        spectraLoaded += 1;

                        Console.WriteLine();
                        Console.WriteLine("ScanIndex {0}, NativeId {1}, Elution Time {2:F2} minutes, MS Level {3}",
                                          spectrumIndex, spectrum.NativeId, spectrum.RetentionTime, spectrum.Level);

                        // Use the following to get the MZs and Intensities
                        var mzList      = spectrum.Mzs.ToList();
                        var intensities = spectrum.Intensities.ToList();

                        if (mzList.Count > 0)
                        {
                            Console.WriteLine("  Data count: " + mzList.Count);

                            totalPointsRead += mzList.Count;

                            double tic = 0;
                            double bpi = 0;
                            for (var index = 0; index <= mzList.Count - 1; index++)
                            {
                                tic += intensities[index];
                                if (intensities[index] > bpi)
                                {
                                    bpi = intensities[index];
                                }
                            }

                            ticSumAllSpectra += tic;
                            bpiSumAllSpectra += bpi;

                            if (!ticIntensities.TryGetValue(spectrumIndex, out var ticFromChromatogram))
                            {
                                ticFromChromatogram = -1;
                            }

                            var spectrumInfo = reader.GetSpectrumObject(spectrumIndex);

                            if (MSDataFileReader.TryGetCVParamDouble(spectrumInfo.cvParams, pwiz.CLI.cv.CVID.MS_total_ion_current,
                                                                     out var ticFromSpectrumObject))
                            {
                                if (ticFromChromatogram < 0)
                                {
                                    // ticIntensities did not have an entry for spectrumIndex
                                    // This could be the case on a Waters Synapt instrument, where ticIntensities has one TIC per frame,
                                    // while pWiz.GetSpectrum() returns individual mass spectra, of which there could be hundreds of spectra per frame
                                    Console.WriteLine("  TIC from actual data is {0:E2} vs. {1:E2} from the spectrum object",
                                                      tic, ticFromSpectrumObject);
                                }
                                else
                                {
                                    // Note: the TIC value from the CvParams has been seen to be drastically off from the manually computed value
                                    Console.WriteLine(
                                        "  TIC from actual data is {0:E2} vs. {1:E2} from the chromatogram and {2:E2} from the spectrum object",
                                        tic, ticFromChromatogram, ticFromSpectrumObject);
                                }
                            }

                            if (MSDataFileReader.TryGetCVParamDouble(spectrumInfo.cvParams, pwiz.CLI.cv.CVID.MS_base_peak_intensity,
                                                                     out var bpiFromSpectrumObject))
                            {
                                if (MSDataFileReader.TryGetCVParamDouble(spectrumInfo.cvParams, pwiz.CLI.cv.CVID.MS_base_peak_m_z,
                                                                         out var bpiMzFromSpectrumObject))
                                {
                                    // Note: the BPI intensity from the CvParams has been seen to be drastically off from the manually computed value
                                    Console.WriteLine("  BPI from spectrum object is {0:E2} at {1:F3} m/z",
                                                      bpiFromSpectrumObject, bpiMzFromSpectrumObject);
                                }
                            }
                        }

                        if (spectrumIndex < 25)
                        {
                            spectrumIndex += 1;
                        }
                        else if (spectrumIndex < 1250)
                        {
                            spectrumIndex += 50;
                        }
                        else
                        {
                            spectrumIndex += 500;
                        }
                    }

                    if (spectraLoaded > 0)
                    {
                        var medianTIC = ticSumAllSpectra / spectraLoaded;
                        var medianBPI = bpiSumAllSpectra / spectraLoaded;

                        Console.WriteLine();
                        Console.WriteLine("Read {0:N0} data points from {1} spectra in {2}",
                                          totalPointsRead, spectraLoaded, Path.GetFileName(fileOrDirectoryName));

                        Console.WriteLine("Median TIC: {0:E4}", medianTIC);
                        Console.WriteLine("Median BPI: {0:E4}", medianBPI);

                        Assert.AreEqual(expectedSpectraInFile, reader.SpectrumCount, "Total spectrum count mismatch");

                        Assert.AreEqual(expectedSpectraLoaded, spectraLoaded, "Spectra loaded mismatch");

                        Assert.AreEqual(expectedTotalDataPoints, totalPointsRead, "Spectra loaded mismatch");
                        var ticComparisonTolerance = expectedMedianTIC * 0.01;
                        var bpiComparisonTolerance = expectedMedianBPI * 0.01;

                        Assert.AreEqual(expectedMedianTIC, medianTIC, ticComparisonTolerance, "Median TIC mismatch");
                        Assert.AreEqual(expectedMedianBPI, medianBPI, bpiComparisonTolerance, "Median BPI mismatch");
                    }
                }
            }
            catch (Exception ex)
            {
                ConsoleMsgUtils.ShowError("Error using ProteoWizard reader", ex);
            }
        }
        public bool StoreMSSpectraInfo(
            bool ticStored,
            ref double runtimeMinutes,
            bool skipExistingScans,
            bool skipScansWithNoIons,
            int maxScansToTrackInDetail,
            int maxScansForTicAndBpi,
            out int scanCountSuccess,
            out int scanCountError)
        {
            scanCountSuccess = 0;
            scanCountError   = 0;

            try
            {
                Console.WriteLine();
                OnStatusEvent("Obtaining scan times and MSLevels (this could take several minutes)");
                mLastScanLoadingDebugProgressTime  = DateTime.UtcNow;
                mLastScanLoadingStatusProgressTime = DateTime.UtcNow;
                mReportedTotalSpectraToExamine     = false;

                mCancellationToken = new CancellationTokenSource();

                var scanTimes = new double[0];
                var msLevels  = new byte[0];

                mGetScanTimesStartTime          = DateTime.UtcNow;
                mGetScanTimesMaxWaitTimeSeconds = 90;
                mGetScanTimesAutoAborted        = false;

                var minScanIndexWithoutScanTimes = int.MaxValue;

                try
                {
                    mPWiz.GetScanTimesAndMsLevels(mCancellationToken.Token, out scanTimes, out msLevels, MonitorScanTimeLoadingProgress);
                }
                catch (OperationCanceledException)
                {
                    // mCancellationToken.Cancel was called in MonitorScanTimeLoadingProgress

                    // Determine the scan index where GetScanTimesAndMsLevels exited the for loop
                    for (var scanIndex = 0; scanIndex <= scanTimes.Length - 1; scanIndex++)
                    {
                        if (msLevels[scanIndex] > 0)
                        {
                            continue;
                        }

                        minScanIndexWithoutScanTimes = scanIndex;
                        break;
                    }

                    if (!mGetScanTimesAutoAborted && minScanIndexWithoutScanTimes < int.MaxValue)
                    {
                        // Manually aborted; shrink the arrays to reflect the amount of data that was actually loaded
                        Array.Resize(ref scanTimes, minScanIndexWithoutScanTimes);
                        Array.Resize(ref msLevels, minScanIndexWithoutScanTimes);
                    }
                }

                var spectrumCount = scanTimes.Length;

                // The scan times returned by .GetScanTimesAndMsLevels() are the acquisition time in seconds from the start of the analysis
                // Convert these to minutes
                for (var scanIndex = 0; scanIndex <= spectrumCount - 1; scanIndex++)
                {
                    if (scanIndex >= minScanIndexWithoutScanTimes)
                    {
                        break;
                    }

                    var scanTimeMinutes = scanTimes[scanIndex] / 60.0;
                    scanTimes[scanIndex] = scanTimeMinutes;
                }

                Console.WriteLine();
                OnStatusEvent("Reading spectra");
                var lastDebugProgressTime  = DateTime.UtcNow;
                var lastStatusProgressTime = DateTime.UtcNow;
                var skippedEmptyScans      = 0;

                var scanNumber           = 0;
                var scansStored          = 0;
                var ticAndBpiScansStored = 0;

                var scanCountHMS  = 0;
                var scanCountHMSn = 0;
                var scanCountMS   = 0;
                var scanCountMSn  = 0;

                for (var scanIndex = 0; scanIndex <= spectrumCount - 1; scanIndex++)
                {
                    try
                    {
                        var computeTIC = true;
                        var computeBPI = true;

                        // Obtain the raw mass spectrum
                        var msDataSpectrum = mPWiz.GetSpectrum(scanIndex);

                        scanNumber = scanIndex + 1;

                        if (scanIndex >= minScanIndexWithoutScanTimes)
                        {
                            // msDataSpectrum.RetentionTime is already in minutes
                            scanTimes[scanIndex] = msDataSpectrum.RetentionTime ?? 0;

                            if (msDataSpectrum.Level >= byte.MinValue && msDataSpectrum.Level <= byte.MaxValue)
                            {
                                msLevels[scanIndex] = (byte)msDataSpectrum.Level;
                            }
                        }

                        var scanStatsEntry = new ScanStatsEntry
                        {
                            ScanNumber = scanNumber,
                            ScanType   = msDataSpectrum.Level
                        };

                        if (msLevels[scanIndex] > 1)
                        {
                            if (HighResMS2)
                            {
                                scanStatsEntry.ScanTypeName = "HMSn";
                                scanCountHMSn++;
                            }
                            else
                            {
                                scanStatsEntry.ScanTypeName = "MSn";
                                scanCountMSn++;
                            }
                        }
                        else
                        {
                            if (HighResMS1)
                            {
                                scanStatsEntry.ScanTypeName = "HMS";
                                scanCountHMS++;
                            }
                            else
                            {
                                scanStatsEntry.ScanTypeName = "MS";
                                scanCountMS++;
                            }
                        }

                        var driftTimeMsec = msDataSpectrum.DriftTimeMsec ?? 0;

                        scanStatsEntry.ScanFilterText = driftTimeMsec > 0 ? "IMS" : string.Empty;
                        scanStatsEntry.ExtendedScanInfo.ScanFilterText = scanStatsEntry.ScanFilterText;

                        scanStatsEntry.DriftTimeMsec = driftTimeMsec.ToString("0.0###");

                        scanStatsEntry.ElutionTime = scanTimes[scanIndex].ToString("0.0###");

                        // Bump up runtimeMinutes if necessary
                        if (scanTimes[scanIndex] > runtimeMinutes)
                        {
                            runtimeMinutes = scanTimes[scanIndex];
                        }

                        var spectrum = mPWiz.GetSpectrumObject(scanIndex);

                        if (MSDataFileReader.TryGetCVParamDouble(spectrum.cvParams, pwiz.CLI.cv.CVID.MS_total_ion_current, out var tic))
                        {
                            // For timsTOF data, this is the TIC of the entire frame
                            scanStatsEntry.TotalIonIntensity = StringUtilities.ValueToString(tic, 5);
                            computeTIC = false;
                        }

                        if (MSDataFileReader.TryGetCVParamDouble(spectrum.cvParams, pwiz.CLI.cv.CVID.MS_base_peak_intensity, out var bpi))
                        {
                            // For timsTOF data, this is the BPI of the entire frame
                            // Additionally, for timsTOF data, MS_base_peak_m_z is not defined
                            scanStatsEntry.BasePeakIntensity = StringUtilities.ValueToString(bpi, 5);

                            if (MSDataFileReader.TryGetCVParamDouble(spectrum.scanList.scans[0].cvParams, pwiz.CLI.cv.CVID.MS_base_peak_m_z, out var basePeakMzFromCvParams))
                            {
                                scanStatsEntry.BasePeakMZ = StringUtilities.ValueToString(basePeakMzFromCvParams, 5);
                                computeBPI = false;
                            }
                        }

                        if (string.IsNullOrEmpty(scanStatsEntry.ScanFilterText))
                        {
                            if (spectrum?.scanList?.scans.Count > 0)
                            {
                                // Bruker timsTOF datasets will have CVParam "inverse reduced ion mobility" for IMS spectra; check for this
                                foreach (var scanItem in spectrum.scanList.scans)
                                {
                                    if (MSDataFileReader.TryGetCVParam(scanItem.cvParams, pwiz.CLI.cv.CVID.MS_inverse_reduced_ion_mobility, out _))
                                    {
                                        scanStatsEntry.ScanFilterText = "IMS";
                                        break;
                                    }
                                }
                            }
                        }

                        // Base peak signal to noise ratio
                        scanStatsEntry.BasePeakSignalToNoiseRatio = "0";

                        scanStatsEntry.IonCount    = msDataSpectrum.Mzs.Length;
                        scanStatsEntry.IonCountRaw = scanStatsEntry.IonCount;

                        if ((computeBPI || computeTIC) && scanStatsEntry.IonCount > 0)
                        {
                            // Step through the raw data to compute the BPI and TIC

                            var mzList      = msDataSpectrum.Mzs;
                            var intensities = msDataSpectrum.Intensities;

                            tic = 0;
                            bpi = 0;
                            double basePeakMZ = 0;

                            for (var index = 0; index <= mzList.Length - 1; index++)
                            {
                                tic += intensities[index];
                                if (intensities[index] > bpi)
                                {
                                    bpi        = intensities[index];
                                    basePeakMZ = mzList[index];
                                }
                            }

                            scanStatsEntry.TotalIonIntensity = StringUtilities.ValueToString(tic, 5);
                            scanStatsEntry.BasePeakIntensity = StringUtilities.ValueToString(bpi, 5);
                            scanStatsEntry.BasePeakMZ        = StringUtilities.ValueToString(basePeakMZ, 5);
                        }

                        var addScan = !skipExistingScans || skipExistingScans && !mDatasetStatsSummarizer.HasScanNumber(scanNumber);

                        if (addScan)
                        {
                            if (skipScansWithNoIons && scanStatsEntry.IonCount == 0)
                            {
                                skippedEmptyScans++;

                                if (skippedEmptyScans < 25 ||
                                    skippedEmptyScans < 100 && skippedEmptyScans % 10 == 0 ||
                                    skippedEmptyScans < 1000 && skippedEmptyScans % 100 == 0 ||
                                    skippedEmptyScans < 10000 && skippedEmptyScans % 1000 == 0 ||
                                    skippedEmptyScans < 100000 && skippedEmptyScans % 10000 == 0 ||
                                    skippedEmptyScans % 100000 == 0)
                                {
                                    ConsoleMsgUtils.ShowDebug("Skipping scan {0:N0} since no ions; {1:N0} total skipped scans", scanNumber, skippedEmptyScans);
                                }
                            }
                            else
                            {
                                if (maxScansToTrackInDetail < 0 || scansStored < maxScansToTrackInDetail)
                                {
                                    mDatasetStatsSummarizer.AddDatasetScan(scanStatsEntry);
                                    scansStored += 1;
                                }
                            }
                        }

                        if (mSaveTICAndBPI && !ticStored && (maxScansForTicAndBpi < 0 || ticAndBpiScansStored < maxScansForTicAndBpi))
                        {
                            mTICAndBPIPlot.AddData(scanStatsEntry.ScanNumber, msLevels[scanIndex], (float)scanTimes[scanIndex], bpi, tic);
                            ticAndBpiScansStored += 1;
                        }

                        if (mSaveLCMS2DPlots && addScan)
                        {
                            mLCMS2DPlot.AddScan(scanStatsEntry.ScanNumber, msLevels[scanIndex], (float)scanTimes[scanIndex], msDataSpectrum.Mzs.Length, msDataSpectrum.Mzs, msDataSpectrum.Intensities);
                        }

                        if (mCheckCentroidingStatus)
                        {
                            mDatasetStatsSummarizer.ClassifySpectrum(msDataSpectrum.Mzs, msLevels[scanIndex], "Scan " + scanStatsEntry.ScanNumber);
                        }

                        scanCountSuccess += 1;
                    }
                    catch (Exception ex)
                    {
                        OnErrorEvent("Error loading header info for scan " + scanNumber, ex);
                        scanCountError += 1;
                    }

                    if (DateTime.UtcNow.Subtract(lastStatusProgressTime).TotalMinutes > 5)
                    {
                        OnStatusEvent(string.Format("Reading spectra, loaded {0:N0} / {1:N0} spectra; " +
                                                    "{2:N0} HMS spectra; {3:N0} HMSn spectra; " +
                                                    "{4:N0} MS spectra; {5:N0} MSn spectra; " +
                                                    "max elution time is {6:F2} minutes",
                                                    scanNumber, spectrumCount,
                                                    scanCountHMS, scanCountHMSn,
                                                    scanCountMS, scanCountMSn,
                                                    runtimeMinutes));

                        lastStatusProgressTime = DateTime.UtcNow;
                        lastDebugProgressTime  = DateTime.UtcNow;
                        continue;
                    }

                    if (DateTime.UtcNow.Subtract(lastDebugProgressTime).TotalSeconds < 15)
                    {
                        continue;
                    }

                    lastDebugProgressTime = DateTime.UtcNow;
                    var percentComplete = scanNumber / (float)spectrumCount * 100;

                    var percentCompleteOverall = clsMSFileInfoProcessorBaseClass.ComputeIncrementalProgress(
                        PROGRESS_SCAN_TIMES_LOADED,
                        clsMSFileInfoProcessorBaseClass.PROGRESS_SPECTRA_LOADED,
                        percentComplete);

                    OnProgressUpdate(string.Format("Spectra processed: {0:N0}", scanNumber), percentCompleteOverall);
                }

                mDatasetStatsSummarizer.StoreScanTypeTotals(scanCountHMS, scanCountHMSn,
                                                            scanCountMS, scanCountMSn,
                                                            runtimeMinutes);

                var scanCountTotal = scanCountSuccess + scanCountError;
                if (scanCountTotal == 0)
                {
                    return(false);
                }

                // Return True if at least 50% of the spectra were successfully read
                return(scanCountSuccess >= scanCountTotal / 2.0);
            }
            catch (AccessViolationException)
            {
                // Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
                if (!mWarnedAccessViolationException)
                {
                    OnWarningEvent("Error reading instrument data with ProteoWizard: Attempted to read or write protected memory. " +
                                   "The instrument data file is likely corrupt.");
                    mWarnedAccessViolationException = true;
                }
                mDatasetStatsSummarizer.CreateEmptyScanStatsFiles = false;
                return(false);
            }
            catch (Exception ex)
            {
                OnErrorEvent("Error reading instrument data with ProteoWizard: " + ex.Message, ex);
                return(false);
            }
        }
        public void StoreChromatogramInfo(DatasetFileInfo datasetFileInfo, out bool ticStored, out bool srmDataCached, out double runtimeMinutes)
        {
            var ticScanTimes   = new List <float>();
            var ticScanNumbers = new List <int>();

            // This dictionary tracks the m/z and intensity values for parent (Q1) ions of each scan
            // Key is ScanNumber; Value is a dictionary holding m/z and intensity values for that scan
            var dct2DDataParent = new Dictionary <int, Dictionary <double, double> >();

            // This dictionary tracks the m/z and intensity values for product (Q3) ions of each scan
            var dct2DDataProduct = new Dictionary <int, Dictionary <double, double> >();

            // This dictionary tracks the scan times for each scan number tracked by dct2DDataParent and/or dct2DDataProduct
            var dct2DDataScanTimes = new Dictionary <int, float>();

            // Note that even for a small .Wiff file (1.5 MB), obtaining the first chromatogram will take some time (20 to 60 seconds)
            // The chromatogram at index 0 should be the TIC
            // The chromatogram at index >=1 will be each SRM

            runtimeMinutes = 0;
            ticStored      = false;
            srmDataCached  = false;

            for (var chromatogramIndex = 0; chromatogramIndex <= mPWiz.ChromatogramCount - 1; chromatogramIndex++)
            {
                try
                {
                    if (chromatogramIndex == 0)
                    {
                        OnStatusEvent("Obtaining chromatograms (this could take as long as 60 seconds)");
                    }

                    mPWiz.GetChromatogram(chromatogramIndex, out var chromatogramID, out var scanTimes, out var intensities);

                    if (chromatogramID == null)
                    {
                        chromatogramID = string.Empty;
                    }

                    var cvParams = mPWiz.GetChromatogramCVParams(chromatogramIndex);

                    if (MSDataFileReader.TryGetCVParam(cvParams, pwiz.CLI.cv.CVID.MS_TIC_chromatogram, out _))
                    {
                        // This chromatogram is the TIC

                        var storeInTICAndBPIPlot = (mSaveTICAndBPI && mPWiz.SpectrumCount == 0);

                        ProcessTIC(scanTimes, intensities, ticScanTimes, ticScanNumbers, ref runtimeMinutes, storeInTICAndBPIPlot);

                        ticStored = storeInTICAndBPIPlot;

                        // This is FrameCount for Bruker timsTOF datasets
                        datasetFileInfo.ScanCount = scanTimes.Length;
                    }

                    if (MSDataFileReader.TryGetCVParam(cvParams, pwiz.CLI.cv.CVID.MS_selected_reaction_monitoring_chromatogram, out _))
                    {
                        // This chromatogram is an SRM scan

                        ProcessSRM(chromatogramID, scanTimes, intensities, ticScanTimes, ticScanNumbers, ref runtimeMinutes, dct2DDataParent,
                                   dct2DDataProduct, dct2DDataScanTimes);

                        srmDataCached = true;
                    }
                }
                catch (AccessViolationException)
                {
                    // Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
                    if (!mWarnedAccessViolationException)
                    {
                        OnWarningEvent("Error loading chromatogram data with ProteoWizard: Attempted to read or write protected memory. " +
                                       "The instrument data file is likely corrupt.");
                        mWarnedAccessViolationException = true;
                    }
                    mDatasetStatsSummarizer.CreateEmptyScanStatsFiles = false;
                }
                catch (Exception ex)
                {
                    OnErrorEvent("Error processing chromatogram " + chromatogramIndex + " with ProteoWizard: " + ex.Message, ex);
                }
            }

            if (!mSaveLCMS2DPlots)
            {
                return;
            }

            if (dct2DDataParent.Count <= 0 && dct2DDataProduct.Count <= 0)
            {
                return;
            }

            // Now that all of the chromatograms have been processed, transfer data from dct2DDataParent and dct2DDataProduct into mLCMS2DPlot
            mLCMS2DPlot.Options.MS1PlotTitle = "Q1 m/z";
            mLCMS2DPlot.Options.MS2PlotTitle = "Q3 m/z";

            Store2DPlotData(dct2DDataScanTimes, dct2DDataParent, dct2DDataProduct);
        }
Exemple #8
0
        public void TestGetScanData(string dotDFolderName, int scanStart, int scanEnd)
        {
            var expectedData = new Dictionary <string, Dictionary <int, string> >();

            // Keys in this dictionary are the scan number of data being retrieved
            var file1Data = new Dictionary <int, string>
            {
                { 5, "5 39775    39775    982.741  0.0E+0   1410.843 8.7E+4" },
                { 6, "6 39775    39775    982.741  0.0E+0   1410.843 9.1E+4" },
                { 7, "7 39775    39775    982.741  0.0E+0   1410.843 8.7E+4" },
                { 8, "8 39775    39775    982.741  0.0E+0   1410.843 4.5E+4" },
                { 9, "9 39775    39775    982.741  0.0E+0   1410.843 1.4E+5" }
            };

            expectedData.Add("Humira_100fmol_20121026_hi_res_9_01_716", file1Data);

            var file2Data = new Dictionary <int, string>
            {
                { 1, "1 7615807  7615807  110.561  3.8E+4   202.468  4.2E+5" }
            };

            expectedData.Add("Blank-2_05May16_Leopard_Infuse_1_01_7976", file2Data);

            var dataFolder = GetBrukerDataFolder(dotDFolderName);

            using (var reader = new MSDataFileReader(dataFolder.FullName))
            {
                Console.WriteLine("Scan data for {0}", dataFolder.Name);
                Console.WriteLine("{0} {1,-8} {2,-8} {3,-8} {4,-8} {5,-8} {6}",
                                  "Scan", "MzCount", "IntCount",
                                  "FirstMz", "FirstInt", "MidMz", "MidInt");

                var scanNumberToIndexMap = reader.GetScanToIndexMapping();

                foreach (var scan in scanNumberToIndexMap.Where(x => x.Key >= scanStart && x.Key <= scanEnd))
                {
                    var scanNumber    = scan.Key;
                    var spectrumIndex = scan.Value;

                    var spectrum = reader.GetSpectrum(spectrumIndex, true);

                    var dataPointsRead = spectrum.Mzs.Length;

                    Assert.IsTrue(dataPointsRead > 0, "GetScanData returned 0 for scan {0}", scanNumber);

                    var midPoint = (int)(spectrum.Intensities.Length / 2f);

                    var scanSummary =
                        string.Format(
                            "{0} {1,-8} {2,-8} {3,-8:0.000} {4,-8:0.0E+0} {5,-8:0.000} {6:0.0E+0}",
                            scanNumber,
                            spectrum.Mzs.Length, spectrum.Intensities.Length,
                            spectrum.Mzs[0], spectrum.Intensities[0],
                            spectrum.Mzs[midPoint], spectrum.Intensities[midPoint]);

                    Console.WriteLine(scanSummary);

                    if (!expectedData.TryGetValue(Path.GetFileNameWithoutExtension(dataFolder.Name), out var expectedDataThisFile))
                    {
                        Assert.Fail("Dataset {0} not found in dictionary expectedData", dataFolder.Name);
                    }

                    if (expectedDataThisFile.TryGetValue(scanNumber, out var expectedDataDetails))
                    {
                        Assert.AreEqual(expectedDataDetails, scanSummary,
                                        "Scan details mismatch, scan " + scanNumber);
                    }
                }
            }
        }
Exemple #9
0
        public void TestCorruptDataHandling(
            string dotDFolderName,
            int scanStart,
            int scanEnd,
            int expectedMS1,
            int expectedMS2)
        {
            var dataFolder = GetBrukerDataFolder(dotDFolderName);

            try
            {
                using (var reader = new MSDataFileReader(dataFolder.FullName))
                {
                    var scanCount = reader.SpectrumCount;
                    Console.WriteLine("Scan count for {0}: {1}", dataFolder.Name, scanCount);

                    if (expectedMS1 + expectedMS2 == 0)
                    {
                        Assert.IsTrue(scanCount == 0, "ScanCount is non-zero, while we expected it to be 0");
                    }
                    else
                    {
                        Assert.IsTrue(scanCount > 0, "ScanCount is zero, while we expected it to be > 0");
                    }

                    var scanNumberToIndexMap = reader.GetScanToIndexMapping();

                    var scanCountMS1 = 0;
                    var scanCountMS2 = 0;

                    foreach (var scan in scanNumberToIndexMap.Where(x => x.Key >= scanStart && x.Key <= scanEnd))
                    {
                        var scanNumber    = scan.Key;
                        var spectrumIndex = scan.Value;

                        try
                        {
                            var spectrum = reader.GetSpectrum(spectrumIndex, true);

                            var cvScanInfo = reader.GetSpectrumScanInfo(spectrumIndex);

                            Assert.IsTrue(cvScanInfo != null, "GetSpectrumScanInfo returned a null object for scan {0}", scanNumber);

                            if (spectrum.Level > 1)
                            {
                                scanCountMS2++;
                            }
                            else
                            {
                                scanCountMS1++;
                            }

                            var dataPointCount = spectrum.Mzs.Length;

                            Assert.IsTrue(dataPointCount > 0, "Data point count is 0 for scan {0}", scanNumber);
                            Assert.IsTrue(spectrum.Mzs.Length > 0, "m/z data is empty for scan {0}", scanNumber);
                            Assert.IsTrue(spectrum.Intensities.Length > 0, "Intensity data is empty for scan {0}", scanNumber);
                            Assert.IsTrue(spectrum.Mzs.Length == spectrum.Intensities.Length, "Array length mismatch for m/z and intensity data for scan {0}", scanNumber);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Exception reading scan {0}: {1}", scanNumber, ex.Message);
                            Assert.Fail("Exception reading scan {0}", scanNumber);
                        }
                    }

                    Console.WriteLine("scanCountMS1={0}", scanCountMS1);
                    Console.WriteLine("scanCountMS2={0}", scanCountMS2);

                    Assert.AreEqual(expectedMS1, scanCountMS1, "MS1 scan count mismatch");
                    Assert.AreEqual(expectedMS2, scanCountMS2, "MS2 scan count mismatch");
                }
            }
            catch (Exception ex)
            {
                if (expectedMS1 + expectedMS2 == 0)
                {
                    Console.WriteLine("Error opening .D folder (this was expected):\n{0}", ex.Message);
                }
                else
                {
                    var msg = string.Format("Exception opening .D folder {0}:\n{1}", dotDFolderName, ex.Message);
                    Console.WriteLine(msg);
                    Assert.Fail(msg);
                }
            }
        }
Exemple #10
0
        public void TestGetScanInfo(string dotDFolderName, int scanStart, int scanEnd, int expectedMS1, int expectedMS2)
        {
            var expectedData = new Dictionary <string, Dictionary <int, string> >();

            // Keys in this dictionary are the scan number whose metadata is being retrieved
            var file1Data = new Dictionary <int, string>
            {
                // Scan MSLevel NumPeaks RetentionTime ScanStartTime DriftTimeMsec LowMass HighMass TotalIonCurrent BasePeakMZ BasePeakIntensity ParentIonMZ
                { 1, "1 1 7794096   0.59  35.34 0  92  1300 7.1E+9    0.000 5.5E+8     0.00          positive False   696.00" },
                { 2, "2 1 7794096   1.10  66.27 0  92  1300 7.2E+9    0.000 5.6E+8     0.00          positive False   696.00" },
                { 3, "3 1 7794096   1.62  97.18 0  92  1300 7.2E+9    0.000 5.5E+8     0.00          positive False   696.00" },
                { 4, "4 1 7794096   2.14 128.17 0  92  1300 7.1E+9    0.000 5.3E+8     0.00          positive False   696.00" },
                { 5, "5 1 7794096   2.65 159.12 0  92  1300 7.1E+9    0.000 5.4E+8     0.00          positive False   696.00" }
            };

            expectedData.Add("2016_04_12_Background_000001", file1Data);

            var file2Data = new Dictionary <int, string>
            {
                { 1, "1 1 7615807   3.58 214.92 0 111  1200 3.6E+10    0.000 3.1E+9     0.00          negative False   655.50" }
            };

            expectedData.Add("Blank-2_05May16_Leopard_Infuse_1_01_7976", file2Data);

            var file3Data = new Dictionary <int, string>
            {
                { 15, "15 1 39775   2.38 142.89 0 983   984 0.0E+0    0.000 0.0E+0     0.00          positive False   983.50" },
                { 16, "16 1 39775   2.53 152.06 0 983   984 0.0E+0    0.000 0.0E+0     0.00          positive False   983.50" },
                { 17, "17 1 39775   2.69 161.24 0 983   984 0.0E+0    0.000 0.0E+0     0.00          positive False   983.50" },
                { 18, "18 1 39775   2.84 170.41 0 983   984 0.0E+0    0.000 0.0E+0     0.00          positive False   983.50" },
                { 19, "19 1 39775   2.99 179.58 0 983   984 0.0E+0    0.000 0.0E+0     0.00          positive False   983.50" },
                { 20, "20 1 39775   3.15 188.76 0 983   984 0.0E+0    0.000 0.0E+0     0.00          positive False   983.50" }
            };

            expectedData.Add("Humira_100fmol_20121026_hi_res_9_01_716", file3Data);

            var file4Data = new Dictionary <int, string>
            {
                { 1, "1 2 8214787   2.20 131.89 0 207 10000 6.0E+8    0.000 1.3E+7  1600.00 cid      negative False  1600.00" }
            };

            expectedData.Add("MZ20160603PPS_edta_000004", file4Data);


            var dataFolder = GetBrukerDataFolder(dotDFolderName);

            using (var reader = new MSDataFileReader(dataFolder.FullName))
            {
                Console.WriteLine("Scan info for {0}", dataFolder.Name);
                Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13} {14} {15}",
                                  "Scan", "MSLevel",
                                  "NumPeaks", "RetentionTime",
                                  "ScanStartTime",
                                  "DriftTimeMsec",
                                  "LowMass", "HighMass", "TotalIonCurrent",
                                  "BasePeakMZ", "BasePeakIntensity",
                                  "ParentIonMZ", "ActivationType",
                                  "IonMode", "IsCentroided",
                                  "IsolationMZ");

                var scanNumberToIndexMap = reader.GetScanToIndexMapping();

                var scanCountMS1 = 0;
                var scanCountMS2 = 0;

                foreach (var scan in scanNumberToIndexMap.Where(x => x.Key >= scanStart && x.Key <= scanEnd))
                {
                    var scanNumber    = scan.Key;
                    var spectrumIndex = scan.Value;

                    var spectrum       = reader.GetSpectrum(spectrumIndex, true);
                    var spectrumParams = reader.GetSpectrumCVParamData(spectrumIndex);
                    var cvScanInfo     = reader.GetSpectrumScanInfo(spectrumIndex);

                    Assert.IsTrue(spectrum != null, "GetSpectrum returned a null object for scan " + scanNumber);

                    var totalIonCurrent   = cvParamUtilities.GetCvParamValueDbl(spectrumParams, cvParamUtilities.CVIDs.MS_TIC);
                    var basePeakMZ        = cvParamUtilities.GetCvParamValueDbl(spectrumParams, cvParamUtilities.CVIDs.MS_base_peak_m_z);
                    var basePeakIntensity = cvParamUtilities.GetCvParamValueDbl(spectrumParams, cvParamUtilities.CVIDs.MS_base_peak_intensity);

                    double isolationMZ    = 0;
                    double parentIonMZ    = 0;
                    var    activationType = string.Empty;

                    if (spectrum.Precursors.Length > 0)
                    {
                        var precursor = spectrum.Precursors[0];

                        isolationMZ = precursor.IsolationMz.GetValueOrDefault();
                        parentIonMZ = precursor.PrecursorMz.GetValueOrDefault();

                        if (precursor.ActivationTypes != null)
                        {
                            activationType = string.Join(", ", precursor.ActivationTypes);
                        }
                    }

                    GetScanMetadata(cvScanInfo, out var scanStartTime, out var lowMass, out var highMass);

                    var retentionTime = cvParamUtilities.CheckNull(spectrum.RetentionTime);

                    var numPeaks = spectrum.Mzs.Length;
                    var ionMode  = spectrum.NegativeCharge ? "negative" : "positive";

                    var scanSummary =
                        string.Format(
                            "{0} {1} {2,5} {3,6:0.00} {4,6:0.00} {5:0} {6,3:0} {7,5:0} {8,6:0.0E+0} {9,8:0.000} {10,6:0.0E+0} {11,8:0.00} {12,-8} {13} {14,-5} {15,8:0.00}",
                            scanNumber, spectrum.Level,
                            numPeaks, retentionTime, scanStartTime,
                            cvParamUtilities.CheckNull(spectrum.DriftTimeMsec),
                            lowMass, highMass,
                            totalIonCurrent,
                            basePeakMZ, basePeakIntensity, parentIonMZ,
                            activationType,
                            ionMode, spectrum.Centroided, isolationMZ);

                    Console.WriteLine(scanSummary);

                    if (spectrum.Level > 1)
                    {
                        scanCountMS2++;
                    }
                    else
                    {
                        scanCountMS1++;
                    }

                    if (!expectedData.TryGetValue(Path.GetFileNameWithoutExtension(dataFolder.Name), out var expectedDataThisFile))
                    {
                        Assert.Fail("Dataset {0} not found in dictionary expectedData", dataFolder.Name);
                    }

                    if (expectedDataThisFile.TryGetValue(scanNumber, out var expectedScanSummary))
                    {
                        Assert.AreEqual(expectedScanSummary, scanSummary,
                                        "Scan summary mismatch, scan " + scanNumber);
                    }

                    var expectedNativeId = string.Format("scan={0}", scanNumber);
                    Assert.AreEqual(spectrum.NativeId, expectedNativeId, "NativeId is not in the expected format for scan {0}", scanNumber);
                }

                Console.WriteLine("scanCountMS1={0}", scanCountMS1);
                Console.WriteLine("scanCountMS2={0}", scanCountMS2);

                Assert.AreEqual(expectedMS1, scanCountMS1, "MS1 scan count mismatch");
                Assert.AreEqual(expectedMS2, scanCountMS2, "MS2 scan count mismatch");
            }
        }
Exemple #11
0
        public void TestGetScanData(string uimfFileName, int frameStart, int frameEnd)
        {
            var expectedData = new Dictionary <string, Dictionary <KeyValuePair <int, int>, string> >();

            // Keys in this dictionary are the FrameNum, ScanNum whose metadata is being retrieved
            var file1Data = new Dictionary <KeyValuePair <int, int>, string>
            {
                { new KeyValuePair <int, int>(21, 1), "  21    1 171      171      73.143   0        4313.446 6" },
                { new KeyValuePair <int, int>(21, 45), "  21   45 132      132      49.420   0        2871.914 0" },
                { new KeyValuePair <int, int>(21, 90), "  21   90 58061    58061    33.139   0        892.171  0" },
                { new KeyValuePair <int, int>(21, 135), "  21  135 1332     1332     59.655   0        1455.314 0" },
                { new KeyValuePair <int, int>(21, 180), "  21  180 213      213      35.827   0        3477.878 16" },
                { new KeyValuePair <int, int>(21, 225), "  21  225 198      198      34.311   0        4724.490 0" },
                { new KeyValuePair <int, int>(21, 270), "  21  270 156      156      137.671  0        4960.353 0" },
                { new KeyValuePair <int, int>(22, 1), "  22    1 171      171      33.352   0        2700.500 2" },
                { new KeyValuePair <int, int>(22, 45), "  22   45 123      123      60.048   0        2958.660 2" },
                { new KeyValuePair <int, int>(22, 90), "  22   90 57811    57811    33.519   0        893.895  0" },
                { new KeyValuePair <int, int>(22, 135), "  22  135 1558     1558     33.800   0        1442.189 141" },
                { new KeyValuePair <int, int>(22, 180), "  22  180 165      165      104.876  0        2716.046 4" },
                { new KeyValuePair <int, int>(22, 225), "  22  225 165      165      49.372   0        5356.743 8" },
                { new KeyValuePair <int, int>(22, 270), "  22  270 168      168      41.214   0        3317.148 0" },
                { new KeyValuePair <int, int>(23, 1), "  23    1 159      159      44.206   0        2656.092 1" },
                { new KeyValuePair <int, int>(23, 45), "  23   45 179      179      66.354   0        4174.595 0" },
                { new KeyValuePair <int, int>(23, 90), "  23   90 59421    59421    33.319   0        901.566  17" },
                { new KeyValuePair <int, int>(23, 135), "  23  135 1398     1398     36.437   0        1429.296 0" },
                { new KeyValuePair <int, int>(23, 180), "  23  180 228      228      124.690  0        2244.101 0" },
                { new KeyValuePair <int, int>(23, 225), "  23  225 186      186      35.140   0        2326.136 0" },
                { new KeyValuePair <int, int>(23, 270), "  23  270 162      162      134.804  0        4518.062 0" }
            };

            expectedData.Add("9_Peptide_Mix_16Oct14_Cedar_Infuse", file1Data);

            var file2Data = new Dictionary <KeyValuePair <int, int>, string>
            {
                { new KeyValuePair <int, int>(50, 90), "  50   90 304      304      166.939  0        316.855  71" },
                { new KeyValuePair <int, int>(50, 135), "  50  135 36       36       479.959  0        532.950  0" },
                { new KeyValuePair <int, int>(51, 90), "  51   90 516      516      166.939  0        320.853  0" },
                { new KeyValuePair <int, int>(51, 135), "  51  135 27       27       474.824  0        532.934  38" },
                { new KeyValuePair <int, int>(51, 315), "  51  315 3        3        250.922  0        250.922  58" },
                { new KeyValuePair <int, int>(52, 90), "  52   90 579      579      166.939  0        319.857  61" },
                { new KeyValuePair <int, int>(52, 135), "  52  135 30       30       479.959  0        532.934  0" },
                { new KeyValuePair <int, int>(52, 315), "  52  315 3        3        250.922  0        250.922  67" },
                { new KeyValuePair <int, int>(53, 90), "  53   90 625      625      164.932  0        321.351  0" },
                { new KeyValuePair <int, int>(53, 135), "  53  135 39       39       391.282  0        532.934  47" },
                { new KeyValuePair <int, int>(54, 90), "  54   90 456      456      164.941  0        318.876  0" },
                { new KeyValuePair <int, int>(54, 135), "  54  135 33       33       391.282  0        530.978  17" },
                { new KeyValuePair <int, int>(55, 90), "  55   90 467      467      164.932  0        318.888  0" },
                { new KeyValuePair <int, int>(55, 135), "  55  135 24       24       479.959  0        532.950  0" }
            };

            expectedData.Add("QC_Shew_IMER_500ng_Run-1_4May16_Oak_15-01-16", file2Data);

            var dataFile = GetUimfDataFile(uimfFileName);

            using (var reader = new MSDataFileReader(dataFile.FullName))
            {
                Console.WriteLine("Scan data for {0}", dataFile.Name);
                Console.WriteLine("{0,4} {1,4} {2,-8} {3,-8} {4,-8} {5,-8} {6,-8} {7}",
                                  "Frame", "Scan", "MzCount", "IntCount",
                                  "FirstMz", "FirstInt", "MidMz", "MidInt");

                var frameScanPairToIndexMap = reader.GetUimfFrameScanPairToIndexMapping();

                foreach (var frame in frameScanPairToIndexMap)
                {
                    var frameNumber   = frame.Key.Key;
                    var scanNumber    = frame.Key.Value;
                    var spectrumIndex = frame.Value;

                    if (frameNumber < frameStart || frameNumber > frameEnd)
                    {
                        continue;
                    }

                    if (!(scanNumber == 1 || scanNumber % 45 == 0))
                    {
                        continue;
                    }

                    var spectrum = reader.GetSpectrum(spectrumIndex, true);

                    var dataPointsRead = spectrum.Mzs.Length;

                    if (dataPointsRead == 0)
                    {
                        Console.WriteLine("Frame {0}, scan {1} has no data; ignoring", frameNumber, scanNumber);
                        continue;
                    }

                    var midPoint = (int)(spectrum.Intensities.Length / 2f);

                    var scanSummary =
                        string.Format(
                            "{0,4} {1,4} {2,-8} {3,-8} {4,-8:0.000} {5,-8:0} {6,-8:0.000} {7:0}",
                            frameNumber, scanNumber,
                            spectrum.Mzs.Length, spectrum.Intensities.Length,
                            spectrum.Mzs[0], spectrum.Intensities[0],
                            spectrum.Mzs[midPoint], spectrum.Intensities[midPoint]);

                    Console.WriteLine(scanSummary);

                    if (!expectedData.TryGetValue(Path.GetFileNameWithoutExtension(dataFile.Name), out var expectedDataThisFile))
                    {
                        Assert.Fail("Dataset {0} not found in dictionary expectedData", dataFile.Name);
                    }

                    if (expectedDataThisFile.TryGetValue(new KeyValuePair <int, int>(frameNumber, scanNumber), out var expectedDataDetails))
                    {
                        Assert.AreEqual(expectedDataDetails, scanSummary,
                                        "Scan details mismatch, scan " + scanNumber);
                    }
                }
            }
        }
Exemple #12
0
        public void TestGetScanInfo(string uimfFileName, int frameStart, int frameEnd, int expectedMS1, int expectedMS2)
        {
            var expectedData = new Dictionary <string, Dictionary <KeyValuePair <int, int>, string> >();

            // Keys in this dictionary are the FrameNum, ScanNum whose metadata is being retrieved
            var file1Data = new Dictionary <KeyValuePair <int, int>, string>
            {
                // Scan MSLevel NumPeaks RetentionTime DriftTimeMsec IonMobilityDriftTime LowMass HighMass TotalIonCurrent BasePeakMZ BasePeakIntensity ParentIonMZ ActivationType IonMode IsCentroided ScanStartTime IonInjectionTime FilterText
                { new KeyValuePair <int, int>(1, 0), "   1    0 1     3   0.01   0.01     0.00     0.00   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(1, 100), "   1  100 1  1317   0.01   0.01    24.68    24.68   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(1, 200), "   1  200 1     3   0.01   0.01    49.36    49.36   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(2, 0), "   2    0 1    16   0.25   0.25     0.00     0.00   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(2, 1), "   2    1 1     6   0.25   0.25     0.25     0.25   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(2, 100), "   2  100 1  3429   0.25   0.25    24.70    24.70   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(2, 200), "   2  200 1     9   0.25   0.25    49.39    49.39   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(3, 0), "   3    0 1    21   0.50   0.50     0.00     0.00   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(3, 100), "   3  100 1  4216   0.50   0.50    24.65    24.65   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(3, 200), "   3  200 1     3   0.50   0.50    49.31    49.31   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(4, 0), "   4    0 1     3   0.75   0.75     0.00     0.00   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(4, 1), "   4    1 1     6   0.75   0.75     0.25     0.25   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(4, 100), "   4  100 1  5640   0.75   0.75    24.58    24.58   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(4, 200), "   4  200 1     6   0.75   0.75    49.16    49.16   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(5, 0), "   5    0 1     9   1.00   1.00     0.00     0.00   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(5, 100), "   5  100 1  4605   1.00   1.00    24.70    24.70   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" },
                { new KeyValuePair <int, int>(5, 200), "   5  200 1     3   1.00   1.00    49.39    49.39   0 14384 0.0E+0    0.000 0.0E+0     0.00          positive False  7192.23" }
            };

            expectedData.Add("9_Peptide_Mix_16Oct14_Cedar_Infuse", file1Data);

            var file2Data = new Dictionary <KeyValuePair <int, int>, string>
            {
                { new KeyValuePair <int, int>(1, 38), "   1   38 1    15   0.01   0.01     6.11     6.11   0  2646 0.0E+0    0.000 0.0E+0     0.00          positive False  1322.76" },
                { new KeyValuePair <int, int>(1, 114), "   1  114 1  1215   0.01   0.01    18.34    18.34   0  2646 0.0E+0    0.000 0.0E+0     0.00          positive False  1322.76" },
                { new KeyValuePair <int, int>(1, 152), "   1  152 1   222   0.01   0.01    24.45    24.45   0  2646 0.0E+0    0.000 0.0E+0     0.00          positive False  1322.76" },
                { new KeyValuePair <int, int>(1, 228), "   1  228 1     3   0.01   0.01    36.67    36.67   0  2646 0.0E+0    0.000 0.0E+0     0.00          positive False  1322.76" },
                { new KeyValuePair <int, int>(1, 304), "   1  304 1     9   0.01   0.01    48.89    48.89   0  2646 0.0E+0    0.000 0.0E+0     0.00          positive False  1322.76" }
            };

            expectedData.Add("9pep_mix_1uM_4bit_50_3Jun16", file2Data);

            var file3Data = new Dictionary <KeyValuePair <int, int>, string>
            {
                { new KeyValuePair <int, int>(1, 100), "   1  100 1   504   0.01   0.01    16.37    16.37   0  2646 0.0E+0    0.000 0.0E+0     0.00          positive False  1322.79" },
                { new KeyValuePair <int, int>(2, 100), "   2  100 1   494   0.06   0.06    16.42    16.42   0  2646 0.0E+0    0.000 0.0E+0     0.00          positive False  1322.79" },
                { new KeyValuePair <int, int>(3, 100), "   3  100 1  1109   0.11   0.11    16.43    16.43   0  2646 0.0E+0    0.000 0.0E+0     0.00          positive False  1322.79" },
                { new KeyValuePair <int, int>(4, 0), "   4    0 1     3   0.17   0.17     0.00     0.00   0  2646 0.0E+0    0.000 0.0E+0     0.00          positive False  1322.79" },
                { new KeyValuePair <int, int>(4, 100), "   4  100 1  1061   0.17   0.17    16.41    16.41   0  2646 0.0E+0    0.000 0.0E+0     0.00          positive False  1322.79" },
                { new KeyValuePair <int, int>(5, 0), "   5    0 1     3   0.22   0.22     0.00     0.00   0  2646 0.0E+0    0.000 0.0E+0     0.00          positive False  1322.79" },
                { new KeyValuePair <int, int>(5, 100), "   5  100 1  1087   0.22   0.22    16.44    16.44   0  2646 0.0E+0    0.000 0.0E+0     0.00          positive False  1322.79" },
            };

            expectedData.Add("QC_Shew_IMER_500ng_Run-1_4May16_Oak_15-01-16", file3Data);

            var file4Data = new Dictionary <KeyValuePair <int, int>, string>
            {
                { new KeyValuePair <int, int>(1, 1), "   1    1 1   344   0.00   0.00     0.12     0.12   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(1, 100), "   1  100 1   345   0.00   0.00    12.10    12.10   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(1, 200), "   1  200 1   577   0.00   0.00    24.20    24.20   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(1, 300), "   1  300 1   996   0.00   0.00    36.30    36.30   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(1, 400), "   1  400 1   469   0.00   0.00    48.40    48.40   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(1, 500), "   1  500 1   336   0.00   0.00    60.50    60.50   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(1, 600), "   1  600 1   369   0.00   0.00    72.60    72.60   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(1, 700), "   1  700 1   423   0.00   0.00    84.70    84.70   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(2, 1), "   2    1 1   381   0.00   0.00     0.12     0.12   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(2, 100), "   2  100 1   243   0.00   0.00    12.10    12.10   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(2, 200), "   2  200 1   669   0.00   0.00    24.20    24.20   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(2, 300), "   2  300 1   770   0.00   0.00    36.30    36.30   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(2, 400), "   2  400 1   372   0.00   0.00    48.40    48.40   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(2, 500), "   2  500 1   355   0.00   0.00    60.50    60.50   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(2, 600), "   2  600 1   441   0.00   0.00    72.60    72.60   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(2, 700), "   2  700 1   328   0.00   0.00    84.70    84.70   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(3, 1), "   3    1 1   405   0.00   0.00     0.12     0.12   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(3, 100), "   3  100 1   419   0.00   0.00    12.10    12.10   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(3, 200), "   3  200 1   705   0.00   0.00    24.20    24.20   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(3, 300), "   3  300 1  1080   0.00   0.00    36.30    36.30   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(3, 400), "   3  400 1   387   0.00   0.00    48.40    48.40   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(3, 500), "   3  500 1   423   0.00   0.00    60.50    60.50   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(3, 600), "   3  600 1   402   0.00   0.00    72.60    72.60   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(3, 700), "   3  700 1   333   0.00   0.00    84.70    84.70   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(4, 1), "   4    1 1   348   0.00   0.00     0.12     0.12   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(4, 100), "   4  100 1   343   0.00   0.00    12.10    12.10   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(4, 200), "   4  200 1   625   0.00   0.00    24.20    24.20   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(4, 300), "   4  300 1  1125   0.00   0.00    36.29    36.29   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(4, 400), "   4  400 1   384   0.00   0.00    48.39    48.39   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(4, 500), "   4  500 1   399   0.00   0.00    60.49    60.49   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(4, 600), "   4  600 1   362   0.00   0.00    72.59    72.59   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" },
                { new KeyValuePair <int, int>(4, 700), "   4  700 1   360   0.00   0.00    84.69    84.69   0  1700 0.0E+0    0.000 0.0E+0     0.00          positive False   849.87" }
            };

            expectedData.Add("20160524_TuneMix_1574V_neg_001", file4Data);


            var dataFile = GetUimfDataFile(uimfFileName);

            using (var reader = new MSDataFileReader(dataFile.FullName))
            {
                Console.WriteLine("Scan info for {0}", dataFile.Name);
                Console.WriteLine("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12} {13} {14} {15} {16} {17}",
                                  "Frame", "Scan", "MSLevel",
                                  "NumPeaks", "RetentionTime",
                                  "ScanStartTime",
                                  "DriftTimeMsec",
                                  "IonMobilityDriftTime",
                                  "LowMass", "HighMass", "TotalIonCurrent",
                                  "BasePeakMZ", "BasePeakIntensity",
                                  "ParentIonMZ", "ActivationType",
                                  "IonMode", "IsCentroided",
                                  "IsolationMZ");

                var frameScanPairToIndexMap = reader.GetUimfFrameScanPairToIndexMapping();

                var scanCountMS1 = 0;
                var scanCountMS2 = 0;

                foreach (var frame in frameScanPairToIndexMap)
                {
                    var frameNumber   = frame.Key.Key;
                    var scanNumber    = frame.Key.Value;
                    var spectrumIndex = frame.Value;

                    if (frameNumber < frameStart || frameNumber > frameEnd)
                    {
                        continue;
                    }

                    if (string.Equals(uimfFileName, "9pep_mix_1uM_4bit_50_3Jun16.uimf", StringComparison.InvariantCultureIgnoreCase))
                    {
                        if (!(scanNumber == 1 || scanNumber % 38 == 0))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        if (!(scanNumber == 1 || scanNumber % 100 == 0))
                        {
                            continue;
                        }
                    }

                    var spectrum       = reader.GetSpectrum(spectrumIndex, true);
                    var spectrumParams = reader.GetSpectrumCVParamData(spectrumIndex);
                    var cvScanInfo     = reader.GetSpectrumScanInfo(spectrumIndex);

                    Assert.IsTrue(spectrum != null, "GetSpectrum returned a null object for frame {0}, scan {1} ", frameNumber, scanNumber);

                    var totalIonCurrent   = cvParamUtilities.GetCvParamValueDbl(spectrumParams, cvParamUtilities.CVIDs.MS_TIC);
                    var basePeakMZ        = cvParamUtilities.GetCvParamValueDbl(spectrumParams, cvParamUtilities.CVIDs.MS_base_peak_m_z);
                    var basePeakIntensity = cvParamUtilities.GetCvParamValueDbl(spectrumParams, cvParamUtilities.CVIDs.MS_base_peak_intensity);

                    double isolationMZ    = 0;
                    double parentIonMZ    = 0;
                    var    activationType = string.Empty;

                    if (spectrum.Precursors.Length > 0)
                    {
                        var precursor = spectrum.Precursors[0];

                        isolationMZ = precursor.IsolationMz.GetValueOrDefault();
                        parentIonMZ = precursor.PrecursorMz.GetValueOrDefault();

                        if (precursor.ActivationTypes != null)
                        {
                            activationType = string.Join(", ", precursor.ActivationTypes);
                        }
                    }

                    GetScanMetadata(cvScanInfo, out var scanStartTime, out var ionMobilityDriftTime, out var lowMass, out var highMass);

                    var retentionTime = cvParamUtilities.CheckNull(spectrum.RetentionTime);

                    var numPeaks = spectrum.Mzs.Length;
                    var ionMode  = spectrum.NegativeCharge ? "negative" : "positive";

                    var scanSummary =
                        string.Format(
                            "{0,4} {1,4} {2} {3,5} {4,6:0.00} {5,6:0.00} {6,8:0.00} {7,8:0.00} {8,3:0} {9,5:0} {10,6:0.0E+0} {11,8:0.000} {12,6:0.0E+0} {13,8:0.00} {14,-8} {15} {16,-5} {17,8:0.00}",
                            frameNumber, scanNumber, spectrum.Level,
                            numPeaks, retentionTime, scanStartTime,
                            cvParamUtilities.CheckNull(spectrum.DriftTimeMsec),
                            ionMobilityDriftTime,
                            lowMass, highMass,
                            totalIonCurrent, basePeakMZ, basePeakIntensity, parentIonMZ,
                            activationType, ionMode,
                            spectrum.Centroided, isolationMZ);

                    Console.WriteLine(scanSummary);

                    if (spectrum.Level > 1)
                    {
                        scanCountMS2++;
                    }
                    else
                    {
                        scanCountMS1++;
                    }

                    if (!expectedData.TryGetValue(Path.GetFileNameWithoutExtension(dataFile.Name), out var expectedDataThisFile))
                    {
                        Assert.Fail("Dataset {0} not found in dictionary expectedData", dataFile.Name);
                    }

                    if (expectedDataThisFile.TryGetValue(new KeyValuePair <int, int>(frameNumber, scanNumber), out var expectedScanSummary))
                    {
                        if (!string.Equals(expectedScanSummary, scanSummary))
                        {
                            Console.WriteLine(
                                "{0,4} {1,4} {2} {3,5} {4,6} {5,6} {6,8} {7,8} {8,3} {9,5} {10,6} {11,8} {12,6} {13,8} {14,-8} {15} {16,-5} {17,8}",
                                "Frame", "Scan", "MSLevel",
                                "NumPeaks", "RetentionTime", "ScanStartTime",
                                "DriftTimeMsec",
                                "IonMobilityDriftTime",
                                "LowMass", "HighMass",
                                "TIC", "BasePeakMZ", "BPI", "ParentIonMZ",
                                "ActivationType", "IonMode",
                                "Centroided?", "IsolationMZ");
                        }

                        Assert.AreEqual(expectedScanSummary, scanSummary,
                                        "Scan summary mismatch, scan " + scanNumber);
                    }

                    var expectedNativeId = string.Format("frame={0} scan={1} frameType=1", frameNumber, scanNumber);
                    Assert.AreEqual(spectrum.NativeId, expectedNativeId, "NativeId is not in the expected format for frame {0}, scan {1} ", frameNumber, scanNumber);
                }

                Console.WriteLine("scanCountMS1={0}", scanCountMS1);
                Console.WriteLine("scanCountMS2={0}", scanCountMS2);

                Assert.AreEqual(expectedMS1, scanCountMS1, "MS1 scan count mismatch");
                Assert.AreEqual(expectedMS2, scanCountMS2, "MS2 scan count mismatch");
            }
        }
Exemple #13
0
        public void TestCorruptDataHandling(
            string uimfFileName,
            int frameStart,
            int frameEnd,
            int expectedMS1,
            int expectedMS2,
            int expectedScansWithData)
        {
            var dataFile = GetUimfDataFile(uimfFileName);

            try
            {
                using (var reader = new MSDataFileReader(dataFile.FullName))
                {
                    var scanCount = reader.SpectrumCount;
                    Console.WriteLine("Scan count for {0}: {1}", dataFile.Name, scanCount);

                    if (expectedMS1 + expectedMS2 == 0)
                    {
                        Assert.IsTrue(scanCount == 0, "ScanCount is non-zero, while we expected it to be 0");
                    }
                    else
                    {
                        Assert.IsTrue(scanCount > 0, "ScanCount is zero, while we expected it to be > 0");
                    }

                    var frameScanPairToIndexMap = reader.GetUimfFrameScanPairToIndexMapping();

                    var scanCountMS1  = 0;
                    var scanCountMS2  = 0;
                    var scansWithData = 0;

                    foreach (var frame in frameScanPairToIndexMap)
                    {
                        var frameNumber   = frame.Key.Key;
                        var scanNumber    = frame.Key.Value;
                        var spectrumIndex = frame.Value;

                        if (frameNumber < frameStart || frameNumber > frameEnd)
                        {
                            continue;
                        }

                        try
                        {
                            var spectrum = reader.GetSpectrum(spectrumIndex, true);

                            var cvScanInfo = reader.GetSpectrumScanInfo(spectrumIndex);

                            Assert.IsTrue(cvScanInfo != null, "GetSpectrumScanInfo returned a null object for frame {0}, scan {1} ", frameNumber, scanNumber);

                            if (spectrum.Level > 1)
                            {
                                scanCountMS2++;
                            }
                            else
                            {
                                scanCountMS1++;
                            }

                            var dataPointCount = spectrum.Mzs.Length;
                            if (dataPointCount > 0)
                            {
                                scansWithData++;
                            }

                            Assert.IsTrue(spectrum.Mzs.Length == spectrum.Intensities.Length, "Array length mismatch for m/z and intensity data for frame {0}, scan {1} ", frameNumber, scanNumber);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Exception reading scan {0}: {1}", scanNumber, ex.Message);
                            Assert.Fail("Exception reading scan {0}", scanNumber);
                        }
                    }

                    Console.WriteLine("scanCountMS1={0}", scanCountMS1);
                    Console.WriteLine("scanCountMS2={0}", scanCountMS2);
                    Console.WriteLine("scansWithData={0}", scansWithData);


                    Assert.AreEqual(expectedMS1, scanCountMS1, "MS1 scan count mismatch");
                    Assert.AreEqual(expectedMS2, scanCountMS2, "MS2 scan count mismatch");
                    Assert.AreEqual(expectedScansWithData, scansWithData, "ScansWithData count mismatch");
                }
            }
            catch (Exception ex)
            {
                if (expectedMS1 + expectedMS2 == 0)
                {
                    Console.WriteLine("Error opening .uimf file (this was expected):\n{0}", ex.Message);
                }
                else
                {
                    var msg = string.Format("Exception opening .uimf file {0}:\n{1}", uimfFileName, ex.Message);
                    Console.WriteLine(msg);
                    Assert.Fail(msg);
                }
            }
        }