Esempio n. 1
0
        PeakMatch MaxBy(List <IPeak> peaks, GlycanFilter glycanFilter)
        {
            PeakMatch best = new PeakMatch();

            foreach (var peptide in matches_.Keys)
            {
                best[peptide] = new Dictionary <string, HashSet <int> >();
                double best_score = 0;
                foreach (var g in matches_[peptide].Keys)
                {
                    if (!glycanFilter(g))
                    {
                        continue;
                    }

                    double score = SearchHelper.ComputePeakScore(peaks, matches_[peptide][g]);
                    if (best_score < score)
                    {
                        best_score       = score;
                        best[peptide]    = new Dictionary <string, HashSet <int> >();
                        best[peptide][g] = matches_[peptide][g];
                    }
                    else if (best_score == score)
                    {
                        best[peptide][g] = matches_[peptide][g];
                    }
                }
            }
            return(best);
        }
Esempio n. 2
0
        public void Max(List <IPeak> peaks)
        {
            PeakMatch best = new PeakMatch();

            GlycanFilter complexFilter = new GlycanFilter((s) => s.Length == 47);

            MergePeakMatch(ref best, MaxBy(peaks, complexFilter));
            GlycanFilter highMannoseFilter = new GlycanFilter((s) => s.Length == 11);

            MergePeakMatch(ref best, MaxBy(peaks, highMannoseFilter));
            MergePeakMatch(ref best, MaxByHybrid(peaks));

            matches_ = best;
        }
Esempio n. 3
0
        PeakMatch MaxByHybrid(List <IPeak> peaks)
        {
            PeakMatch best = new PeakMatch();

            foreach (var peptide in matches_.Keys)
            {
                best[peptide] = new Dictionary <string, HashSet <int> >();
                Dictionary <string, List <string> > mannosePart = new Dictionary <string, List <string> >();
                foreach (var glycan_id in matches_[peptide].Keys)
                {
                    if (glycan_id.Length != 31)
                    {
                        continue;
                    }

                    string mannose = glycan_id.Substring(8, 4);
                    if (!mannosePart.ContainsKey(mannose))
                    {
                        mannosePart[mannose] = new List <string>();
                    }
                    mannosePart[mannose].Add(glycan_id);
                }

                foreach (var glycan_ids in mannosePart.Values)
                {
                    double best_score = 0;
                    Dictionary <string, HashSet <int> > sub_best = new Dictionary <string, HashSet <int> >();
                    foreach (string glycan_id in glycan_ids)
                    {
                        double score = SearchHelper.ComputePeakScore(peaks, matches_[peptide][glycan_id]);
                        if (best_score < score)
                        {
                            best_score          = score;
                            sub_best            = new Dictionary <string, HashSet <int> >();
                            sub_best[glycan_id] = matches_[peptide][glycan_id];
                        }
                        else if (best_score == score)
                        {
                            sub_best[glycan_id] = matches_[peptide][glycan_id];
                        }
                    }

                    foreach (string glycan_id in sub_best.Keys)
                    {
                        best[peptide][glycan_id] = sub_best[glycan_id];
                    }
                }
            }
            return(best);
        }
Esempio n. 4
0
 void MergePeakMatch(ref PeakMatch to, PeakMatch from)
 {
     foreach (var peptide in from.Keys)
     {
         if (!to.ContainsKey(peptide))
         {
             to[peptide] = new Dictionary <string, HashSet <int> >();
         }
         foreach (var glycan_id in from[peptide].Keys)
         {
             to[peptide][glycan_id] = from[peptide][glycan_id];
         }
     }
 }
