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

[WIP ]Add tailor score -NOT AN ACTUAL PR #2298

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
19 changes: 19 additions & 0 deletions MetaMorpheus/EngineLayer/ClassicSearch/ClassicSearchEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Proteomics.ProteolyticDigestion;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -167,6 +177,15 @@ protected override MetaMorpheusEngineResults RunSpecific()
psm.ResolveAllAmbiguities();
}

List<string> myOut = new List<string>();

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);
}

Expand Down
48 changes: 48 additions & 0 deletions MetaMorpheus/EngineLayer/Ms2ScanWithSpecificMass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public Ms2ScanWithSpecificMass(MsDataScan mzLibScan, double precursorMonoisotopi
{
DeconvolutedMonoisotopicMasses = new double[0];
}

Scores = new List<double>();
}

public MsDataScan TheScan { get; }
Expand All @@ -53,6 +55,52 @@ public Ms2ScanWithSpecificMass(MsDataScan mzLibScan, double precursorMonoisotopi
public int NumPeaks => TheScan.MassSpectrum.Size;

public double TotalIonCurrent => TheScan.TotalIonCurrent;
public List<double> 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)
{
Expand Down
9 changes: 4 additions & 5 deletions MetaMorpheus/Test/MultiProteaseParsimonyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ public static void MultiProteaseParsimony_TestingGreedyAlgorithm()
}

/// <summary>
/// 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
/// </summary>
[Test]
public static void MultiProteaseParsimony_TestingProteaseSpecificFDRCalculations()
Expand Down Expand Up @@ -1030,16 +1030,15 @@ public static void MultiProteaseParsimony_TestingProteaseSpecificFDRCalculations
new FdrAnalysisEngine(psms, 0, new CommonParameters(), fsp, new List<string>()).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));
}
}
}