Skip to content

Commit

Permalink
Peptide Level PEP-Q Value changes (#2431)
Browse files Browse the repository at this point in the history
* Buncha changes to PEP

* Increase Q-Value cutoff for top-down PEP positive training examples

* removed unused RNG

* First changes

* Updated FilterePsms to only iterate through PSMs once

* Updated filtering

* Made suggested changes

* fixed bugs

---------

Co-authored-by: Nic Bollis <[email protected]>
  • Loading branch information
Alexander-Sol and nbollis authored Oct 31, 2024
1 parent 32658b1 commit 7dafd00
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
29 changes: 14 additions & 15 deletions MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,24 @@ private void DoFalseDiscoveryRateAnalysis(FdrAnalysisResults myAnalysisResults)
//PEP will model will be developed using peptides and then applied to all PSMs.
Compute_PEPValue(myAnalysisResults, psms);

// peptides are ordered by MM score from good to bad in order to select the best PSM for each peptide
// peptides are ordered by PEP score from good to bad in order to select the best PSM for each peptide
peptides = psms
.OrderByDescending(p => p)
.GroupBy(p => p.FullSequence)
.Select(p => p.FirstOrDefault())
.OrderBy(p => p.FdrInfo.PEP) // Then order by PEP (PSM PEP and Peptide PEP are the same)
.OrderBy(p => p.FdrInfo.PEP)
.ThenByDescending(p => p)
.GroupBy(p => p.FullSequence)
.Select(p => p.FirstOrDefault()) // Get the best psm for each peptide based on PEP (default comparer is used to break ties)
.ToList();
CalculateQValue(peptides, peptideLevelCalculation: true, pepCalculation: true);

psms = psms.OrderBy(p => p.PsmFdrInfo.PEP).ThenByDescending(p => p).ToList();
psms = psms.OrderBy(p => p.FdrInfo.PEP).ThenByDescending(p => p).ToList();
CalculateQValue(psms, peptideLevelCalculation: false, pepCalculation: true);

}
else //we have more than 100 psms but less than 100 peptides so
{
//this will be done using PSMs because we dont' have enough peptides
Compute_PEPValue(myAnalysisResults, psms);
psms = psms.OrderBy(p => p.PsmFdrInfo.PEP).ThenByDescending(p => p).ToList();
psms = psms.OrderBy(p => p.FdrInfo.PEP).ThenByDescending(p => p).ToList();
CalculateQValue(psms, peptideLevelCalculation: false, pepCalculation: true);
}
}
Expand All @@ -110,27 +109,27 @@ private void DoFalseDiscoveryRateAnalysis(FdrAnalysisResults myAnalysisResults)
// really, in this case, we only need to run one or the other (i.e., only peptides or psms are passed in)
// but there's no mechanism to pass that info to the FDR analysis engine, so we'll do this for now
peptides = psms
.OrderByDescending(p => p)
.GroupBy(p => p.FullSequence)
.Select(p => p.FirstOrDefault()) // Get the best psm for each peptide based on MBR score
.OrderBy(p => p.FdrInfo.PEP) // Then order by PEP (PSM PEP and Peptide PEP are the same)
.OrderBy(p => p.FdrInfo.PEP)
.ThenByDescending(p => p)
.GroupBy(p => p.FullSequence)
.Select(p => p.FirstOrDefault()) // Get the best psm for each peptide based on PEP (default comparer is used to break ties)
.ToList();
CalculateQValue(peptides, peptideLevelCalculation: true, pepCalculation: true);

psms = psms
.OrderBy(p => p.PsmFdrInfo.PEP)
.OrderBy(p => p.FdrInfo.PEP)
.ThenByDescending(p => p)
.ToList();
CalculateQValue(psms, peptideLevelCalculation: false, pepCalculation: true);

}

//we do this section last so that target and decoy counts written in the psmtsv files are appropriate for the sort order which is by MM score
peptides = psms
.OrderByDescending(p => p)
.OrderBy(p => p.FdrInfo.PEP)
.ThenByDescending(p => p)
.GroupBy(b => b.FullSequence)
.Select(b => b.FirstOrDefault())
.Select(b => b.FirstOrDefault()) // Get the best psm for each peptide based on PEP (default comparer is used to break ties)
.OrderByDescending(p => p) // Sort using the default comparer before calculating Q Values
.ToList();
CalculateQValue(peptides, peptideLevelCalculation: true, pepCalculation: false);

Expand Down
10 changes: 6 additions & 4 deletions MetaMorpheus/TaskLayer/FilteredPsms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,18 @@ public static class FilteredPsmsExtensions
{
public static IEnumerable<SpectralMatch> CollapseToPeptides(this IEnumerable<SpectralMatch> psms, bool filterAtPeptideLevel)
{
if(!filterAtPeptideLevel)
if (!filterAtPeptideLevel)
{
return psms;
}
else
{
return psms
.OrderByDescending(p => p)
.GroupBy(b => b.FullSequence)
.Select(b => b.FirstOrDefault());
.OrderBy(p => p.FdrInfo.PEP) // Order by PEP first
.ThenByDescending(p => p) // Use the default comparer to break ties
.GroupBy(p => p.FullSequence)
.Select(p => p.FirstOrDefault()) // Choose the PSM with the lowest PEP for each peptide
.OrderByDescending(p => p); // Use the default comparer to order the resulting list, so that the output is ordered by MetaMorpheus Score
}
}

Expand Down

0 comments on commit 7dafd00

Please sign in to comment.