Skip to content

Commit c76418c

Browse files
committed
fixes to tests and occupancy to pass said tests. need to do a final test before pr.
1 parent 903812e commit c76418c

8 files changed

Lines changed: 56 additions & 80 deletions

File tree

MetaMorpheus/EngineLayer/ProteinParsimony/ProteinGroup.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,13 @@ public override string ToString()
349349
}
350350
}
351351
}
352+
else
353+
{
354+
sb.Append("\t");
355+
}
352356

353-
// number of PSMs for listed peptides
354-
sb.Append("" + AllPsmsBelowOnePercentFDR.Count);
357+
// number of PSMs for listed peptides
358+
sb.Append("" + AllPsmsBelowOnePercentFDR.Count);
355359
sb.Append("\t");
356360

357361
// isDecoy
@@ -445,7 +449,6 @@ public string ModInfoStringFromGroupedFiles(List<SpectraFileInfo> spectraFiles)
445449
{
446450
return "";
447451
}
448-
449452
}
450453

451454
// this method is only used internally, to make protein grouping faster

MetaMorpheus/EngineLayer/Silac/SilacConversions.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
using Omics;
1010
using Omics.Digestion;
1111
using EngineLayer.SpectrumMatch;
12+
using MzLibUtil.PositionFrequencyAnalysis;
13+
using Easy.Common.Extensions;
1214

