Exemple #1
0
        private static void GetReferenceData(SrmDocument doc, PeptideDocNode nodePep, TransitionGroupDocNode nodeTranGroup, int resultsIndex, ChromFileInfoId resultsFile,
                                             out PeakMatchData referenceTarget, out PeakMatchData[] referenceMatchData, out DateTime?runTime)
        {
            referenceTarget    = null;
            referenceMatchData = new PeakMatchData[0];
            runTime            = null;

            var referenceMatchDataList = new List <PeakMatchData>();

            var mzMatchTolerance = (float)doc.Settings.TransitionSettings.Instrument.MzMatchTolerance;

            if (!nodeTranGroup.HasResults || resultsIndex < 0 || resultsIndex >= nodeTranGroup.Results.Count)
            {
                return;
            }

            var tranGroupChromInfo = nodeTranGroup.GetChromInfo(resultsIndex, resultsFile);

            if (tranGroupChromInfo == null)
            {
                return;
            }

            var chromSet = doc.Settings.MeasuredResults.Chromatograms[resultsIndex];

            if (!doc.Settings.MeasuredResults.TryLoadChromatogram(chromSet, nodePep, nodeTranGroup, mzMatchTolerance, true, out var chromGroupInfos))
            {
                return;
            }

            var chromGroupInfo = chromGroupInfos.FirstOrDefault(info => Equals(chromSet.GetFileInfo(tranGroupChromInfo.FileId).FilePath, info.FilePath));

            if (chromGroupInfo == null || chromGroupInfo.NumPeaks == 0 || !chromGroupInfo.TimeIntensitiesGroup.HasAnyPoints)
            {
                return;
            }

            runTime = chromGroupInfo.RunStartTime;

            if (!tranGroupChromInfo.RetentionTime.HasValue || !tranGroupChromInfo.StartRetentionTime.HasValue || !tranGroupChromInfo.EndRetentionTime.HasValue)
            {
                return;
            }

            int peakIndex = -1;

            foreach (var transition in chromGroupInfo.TransitionPointSets)
            {
                peakIndex = transition.IndexOfPeak(tranGroupChromInfo.RetentionTime.Value);
                if (peakIndex != -1)
                {
                    break;
                }
            }

            // Get time information
            float timeMin = chromGroupInfo.TimeIntensitiesGroup.MinTime;
            float timeMax = chromGroupInfo.TimeIntensitiesGroup.MaxTime;

            float totalArea = chromGroupInfo.TransitionPointSets.Sum(chromInfo => chromInfo.Peaks.Sum(peak => peak.Area));

            for (int i = 0; i < chromGroupInfo.NumPeaks; i++)
            {
                referenceMatchDataList.Add(new PeakMatchData(nodeTranGroup, chromGroupInfo, mzMatchTolerance, i, totalArea, chromSet.OptimizationFunction));
            }

            // Get ion abundance information
            var abundances = new IonAbundances();

            foreach (var nodeTran in nodeTranGroup.Transitions)
            {
                var chromInfoCached = chromGroupInfo.GetTransitionInfo(nodeTran, mzMatchTolerance, chromSet.OptimizationFunction);
                if (chromInfoCached == null)
                {
                    continue;
                }

                var tranChromInfo = nodeTran.Results[resultsIndex].First(r => r.FileIndex == tranGroupChromInfo.FileIndex);

                float area;
                if (peakIndex != -1)
                {
                    // A peak exists here
                    var cachedPeak = chromInfoCached.GetPeak(peakIndex);
                    area = cachedPeak.Area;

                    if (cachedPeak.RetentionTime.Equals(tranGroupChromInfo.RetentionTime.Value))
                    {
                        var range = cachedPeak.EndTime - cachedPeak.StartTime;
                        referenceMatchDataList[peakIndex].ShiftLeft  = (tranChromInfo.StartRetentionTime - cachedPeak.StartTime) / range;
                        referenceMatchDataList[peakIndex].ShiftRight = (tranChromInfo.EndRetentionTime - cachedPeak.EndTime) / range;
                    }
                }
                else
                {
                    area = tranChromInfo.Area;
                }
                abundances.Add(nodeTran, area);
            }

            referenceTarget = peakIndex != -1
                ? referenceMatchDataList[peakIndex]
                : new PeakMatchData(abundances, abundances.Sum() / totalArea, tranGroupChromInfo.RetentionTime.Value,
                                    tranGroupChromInfo.StartRetentionTime.Value, tranGroupChromInfo.EndRetentionTime.Value, timeMin, timeMax);

            referenceMatchData = referenceMatchDataList.ToArray();
        }