Skip to content

Commit

Permalink
calculate notch specific inverted qVAlue
Browse files Browse the repository at this point in the history
  • Loading branch information
trishorts committed Oct 15, 2024
1 parent 5186b82 commit 4f9e99f
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public void CalculateQValue(List<SpectralMatch> 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)
{
Expand Down Expand Up @@ -220,39 +221,50 @@ public void CalculateQValue(List<SpectralMatch> psms, bool peptideLevelCalculati
private void QValueTraditional(List<SpectralMatch> 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<SpectralMatch> psms, bool peptideLevelAnalysis)
private void QValueInverted(List<SpectralMatch> 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
}
Expand Down

0 comments on commit 4f9e99f

Please sign in to comment.