예제 #1
0
        /// <summary>
        /// Reads a Spectrum from the DPBF file with isotope peaks populated
        /// </summary>
        /// <param name="fullData">The file used to create the DPBF file (throws <see cref="System.ArgumentException"/> if it is not) - PBF file preferred.</param>
        /// <param name="scanNum">The scan to read</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">If the checksum of the source file does not match the checksum stored in the DPBF file</exception>
        public DeconvolutedSpectrum GetSpectrumWithIsotopePeaks(IMassSpecDataReader fullData, int scanNum)
        {
            if (SrcFileChecksum != fullData.SrcFileChecksum || (fullData is PbfLcMsRun && SrcFileChecksum != ((PbfLcMsRun)fullData).PbfFileChecksum))
            {
                throw new ArgumentException("Supplied file was not used to create this DPBF file!", nameof(fullData));
            }

            if (!(GetSpectrum(scanNum, true) is DeconvolutedSpectrum spec))
            {
                return(null);
            }

            var pbfSpec = fullData.ReadMassSpectrum(scanNum, true);

            foreach (var peakBase in spec.Peaks)
            {
                var peak = peakBase as DeconvolutedPeak;
                if (peak == null)
                {
                    continue;
                }

                peak.SetObservedPeaksFromSpectrum(pbfSpec);
            }

            return(spec);
        }
예제 #2
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();
        }
예제 #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();
        }