1315
namespace EngineLayer
1416
{
@@ -460,6 +462,7 @@ public static void SilacConversionsPostQuantification(List<SilacLabel> allSilacL
460462
{
461463
proteinGroup.FilesForQuantification = allInfo;
462464
proteinGroup.IntensitiesByFile = new Dictionary<SpectraFileInfo, double>();
465+
proteinGroup.ModsInfo = new Dictionary<SpectraFileInfo, QuantifiedProteinGroup>();
463466

464467
foreach (var spectraFile in allInfo)
465468
{
@@ -472,6 +475,28 @@ public static void SilacConversionsPostQuantification(List<SilacLabel> allSilacL
472475
//needed for decoys/contaminants/proteins that aren't quantified
473476
proteinGroup.IntensitiesByFile.Add(spectraFile, 0);
474477
}
478+
479+
// get modification stoichiometry using FlashLFQ spectraFile-specific intensities
480+
var pgQuantifiedPeptides = flashLfqResults.PeptideModifiedSequences.Where(x => proteinGroup.AllPeptides.Select(x => x.FullSequence).Contains(x.Key)).ToList();
481+
482+
if (pgQuantifiedPeptides.IsNotNullOrEmpty())
483+
{
484+
var peptides = pgQuantifiedPeptides.Where(pep => pep.Value.GetIntensity(spectraFile) > 0)
485+
.Select(pep => (pep.Value.Sequence,
486+
new List<string> { proteinGroup.ProteinGroupName },
487+
pep.Value.GetIntensity(spectraFile))).ToList();
488+
if (!peptides.IsNotNullOrEmpty())
489+
{
490+
proteinGroup.ModsInfo.Add(spectraFile, new QuantifiedProteinGroup(proteinGroup.ProteinGroupName));
491+
continue;
492+
}
493+
494+
PositionFrequencyAnalysis pfa = new PositionFrequencyAnalysis();
495+
var proteins = proteinGroup.Proteins.Select(p => new KeyValuePair<string, string>(p.Accession, p.BaseSequence)).ToDictionary();
496+
pfa.SetUpQuantificationObjectsFromFullSequences(peptides, proteins); // uses zero-based indexes for the mods.
497+
498+
proteinGroup.ModsInfo.Add(spectraFile, pfa.ProteinGroups.First().Value); // Getting stoich one protein group at a time, so only getting First() is ok here.
499+
}
475500
}
476501
}
477502
}

MetaMorpheus/TaskLayer/SearchTask/PostSearchAnalysisTask.cs

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,6 @@ private void QuantificationAnalysis()
572572
else
573573
{
574574
proteinGroup.IntensitiesByFile.Add(spectraFile, 0);
575-
continue; // no need to calculate stoichiometry if the protein group is not in the FlashLFQ results
576575
}
577576

578577
// get modification stoichiometry using FlashLFQ spectraFile-specific intensities
@@ -584,7 +583,7 @@ private void QuantificationAnalysis()
584583
.Select(pep => (pep.Value.Sequence,
585584
new List<string> { proteinGroup.ProteinGroupName },
586585
pep.Value.GetIntensity(spectraFile))).ToList();
587-
if (!peptides.IsNotNullOrEmpty())
586+
if (peptides.IsNullOrEmpty())
588587
{
589588
proteinGroup.ModsInfo.Add(spectraFile, new QuantifiedProteinGroup(proteinGroup.ProteinGroupName));
590589
continue;
@@ -595,64 +594,9 @@ private void QuantificationAnalysis()
595594
pfa.SetUpQuantificationObjectsFromFullSequences(peptides, proteins); // uses zero-based indexes for the mods.
596595

597596
proteinGroup.ModsInfo.Add(spectraFile, pfa.ProteinGroups.First().Value); // Getting stoich one protein group at a time, so only getting First() is ok here.
598-
599597
}
600598
}
601599
}
602-
603-
604-
605-
//foreach (var proteinGroup in ProteinGroups)
606-
//{
607-
// if (proteinGroup.FilesForQuantification.IsNotNullOrEmpty())
608-
// {
609-
// var pgQuantifiedPeptides = Parameters.FlashLfqResults.PeptideModifiedSequences.Where(p => peptideSequencesForQuantification.Contains(p.Key)).Select(p => p.Value);
610-
//
611-
//
612-
//
613-
//
614-
// var sb = new StringBuilder();
615-
//
616-
//
617-
// foreach (var file in proteinGroup.FilesForQuantification)
618-
// {
619-
//
620-
//
621-
//
622-
//
623-
// proteinGroupsOccupancyByProteins[proteinGroup.ProteinGroupName]
624-
// .Proteins[protein.Accession]
625-
// .SetProteinModsFromPeptides();
626-
//
627-
// // build modInfoString for this protein
628-
// var occupancyPGProtein = proteinGroupsOccupancyByProteins[proteinGroup.ProteinGroupName].Proteins[protein.Accession];
629-
// var proteinStoichiometry = occupancyPGProtein.GetModStoichiometryFromProteinMods();
630-
// var aaModStrings = new List<string>();
631-
//
632-
// foreach (var modpos in occupancyPGProtein.ModifiedAminoAcidPositionsInProtein.Keys.Order())
633-
// {
634-
// var totalIntensity = occupancyPGProtein.Peptides.Where(pep => occupancyPGProtein.PeptidesByProteinPosition[modpos].Contains(pep.Key)).Sum(pep => pep.Value.Intensity);
635-
// var aaModString = new StringBuilder();
636-
// aaModString.Append($"aa#{modpos.ToString()}");
637-
//
638-
// foreach (var mod in occupancyPGProtein.ModifiedAminoAcidPositionsInProtein[modpos])
639-
// {
640-
// var modStoichiometry = mod.Value.Intensity;
641-
// aaModString.Append($"[{mod.Key}, info:occupancy={modStoichiometry.ToString("N4")}({totalIntensity})]");
642-
// }
643-
//
644-
// aaModStrings.Add(aaModString.ToString());
645-
// }
646-
// if (aaModStrings.IsNotNullOrEmpty())
647-
// {
648-
// sb.Append($"protein:{protein.Accession}{{{string.Join(";", aaModStrings)}}}");
649-
// }
650-
// }
651-
// proteinGroup.ModsInfo = new Dictionary<SpectraFileInfo, string>();
652-
// proteinGroup.ModsInfo.Add(file.First(), sb.ToString());
653-
// }
654-
// }
655-
//}
656600
}
657601

658602
//Silac stuff for post-quantification

MetaMorpheus/Test/ProteinGroupTest.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ public static void ProteinGroupToStringTest()
8484

8585
//string exectedProteinGroupToString = proteinGroup1.ToString();
8686
string exectedProteinGroupToString = "prot1|prot2\t|\t\t\t779.30073507823|778.3167194953201\t2\t\t\t2\t2\t\t\t\t\t\t0\tT\t0\t0\t0\t0\t0";
87-
var out1 = proteinGroup1.ToString();
88-
var out1h = proteinGroup1.GetTabSeparatedHeader();
87+
var out1 = proteinGroup1.ToString().Split("\t");
88+
var out1h = proteinGroup1.GetTabSeparatedHeader().Split("\t");
89+
var out1zipped = out1h.Zip(out1, (a, b) => (a, b)).ToDictionary();
8990
Assert.That(proteinGroup1.ToString(), Is.EqualTo(exectedProteinGroupToString));
9091

