Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Andromeda score #2329

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
13 changes: 8 additions & 5 deletions MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ protected override MetaMorpheusEngineResults RunSpecific()

// calculate the peptide's score
double thisScore = CalculatePeptideScore(scan.TheScan.TheScan, matchedIons, fragmentsCanHaveDifferentCharges: WriteSpectralLibrary);

double numberOfPeaksPer100Thomsons = scan.TheScan.NumPeaks / ((scan.TheScan.TheScan.ScanWindowRange.Maximum- scan.TheScan.TheScan.ScanWindowRange.Minimum)/100.0);
double andromedaScore = AndromedaScore(peptideTheorProducts.Count, matchedIons.Count, numberOfPeaksPer100Thomsons);

AddPeptideCandidateToPsm(scan, myLocks, thisScore, peptide, matchedIons);
AddPeptideCandidateToPsm(scan, myLocks, thisScore, peptide, matchedIons, andromedaScore);

if (SpectralLibrary != null)
{
Expand Down Expand Up @@ -186,10 +189,10 @@ private void DecoyScoreForSpectralLibrarySearch(ScanWithIndexAndNotchInfo scan,
// calculate decoy's score
var decoyScore = CalculatePeptideScore(scan.TheScan.TheScan, decoyMatchedIons, fragmentsCanHaveDifferentCharges: WriteSpectralLibrary);

AddPeptideCandidateToPsm(scan, myLocks, decoyScore, reversedOnTheFlyDecoy, decoyMatchedIons);
AddPeptideCandidateToPsm(scan, myLocks, decoyScore, reversedOnTheFlyDecoy, decoyMatchedIons,0);
}

private void AddPeptideCandidateToPsm(ScanWithIndexAndNotchInfo scan, object[] myLocks, double thisScore, PeptideWithSetModifications peptide, List<MatchedFragmentIon> matchedIons)
private void AddPeptideCandidateToPsm(ScanWithIndexAndNotchInfo scan, object[] myLocks, double thisScore, PeptideWithSetModifications peptide, List<MatchedFragmentIon> matchedIons, double andromedaScore)
{
bool meetsScoreCutoff = thisScore >= CommonParameters.ScoreCutoff;

Expand All @@ -206,11 +209,11 @@ private void AddPeptideCandidateToPsm(ScanWithIndexAndNotchInfo scan, object[] m
{
if (PeptideSpectralMatches[scan.ScanIndex] == null)
{
PeptideSpectralMatches[scan.ScanIndex] = new PeptideSpectralMatch(peptide, scan.Notch, thisScore, scan.ScanIndex, scan.TheScan, CommonParameters, matchedIons, 0);
PeptideSpectralMatches[scan.ScanIndex] = new PeptideSpectralMatch(peptide, scan.Notch, thisScore, scan.ScanIndex, scan.TheScan, CommonParameters, matchedIons, 0, andromedaScore);
}
else
{
PeptideSpectralMatches[scan.ScanIndex].AddOrReplace(peptide, thisScore, scan.Notch, CommonParameters.ReportAllAmbiguity, matchedIons, 0);
PeptideSpectralMatches[scan.ScanIndex].AddOrReplace(peptide, thisScore, scan.Notch, CommonParameters.ReportAllAmbiguity, matchedIons, 0, andromedaScore);
}
}
}
Expand Down
12 changes: 11 additions & 1 deletion MetaMorpheus/EngineLayer/MetaMorpheusEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace EngineLayer
{
Expand Down Expand Up @@ -128,9 +129,18 @@ private static double CalculateAllChargesPeptideScore(MsDataScan thisScan, List<
}

return score;

}

public static double AndromedaScore(int totalNumberOfTheoreticalIons, int totalNumberOfMatchingIons, double numberOfPeaksPer100Thomsons)
{
double localSum = 0;
for (int j = totalNumberOfMatchingIons; j <= totalNumberOfTheoreticalIons; j++)
{
localSum += (Math.Pow((numberOfPeaksPer100Thomsons/100),j)*Math.Pow((1-numberOfPeaksPer100Thomsons/100),totalNumberOfTheoreticalIons-j));
}

return -10.0 * Math.Log10(localSum);
}
public static List<MatchedFragmentIon> MatchFragmentIons(Ms2ScanWithSpecificMass scan, List<Product> theoreticalProducts, CommonParameters commonParameters, bool matchAllCharges = false)
{
if (matchAllCharges)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ protected PeptideSpectralMatch FineScorePeptide(int id, Ms2ScanWithSpecificMass
}
else
{
PeptideSpectralMatches[scanIndex].AddOrReplace(peptide, thisScore, notch, CommonParameters.ReportAllAmbiguity, matchedIons, 0);
PeptideSpectralMatches[scanIndex].AddOrReplace(peptide, thisScore, notch, CommonParameters.ReportAllAmbiguity, matchedIons, 0,0);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected override MetaMorpheusEngineResults RunSpecific()
}
else
{
localPeptideSpectralMatches[ms2ArrayIndex].AddOrReplace(peptide, thisScore, notch, CommonParameters.ReportAllAmbiguity, matchedIons, 0);
localPeptideSpectralMatches[ms2ArrayIndex].AddOrReplace(peptide, thisScore, notch, CommonParameters.ReportAllAmbiguity, matchedIons, 0,0);
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions MetaMorpheus/EngineLayer/PeptideSpectralMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class PeptideSpectralMatch
public const double ToleranceForScoreDifferentiation = 1e-9;
protected List<(int Notch, PeptideWithSetModifications Pwsm)> _BestMatchingPeptides;

public PeptideSpectralMatch(PeptideWithSetModifications peptide, int notch, double score, int scanIndex, Ms2ScanWithSpecificMass scan, CommonParameters commonParameters, List<MatchedFragmentIon> matchedFragmentIons, double xcorr = 0)
public PeptideSpectralMatch(PeptideWithSetModifications peptide, int notch, double score, int scanIndex, Ms2ScanWithSpecificMass scan, CommonParameters commonParameters, List<MatchedFragmentIon> matchedFragmentIons, double xcorr = 0, double andromedaScore = 0)
{
_BestMatchingPeptides = new List<(int, PeptideWithSetModifications)>();
ScanIndex = scanIndex;
Expand All @@ -36,12 +36,13 @@ public PeptideSpectralMatch(PeptideWithSetModifications peptide, int notch, doub
DigestionParams = commonParameters.DigestionParams;
PeptidesToMatchingFragments = new Dictionary<PeptideWithSetModifications, List<MatchedFragmentIon>>();
Xcorr = xcorr;
AndromedaScore = andromedaScore;
NativeId = scan.NativeId;
RunnerUpScore = commonParameters.ScoreCutoff;
MsDataScan = scan.TheScan;
SpectralAngle = -1;

AddOrReplace(peptide, score, notch, true, matchedFragmentIons, xcorr);
AddOrReplace(peptide, score, notch, true, matchedFragmentIons, xcorr, andromedaScore);
}

public MsDataScan MsDataScan { get; set; }
Expand Down Expand Up @@ -77,6 +78,7 @@ public PeptideSpectralMatch(PeptideWithSetModifications peptide, int notch, doub

public double Score { get; private set; }
public double Xcorr;
public double AndromedaScore { get; private set; }
public double SpectralAngle { get; set; }
public string NativeId; // this is a property of the scan. used for mzID writing

Expand Down Expand Up @@ -108,7 +110,7 @@ public static string GetTabSeparatedHeader()
return string.Join("\t", DataDictionary(null, null).Keys);
}

public void AddOrReplace(PeptideWithSetModifications pwsm, double newScore, int notch, bool reportAllAmbiguity, List<MatchedFragmentIon> matchedFragmentIons, double newXcorr)
public void AddOrReplace(PeptideWithSetModifications pwsm, double newScore, int notch, bool reportAllAmbiguity, List<MatchedFragmentIon> matchedFragmentIons, double newXcorr, double newAndromedaScore)
{
if (newScore - Score > ToleranceForScoreDifferentiation) //if new score beat the old score, overwrite it
{
Expand All @@ -122,6 +124,7 @@ public void AddOrReplace(PeptideWithSetModifications pwsm, double newScore, int

Score = newScore;
Xcorr = newXcorr;
AndromedaScore = newAndromedaScore;

PeptidesToMatchingFragments.Clear();
PeptidesToMatchingFragments.Add(pwsm, matchedFragmentIons);
Expand Down Expand Up @@ -491,6 +494,7 @@ protected PeptideSpectralMatch(PeptideSpectralMatch psm, List<(int Notch, Peptid
FdrInfo = psm.FdrInfo;
Score = psm.Score;
Xcorr = psm.Xcorr;
AndromedaScore = psm.AndromedaScore;
RunnerUpScore = psm.RunnerUpScore;
IsDecoy = psm.IsDecoy;
IsContaminant = psm.IsContaminant;
Expand Down
1 change: 1 addition & 0 deletions MetaMorpheus/EngineLayer/PsmTsv/PsmTsvHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static class PsmTsvHeader
public const string PrecursorMz = "Precursor MZ";
public const string PrecursorMass = "Precursor Mass";
public const string Score = "Score";
public const string AndromedaScore = "AndromedaScore";
public const string DeltaScore = "Delta Score";
public const string Notch = "Notch";

Expand Down
1 change: 1 addition & 0 deletions MetaMorpheus/EngineLayer/PsmTsv/PsmTsvWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ internal static void AddBasicMatchData(Dictionary<string, string> s, PeptideSpec
s[PsmTsvHeader.PrecursorMz] = psm == null ? " " : psm.ScanPrecursorMonoisotopicPeakMz.ToString("F5", CultureInfo.InvariantCulture);
s[PsmTsvHeader.PrecursorMass] = psm == null ? " " : psm.ScanPrecursorMass.ToString("F5", CultureInfo.InvariantCulture);
s[PsmTsvHeader.Score] = psm == null ? " " : psm.Score.ToString("F3", CultureInfo.InvariantCulture);
s[PsmTsvHeader.AndromedaScore] = psm == null ? " " : psm.AndromedaScore.ToString("F3", CultureInfo.InvariantCulture);
s[PsmTsvHeader.DeltaScore] = psm == null ? " " : psm.DeltaScore.ToString("F3", CultureInfo.InvariantCulture);
s[PsmTsvHeader.Notch] = psm == null ? " " : Resolve(psm.BestMatchingPeptides.Select(p => p.Notch)).ResolvedString;
}
Expand Down