Esempio n. 1
0
        public void FindPeaks(double[] retentionTimes, TimeIntervals timeIntervals, ExplicitRetentionTimeInfo explicitRT)
        {
            Finder = Crawdads.NewCrawdadPeakFinder();
            Finder.SetChromatogram(Times, Intensities);
            if (timeIntervals == null)
            {
                RawPeaks = Finder.CalcPeaks(MAX_PEAKS, TimesToIndices(retentionTimes));
            }
            else
            {
                var identifiedIndices = TimesToIndices(retentionTimes);
                var allPeaks          = timeIntervals.Intervals.SelectMany(interval =>
                                                                           FindIntervalPeaks(interval.Key, interval.Value, identifiedIndices));
                RawPeaks = allPeaks.OrderByDescending(peak => Tuple.Create(peak.Identified, peak.Area))
                           .Take(MAX_PEAKS).ToArray();
            }
            // Calculate smoothing for later use in extending the Crawdad peaks
            IntensitiesSmooth = ChromatogramInfo.SavitzkyGolaySmooth(Intensities.ToArray());

            // Accept only peaks within the user-provided RT window, if any
            if (explicitRT != null)
            {
                var winLow  = (float)(explicitRT.RetentionTime - 0.5 * (explicitRT.RetentionTimeWindow ?? 0));
                var winHigh = winLow + (float)(explicitRT.RetentionTimeWindow ?? 0);
                RawPeaks = RawPeaks.Where(rp =>
                {
                    var t = Times[rp.TimeIndex];
                    return(winLow <= t && t <= winHigh);
                });
            }
        }
Esempio n. 2
0
        public TimeIntervals InferTimeIntervals(IEnumerable <IList <float> > timesList)
        {
            TimeIntervals result   = null;
            var           timesSet = new HashSet <object>(new IdentityEqualityComparer <object>());

            foreach (var times in timesList)
            {
                if (!timesSet.Add(times))
                {
                    continue;
                }
                TimeIntervals timeIntervals = InferTimeIntervalsFromScanTimes(times);
                if (result == null)
                {
                    result = timeIntervals;
                }
                else
                {
                    var newResult = result.Intersect(timeIntervals);
                    result = newResult;
                }
            }

            return(result);
        }
Esempio n. 3
0
 public TimeIntervals Intersect(TimeIntervals other)
 {
     using (var myIntervals = Intervals.GetEnumerator())
         using (var otherIntervals = other.Intervals.GetEnumerator())
         {
             return(FromIntervalsSorted(Intersect(myIntervals, otherIntervals)));
         }
 }
Esempio n. 4
0
        public static RawTimeIntensities FromChromatogramGroupData(ChromatogramGroupData chromatogramGroupData)
        {
            var timeIntensitiesList = new List <TimeIntensities>();
            var timeLists           = chromatogramGroupData.TimeLists.Select(timeList => ImmutableList.ValueOf(timeList.Times)).ToArray();
            var scanIdLists         = chromatogramGroupData.ScanIdLists
                                      .Select(scanIdList => ImmutableList.ValueOf(scanIdList.ScanIds)).ToArray();

            foreach (var chromatogram in chromatogramGroupData.Chromatograms)
            {
                IEnumerable <float> massErrors = null;
                if (chromatogram.MassErrors100X.Count > 0)
                {
                    massErrors = chromatogram.MassErrors100X.Select(error => error / 100.0f);
                }
                else if (chromatogram.MassErrorsDeprecated.Count > 0)
                {
                    massErrors = chromatogram.MassErrorsDeprecated;
                }
                var timeIntensities = new TimeIntensities(timeLists[chromatogram.TimeListIndex - 1],
                                                          chromatogram.Intensities,
                                                          massErrors,
                                                          chromatogram.ScanIdListIndex == 0 ? null : scanIdLists[chromatogram.ScanIdListIndex - 1]);
                timeIntensitiesList.Add(timeIntensities);
            }
            InterpolationParams interpolationParams;

            if (chromatogramGroupData.InterpolatedNumPoints == 0)
            {
                interpolationParams = null;
            }
            else
            {
                interpolationParams = new InterpolationParams(chromatogramGroupData.InterpolatedStartTime, chromatogramGroupData.InterpolatedEndTime, chromatogramGroupData.InterpolatedNumPoints, chromatogramGroupData.InterpolatedDelta)
                                      .ChangeInferZeroes(chromatogramGroupData.InferZeroes);
            }
            var rawTimeIntensities = new RawTimeIntensities(timeIntensitiesList, interpolationParams);

            if (chromatogramGroupData.TimeIntervals != null)
            {
                var startTimes = chromatogramGroupData.TimeIntervals.StartTimes;
                var endTimes   = chromatogramGroupData.TimeIntervals.EndTimes;

                var timeIntervals = TimeIntervals.FromIntervals(Enumerable.Range(0, startTimes.Count)
                                                                .Select(i => new KeyValuePair <float, float>(startTimes[i], endTimes[i])));
                rawTimeIntensities = rawTimeIntensities.ChangeTimeIntervals(timeIntervals);
            }

            return(rawTimeIntensities);
        }
Esempio n. 5
0
 public RawTimeIntensities ChangeTimeIntervals(TimeIntervals timeIntervals)
 {
     return(ChangeProp(ImClone(this), im => im.TimeIntervals = timeIntervals));
 }
Esempio n. 6
0
 public ChromPeak CalcChromPeak(IFoundPeak peakMax, ChromPeak.FlagValues flags, TimeIntervals timeIntervals)
 {
     _chromPeak = Data.CalcChromPeak(peakMax, flags, timeIntervals, out _crawPeak);
     return(_chromPeak);
 }
Esempio n. 7
0
        public ChromPeak CalcChromPeak(IFoundPeak peakMax, ChromPeak.FlagValues flags, TimeIntervals timeIntervals, out IFoundPeak peak)
        {
            // Reintegrate all peaks to the max peak, even the max peak itself, since its boundaries may
            // have been extended from the Crawdad originals.
            if (peakMax == null)
            {
                peak = null;
                return(ChromPeak.EMPTY);
            }

            var peakIntegrator = new PeakIntegrator(TimeIntensities, Finder)
            {
                RawTimeIntensities = RawTimeIntensities,
                TimeIntervals      = timeIntervals
            };
            var tuple = peakIntegrator.IntegrateFoundPeak(peakMax, flags);

            peak = tuple.Item2;
            return(tuple.Item1);
        }
Esempio n. 8
0
        public TimeIntervals InferTimeIntervalsFromScanTimes(IList <float> times)
        {
            float medianDuration = GetMedianScanDuration(times);

            return(TimeIntervals.FromScanTimes(times, (float)(medianDuration * ScanTimeTolerance)));
        }