コード例 #1
0
        private static void TestSpectrumProcessor(TransitionBinner transBinner, AbstractIsoWindowMapper isoMapper,
                                                  MsDataFileImpl file, int testSpectrumNum)
        {
            int lastSpectrum      = testSpectrumNum + 60;
            int firstSpectrum     = testSpectrumNum - 60;
            var spectrumProcessor = new SpectrumProcessor(lastSpectrum + 1, isoMapper, transBinner);

            // Make a new spectrum processor using the testing constructor that takes in
            // a TransitionBinner, which will be the one used for overlap
            // Add the spectra to the cache +/- 60 from the spectrum of interest
            for (int i = firstSpectrum; i <= lastSpectrum; ++i)
            {
                var spectrum = file.GetSpectrum(i);
                spectrumProcessor.AddSpectrum(i, spectrum);
            }

            // Check that the caching worked correctly
            for (int spectrumIndex = firstSpectrum; spectrumIndex <= lastSpectrum; ++spectrumIndex)
            {
                ScanCached specData;
                Assert.IsTrue(spectrumProcessor.TryGetSpectrum(spectrumIndex, out specData));

                // Check that the cached processing results match the output of
                // redoing the processing manually by extracting the spectrum from
                // the file again and using transBinner to bin the data
                var      testSpectrum       = file.GetSpectrum(spectrumIndex);
                double[] expectedBinnedData = new double[transBinner.NumBins];
                transBinner.BinData(testSpectrum.Mzs, testSpectrum.Intensities, ref expectedBinnedData);
                ScanCached testSpecData;
                spectrumProcessor.TryGetSpectrum(spectrumIndex, out testSpecData);
                var seenBinnedData = testSpecData.Data;
                Assert.AreEqual(expectedBinnedData.Length, seenBinnedData.Length);
                for (int i = 0; i < expectedBinnedData.Length; ++i)
                {
                    Assert.AreEqual(expectedBinnedData[i], seenBinnedData[i], 0.0001);
                }
            }
        }
コード例 #2
0
ファイル: MsxTest.cs プロジェクト: lgatto/proteowizard
        private static TransitionBinner TestTransitionBinnerOverlap(MsDataSpectrum spectrum, 
            AbstractIsoWindowMapper isoMapper, double[] binnedIntensities)
        {
            // Multiple transitions overlapping the same peak from the same precursor
            var precursorList = new List<double>();
            var transitionList = new List<KeyValuePair<double, double>>();
            precursorList.Add(710.5);                                 //transition: start - stop     index
            transitionList.Add(new KeyValuePair<double, double>(380.19,1.0));   // 379.69-380.69     Bin3
            precursorList.Add(710.5);
            transitionList.Add(new KeyValuePair<double, double>(380.44,1.0));   // 379.94-380.94     Bin4
            precursorList.Add(710.5);
            transitionList.Add(new KeyValuePair<double, double>(380.49,0.6));   // 380.19-380.79     Bin5
            // And a non-overlapping transition for good measure
            precursorList.Add(710.5);
            transitionList.Add(new KeyValuePair<double, double>(389.19,0.3));   // 389.04 - 389.34   Bin7
            // And a transition that won't have any peaks in the spectrum
            precursorList.Add(710.5);
            transitionList.Add(new KeyValuePair<double, double>(377.0,0.7));    // 376.65-377.35     Bin0

            // And now another precursor with some of the transitions overlapping the first
            precursorList.Add(595.0);
            transitionList.Add(new KeyValuePair<double, double>(380.0,1.0));    // 379.5 - 380.5     Bin2
            precursorList.Add(595.0);
            transitionList.Add(new KeyValuePair<double, double>(379.55,1.0));   // 379.05 - 380.05   Bin1
            precursorList.Add(595.0);
            transitionList.Add(new KeyValuePair<double, double>(389.15, 0.4));  // 388.95 - 389.35   Bin6

            var transitionBinner = new TransitionBinner(precursorList, transitionList, isoMapper);

            double[] binnedData = new double[transitionList.Count];
            transitionBinner.BinData(spectrum.Mzs, spectrum.Intensities, ref binnedData);

            // Test that m/z, intensity pairs were binned correctly into their transitions
            for (int i = 0; i< binnedData.Length; ++i)
            {
                Assert.AreEqual(binnedIntensities[i], binnedData[i], 0.001);
            }

            // Get the precursor index for this precursor
            // make sure the precursor -> transition mapping is working for the first precursor
            int windowIndexOne;
            Assert.IsTrue(isoMapper.TryGetDeconvFromMz(710.5, out windowIndexOne));
            // Use the precursor index to get the bins mapping to this precursor
            var precursorBins = new HashSet<int>(transitionBinner.BinsForDeconvWindows(new[] {windowIndexOne}));
            var expectedPrecursorBins = new HashSet<int>(new[]{0,3,4,5,7});
            var setComparer = HashSet<int>.CreateSetComparer();
            Assert.IsTrue(setComparer.Equals(expectedPrecursorBins, precursorBins));

            // Make sure the precursor -> transition mapping is working for the second precursor
            int windowIndexTwo;
            Assert.IsTrue(isoMapper.TryGetDeconvFromMz(595.0, out windowIndexTwo));
            precursorBins = new HashSet<int>(transitionBinner.BinsForDeconvWindows(new[]{windowIndexOne, windowIndexTwo}));
            expectedPrecursorBins = new HashSet<int>(new[]{0,1,2,3,4,5,6,7});
            Assert.IsTrue(setComparer.Equals(expectedPrecursorBins, precursorBins));

            // m/z values to test mapping of m/z value -> multiplex matching transition bins
            var queryVals = new[] {252.0, 377.0, 379.92, 379.95};
            var bins = transitionBinner.BinsFromValues(queryVals, true).ToList();

            var expectedBins = new List<KeyValuePair<int, int>>
                                   {
                                       new KeyValuePair<int, int>(1, 0),
                                       new KeyValuePair<int, int>(2, 1),
                                       new KeyValuePair<int, int>(2, 2),
                                       new KeyValuePair<int, int>(2, 3),
                                       new KeyValuePair<int, int>(3, 1),
                                       new KeyValuePair<int, int>(3, 2),
                                       new KeyValuePair<int, int>(3, 3),
                                       new KeyValuePair<int, int>(3, 4)
                                   };
            AssertEx.AreEqualDeep(expectedBins, bins);
            Assert.AreEqual(376.65, transitionBinner.LowerValueFromBin(0),0.0001);
            Assert.AreEqual(377.35, transitionBinner.UpperValueFromBin(0),0.0001);
            Assert.AreEqual(377.0, transitionBinner.CenterValueFromBin(0),0.0001);
            return transitionBinner;
        }