9192

@@ -248,7 +249,8 @@ public static void TestModificationInfoListInProteinGroupsOutput()
248249
List<string> proteinGroupsOutput = File.ReadAllLines(Path.Combine(outputFolder, "task2", "AllQuantifiedProteinGroups.tsv")).ToList();
249250
string firstDataLine = proteinGroupsOutput[2];
250251
string modInfoListProteinTwo = firstDataLine.Split('\t')[14];
251-
Assert.That(modInfoListProteinTwo, Is.EqualTo("#aa71[Oxidation on S,info:occupancy=0.50(1/2)]"));
252+
Assert.That(modInfoListProteinTwo, Is.EqualTo("P10591:{M#65[Common Variable:Oxidation on M, info: occupancy=1.0000(654315.977066199)]S#71[Less Common:Oxidation on S, info: occupancy=0.1957(654315.977066199)]}" +
253+
"P10592:{M#65[Common Variable:Oxidation on M, info: occupancy=1.0000(654315.977066199)]S#71[Less Common:Oxidation on S, info: occupancy=0.1957(654315.977066199)]}"));
252254

253255
Directory.Delete(outputFolder, true);
254256
}

MetaMorpheus/Test/QuantificationTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public static void TestProteinQuantFileHeaders(bool hasDefinedExperimentalDesign
165165
string condition = hasDefinedExperimentalDesign ? "TestCondition" : "";
166166

167167
// create the protein database
168-
Protein prot = new(peptide, @"");
168+
Protein prot = new(peptide, @"test"); // necessary to pass name to protein. otherwise dbloader will do crazy things
169169
string dbName = Path.Combine(unitTestFolder, "testDB.fasta");
170170
UsefulProteomicsDatabases.ProteinDbWriter.WriteFastaDatabase(new List<Protein> { prot }, dbName, ">");
171171

MetaMorpheus/Test/RobTest.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
using Omics.Modifications;
1414
using Omics;
1515
using Transcriptomics;
16+
using EngineLayer.ModernSearch;
17+
using EngineLayer.Indexing;
18+
using System.IO;
19+
using TaskLayer;
20+
using UsefulProteomicsDatabases;
1621

1722
namespace Test
1823
{
@@ -254,8 +259,10 @@ public static void TestPTMOutput()
254259
ProteinScoringAndFdrEngine f = new ProteinScoringAndFdrEngine(proteinGroups, psms, false, false, true, new CommonParameters(), null, new List<string>());
255260
f.Run();
256261

257-
//Assert.That(proteinGroups.First().ModsInfo[0], Is.EqualTo("#aa5[resMod on S,info:occupancy=0.67(2/3)];#aa10[iModOne on I,info:occupancy=0.33(2/6)];#aa10[iModTwo on I,info:occupancy=0.33(2/6)]"));
258-
Assert.That(true == false); // intentional test fail.
262+
// inclined to delete this test
263+
// Otherwise, readapt to run flashlfq and then correctly check modinfo...
264+
Assert.That(proteinGroups.First().ModsInfo, Is.Null);
265+
Assert.That(proteinGroups.First().ModInfoStringFromGroupedFiles(proteinGroups.First().FilesForQuantification), Is.EqualTo(""));
259266
}
260267

261268
[Test]

MetaMorpheus/Test/SeqCoverageTest.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,6 @@ public static void TryFailSequenceCoverage()
9797
var firstSequenceCoverageDisplayListWithMods = fjkd.ProteinGroups.First().SequenceCoverageDisplayListWithMods.First();
9898
Assert.That(firstSequenceCoverageDisplayListWithMods, Is.EqualTo("[mod1 on M]-MM[mod3 on M]KM[mod3 on M]MK-[mod5 on K]"));
9999

100-
// This needs to update to intensity based occupancy reporting
101-
var firstModInfo = fjkd.ProteinGroups.First().ModsInfo.First();
102-
//Assert.That(firstModInfo.Contains(@"#aa1[mod1 on M,info:occupancy=1.00(2/2)]"));
103-
//Assert.That(firstModInfo.Contains(@"#aa2[mod3 on M,info:occupancy=0.50(1/2)]"));
104-
//Assert.That(!(firstModInfo.Contains(@"#aa3")));
105-
//Assert.That(firstModInfo.Contains(@"#aa4[mod3 on M,info:occupancy=0.50(1/2)]"));
106-
//Assert.That(!(firstModInfo.Contains(@"#aa5")));
107-
//Assert.That(firstModInfo.Contains(@"#aa6[mod5 on K,info:occupancy=1.00(2/2)]"));
108100
Console.WriteLine("Test output: " + firstSequenceCoverageDisplayList);
109101
}
110102

