Skip to content

Commit

Permalink
commit before breaking things
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Sol committed Sep 12, 2024
1 parent 2665cfb commit ae3b811
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 59 deletions.
6 changes: 3 additions & 3 deletions MetaMorpheus/CMD/CMD.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Microsoft.ML" Version="3.0.1" />
<PackageReference Include="Microsoft.ML.CpuMath" Version="3.0.1" />
<PackageReference Include="Microsoft.ML.FastTree" Version="3.0.1" />
<PackageReference Include="Microsoft.ML" Version="2.0.0" />
<PackageReference Include="Microsoft.ML.CpuMath" Version="2.0.0" />
<PackageReference Include="Microsoft.ML.FastTree" Version="2.0.0" />
<PackageReference Include="Microsoft.NETCore.App" Version="2.2.8" />
<PackageReference Include="mzLib" Version="1.0.551" />
<PackageReference Include="Nett" Version="0.15.0" />
Expand Down
6 changes: 3 additions & 3 deletions MetaMorpheus/EngineLayer/EngineLayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.ML" Version="3.0.1" />
<PackageReference Include="Microsoft.ML.CpuMath" Version="3.0.1" />
<PackageReference Include="Microsoft.ML.FastTree" Version="3.0.1" />
<PackageReference Include="Microsoft.ML" Version="2.0.0" />
<PackageReference Include="Microsoft.ML.CpuMath" Version="2.0.0" />
<PackageReference Include="Microsoft.ML.FastTree" Version="2.0.0" />
<PackageReference Include="Microsoft.NETCore.App" Version="2.2.8" />
<PackageReference Include="mzLib" Version="1.0.551" />
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
Expand Down
45 changes: 33 additions & 12 deletions MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,22 +256,43 @@ private static void QValueInverted(List<SpectralMatch> psms, bool peptideLevelAn

public static void PepQValueInverted(List<SpectralMatch> psms, bool peptideLevelAnalysis)
{
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;

//Assign FDR values to PSMs
for (int i = 0; i < psms.Count; i++)
{
// Stop if canceled
if (GlobalVariables.StopLoops) { break; }
double[] allPEPValues = psms.Select(p => p.FdrInfo.PEP).ToArray();
double runningSum = 0;
double qValue = 1;

qValue = Math.Min(qValue, (psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoy + 1) / psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTarget);
for (int i = 0; i < allPEPValues.Length; i++)
{
runningSum += allPEPValues[i];
qValue = runningSum / (i + 1);
psms[i].GetFdrInfo(peptideLevelAnalysis).PEP_QValue = Math.Round(qValue, 6);
}


psms[i].GetFdrInfo(peptideLevelAnalysis).PEP_QValue = qValue;
psms.Reverse();
foreach(var psm in psms)
{
qValue = Math.Min(qValue, psm.GetFdrInfo(peptideLevelAnalysis).PEP_QValue);
psm.GetFdrInfo(peptideLevelAnalysis).PEP_QValue = qValue;
}
psms.Reverse(); //we inverted the psms for this calculation. now we need to put them back into the original order
psms.Reverse();

//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;

////Assign FDR values to PSMs
//for (int i = 0; i < psms.Count; i++)
//{
// // Stop if canceled
// if (GlobalVariables.StopLoops) { break; }

// qValue = Math.Min(qValue, (psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoy + 1) / psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTarget);

// psms[i].GetFdrInfo(peptideLevelAnalysis).PEP_QValue = qValue;
//}
//psms.Reverse(); //we inverted the psms for this calculation. now we need to put them back into the original order
}

public void Compute_PEPValue(FdrAnalysisResults myAnalysisResults, List<SpectralMatch> psms)
Expand Down
16 changes: 9 additions & 7 deletions MetaMorpheus/EngineLayer/FdrAnalysis/PEPAnalysisEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,16 @@ public PepAnalysisEngine(List<SpectralMatch> psms, string searchType, List<(stri

public string ComputePEPValuesForAllPSMs()
{
List<PeptideMatchGroup> peptideGroups = UsePeptideLevelQValueForTraining
? PeptideMatchGroup.GroupByBaseSequence(AllPsms)
: PeptideMatchGroup.GroupByIndividualPsm(AllPsms);
//List<PeptideMatchGroup> peptideGroups = UsePeptideLevelQValueForTraining
// ? PeptideMatchGroup.GroupByBaseSequence(AllPsms)
// : PeptideMatchGroup.GroupByIndividualPsm(AllPsms);

if(UsePeptideLevelQValueForTraining && (peptideGroups.Count(g => g.BestMatch.IsDecoy) < 4 || peptideGroups.Count(g => !g.BestMatch.IsDecoy) < 4))
{
peptideGroups = PeptideMatchGroup.GroupByIndividualPsm(AllPsms);
}
List<PeptideMatchGroup> peptideGroups = PeptideMatchGroup.GroupByIndividualPsm(AllPsms);

//if(UsePeptideLevelQValueForTraining && (peptideGroups.Count(g => g.BestMatch.IsDecoy) < 4 || peptideGroups.Count(g => !g.BestMatch.IsDecoy) < 4))
//{
// peptideGroups = PeptideMatchGroup.GroupByIndividualPsm(AllPsms);
//}

int numGroups = 4;
List<int>[] peptideGroupIndices = GetPeptideGroupIndices(peptideGroups, numGroups);
Expand Down
6 changes: 3 additions & 3 deletions MetaMorpheus/GUI/GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@
<ItemGroup>
<PackageReference Include="MarkdownSharp" Version="2.0.5" />
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="Microsoft.ML" Version="3.0.1" />
<PackageReference Include="Microsoft.ML.CpuMath" Version="3.0.1" />
<PackageReference Include="Microsoft.ML.FastTree" Version="3.0.1" />
<PackageReference Include="Microsoft.ML" Version="2.0.0" />
<PackageReference Include="Microsoft.ML.CpuMath" Version="2.0.0" />
<PackageReference Include="Microsoft.ML.FastTree" Version="2.0.0" />
<PackageReference Include="Microsoft.NETCore.App" Version="2.2.8" />
<PackageReference Include="mzLib" Version="1.0.551" />
<PackageReference Include="Nett" Version="0.15.0" />
Expand Down
58 changes: 30 additions & 28 deletions MetaMorpheus/TaskLayer/SearchTask/PostSearchAnalysisTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,36 +137,38 @@ private void CalculatePsmAndPeptideFdr(List<SpectralMatch> psms, string analysis
// this could cause weird PSM FDR issues

Status("Estimating PSM FDR...", Parameters.SearchTaskId);

List<int> psmsAboveQ = new List<int>();
List<int> peptidesAboveQ = new List<int>();
List<int> psmsAbovePepQ = new List<int>();
List<int> peptidesAbovePepQ = new List<int>();

for (int i = 0; i < 10; i++)
{
var tempPsms = psms
.Select(p => new PeptideSpectralMatch(p))
.Cast<SpectralMatch>()
.ToList();
new FdrAnalysisEngine(tempPsms, Parameters.NumNotches, CommonParameters, this.FileSpecificParameters,
new FdrAnalysisEngine(psms, Parameters.NumNotches, CommonParameters, this.FileSpecificParameters,
new List<string> { Parameters.SearchTaskId }, analysisType: analysisType, doPEP: doPep, outputFolder: Parameters.OutputFolder).Run();
psmsAboveQ.Add(tempPsms.Count(p => p.FdrInfo.QValue <= 0.01));
peptidesAboveQ.Add(tempPsms.Count(p => p.PeptideFdrInfo.QValue <= 0.01));
psmsAbovePepQ.Add(tempPsms.Count(p => p.FdrInfo.PEP_QValue <= 0.01));
peptidesAbovePepQ.Add(tempPsms.Count(p => p.PeptideFdrInfo.PEP_QValue <= 0.01));
}

//List<int> psmsAboveQ = new List<int>();
//List<int> peptidesAboveQ = new List<int>();
//List<int> psmsAbovePepQ = new List<int>();
//List<int> peptidesAbovePepQ = new List<int>();

//for (int i = 0; i < 10; i++)
//{
// var tempPsms = psms
// .Select(p => new PeptideSpectralMatch(p))
// .Cast<SpectralMatch>()
// .ToList();
// new FdrAnalysisEngine(tempPsms, Parameters.NumNotches, CommonParameters, this.FileSpecificParameters,
// new List<string> { Parameters.SearchTaskId }, analysisType: analysisType, doPEP: doPep, outputFolder: Parameters.OutputFolder).Run();
// psmsAboveQ.Add(tempPsms.Count(p => p.FdrInfo.QValue <= 0.01));
// peptidesAboveQ.Add(tempPsms.Count(p => p.PeptideFdrInfo.QValue <= 0.01));
// psmsAbovePepQ.Add(tempPsms.Count(p => p.FdrInfo.PEP_QValue <= 0.01));
// peptidesAbovePepQ.Add(tempPsms.Count(p => p.PeptideFdrInfo.PEP_QValue <= 0.01));
//}

// write summary text
using(StreamWriter writer = new StreamWriter(@"C:\Users\Alex\PEP_NoRandomOrdering.tsv"))
{
writer.WriteLine("PSMs Q\tPeptides Q\tPSMs PEP-Q\tPeptides PEP-Q");
for(int i = 0; i < 10; i++)
{
writer.WriteLine(String.Join('\t', psmsAboveQ[i], peptidesAboveQ[i], psmsAbovePepQ[i], peptidesAbovePepQ[i]));
}
}
throw new Exception("PEP Seed Results written to file");
//// write summary text
//using(StreamWriter writer = new StreamWriter(@"C:\Users\Alex\PEP_NoRandomOrdering.tsv"))
//{
// writer.WriteLine("PSMs Q\tPeptides Q\tPSMs PEP-Q\tPeptides PEP-Q");
// for(int i = 0; i < 10; i++)
// {
// writer.WriteLine(String.Join('\t', psmsAboveQ[i], peptidesAboveQ[i], psmsAbovePepQ[i], peptidesAbovePepQ[i]));
// }
//}
//throw new Exception("PEP Seed Results written to file");
Status("Done estimating PSM FDR!", Parameters.SearchTaskId);
}

Expand Down
6 changes: 3 additions & 3 deletions MetaMorpheus/TaskLayer/TaskLayer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

<ItemGroup>
<PackageReference Include="MathNet.Numerics" Version="5.0.0" />
<PackageReference Include="Microsoft.ML" Version="3.0.1" />
<PackageReference Include="Microsoft.ML.CpuMath" Version="3.0.1" />
<PackageReference Include="Microsoft.ML.FastTree" Version="3.0.1" />
<PackageReference Include="Microsoft.ML" Version="2.0.0" />
<PackageReference Include="Microsoft.ML.CpuMath" Version="2.0.0" />
<PackageReference Include="Microsoft.ML.FastTree" Version="2.0.0" />
<PackageReference Include="Microsoft.NETCore.App" Version="2.2.8" />
<PackageReference Include="mzLib" Version="1.0.551" />
<PackageReference Include="NetSerializer" Version="4.1.2" />
Expand Down

0 comments on commit ae3b811

Please sign in to comment.