Ejemplo n.º 1
0
        private void HandleSpectrum(
            ref SpectrumTrackingInfo trackingInfo,
            Dictionary <int, List <int> > isolationMzBinToScanNums,
            Spectrum spec)
        {
            trackingInfo.SpecRead += 1;

            //Console.WriteLine("Reading Scan {0}; {1} peaks", spec.ScanNum, spec.Peaks.Length);
            ScanNumToMsLevel[spec.ScanNum]      = spec.MsLevel;
            ScanNumElutionTimeMap[spec.ScanNum] = spec.ElutionTime;
            if (spec.MsLevel == 1)
            {
                if (trackingInfo.PrecursorSignalToNoiseRatioThreshold > 0.0)
                {
                    spec.FilterNoise(trackingInfo.PrecursorSignalToNoiseRatioThreshold);
                }

                //foreach (var peak in spec.Peaks)
                //{
                //    _ms1PeakList.Add(new LcMsPeak(peak.Mz, peak.Intensity, spec.ScanNum));
                //}
                _ms1PeakList.AddRange(spec.Peaks.Select(peak => new LcMsPeak(peak.Mz, peak.Intensity, spec.ScanNum)));
                _scanNumSpecMap.Add(spec.ScanNum, spec);
            }
            else if (spec.MsLevel == 2)
            {
                var productSpec = spec as ProductSpectrum;

                if (productSpec != null)
                {
                    if (trackingInfo.ProductSignalToNoiseRatioThreshold > 0.0)
                    {
                        productSpec.FilterNoise(trackingInfo.ProductSignalToNoiseRatioThreshold);
                    }

                    var isolationWindow = productSpec.IsolationWindow;
                    var minBinNum       = (int)Math.Round(isolationWindow.MinMz * IsolationWindowBinningFactor);
                    var maxBinNum       = (int)Math.Round(isolationWindow.MaxMz * IsolationWindowBinningFactor);
                    for (var binNum = minBinNum; binNum <= maxBinNum; binNum++)
                    {
                        List <int> scanNumList;
                        if (!isolationMzBinToScanNums.TryGetValue(binNum, out scanNumList))
                        {
                            scanNumList = new List <int>();
                            isolationMzBinToScanNums[binNum] = scanNumList;
                        }
                        scanNumList.Add(productSpec.ScanNum);
                    }
                    _scanNumSpecMap.Add(spec.ScanNum, productSpec);
                }
            }

            if (spec.ScanNum < trackingInfo.MinScanNum)
            {
                trackingInfo.MinScanNum = spec.ScanNum;
            }
            if (spec.ScanNum > trackingInfo.MaxScanNum)
            {
                trackingInfo.MaxScanNum = spec.ScanNum;
            }

            if (spec.MsLevel < trackingInfo.MinMsLevel)
            {
                trackingInfo.MinMsLevel = spec.MsLevel;
            }
            if (spec.MsLevel > trackingInfo.MaxMsLevel)
            {
                trackingInfo.MaxMsLevel = spec.MsLevel;
            }
        }
