Example #1
0
 public bool Equals(MSDataScan <TSpectrum> other)
 {
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(SpectrumNumber.Equals(other.SpectrumNumber) && ParentFile.Equals(other.ParentFile));
 }
Example #2
0
        protected virtual MSDataScan <TSpectrum> GetMSDataScan(int spectrumNumber)
        {
            int msn = GetMsnOrder(spectrumNumber);

            MSDataScan <TSpectrum> scan = msn > 1 ? new MsnDataScan <TSpectrum>(spectrumNumber, msn, this) : new MSDataScan <TSpectrum>(spectrumNumber, msn, this);

            return(scan);
        }
Example #3
0
        public virtual IEnumerable <MSDataScan <TSpectrum> > GetMsScans(double firstRT, double lastRT)
        {
            int spectrumNumber = GetSpectrumNumber(firstRT - 0.0000001);

            while (spectrumNumber <= LastSpectrumNumber)
            {
                MSDataScan <TSpectrum> scan = GetMsScan(spectrumNumber++);
                double rt = scan.RetentionTime;
                if (rt < firstRT)
                {
                    continue;
                }
                if (rt > lastRT)
                {
                    yield break;
                }
                yield return(scan);
            }
        }
Example #4
0
        public IEnumerable <Feature> ExtractFeatures(IList <int> scans, double ppmTolerance, int minConsecutiveScans = 5)
        {
            List <Feature>      activeFeatures = new List <Feature>();
            List <ThermoMzPeak> outPeaks       = new List <ThermoMzPeak>();

            rawFile.GetLabeledSpectrum(scans[0]).TryGetPeaks(0, 1000, out outPeaks);
            double currRT = rawFile.GetRetentionTime(scans[0]);

            //MZPeak[] currentPeaks = currentScan.MassSpectrum.GetPeaks(0, 1000).ToArray();
            MZPeak[] currentPeaks = outPeaks.ToArray();
            activeFeatures.AddRange(currentPeaks.Select(p => new Feature(p, currRT)));
            int counter = 0;
            int percent = (scans.Count) / 100;

            for (int i = 1; i < scans.Count; i++)
            {
                rawFile.ClearCachedScans();
                if (i % percent == 0)
                {
                    counter++;
                    if (counter < 100)
                    {
                        OnProgressUpdate(0.01);
                    }
                }
                MSDataScan <ThermoSpectrum> currentScan = rawFile.GetMsScan(scans[i]);
                //currentScan = scans[i];

                // outPeaks = new List<ThermoMzPeak>();
                // double[,] peakArray = currentScan.MassSpectrum.ToArray();
                //for (int j = 0; j < peakArray.Length / 2; j++)
                //{
                //    outPeaks.Add(new MZPeak(peakArray[0, j], peakArray[1, j]));
                //}
                rawFile.GetLabeledSpectrum(currentScan.SpectrumNumber).TryGetPeaks(0, 1000, out outPeaks);
                outPeaks = outPeaks.OrderBy(x => x.MZ).ToList();
                //currentPeaks = currentScan.MassSpectrum.GetPeaks(0, 1000).ToArray();
                currentPeaks = outPeaks.ToArray();

                double rt = currentScan.RetentionTime;

                // Order features based on their average m/z which may change each round as new peaks are added
                activeFeatures = activeFeatures.OrderBy(feat => feat.AverageMZ).ToList();

                // Match all the active features to the current spectrum at a given ppm tolerance
                MatchPeaks(activeFeatures, currentPeaks, ppmTolerance, rt);

                // Find features that are finished and return them if they pass the filters
                int f = 0;
                while (f < activeFeatures.Count)
                {
                    var feature = activeFeatures[f];
                    //DJB
                    //if (feature.LastAddedTime < rt || feature.CurrentState == PeakState.Tailing)
                    //NWK
                    if (feature.MaxRT < rt)
                    {
                        //DJB
                        //if (feature.Count >= minConsecutiveScans && (feature.TotalStates & PeakState.Tailing) == PeakState.Tailing)
                        //NWK
                        if (feature.Count >= minConsecutiveScans && CheckPeakRise(feature))
                        {
                            yield return(feature);
                        }
                        activeFeatures.RemoveAt(f);
                    }
                    else
                    {
                        f++;
                    }
                }
            }

            //DJB
            //foreach (var feature in activeFeatures.Where(f => f.Count > minConsecutiveScans && f.CurrentState != PeakState.Random))
            //NWK
            foreach (var feature in activeFeatures.Where(f => f.Count > minConsecutiveScans))
            {
                if (CheckPeakRise(feature))
                {
                    yield return(feature);
                }
            }
        }