예제 #1
0
            public double Dot(IonAbundances other)
            {
                var abundancesThis  = new List <double>();
                var abundancesOther = new List <double>();

                foreach (var fragment in _abundances.Keys.Union(other._abundances.Keys))
                {
                    abundancesThis.Add(_abundances.ContainsKey(fragment) ? _abundances[fragment] : 0);
                    abundancesOther.Add(other._abundances.ContainsKey(fragment) ? other._abundances[fragment] : 0);
                }
                var statisticsThis  = new Statistics(abundancesThis);
                var statisticsOther = new Statistics(abundancesOther);

                return(statisticsThis.Angle(statisticsOther));
            }
예제 #2
0
            public PeakMatchData(TransitionGroupDocNode nodeTranGroup, ChromatogramGroupInfo chromGroupInfo,
                                 float mzMatchTolerance, int peakIndex, double totalChromArea)
            {
                Abundances  = new IonAbundances(nodeTranGroup, chromGroupInfo, mzMatchTolerance, peakIndex);
                PercentArea = Abundances.Sum() / totalChromArea;
                var peak = GetLargestPeak(nodeTranGroup, chromGroupInfo, peakIndex, mzMatchTolerance);

                RetentionTime = peak.RetentionTime;
                StartTime     = peak.StartTime;
                EndTime       = peak.EndTime;
                ShiftLeft     = 0;
                ShiftRight    = 0;
                MinTime       = chromGroupInfo.Times.First();
                MaxTime       = chromGroupInfo.Times.Last();
            }
예제 #3
0
            public PeakMatchData(TransitionGroupDocNode nodeTranGroup, ChromatogramGroupInfo chromGroupInfo,
                                 float mzMatchTolerance, int peakIndex, double totalChromArea,
                                 OptimizableRegression regression)
            {
                Abundances  = new IonAbundances(nodeTranGroup, chromGroupInfo, mzMatchTolerance, peakIndex, regression);
                PercentArea = Abundances.Sum() / totalChromArea;
                var peak = GetLargestPeak(nodeTranGroup, chromGroupInfo, peakIndex, mzMatchTolerance, regression);

                RetentionTime = peak.RetentionTime;
                StartTime     = peak.StartTime;
                EndTime       = peak.EndTime;
                ShiftLeft     = 0;
                ShiftRight    = 0;
                MinTime       = chromGroupInfo.TimeIntensitiesGroup.MinTime;
                MaxTime       = chromGroupInfo.TimeIntensitiesGroup.MaxTime;
            }
예제 #4
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();
        }
예제 #5
0
 public PeakMatchData(TransitionGroupDocNode nodeTranGroup, ChromatogramGroupInfo chromGroupInfo,
     float mzMatchTolerance, int peakIndex, double totalChromArea)
 {
     Abundances = new IonAbundances(nodeTranGroup, chromGroupInfo, mzMatchTolerance, peakIndex);
     PercentArea = Abundances.Sum()/totalChromArea;
     var peak = GetLargestPeak(nodeTranGroup, chromGroupInfo, peakIndex, mzMatchTolerance);
     RetentionTime = peak.RetentionTime;
     StartTime = peak.StartTime;
     EndTime = peak.EndTime;
     ShiftLeft = 0;
     ShiftRight = 0;
     MinTime = chromGroupInfo.Times.First();
     MaxTime = chromGroupInfo.Times.Last();
 }
예제 #6
0
 public PeakMatchData(IonAbundances abundances, double percentArea,
     float rt, float rtStart, float rtEnd, float rtMin, float rtMax)
 {
     Abundances = abundances;
     PercentArea = percentArea;
     RetentionTime = rt;
     StartTime = rtStart;
     EndTime = rtEnd;
     ShiftLeft = 0;
     ShiftRight = 0;
     MinTime = rtMin;
     MaxTime = rtMax;
 }
예제 #7
0
 public double Dot(IonAbundances other)
 {
     var abundancesThis = new List<double>();
     var abundancesOther = new List<double>();
     foreach (var fragment in _abundances.Keys.Union(other._abundances.Keys))
     {
         abundancesThis.Add(_abundances.ContainsKey(fragment) ? _abundances[fragment] : 0);
         abundancesOther.Add(other._abundances.ContainsKey(fragment) ? other._abundances[fragment] : 0);
     }
     var statisticsThis = new Statistics(abundancesThis);
     var statisticsOther = new Statistics(abundancesOther);
     return statisticsThis.Angle(statisticsOther);
 }
예제 #8
0
        private static void GetReferenceData(SrmDocument doc, PeptideDocNode nodePep, TransitionGroupDocNode nodeTranGroup, int resultsIndex, int? 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.Results[resultsIndex][resultsFile ?? 0];
            if (tranGroupChromInfo == null)
                return;

            var chromSet = doc.Settings.MeasuredResults.Chromatograms[resultsIndex];
            ChromatogramGroupInfo[] chromGroupInfos;
            if (!doc.Settings.MeasuredResults.TryLoadChromatogram(chromSet, nodePep, nodeTranGroup, mzMatchTolerance, true, out chromGroupInfos))
                return;

            var chromGroupInfo = chromGroupInfos.FirstOrDefault(info => Equals(chromSet.GetFileInfo(tranGroupChromInfo.FileId).FilePath, info.FilePath));
            if (chromGroupInfo == null || chromGroupInfo.NumPeaks == 0 || !chromGroupInfo.Times.Any())
                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.Times.First();
            float timeMax = chromGroupInfo.Times.Last();

            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));

            // Get ion abundance information
            var abundances = new IonAbundances();
            foreach (var nodeTran in nodeTranGroup.Transitions)
            {
                var chromInfoCached = chromGroupInfo.GetTransitionInfo((float) nodeTran.Mz, mzMatchTolerance);
                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();
        }