Beispiel #1
0
        private static void TestIsolationWindowMapper(AbstractIsoWindowMapper isoMapper, MsDataFileImpl file, double width)
        {
            // Check the first five spectra in the file
            for (int checkIndex = 0; checkIndex < 5; ++checkIndex)
            {
                var        spectrum   = file.GetSpectrum(checkIndex);
                var        precursors = spectrum.Precursors;
                List <int> isoIndices = new List <int>();
                // Make sure that each precursor read from the file is included in the isolation
                // window mapper
                foreach (var precursor in precursors)
                {
                    int index;
                    Assert.IsTrue(precursor.IsolationMz.HasValue);
                    Assert.IsTrue(isoMapper.TryGetWindowIndex(precursor.IsolationMz.Value, out index));
                    isoIndices.Add(index);
                }
                int[]    isoIndicesFromMapper;
                int[]    overlapIndicesFromMapper;
                double[] mask = new double[isoMapper.NumWindows];
                // Make sure the isolation windows called from GetWindowMask match those
                // extracted from the spectrum manually above using TryGetWindowIndex
                isoMapper.GetWindowMask(spectrum, out isoIndicesFromMapper, out overlapIndicesFromMapper, ref mask);
                Assert.AreEqual(isoIndices.Count, isoIndicesFromMapper.Length);
                foreach (int index in isoIndicesFromMapper)
                {
                    Assert.IsTrue(isoIndices.Contains(index));
                }
                // Make sure the overlapIndicesFromMapper matches the mask
                for (int i = 0; i < mask.Length; ++i)
                {
                    if (mask[i] < 0.5)
                    {
                        Assert.AreEqual(0.0, mask[i]);
                    }
                    else
                    {
                        Assert.AreEqual(1.0, mask[i]);
                        Assert.IsTrue(overlapIndicesFromMapper.Contains(i));
                    }
                }
            }

            var testMzs = new[] { 553.49, 623.7, 859, 658.55, 768.7, 621.52 };

            // For each test m/z, get the matching isolation window from isoMapper and
            // make sure the m/z does indeed fall within the window
            foreach (var checkMz in testMzs)
            {
                int windowIndex;
                Assert.IsTrue(isoMapper.TryGetWindowFromMz(checkMz, out windowIndex));
                var matchWindowCenterMz = isoMapper.GetPrecursor(windowIndex);
                Assert.IsTrue(matchWindowCenterMz.IsolationMz.HasValue);
                // Check that mz is within window (width/2 )
                Assert.IsTrue(Math.Abs(matchWindowCenterMz.IsolationMz.Value - checkMz) < width / 2);
            }

            // Test out of range precursors
            int dummyIndex;

            Assert.IsFalse(isoMapper.TryGetDeconvFromMz(315.25, out dummyIndex));
            Assert.AreEqual(-1, dummyIndex);
            Assert.IsFalse(isoMapper.TryGetDeconvFromMz(1005.2, out dummyIndex));
            Assert.AreEqual(-1, dummyIndex);
        }
Beispiel #2
0
        private static void TestIsolationWindowMapper(AbstractIsoWindowMapper isoMapper, MsDataFileImpl file, double width)
        {
            // Check the first five spectra in the file
            for (int checkIndex = 0 ; checkIndex < 5; ++checkIndex)
            {
                var spectrum = file.GetSpectrum(checkIndex);
                var precursors = spectrum.Precursors;
                List<int> isoIndices = new List<int>();
                // Make sure that each precursor read from the file is included in the isolation
                // window mapper
                foreach (var precursor in precursors)
                {
                    int index;
                    Assert.IsTrue(precursor.IsolationMz.HasValue);
                    Assert.IsTrue(isoMapper.TryGetWindowIndex(precursor.IsolationMz.Value, out index));
                    isoIndices.Add(index);
                }
                int[] isoIndicesFromMapper;
                int[] overlapIndicesFromMapper;
                double[] mask = new double[isoMapper.NumWindows];
                // Make sure the isolation windows called from GetWindowMask match those
                // extracted from the spectrum manually above using TryGetWindowIndex
                isoMapper.GetWindowMask(spectrum, out isoIndicesFromMapper, out overlapIndicesFromMapper, ref mask);
                Assert.AreEqual(isoIndices.Count,isoIndicesFromMapper.Length);
                foreach (int index in isoIndicesFromMapper)
                {
                    Assert.IsTrue(isoIndices.Contains(index));
                }
                // Make sure the overlapIndicesFromMapper matches the mask
                for (int i = 0; i < mask.Length; ++i)
                {
                    if (mask[i] < 0.5)
                        Assert.AreEqual(0.0, mask[i]);
                    else
                    {
                        Assert.AreEqual(1.0, mask[i]);
                        Assert.IsTrue(overlapIndicesFromMapper.Contains(i));
                    }
                }
            }

            var testMzs = new[] {553.49, 623.7, 859, 658.55, 768.7, 621.52};
            // For each test m/z, get the matching isolation window from isoMapper and
            // make sure the m/z does indeed fall within the window
            foreach (var checkMz in testMzs)
            {
                int windowIndex;
                Assert.IsTrue(isoMapper.TryGetWindowFromMz(checkMz, out windowIndex));
                var matchWindowCenterMz = isoMapper.GetPrecursor(windowIndex);
                Assert.IsTrue(matchWindowCenterMz.IsolationMz.HasValue);
                // Check that mz is within window (width/2 )
                Assert.IsTrue(Math.Abs(matchWindowCenterMz.IsolationMz.Value - checkMz) < width/2);
            }

            // Test out of range precursors
            int dummyIndex;
            Assert.IsFalse(isoMapper.TryGetDeconvFromMz(315.25, out dummyIndex));
            Assert.AreEqual(-1, dummyIndex);
            Assert.IsFalse(isoMapper.TryGetDeconvFromMz(1005.2, out dummyIndex));
            Assert.AreEqual(-1, dummyIndex);
        }