Ejemplo n.º 2
0
        private void HandleSpectrum(
            ref SpectrumTrackingInfo trackingInfo,
            Dictionary<int, List<int>> isolationMzBinToScanNums,
            Spectrum spec)
        {
            trackingInfo.SpecRead += 1;

            //Console.WriteLine("Reading Scan {0}; {1} peaks", spec.ScanNum, spec.Peaks.Length);
            ScanNumToMsLevel[spec.ScanNum] = spec.MsLevel;
            ScanNumElutionTimeMap[spec.ScanNum] = spec.ElutionTime;
            if (spec.MsLevel == 1)
            {
                if (trackingInfo.PrecursorSignalToNoiseRatioThreshold > 0.0)
                    spec.FilterNoise(trackingInfo.PrecursorSignalToNoiseRatioThreshold);

                //foreach (var peak in spec.Peaks)
                //{
                //    _ms1PeakList.Add(new LcMsPeak(peak.Mz, peak.Intensity, spec.ScanNum));
                //}
                _ms1PeakList.AddRange(spec.Peaks.Select(peak => new LcMsPeak(peak.Mz, peak.Intensity, spec.ScanNum)));
                _scanNumSpecMap.Add(spec.ScanNum, spec);
            }
            else if (spec.MsLevel == 2)
            {
                var productSpec = spec as ProductSpectrum;

                if (productSpec != null)
                {
                    if (trackingInfo.ProductSignalToNoiseRatioThreshold > 0.0)
                        productSpec.FilterNoise(trackingInfo.ProductSignalToNoiseRatioThreshold);

                    var isolationWindow = productSpec.IsolationWindow;
                    var minBinNum = (int)Math.Round(isolationWindow.MinMz * IsolationWindowBinningFactor);
                    var maxBinNum = (int)Math.Round(isolationWindow.MaxMz * IsolationWindowBinningFactor);
                    for (var binNum = minBinNum; binNum <= maxBinNum; binNum++)
                    {
                        List<int> scanNumList;
                        if (!isolationMzBinToScanNums.TryGetValue(binNum, out scanNumList))
                        {
                            scanNumList = new List<int>();
                            isolationMzBinToScanNums[binNum] = scanNumList;
                        }
                        scanNumList.Add(productSpec.ScanNum);
                    }
                    _scanNumSpecMap.Add(spec.ScanNum, productSpec);
                }
            }

            if (spec.ScanNum < trackingInfo.MinScanNum) trackingInfo.MinScanNum = spec.ScanNum;
            if (spec.ScanNum > trackingInfo.MaxScanNum) trackingInfo.MaxScanNum = spec.ScanNum;

            if (spec.MsLevel < trackingInfo.MinMsLevel) trackingInfo.MinMsLevel = spec.MsLevel;
            if (spec.MsLevel > trackingInfo.MaxMsLevel) trackingInfo.MaxMsLevel = spec.MsLevel;
        }
Ejemplo n.º 3
0
        public InMemoryLcMsRun(
            IMassSpecDataReader massSpecDataReader,
            double precursorSignalToNoiseRatioThreshold,
            double productSignalToNoiseRatioThreshold,
            IProgress <ProgressData> progress = null,
            int scanStart = 0,
            int scanEnd   = 0)
        {
            ScanNumElutionTimeMap    = new Dictionary <int, double>();
            ScanNumToMsLevel         = new Dictionary <int, int>();
            IsolationMzBinToScanNums = new Dictionary <int, int[]>();

            _ms1PeakList    = new List <LcMsPeak>();
            _scanNumSpecMap = new Dictionary <int, Spectrum>();

            var isolationMzBinToScanNums = new Dictionary <int, List <int> >();

            // Read all spectra

            var progressData = new ProgressData(progress)
            {
                Status = "Reading spectra from file"
            };

            var trackingInfo = new SpectrumTrackingInfo
            {
                NumSpectra = massSpecDataReader.NumSpectra,
                PrecursorSignalToNoiseRatioThreshold = precursorSignalToNoiseRatioThreshold,
                ProductSignalToNoiseRatioThreshold   = productSignalToNoiseRatioThreshold,
                SpecRead   = 0,
                MinScanNum = int.MaxValue,
                MaxScanNum = int.MinValue,
                MinMsLevel = int.MaxValue,
                MaxMsLevel = int.MinValue
            };

            NumSpectra = massSpecDataReader.NumSpectra;

            progressData.StepRange(95.0);

            if (scanStart > 0 && scanEnd >= scanStart)
            {
                for (var scanNum = scanStart; scanNum <= scanEnd; scanNum++)
                {
                    var spec = massSpecDataReader.ReadMassSpectrum(scanNum);
                    progressData.Report(trackingInfo.SpecRead, trackingInfo.NumSpectra);
                    HandleSpectrum(ref trackingInfo, isolationMzBinToScanNums, spec);
                }
            }
            else
            {
                foreach (var spec in massSpecDataReader.ReadAllSpectra())
                {
                    progressData.Report(trackingInfo.SpecRead, trackingInfo.NumSpectra);
                    HandleSpectrum(ref trackingInfo, isolationMzBinToScanNums, spec);
                }
            }

            progressData.Status         = "Processing Isolation Bins";
            progressData.IsPartialRange = false;
            progressData.Report(95.1);

            foreach (var entry in isolationMzBinToScanNums)
            {
                var binNum = entry.Key;
                entry.Value.Sort();
                var scanNumList = entry.Value.ToArray();
                IsolationMzBinToScanNums[binNum] = scanNumList;
            }

            _ms1PeakList.Sort();
            //_ms2PeakList.Sort();

            progressData.Report(99.5);

            // Read MS levels and precursor information

            MinLcScan = trackingInfo.MinScanNum;
            MaxLcScan = trackingInfo.MaxScanNum;

            MinMsLevel = trackingInfo.MinMsLevel;
            MaxMsLevel = trackingInfo.MaxMsLevel;

            //var precursorMap = new Dictionary<int, int>();
            //var nextScanMap = new Dictionary<int, int>();
            //
            //for (var msLevel = MinMsLevel; msLevel <= maxMsLevel; msLevel++)
            //{
            //    precursorMap[msLevel] = 0;
            //    nextScanMap[msLevel] = MaxLcScan + 1;
            //}
            //progressData.Report(99.8);

            progressData.Report(100.0);
            CreatePrecursorNextScanMap();
        }
