示例#1
0
        public static RawTimeIntensities ReadFromStream(Stream stream)
        {
            var chromatogramGroupData = new ChromatogramGroupData();

            chromatogramGroupData.MergeFrom(new CodedInputStream(stream));
            return(FromChromatogramGroupData(chromatogramGroupData));
        }
示例#2
0
        public ChromatogramGroupData ToChromatogramGroupData()
        {
            var timeLists             = new Dictionary <ImmutableList <float>, int>();
            var scanIdLists           = new Dictionary <ImmutableList <int>, int>();
            var chromatogramGroupData = new ChromatogramGroupData();

            for (int i = 0; i < TransitionTimeIntensities.Count; i++)
            {
                var timeIntensities = TransitionTimeIntensities[i];
                var chromatogram    = new ChromatogramGroupData.Types.Chromatogram();
                int timeListIndex;
                if (!timeLists.TryGetValue(timeIntensities.Times, out timeListIndex))
                {
                    timeListIndex = timeLists.Count + 1;
                    timeLists.Add(timeIntensities.Times, timeListIndex);
                    var timeList = new ChromatogramGroupData.Types.TimeList();
                    timeList.Times.AddRange(timeIntensities.Times);
                    chromatogramGroupData.TimeLists.Add(timeList);
                }
                chromatogram.TimeListIndex = timeListIndex;
                chromatogram.Intensities.AddRange(timeIntensities.Intensities);
                if (null != timeIntensities.MassErrors)
                {
                    chromatogram.MassErrors100X.AddRange(timeIntensities.MassErrors.Select(error => (int)Math.Round(error * 100)));
                }

                if (null != timeIntensities.ScanIds)
                {
                    int scanIdListIndex;
                    if (!scanIdLists.TryGetValue(timeIntensities.ScanIds, out scanIdListIndex))
                    {
                        scanIdListIndex = scanIdLists.Count + 1;
                        scanIdLists.Add(timeIntensities.ScanIds, scanIdListIndex);
                        var scanIdList = new ChromatogramGroupData.Types.ScanIdList();
                        scanIdList.ScanIds.AddRange(timeIntensities.ScanIds);
                        chromatogramGroupData.ScanIdLists.Add(scanIdList);
                    }
                    chromatogram.ScanIdListIndex = scanIdListIndex;
                }
                chromatogramGroupData.Chromatograms.Add(chromatogram);
            }
            if (InterpolationParams != null)
            {
                chromatogramGroupData.InterpolatedStartTime = InterpolationParams.StartTime;
                chromatogramGroupData.InterpolatedEndTime   = InterpolationParams.EndTime;
                chromatogramGroupData.InterpolatedNumPoints = InterpolationParams.NumPoints;
                chromatogramGroupData.InterpolatedDelta     = InterpolationParams.IntervalDelta;
                chromatogramGroupData.InferZeroes           = InterpolationParams.InferZeroes;
            }

            if (TimeIntervals != null)
            {
                chromatogramGroupData.TimeIntervals = new ChromatogramGroupData.Types.TimeIntervals();
                chromatogramGroupData.TimeIntervals.StartTimes.AddRange(TimeIntervals.Starts);
                chromatogramGroupData.TimeIntervals.EndTimes.AddRange(TimeIntervals.Ends);
            }
            return(chromatogramGroupData);
        }
示例#3
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);
        }