MetaMorpheus/Test/SilacTest.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public static void TestSilacNoLightProtein()
5757
//test proteins
5858
string[] output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllQuantifiedProteinGroups.tsv");
5959
Assert.That(output.Length, Is.EqualTo(2));
60-
Assert.That(output[0].Contains("Modification Info List\tIntensity_silac(R+3.988)\tIntensity_silac(R+10.008)")); //test that two files were made and no light file
61-
Assert.That(output[1].Contains("875000.0000000009\t437500.00000000047")); //test the heavier intensity is half that of the heavy (per the raw file)
60+
Assert.That(output[0].Contains("Mods_silac(R+3.988)\tIntensity_silac(R+3.988)\tMods_silac(R+10.008)\tIntensity_silac(R+10.008)")); //test that two files were made and no light file
61+
Assert.That(output[1].Contains("875000.0000000009\t\t437500.00000000047")); //test the heavier intensity is half that of the heavy (per the raw file)
6262

6363
//test peptides
6464
output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllQuantifiedPeptides.tsv");
@@ -131,8 +131,8 @@ public static void TestSilacMultipleModsPerCondition()
131131
//test proteins
132132
string[] output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllQuantifiedProteinGroups.tsv");
133133
Assert.That(output.Length, Is.EqualTo(2));
134-
Assert.That(output[0].Contains("Intensity_silac\tIntensity_silac(K+8.014 & R+6.020)")); //test that two files were made
135-
Assert.That(output[1].Contains("1374999.999999999\t687499.9999999995")); //test the heavy intensity is half that of the light (per the raw file)
134+
Assert.That(output[0].Contains("Mods_silac\tIntensity_silac\tMods_silac(K+8.014 & R+6.020)\tIntensity_silac(K+8.014 & R+6.020)")); //test that two files were made
135+
Assert.That(output[1].Contains("1374999.999999999\t\t687499.9999999995")); //test the heavy intensity is half that of the light (per the raw file)
136136

137137
//test peptides
138138
output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllQuantifiedPeptides.tsv");
@@ -222,8 +222,11 @@ public static void TestSilacQuantification()
222222
//test proteins
223223
string[] output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"\TestSilac\AllQuantifiedProteinGroups.tsv");
224224
Assert.That(output.Length, Is.EqualTo(2));
225-
Assert.That(output[0].Contains("Intensity_silac\tIntensity_silacPart2\tIntensity_silac(K+8.014)\tIntensity_silacPart2(K+8.014)")); //test that two files were made
226-
Assert.That(output[1].Contains("875000.0000000009\t875000.0000000009\t437500.00000000047\t437500.00000000047")); //test the heavy intensity is half that of the light (per the raw file)
225+
Assert.That(output[0].Contains("Mods_silac\tIntensity_silac\t"+
226+
"Mods_silacPart2\tIntensity_silacPart2\t"+
227+
"Mods_silac(K+8.014)\tIntensity_silac(K+8.014)\t"+
228+
"Mods_silacPart2(K+8.014)\tIntensity_silacPart2(K+8.014)")); //test that two files were made
229+
Assert.That(output[1].Contains("875000.0000000009\t\t875000.0000000009\t\t437500.00000000047\t\t437500.00000000047")); //test the heavy intensity is half that of the light (per the raw file)
227230

228231
//test peptides
229232
output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"\TestSilac\AllQuantifiedPeptides.tsv");

0 commit comments

Comments
 (0)