From 4f9e99f7f87c7b3fa86b3e8d96b86d95646b3466 Mon Sep 17 00:00:00 2001 From: trishorts Date: Tue, 15 Oct 2024 15:17:50 -0500 Subject: [PATCH] calculate notch specific inverted qVAlue --- .../FdrAnalysis/FdrAnalysisEngine.cs | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs b/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs index 576a61bb4..21a1eac5c 100644 --- a/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs +++ b/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs @@ -164,6 +164,7 @@ public void CalculateQValue(List psms, bool peptideLevelCalculati // Stop if canceled if (GlobalVariables.StopLoops) { break; } + // we have to keep track of q-values separately for each notch int notch = psm.Notch ?? MassDiffAcceptorNumNotches; if (psm.IsDecoy) { @@ -220,39 +221,50 @@ public void CalculateQValue(List psms, bool peptideLevelCalculati private void QValueTraditional(List psms, bool peptideLevelAnalysis) { double qValue = 0; - double qValueNotch = 0; + double[] qValueNotch = new double[MassDiffAcceptorNumNotches + 1]; + for (int i = 0; i < psms.Count; i++) { // Stop if canceled if (GlobalVariables.StopLoops) { break; } - + int notch = psms[i].Notch ?? MassDiffAcceptorNumNotches; qValue = Math.Max(qValue, psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoy / Math.Max(psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTarget, 1)); - qValueNotch = Math.Max(qValueNotch, psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoyNotch / Math.Max(psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTargetNotch, 1)); + qValueNotch[notch] = Math.Max(qValueNotch[notch], psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoyNotch / Math.Max(psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTargetNotch, 1)); psms[i].GetFdrInfo(peptideLevelAnalysis).QValue = Math.Min(qValue, 1); - psms[i].GetFdrInfo(peptideLevelAnalysis).QValueNotch = Math.Min(qValueNotch, 1); + psms[i].GetFdrInfo(peptideLevelAnalysis).QValueNotch = Math.Min(qValueNotch[notch], 1); } } - private static void QValueInverted(List psms, bool peptideLevelAnalysis) + private void QValueInverted(List psms, bool peptideLevelAnalysis) { + double[] qValueNotch = new double[MassDiffAcceptorNumNotches + 1]; + bool[] qValueNotchCalculated = new bool[MassDiffAcceptorNumNotches + 1]; psms.Reverse(); //this calculation is performed from bottom up. So, we begin the loop by computing qValue //and qValueNotch for the last/lowest scoring psm in the bunch double qValue = (psms[0].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoy + 1) / psms[0].GetFdrInfo(peptideLevelAnalysis).CumulativeTarget; - double qValueNotch = (psms[0].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoyNotch + 1) / psms[0].GetFdrInfo(peptideLevelAnalysis).CumulativeTargetNotch; + //double qValueNotch = (psms[0].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoyNotch + 1) / psms[0].GetFdrInfo(peptideLevelAnalysis).CumulativeTargetNotch; //Assign FDR values to PSMs for (int i = 0; i < psms.Count; i++) { // Stop if canceled if (GlobalVariables.StopLoops) { break; } + int notch = psms[i].Notch ?? MassDiffAcceptorNumNotches; + + // populate the highest q-Value for each notch + if (!qValueNotchCalculated[notch]) + { + qValueNotch[notch] = (psms[0].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoyNotch + 1) / psms[0].GetFdrInfo(peptideLevelAnalysis).CumulativeTargetNotch; + qValueNotchCalculated[notch] = true; + } qValue = Math.Min(qValue, (psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoy + 1) / Math.Max(psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTarget, 1)); - qValueNotch = Math.Min(qValueNotch, (psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoyNotch + 1) / Math.Max(psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTargetNotch, 1)); + qValueNotch[notch] = Math.Min(qValueNotch[notch], (psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoyNotch + 1) / Math.Max(psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTargetNotch, 1)); psms[i].GetFdrInfo(peptideLevelAnalysis).QValue = Math.Min(qValue, 1); - psms[i].GetFdrInfo(peptideLevelAnalysis).QValueNotch = Math.Min(qValueNotch, 1); + psms[i].GetFdrInfo(peptideLevelAnalysis).QValueNotch = Math.Min(qValueNotch[notch], 1); } psms.Reverse(); //we inverted the psms for this calculation. now we need to put them back into the original order }