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); }
public ChromData Truncate(double minTime, double maxTime) { if (!ReferenceEquals(Times, RawTimes)) { throw new InvalidOperationException("Cannot truncate data set after interpolation"); // Not L10N } if (Peaks.Count > 0) { throw new InvalidOperationException("Cannot truncate after peak detection"); // Not L10N } // Avoid truncating chromatograms down to something less than half the window width. double minLength = (maxTime - minTime) / 2; minTime = Math.Min(minTime, Times[Times.Count - 1] - minLength); maxTime = Math.Max(maxTime, Times[0] + minLength); int firstIndex = CollectionUtil.BinarySearch(Times, (float)minTime); if (firstIndex < 0) { firstIndex = ~firstIndex; firstIndex = Math.Max(firstIndex, 0); } int lastIndex = CollectionUtil.BinarySearch(Times, (float)maxTime); if (lastIndex < 0) { lastIndex = ~lastIndex + 1; lastIndex = Math.Min(lastIndex, Times.Count - 1); } if (firstIndex >= lastIndex) { return(this); } if (firstIndex == 0 && lastIndex == Times.Count - 1) { return(this); } var newChromData = new ChromData(Key, ProviderId) { Extra = Extra, }; newChromData.TimeIntensities = newChromData.RawTimeIntensities = RawTimeIntensities.Truncate(Times[firstIndex], Times[lastIndex]); newChromData.DocNode = DocNode; return(newChromData); }