Esempio n. 5
0
        private static PeakMatch GetPeakMatch(SrmDocument doc, ChromatogramSet chromSet, IPathContainer fileInfo, TransitionGroupDocNode nodeTranGroup,
                                              PeakMatchData referenceTarget, IEnumerable <PeakMatchData> referenceMatchData)
        {
            if (referenceTarget == null)
            {
                return(new PeakMatch(0, 0));
            }

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

            ChromatogramGroupInfo[] loadInfos;
            if (!nodeTranGroup.HasResults || !doc.Settings.MeasuredResults.TryLoadChromatogram(chromSet, null, nodeTranGroup, mzMatchTolerance, true, out loadInfos))
            {
                return(null);
            }

            var chromGroupInfo = loadInfos.FirstOrDefault(info => Equals(info.FilePath, fileInfo.FilePath));

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

            var    matchData = new List <PeakMatchData>();
            double totalArea = chromGroupInfo.TransitionPointSets.Sum(chromInfo => chromInfo.Peaks.Sum(peak => peak.Area));

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

            // TODO: Try to improve this. Align peaks in area descending order until peaks do not match
            var  alignments       = new List <PeakAlignment>();
            bool referenceAligned = false;

            using (var referenceIter = referenceMatchData.OrderByDescending(d => d.PercentArea).GetEnumerator())
                using (var curIter = matchData.OrderByDescending(d => d.PercentArea).GetEnumerator())
                {
                    while (referenceIter.MoveNext() && curIter.MoveNext())
                    {
                        var alignAttempt = new PeakAlignment(referenceIter.Current, curIter.Current);
                        if (!TryInsertPeakAlignment(alignments, alignAttempt))
                        {
                            break;
                        }

                        if (referenceTarget == alignAttempt.ReferencePeak)
                        {
                            // Reference target aligned
                            referenceAligned = true;
                            matchData        = new List <PeakMatchData> {
                                alignAttempt.AlignedPeak
                            };
                            break;
                        }
                    }
                }

            PeakMatch manualMatch = null;

            if (!referenceAligned)
            {
                PeakAlignment prev, next;
                GetSurroundingAlignments(alignments, referenceTarget, out prev, out next);
                if (prev != null || next != null)
                {
                    // At least one alignment occurred
                    var chromGroupMinTime = chromGroupInfo.TimeIntensitiesGroup.MinTime;
                    var chromGroupMaxTime = chromGroupInfo.TimeIntensitiesGroup.MaxTime;

                    float scale = (chromGroupMaxTime - chromGroupMinTime) / (referenceTarget.MaxTime - referenceTarget.MinTime);
                    manualMatch = MakePeakMatchBetween(scale, referenceTarget, prev, next);
                    if (chromGroupMinTime >= manualMatch.EndTime || manualMatch.StartTime >= chromGroupMaxTime)
                    {
                        manualMatch = null;
                    }

                    float curMinTime = prev == null ? chromGroupMinTime : prev.AlignedPeak.RetentionTime;
                    float curMaxTime = next == null ? chromGroupMaxTime : next.AlignedPeak.RetentionTime;

                    matchData = matchData.Where(d => curMinTime < d.RetentionTime && d.RetentionTime < curMaxTime).ToList();
                }
            }

            PeakMatchData bestMatch = null;
            double        bestScore = double.MinValue;

            foreach (var other in matchData)
            {
                var score = referenceTarget.GetMatchScore(other);
                if (bestMatch == null || score > bestScore)
                {
                    bestScore = score;
                    bestMatch = other;
                }
            }

            // If no matching peak with high enough score was found, but there is a matching
            // peak or some peak with a low score.
            if (bestMatch == null || (!referenceAligned && bestScore < INTEGRATE_SCORE_THRESHOLD && manualMatch != null))
            {
                return(manualMatch);
            }

            if (referenceTarget.ShiftLeft == 0 && referenceTarget.ShiftRight == 0)
            {
                return(new PeakMatch(bestMatch.RetentionTime));
            }

            var range     = bestMatch.EndTime - bestMatch.StartTime;
            var startTime = bestMatch.StartTime + (referenceTarget.ShiftLeft * range);
            var endTime   = bestMatch.EndTime + (referenceTarget.ShiftRight * range);

            return(startTime <= bestMatch.RetentionTime && bestMatch.RetentionTime <= endTime
                ? new PeakMatch(startTime, endTime)
                : new PeakMatch(bestMatch.RetentionTime)); // If the shifted boundaries exclude the peak itself, don't change the boundaries
        }
Esempio n. 6
0
 public void set_matches(PeakMatch matches)
 {
     matches_ = matches;
 }