diff --git a/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs b/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs index 3a3eb2a68..2789f42c5 100644 --- a/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs +++ b/MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs @@ -5,6 +5,7 @@ using Proteomics.ProteolyticDigestion; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading.Tasks; @@ -140,6 +141,15 @@ protected override MetaMorpheusEngineResults RunSpecific() // calculate the peptide's score double thisScore = CalculatePeptideScore(scan.TheScan.TheScan, matchedIons, fragmentsCanHaveDifferentCharges: WriteSpectralLibrary); + if (peptide.Protein.IsDecoy) + { + lock (myLocks[scan.ScanIndex]) + { + scan.TheScan.AddNewScore(thisScore); + } + } + + AddPeptideCandidateToPsm(scan, myLocks, thisScore, peptide, matchedIons); if (SpectralLibrary != null) @@ -167,6 +177,15 @@ protected override MetaMorpheusEngineResults RunSpecific() psm.ResolveAllAmbiguities(); } + List myOut = new List(); + + foreach (var scan in ArrayOfSortedMS2Scans) + { + myOut.Add(scan.OneBasedScanNumber + "\t" + scan.ComputeTailorDenominator()); + } + + File.WriteAllLines(@"E:\Projects\Mann_11cell_lines\A549\A549_1\myTailor.tsv", myOut); + return new MetaMorpheusEngineResults(this); } diff --git a/MetaMorpheus/EngineLayer/Ms2ScanWithSpecificMass.cs b/MetaMorpheus/EngineLayer/Ms2ScanWithSpecificMass.cs index 4e0d8f4c4..56deeafac 100644 --- a/MetaMorpheus/EngineLayer/Ms2ScanWithSpecificMass.cs +++ b/MetaMorpheus/EngineLayer/Ms2ScanWithSpecificMass.cs @@ -32,6 +32,8 @@ public Ms2ScanWithSpecificMass(MsDataScan mzLibScan, double precursorMonoisotopi { DeconvolutedMonoisotopicMasses = new double[0]; } + + Scores = new List(); } public MsDataScan TheScan { get; } @@ -53,6 +55,52 @@ public Ms2ScanWithSpecificMass(MsDataScan mzLibScan, double precursorMonoisotopi public int NumPeaks => TheScan.MassSpectrum.Size; public double TotalIonCurrent => TheScan.TotalIonCurrent; + public List Scores { get; set; } + + public void AddNewScore(double score) + { + Scores.Add(score); + } + + public double ComputeTailorDenominator() + { + if (Scores.Count() == 0) + { + return 1; + } + else + { + //sort ascending + Scores.Sort(); + + int positionOfThe100thQuantile = (int)Math.Round((double)Scores.Count / 100.0, 0) - 1; + + if (positionOfThe100thQuantile > 0) + { + return Math.Max(1, Scores.ToArray()[0..positionOfThe100thQuantile].Average()); + } + return Math.Max(1, Scores[0]); + } + } + public double ComputeTailorScore() + { + if (Scores.Count() == 0) + { + return 1; + } + else + { + //sort ascending + Scores.Sort(); + + int positionOfThe100thQuantile = (int)Math.Round((double)Scores.Count / 100.0, 0); + double tailorNumerator = Scores.Max(); + + double tailorDenominator = Math.Max(1, Scores.ToArray()[0..positionOfThe100thQuantile].Average()); + + return tailorNumerator/tailorDenominator; + } + } public static IsotopicEnvelope[] GetNeutralExperimentalFragments(MsDataScan scan, CommonParameters commonParam) { diff --git a/MetaMorpheus/Test/MultiProteaseParsimonyTest.cs b/MetaMorpheus/Test/MultiProteaseParsimonyTest.cs index e1b4c513c..69bc6d434 100644 --- a/MetaMorpheus/Test/MultiProteaseParsimonyTest.cs +++ b/MetaMorpheus/Test/MultiProteaseParsimonyTest.cs @@ -988,7 +988,7 @@ public static void MultiProteaseParsimony_TestingGreedyAlgorithm() } /// - /// This test ensures that FDR for each psm is calculated accoriding to its protease + /// This test ensures that FDR for each psm is calculated according to its protease /// [Test] public static void MultiProteaseParsimony_TestingProteaseSpecificFDRCalculations() @@ -1030,16 +1030,15 @@ public static void MultiProteaseParsimony_TestingProteaseSpecificFDRCalculations new FdrAnalysisEngine(psms, 0, new CommonParameters(), fsp, new List()).Run(); psms = psms.OrderByDescending(p => p.Score).ToList(); - Assert.AreEqual(0.00, Math.Round(psms[0].FdrInfo.QValue, 2)); Assert.AreEqual(0.00, Math.Round(psms[1].FdrInfo.QValue, 2)); Assert.AreEqual(0.00, Math.Round(psms[2].FdrInfo.QValue, 2)); Assert.AreEqual(0.00, Math.Round(psms[3].FdrInfo.QValue, 2)); - Assert.AreEqual(0.33, Math.Round(psms[4].FdrInfo.QValue, 2)); + Assert.AreEqual(0.5, Math.Round(psms[4].FdrInfo.QValue, 2)); Assert.AreEqual(0.33, Math.Round(psms[5].FdrInfo.QValue, 2)); Assert.AreEqual(0.00, Math.Round(psms[6].FdrInfo.QValue, 2)); Assert.AreEqual(0.33, Math.Round(psms[7].FdrInfo.QValue, 2)); - Assert.AreEqual(0.50, Math.Round(psms[8].FdrInfo.QValue, 2)); - Assert.AreEqual(0.50, Math.Round(psms[9].FdrInfo.QValue, 2)); + Assert.AreEqual(0.67, Math.Round(psms[8].FdrInfo.QValue, 2)); + Assert.AreEqual(0.5, Math.Round(psms[9].FdrInfo.QValue, 2)); } } } \ No newline at end of file