Ejemplo n.º 1
0
        /// <summary>
        /// Builds an in memory retention time index of mass spectra ids.
        /// </summary>
        public static IMzLiteArray <RtIndexEntry> BuildRtIndex(
            this IMzLiteDataReader dataReader,
            string runID,
            int msLevel = 1)
        {
            if (dataReader == null)
            {
                throw new ArgumentNullException("dataReader");
            }
            if (string.IsNullOrWhiteSpace(runID))
            {
                throw new ArgumentNullException("runID");
            }

            IEnumerable <MassSpectrum> massSpectra = dataReader.ReadMassSpectra(runID);
            List <RtIndexEntry>        entries     = new List <RtIndexEntry>();
            RtIndexEntry entry;

            foreach (var ms in massSpectra)
            {
                if (TryCreateEntry(ms, msLevel, out entry))
                {
                    entries.Add(entry);
                }
            }

            entries.Sort(new RtIndexEntrySorting());

            return(MzLiteArray.ToMzLiteArray(entries));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Extract a rt profile for specified target mass and rt range.
        /// Mz range peak aggregation is closest lock mz.
        /// </summary>
        /// <returns>
        /// Profile array with index corresponding to continous mass spectra over rt range and mz range given.
        /// </returns>
        public static Peak2D[] RtProfile(
            this IMzLiteDataReader dataReader,
            IMzLiteArray <RtIndexEntry> rtIndex,
            RangeQuery rtRange,
            RangeQuery mzRange)
        {
            if (dataReader == null)
            {
                throw new ArgumentNullException("dataReader");
            }
            if (rtIndex == null)
            {
                throw new ArgumentNullException("rtIndex");
            }

            var entries = rtIndex.Search(rtRange).ToArray();
            var profile = new Peak2D[entries.Length];

            for (int rtIdx = 0; rtIdx < entries.Length; rtIdx++)
            {
                var entry = entries[rtIdx];
                var peaks = dataReader.ReadSpectrumPeaks(entry).Peaks;
                var p     = peaks.MzSearch(mzRange)
                            .DefaultIfEmpty(new Peak1D(0, mzRange.LockValue))
                            .ClosestMz(mzRange.LockValue)
                            .AsPeak2D(entry.Rt);
                profile[rtIdx] = p;
            }
            return(profile);
        }
Ejemplo n.º 3
0
        public static MassSpectrum ReadMassSpectrum(
            this IMzLiteDataReader dataReader,
            RtIndexEntry entry)
        {
            if (dataReader == null)
            {
                throw new ArgumentNullException("dataReader");
            }

            return(dataReader.ReadMassSpectrum(entry.SpectrumID));
        }
Ejemplo n.º 4
0
        public static Peak1DArray ReadSpectrumPeaks(
            this IMzLiteDataReader dataReader,
            RtIndexEntry entry)
        {
            if (dataReader == null)
            {
                throw new ArgumentNullException("dataReader");
            }

            return(dataReader.ReadSpectrumPeaks(entry.SpectrumID));
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public static SWATHIndexer Build(IMzLiteDataReader reader, string runID, Func <MassSpectrum, SWATHIndexerItem> createItem)
        {
            IList <SWATHIndexerItem> list = new List <SWATHIndexerItem>(65000);

            foreach (MassSpectrum ms in reader.ReadMassSpectra(runID))
            {
                SWATHIndexerItem item = createItem.Invoke(ms);

                if (item != null)
                {
                    list.Add(item);
                }
            }

            SWATHIndexer indexer = new SWATHIndexer();

            indexer.items = new SWATHIndexerItem[list.Count];
            list.CopyTo(indexer.items, 0);

            Array.Sort(indexer.items, new ItemSorting());

            return(indexer);
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
 public static SWATHIndexer Build(IMzLiteDataReader reader, string runID)
 {
     return(Build(reader, runID, CreateItem));
 }