コード例 #3
0
        private static TransitionBinner TestTransitionBinnerOverlap(MsDataSpectrum spectrum,
                                                                    AbstractIsoWindowMapper isoMapper, double[] binnedIntensities)
        {
            // Multiple transitions overlapping the same peak from the same precursor
            var precursorList  = new List <double>();
            var transitionList = new List <KeyValuePair <double, double> >();

            precursorList.Add(710.5);                                           //transition: start - stop     index
            transitionList.Add(new KeyValuePair <double, double>(380.19, 1.0)); // 379.69-380.69     Bin3
            precursorList.Add(710.5);
            transitionList.Add(new KeyValuePair <double, double>(380.44, 1.0)); // 379.94-380.94     Bin4
            precursorList.Add(710.5);
            transitionList.Add(new KeyValuePair <double, double>(380.49, 0.6)); // 380.19-380.79     Bin5
            // And a non-overlapping transition for good measure
            precursorList.Add(710.5);
            transitionList.Add(new KeyValuePair <double, double>(389.19, 0.3));   // 389.04 - 389.34   Bin7
            // And a transition that won't have any peaks in the spectrum
            precursorList.Add(710.5);
            transitionList.Add(new KeyValuePair <double, double>(377.0, 0.7));    // 376.65-377.35     Bin0

            // And now another precursor with some of the transitions overlapping the first
            precursorList.Add(595.0);
            transitionList.Add(new KeyValuePair <double, double>(380.0, 1.0));   // 379.5 - 380.5     Bin2
            precursorList.Add(595.0);
            transitionList.Add(new KeyValuePair <double, double>(379.55, 1.0));  // 379.05 - 380.05   Bin1
            precursorList.Add(595.0);
            transitionList.Add(new KeyValuePair <double, double>(389.15, 0.4));  // 388.95 - 389.35   Bin6

            var transitionBinner = new TransitionBinner(precursorList, transitionList, isoMapper);

            double[] binnedData = new double[transitionList.Count];
            transitionBinner.BinData(spectrum.Mzs, spectrum.Intensities, ref binnedData);

            // Test that m/z, intensity pairs were binned correctly into their transitions
            for (int i = 0; i < binnedData.Length; ++i)
            {
                Assert.AreEqual(binnedIntensities[i], binnedData[i], 0.001);
            }

            // Get the precursor index for this precursor
            // make sure the precursor -> transition mapping is working for the first precursor
            int windowIndexOne;

            Assert.IsTrue(isoMapper.TryGetDeconvFromMz(710.5, out windowIndexOne));
            // Use the precursor index to get the bins mapping to this precursor
            var precursorBins         = new HashSet <int>(transitionBinner.BinsForDeconvWindows(new[] { windowIndexOne }));
            var expectedPrecursorBins = new HashSet <int>(new[] { 0, 3, 4, 5, 7 });
            var setComparer           = HashSet <int> .CreateSetComparer();

            Assert.IsTrue(setComparer.Equals(expectedPrecursorBins, precursorBins));

            // Make sure the precursor -> transition mapping is working for the second precursor
            int windowIndexTwo;

            Assert.IsTrue(isoMapper.TryGetDeconvFromMz(595.0, out windowIndexTwo));
            precursorBins         = new HashSet <int>(transitionBinner.BinsForDeconvWindows(new[] { windowIndexOne, windowIndexTwo }));
            expectedPrecursorBins = new HashSet <int>(new[] { 0, 1, 2, 3, 4, 5, 6, 7 });
            Assert.IsTrue(setComparer.Equals(expectedPrecursorBins, precursorBins));

            // m/z values to test mapping of m/z value -> multiplex matching transition bins
            var queryVals = new[] { 252.0, 377.0, 379.92, 379.95 };
            var bins      = transitionBinner.BinsFromValues(queryVals, true).ToList();

            var expectedBins = new List <KeyValuePair <int, int> >
            {
                new KeyValuePair <int, int>(1, 0),
                new KeyValuePair <int, int>(2, 1),
                new KeyValuePair <int, int>(2, 2),
                new KeyValuePair <int, int>(2, 3),
                new KeyValuePair <int, int>(3, 1),
                new KeyValuePair <int, int>(3, 2),
                new KeyValuePair <int, int>(3, 3),
                new KeyValuePair <int, int>(3, 4)
            };

            AssertEx.AreEqualDeep(expectedBins, bins);
            Assert.AreEqual(376.65, transitionBinner.LowerValueFromBin(0), 0.0001);
            Assert.AreEqual(377.35, transitionBinner.UpperValueFromBin(0), 0.0001);
            Assert.AreEqual(377.0, transitionBinner.CenterValueFromBin(0), 0.0001);
            return(transitionBinner);
        }
