From ae3b8116eb88f8225c434d32a2b078b6a7eefdb8 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 12 Sep 2024 14:48:19 -0500 Subject: [PATCH] commit before breaking things --- MetaMorpheus/CMD/CMD.csproj | 6 +- MetaMorpheus/EngineLayer/EngineLayer.csproj | 6 +- .../FdrAnalysis/FdrAnalysisEngine.cs | 45 ++++++++++---- .../FdrAnalysis/PEPAnalysisEngine.cs | 16 ++--- MetaMorpheus/GUI/GUI.csproj | 6 +- .../SearchTask/PostSearchAnalysisTask.cs | 58 ++++++++++--------- MetaMorpheus/TaskLayer/TaskLayer.csproj | 6 +- 7 files changed, 84 insertions(+), 59 deletions(-) diff --git a/MetaMorpheus/CMD/CMD.csproj b/MetaMorpheus/CMD/CMD.csproj index 44eb33bbe3..b4dde781fa 100644 --- a/MetaMorpheus/CMD/CMD.csproj +++ b/MetaMorpheus/CMD/CMD.csproj @@ -20,9 +20,9 @@ - - - + + + diff --git a/MetaMorpheus/EngineLayer/EngineLayer.csproj b/MetaMorpheus/EngineLayer/EngineLayer.csproj index 9c82f4ec24..c2f6a4c2d5 100644 --- a/MetaMorpheus/EngineLayer/EngineLayer.csproj +++ b/MetaMorpheus/EngineLayer/EngineLayer.csproj @@ -17,9 +17,9 @@ - - - + + + diff --git a/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs b/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs index e75e91b197..68e1d58d5f 100644 --- a/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs +++ b/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs @@ -256,22 +256,43 @@ private static void QValueInverted(List psms, bool peptideLevelAn public static void PepQValueInverted(List psms, bool peptideLevelAnalysis) { - 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; - //Assign FDR values to PSMs - for (int i = 0; i < psms.Count; i++) - { - // Stop if canceled - if (GlobalVariables.StopLoops) { break; } + double[] allPEPValues = psms.Select(p => p.FdrInfo.PEP).ToArray(); + double runningSum = 0; + double qValue = 1; - qValue = Math.Min(qValue, (psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoy + 1) / psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTarget); + for (int i = 0; i < allPEPValues.Length; i++) + { + runningSum += allPEPValues[i]; + qValue = runningSum / (i + 1); + psms[i].GetFdrInfo(peptideLevelAnalysis).PEP_QValue = Math.Round(qValue, 6); + } + - psms[i].GetFdrInfo(peptideLevelAnalysis).PEP_QValue = qValue; + psms.Reverse(); + foreach(var psm in psms) + { + qValue = Math.Min(qValue, psm.GetFdrInfo(peptideLevelAnalysis).PEP_QValue); + psm.GetFdrInfo(peptideLevelAnalysis).PEP_QValue = qValue; } - psms.Reverse(); //we inverted the psms for this calculation. now we need to put them back into the original order + psms.Reverse(); + + //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; + + ////Assign FDR values to PSMs + //for (int i = 0; i < psms.Count; i++) + //{ + // // Stop if canceled + // if (GlobalVariables.StopLoops) { break; } + + // qValue = Math.Min(qValue, (psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoy + 1) / psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTarget); + + // psms[i].GetFdrInfo(peptideLevelAnalysis).PEP_QValue = qValue; + //} + //psms.Reverse(); //we inverted the psms for this calculation. now we need to put them back into the original order } public void Compute_PEPValue(FdrAnalysisResults myAnalysisResults, List psms) diff --git a/MetaMorpheus/EngineLayer/FdrAnalysis/PEPAnalysisEngine.cs b/MetaMorpheus/EngineLayer/FdrAnalysis/PEPAnalysisEngine.cs index 5425c30615..6d57388bf0 100644 --- a/MetaMorpheus/EngineLayer/FdrAnalysis/PEPAnalysisEngine.cs +++ b/MetaMorpheus/EngineLayer/FdrAnalysis/PEPAnalysisEngine.cs @@ -104,14 +104,16 @@ public PepAnalysisEngine(List psms, string searchType, List<(stri public string ComputePEPValuesForAllPSMs() { - List peptideGroups = UsePeptideLevelQValueForTraining - ? PeptideMatchGroup.GroupByBaseSequence(AllPsms) - : PeptideMatchGroup.GroupByIndividualPsm(AllPsms); + //List peptideGroups = UsePeptideLevelQValueForTraining + // ? PeptideMatchGroup.GroupByBaseSequence(AllPsms) + // : PeptideMatchGroup.GroupByIndividualPsm(AllPsms); - if(UsePeptideLevelQValueForTraining && (peptideGroups.Count(g => g.BestMatch.IsDecoy) < 4 || peptideGroups.Count(g => !g.BestMatch.IsDecoy) < 4)) - { - peptideGroups = PeptideMatchGroup.GroupByIndividualPsm(AllPsms); - } + List peptideGroups = PeptideMatchGroup.GroupByIndividualPsm(AllPsms); + + //if(UsePeptideLevelQValueForTraining && (peptideGroups.Count(g => g.BestMatch.IsDecoy) < 4 || peptideGroups.Count(g => !g.BestMatch.IsDecoy) < 4)) + //{ + // peptideGroups = PeptideMatchGroup.GroupByIndividualPsm(AllPsms); + //} int numGroups = 4; List[] peptideGroupIndices = GetPeptideGroupIndices(peptideGroups, numGroups); diff --git a/MetaMorpheus/GUI/GUI.csproj b/MetaMorpheus/GUI/GUI.csproj index df8cfd5df1..9c54f831bc 100644 --- a/MetaMorpheus/GUI/GUI.csproj +++ b/MetaMorpheus/GUI/GUI.csproj @@ -51,9 +51,9 @@ - - - + + + diff --git a/MetaMorpheus/TaskLayer/SearchTask/PostSearchAnalysisTask.cs b/MetaMorpheus/TaskLayer/SearchTask/PostSearchAnalysisTask.cs index c7029bcdc2..bb6c04d78a 100644 --- a/MetaMorpheus/TaskLayer/SearchTask/PostSearchAnalysisTask.cs +++ b/MetaMorpheus/TaskLayer/SearchTask/PostSearchAnalysisTask.cs @@ -137,36 +137,38 @@ private void CalculatePsmAndPeptideFdr(List psms, string analysis // this could cause weird PSM FDR issues Status("Estimating PSM FDR...", Parameters.SearchTaskId); - - List psmsAboveQ = new List(); - List peptidesAboveQ = new List(); - List psmsAbovePepQ = new List(); - List peptidesAbovePepQ = new List(); - - for (int i = 0; i < 10; i++) - { - var tempPsms = psms - .Select(p => new PeptideSpectralMatch(p)) - .Cast() - .ToList(); - new FdrAnalysisEngine(tempPsms, Parameters.NumNotches, CommonParameters, this.FileSpecificParameters, + new FdrAnalysisEngine(psms, Parameters.NumNotches, CommonParameters, this.FileSpecificParameters, new List { Parameters.SearchTaskId }, analysisType: analysisType, doPEP: doPep, outputFolder: Parameters.OutputFolder).Run(); - psmsAboveQ.Add(tempPsms.Count(p => p.FdrInfo.QValue <= 0.01)); - peptidesAboveQ.Add(tempPsms.Count(p => p.PeptideFdrInfo.QValue <= 0.01)); - psmsAbovePepQ.Add(tempPsms.Count(p => p.FdrInfo.PEP_QValue <= 0.01)); - peptidesAbovePepQ.Add(tempPsms.Count(p => p.PeptideFdrInfo.PEP_QValue <= 0.01)); - } + + //List psmsAboveQ = new List(); + //List peptidesAboveQ = new List(); + //List psmsAbovePepQ = new List(); + //List peptidesAbovePepQ = new List(); + + //for (int i = 0; i < 10; i++) + //{ + // var tempPsms = psms + // .Select(p => new PeptideSpectralMatch(p)) + // .Cast() + // .ToList(); + // new FdrAnalysisEngine(tempPsms, Parameters.NumNotches, CommonParameters, this.FileSpecificParameters, + // new List { Parameters.SearchTaskId }, analysisType: analysisType, doPEP: doPep, outputFolder: Parameters.OutputFolder).Run(); + // psmsAboveQ.Add(tempPsms.Count(p => p.FdrInfo.QValue <= 0.01)); + // peptidesAboveQ.Add(tempPsms.Count(p => p.PeptideFdrInfo.QValue <= 0.01)); + // psmsAbovePepQ.Add(tempPsms.Count(p => p.FdrInfo.PEP_QValue <= 0.01)); + // peptidesAbovePepQ.Add(tempPsms.Count(p => p.PeptideFdrInfo.PEP_QValue <= 0.01)); + //} - // write summary text - using(StreamWriter writer = new StreamWriter(@"C:\Users\Alex\PEP_NoRandomOrdering.tsv")) - { - writer.WriteLine("PSMs Q\tPeptides Q\tPSMs PEP-Q\tPeptides PEP-Q"); - for(int i = 0; i < 10; i++) - { - writer.WriteLine(String.Join('\t', psmsAboveQ[i], peptidesAboveQ[i], psmsAbovePepQ[i], peptidesAbovePepQ[i])); - } - } - throw new Exception("PEP Seed Results written to file"); + //// write summary text + //using(StreamWriter writer = new StreamWriter(@"C:\Users\Alex\PEP_NoRandomOrdering.tsv")) + //{ + // writer.WriteLine("PSMs Q\tPeptides Q\tPSMs PEP-Q\tPeptides PEP-Q"); + // for(int i = 0; i < 10; i++) + // { + // writer.WriteLine(String.Join('\t', psmsAboveQ[i], peptidesAboveQ[i], psmsAbovePepQ[i], peptidesAbovePepQ[i])); + // } + //} + //throw new Exception("PEP Seed Results written to file"); Status("Done estimating PSM FDR!", Parameters.SearchTaskId); } diff --git a/MetaMorpheus/TaskLayer/TaskLayer.csproj b/MetaMorpheus/TaskLayer/TaskLayer.csproj index 35f0630068..568b9ed179 100644 --- a/MetaMorpheus/TaskLayer/TaskLayer.csproj +++ b/MetaMorpheus/TaskLayer/TaskLayer.csproj @@ -17,9 +17,9 @@ - - - + + +