Пример #1
0
            private static int RtRangeCompare(SwathSpectrumEntry item, SwathQuery query)
            {
                if (item.Rt < query.RtRange.LowValue)
                {
                    return(-1);
                }

                if (item.Rt > query.RtRange.HighValue)
                {
                    return(1);
                }

                return(0);
            }
Пример #2
0
        public Peak2D[] GetMS2(
            IMzLiteDataReader dataReader,
            SwathQuery query,
            Func <IEnumerable <Peak1D>, RangeQuery, Peak1D> mzRangeSelector = null)
        {
            if (dataReader == null)
            {
                throw new ArgumentNullException("dataReader");
            }
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }
            if (mzRangeSelector == null)
            {
                mzRangeSelector = GetClosestMz;
            }

            MSSwath swath = swathList.SearchClosestTargetMz(query);

            if (swath == null)
            {
                return(new Peak2D[0]);
            }

            SwathSpectrumEntry swathSpec = swath.SearchClosestRt(query);

            if (swathSpec == null)
            {
                return(new Peak2D[0]);
            }

            Peak1DArray spectrumPeaks = dataReader.ReadSpectrumPeaks(swathSpec.SpectrumID);

            Peak2D[] ms2Peaks = new Peak2D[query.CountMS2Masses];

            for (int i = 0; i < query.CountMS2Masses; i++)
            {
                RangeQuery           mzRange = query[i];
                IEnumerable <Peak1D> mzPeaks = BinarySearch.Search(spectrumPeaks.Peaks, mzRange, MzRangeCompare);
                Peak1D p = mzRangeSelector(mzPeaks, mzRange);
                ms2Peaks[i] = new Peak2D(p.Intensity, p.Mz, swathSpec.Rt);
            }

            return(ms2Peaks);
        }
Пример #3
0
            private static bool TryCreateSwathSpectrum(MassSpectrum ms, out SwathSpectrumEntry sws)
            {
                sws = null;
                int msLevel;

                if (!ms.TryGetMsLevel(out msLevel) || msLevel != 2)
                {
                    return(false);
                }

                if (ms.Precursors.Count < 1 ||
                    ms.Precursors[0].SelectedIons.Count < 1 ||
                    ms.Scans.Count < 1)
                {
                    return(false);
                }

                double rt, mz, mzLow, mzHeigh;
                var    isoWin = ms.Precursors[0].IsolationWindow;
                var    scan   = ms.Scans[0];

                if (scan.TryGetScanStartTime(out rt) &&
                    isoWin.TryGetIsolationWindowTargetMz(out mz) &&
                    isoWin.TryGetIsolationWindowLowerOffset(out mzLow) &&
                    isoWin.TryGetIsolationWindowUpperOffset(out mzHeigh))
                {
                    sws = new SwathSpectrumEntry(
                        ms.ID,
                        mz,
                        mz - mzLow,
                        mz + mzHeigh,
                        rt);

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
Пример #4
0
        public static SwathIndexer Create(IMzLiteDataReader dataReader, string runID)
        {
            if (dataReader == null)
            {
                throw new ArgumentNullException("dataReader");
            }
            if (string.IsNullOrWhiteSpace(runID))
            {
                throw new ArgumentNullException("runID");
            }

            var spectra = SwathSpectrumEntry.Scan(dataReader.ReadMassSpectra(runID));
            var groups  = spectra.GroupBy(x => x.SwathWindow, new SwathWindowGroupingComparer()).ToArray();
            var swathes = new MSSwath[groups.Length];

            for (int i = 0; i < groups.Length; i++)
            {
                swathes[i] = new MSSwath(groups[i].Key, groups[i].ToArray());
            }

            SwathList swathList = new SwathList(swathes);

            return(new SwathIndexer(swathList));
        }
Пример #5
0
 private static double CalcLockRtDiffAbs(SwathSpectrumEntry swathSpectrum, SwathQuery query)
 {
     return(Math.Abs(swathSpectrum.Rt - query.RtRange.LockValue));
 }