Ejemplo n.º 4
0
        public InMemoryLcMsRun(
            IMassSpecDataReader massSpecDataReader, 
            double precursorSignalToNoiseRatioThreshold, 
            double productSignalToNoiseRatioThreshold,            
            IProgress<ProgressData> progress = null,
            int scanStart = 0,
            int scanEnd = 0)
        {
            ScanNumElutionTimeMap = new Dictionary<int, double>();
            ScanNumToMsLevel = new Dictionary<int, int>();
            IsolationMzBinToScanNums = new Dictionary<int, int[]>();

            _ms1PeakList = new List<LcMsPeak>();
            _scanNumSpecMap = new Dictionary<int, Spectrum>();

            var isolationMzBinToScanNums = new Dictionary<int, List<int>>();

            // Read all spectra

            var progressData = new ProgressData(progress)
            {
                Status = "Reading spectra from file"
            };

            var trackingInfo = new SpectrumTrackingInfo
            {
                NumSpectra = massSpecDataReader.NumSpectra,
                PrecursorSignalToNoiseRatioThreshold = precursorSignalToNoiseRatioThreshold,
                ProductSignalToNoiseRatioThreshold = productSignalToNoiseRatioThreshold,
                SpecRead = 0,
                MinScanNum = int.MaxValue,
                MaxScanNum = int.MinValue,
                MinMsLevel = int.MaxValue,
                MaxMsLevel = int.MinValue
            };

            NumSpectra = massSpecDataReader.NumSpectra;

            progressData.StepRange(95.0);

            if (scanStart > 0 && scanEnd >= scanStart)
            {
                for (var scanNum = scanStart; scanNum <= scanEnd; scanNum++)
                {
                    var spec = massSpecDataReader.ReadMassSpectrum(scanNum);
                    progressData.Report(trackingInfo.SpecRead, trackingInfo.NumSpectra);
                    HandleSpectrum(ref trackingInfo, isolationMzBinToScanNums, spec);
                }
            }
            else
            {
                foreach (var spec in massSpecDataReader.ReadAllSpectra())
                {
                    progressData.Report(trackingInfo.SpecRead, trackingInfo.NumSpectra);
                    HandleSpectrum(ref trackingInfo, isolationMzBinToScanNums, spec);
                }
            }
                        
            progressData.Status = "Processing Isolation Bins";
            progressData.IsPartialRange = false;
            progressData.Report(95.1);

            foreach (var entry in isolationMzBinToScanNums)
            {
                var binNum = entry.Key;
                entry.Value.Sort();
                var scanNumList = entry.Value.ToArray();
                IsolationMzBinToScanNums[binNum] = scanNumList;
            }

            _ms1PeakList.Sort();
            //_ms2PeakList.Sort();

            progressData.Report(99.5);

            // Read MS levels and precursor information

            MinLcScan = trackingInfo.MinScanNum;
            MaxLcScan = trackingInfo.MaxScanNum;

            MinMsLevel = trackingInfo.MinMsLevel;
            MaxMsLevel = trackingInfo.MaxMsLevel;

            //var precursorMap = new Dictionary<int, int>();
            //var nextScanMap = new Dictionary<int, int>();
            //
            //for (var msLevel = MinMsLevel; msLevel <= maxMsLevel; msLevel++)
            //{
            //    precursorMap[msLevel] = 0;
            //    nextScanMap[msLevel] = MaxLcScan + 1;
            //}
            //progressData.Report(99.8);

            progressData.Report(100.0);
            CreatePrecursorNextScanMap();
        }