diff --git a/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs b/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs index 3a3eb2a68..9eff38f71 100644 --- a/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs @@ -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) { @@ -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 matchedIons) + private void AddPeptideCandidateToPsm(ScanWithIndexAndNotchInfo scan, object[] myLocks, double thisScore, PeptideWithSetModifications peptide, List matchedIons, double andromedaScore) { bool meetsScoreCutoff = thisScore >= CommonParameters.ScoreCutoff; @@ -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); } } } diff --git a/MetaMorpheus/EngineLayer/MetaMorpheusEngine.cs b/MetaMorpheus/EngineLayer/MetaMorpheusEngine.cs index 8afbc1647..0306c241b 100644 --- a/MetaMorpheus/EngineLayer/MetaMorpheusEngine.cs +++ b/MetaMorpheus/EngineLayer/MetaMorpheusEngine.cs @@ -10,6 +10,7 @@ using System.Diagnostics; using System.Linq; using System.Threading.Tasks; +using Newtonsoft.Json.Linq; namespace EngineLayer { @@ -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 MatchFragmentIons(Ms2ScanWithSpecificMass scan, List theoreticalProducts, CommonParameters commonParameters, bool matchAllCharges = false) { if (matchAllCharges) diff --git a/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs b/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs index 0275879c9..141538b95 100644 --- a/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/ModernSearch/ModernSearchEngine.cs @@ -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); } } diff --git a/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs b/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs index 1b211f51b..f8ae9e983 100644 --- a/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/NonSpecificEnzymeSearch/NonSpecificEnzymeSearchEngine.cs @@ -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); } } } diff --git a/MetaMorpheus/EngineLayer/PeptideSpectralMatch.cs b/MetaMorpheus/EngineLayer/PeptideSpectralMatch.cs index abe52ebf1..03fd80319 100644 --- a/MetaMorpheus/EngineLayer/PeptideSpectralMatch.cs +++ b/MetaMorpheus/EngineLayer/PeptideSpectralMatch.cs @@ -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 matchedFragmentIons, double xcorr = 0) + public PeptideSpectralMatch(PeptideWithSetModifications peptide, int notch, double score, int scanIndex, Ms2ScanWithSpecificMass scan, CommonParameters commonParameters, List matchedFragmentIons, double xcorr = 0, double andromedaScore = 0) { _BestMatchingPeptides = new List<(int, PeptideWithSetModifications)>(); ScanIndex = scanIndex; @@ -36,12 +36,13 @@ public PeptideSpectralMatch(PeptideWithSetModifications peptide, int notch, doub DigestionParams = commonParameters.DigestionParams; PeptidesToMatchingFragments = new Dictionary>(); 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; } @@ -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 @@ -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 matchedFragmentIons, double newXcorr) + public void AddOrReplace(PeptideWithSetModifications pwsm, double newScore, int notch, bool reportAllAmbiguity, List matchedFragmentIons, double newXcorr, double newAndromedaScore) { if (newScore - Score > ToleranceForScoreDifferentiation) //if new score beat the old score, overwrite it { @@ -122,6 +124,7 @@ public void AddOrReplace(PeptideWithSetModifications pwsm, double newScore, int Score = newScore; Xcorr = newXcorr; + AndromedaScore = newAndromedaScore; PeptidesToMatchingFragments.Clear(); PeptidesToMatchingFragments.Add(pwsm, matchedFragmentIons); @@ -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; diff --git a/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvHeader.cs b/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvHeader.cs index b1417ef83..c866908f5 100644 --- a/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvHeader.cs +++ b/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvHeader.cs @@ -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"; diff --git a/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvWriter.cs b/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvWriter.cs index 509af5e42..3c5129d2b 100644 --- a/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvWriter.cs +++ b/MetaMorpheus/EngineLayer/PsmTsv/PsmTsvWriter.cs @@ -186,6 +186,7 @@ internal static void AddBasicMatchData(Dictionary 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; }