Пример #1
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);
                }
            }
        }
Пример #2
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");
            }
        }
Пример #3
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");
            }
        }
Пример #4
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);
                }
            }
        }