コード例 #4
0
ファイル: MsxTest.cs プロジェクト: lgatto/proteowizard
        private static void TestSpectrumProcessor(TransitionBinner transBinner,AbstractIsoWindowMapper isoMapper, 
            MsDataFileImpl file, int testSpectrumNum)
        {
            int lastSpectrum = testSpectrumNum + 60;
            int firstSpectrum = testSpectrumNum - 60;
            var spectrumProcessor = new SpectrumProcessor(lastSpectrum + 1, isoMapper, transBinner);

            // Make a new spectrum processor using the testing constructor that takes in
            // a TransitionBinner, which will be the one used for overlap
            // Add the spectra to the cache +/- 60 from the spectrum of interest
            for (int i = firstSpectrum; i <= lastSpectrum; ++i)
            {
                var spectrum = file.GetSpectrum(i);
                spectrumProcessor.AddSpectrum(i, spectrum);
            }

            // Check that the caching worked correctly
            for (int spectrumIndex = firstSpectrum; spectrumIndex <= lastSpectrum; ++spectrumIndex)
            {
                ScanCached specData;
                Assert.IsTrue(spectrumProcessor.TryGetSpectrum(spectrumIndex, out specData));

                // Check that the cached processing results match the output of
                // redoing the processing manually by extracting the spectrum from
                // the file again and using transBinner to bin the data
                var testSpectrum = file.GetSpectrum(spectrumIndex);
                double[] expectedBinnedData = new double[transBinner.NumBins];
                transBinner.BinData(testSpectrum.Mzs, testSpectrum.Intensities, ref expectedBinnedData);
                ScanCached testSpecData;
                spectrumProcessor.TryGetSpectrum(spectrumIndex, out testSpecData);
                var seenBinnedData = testSpecData.Data;
                Assert.AreEqual(expectedBinnedData.Length, seenBinnedData.Length);
                for (int i = 0; i < expectedBinnedData.Length; ++i)
                {
                    Assert.AreEqual(expectedBinnedData[i], seenBinnedData[i], 0.0001);
                }
            }
        }