public static void CalculateUniqueQValue(List <IIdentifiedSpectrum> peptides, IScoreFunction scoreFuncs, IFalseDiscoveryRateCalculator fdrCalc) { if (peptides.Count == 0) { return; } scoreFuncs.SortSpectrum(peptides); List <IIdentifiedSpectrum> sameScores = new List <IIdentifiedSpectrum>(); HashSet <string> targetSeq = new HashSet <string>(); HashSet <string> decoySeq = new HashSet <string>(); double lastScore = scoreFuncs.GetScore(peptides[0]); for (int i = 0; i < peptides.Count; i++) { IIdentifiedSpectrum spectrum = peptides[i]; double score = scoreFuncs.GetScore(peptides[i]); if (score == lastScore) { sameScores.Add(spectrum); if (spectrum.FromDecoy) { decoySeq.Add(spectrum.Peptide.PureSequence); } else { targetSeq.Add(spectrum.Peptide.PureSequence); } continue; } else { double qValue = fdrCalc.Calculate(decoySeq.Count, targetSeq.Count); foreach (IIdentifiedSpectrum sameScoreSpectrum in sameScores) { sameScoreSpectrum.QValue = qValue; } sameScores.Clear(); lastScore = score; sameScores.Add(spectrum); if (spectrum.FromDecoy) { decoySeq.Add(spectrum.Peptide.PureSequence); } else { targetSeq.Add(spectrum.Peptide.PureSequence); } continue; } } double lastQValue = fdrCalc.Calculate(decoySeq.Count, targetSeq.Count); foreach (IIdentifiedSpectrum sameScoreSpectrum in sameScores) { sameScoreSpectrum.QValue = lastQValue; } }
public void CalculateToleranceScore(IScoreFunction scoreFunc) { scoreFunc.SortSpectrum(this.Spectra); this.Result.Score = this.Spectra.Count > 0 ? scoreFunc.GetScore(this.Spectra.Last()) : 0.0; }
/// <summary> /// 根据给定分数排序函数以及FDR计算器对鉴定谱图列表计算QValue。 /// </summary> /// <param name="peptides">谱图列表</param> /// <param name="scoreFuncs">与分数提取、排序相关类</param> /// <param name="fdrCalc">FDR计算器</param> public static void CalculateQValue(List <IIdentifiedSpectrum> peptides, IScoreFunction scoreFuncs, IFalseDiscoveryRateCalculator fdrCalc) { if (peptides.Count == 0) { return; } scoreFuncs.SortSpectrum(peptides); int totalTarget = 0; int totalDecoy = 0; HashSet <string> filenames = new HashSet <string>(); foreach (IIdentifiedSpectrum spectrum in peptides) { spectrum.QValue = 0.0; if (filenames.Contains(spectrum.Query.FileScan.LongFileName)) { continue; } filenames.Add(spectrum.Query.FileScan.LongFileName); if (spectrum.FromDecoy) { totalDecoy++; } else { totalTarget++; } } double lastScore = scoreFuncs.GetScore(peptides[peptides.Count - 1]); double lastQvalue = fdrCalc.Calculate(totalDecoy, totalTarget); for (int i = peptides.Count - 1; i >= 0; i--) { double score = scoreFuncs.GetScore(peptides[i]); if (score != lastScore) { lastScore = score; lastQvalue = fdrCalc.Calculate(totalDecoy, totalTarget); if (lastQvalue == 0.0) { break; } peptides[i].QValue = lastQvalue; } else { peptides[i].QValue = lastQvalue; } if (peptides[i].FromDecoy) { totalDecoy--; } else { totalTarget--; } } }