Skip to content

Commit

Permalink
dg
Browse files Browse the repository at this point in the history
  • Loading branch information
trishorts committed Nov 5, 2024
1 parent cef3bb3 commit 2bfe86a
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 26 deletions.
1 change: 0 additions & 1 deletion MetaMorpheus/Test/EverythingRunnerEngineTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,3 @@ static EverythingRunnerEngineTestCase()
}
}


184 changes: 184 additions & 0 deletions MetaMorpheus/Test/PostSearchAnalysisTaskTestPsmCountOverride.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using EngineLayer.FdrAnalysis;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Nett;
using NUnit.Framework;
using TaskLayer;
using Assert = NUnit.Framework.Legacy.ClassicAssert;

namespace Test
{
/// <summary>
/// Uses test cases found in EverythingRunnerEngineTestCase.cs
/// </summary>
[TestFixture]
[ExcludeFromCodeCoverage]
public static class PostSearchAnalysisTaskTestsPsmCountOverride
{

//[Test]
//[NonParallelizable]
//public static void AllResultsAndResultsTxtContainsCorrectValues_QValue_BottomUp()
//{
// //override to be only used for unit tests in non-parallelizable format
// //must set to false at the end of this method
// var type = typeof(FdrAnalysisEngine);
// var property = type.GetProperty("QvalueThresholdOverride");
// property.SetValue(null, true);

// var ResultDirectory =
// Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PsmCountOverrideTest");

// // Directory GlobalSetup
// if (Directory.Exists(ResultDirectory))
// Directory.Delete(ResultDirectory, true);

// if (!Directory.Exists(ResultDirectory))
// Directory.CreateDirectory(ResultDirectory);

// string myTomlPath = Path.Combine(TestContext.CurrentContext.TestDirectory,
// @"TestData\Task1-SearchTaskconfig.toml");
// SearchTask searchTaskLoaded = Toml.ReadFile<SearchTask>(myTomlPath, MetaMorpheusTask.tomlConfig);
// string myFile1 = Path.Combine(TestContext.CurrentContext.TestDirectory,
// @"TestData\TaGe_SA_A549_3_snip.mzML");
// string myFile2 = Path.Combine(TestContext.CurrentContext.TestDirectory,
// @"TestData\TaGe_SA_A549_3_snip_2.mzML");
// string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory,
// @"TestData\TaGe_SA_A549_3_snip.fasta");
// searchTaskLoaded = Toml.ReadFile<SearchTask>(myTomlPath, MetaMorpheusTask.tomlConfig);
// searchTaskLoaded.SearchParameters.WriteIndividualFiles = true;
// searchTaskLoaded.SearchParameters.WriteMzId = true;
// searchTaskLoaded.SearchParameters.WritePepXml = true;

// List<(string, MetaMorpheusTask)> taskList = new() { ("searchTask",searchTaskLoaded)};
// List<DbForTask> DatabaseList = new() { new DbForTask(myDatabase, false) };
// List<string> DataFileList = new() { myFile1, myFile2 };
// string OutputDirectory = Path.Combine(ResultDirectory, "BottomUpQValue");

// var e = new EverythingRunnerEngine(taskList, DataFileList, DatabaseList, OutputDirectory);

// e.Run();

// string allResultsFile = Path.Combine(OutputDirectory, "allResults.txt");
// string[] allResults = File.ReadAllLines(allResultsFile);

// // The new PEP calculation method improves things, so all these numbers are increasing as of (7/17/24)
// // There is a discrepancy between the number of All target peptides and individual file target peptides,
// // presumably due to the way protein inference is performed.
// Assert.AreEqual("All target PSMs with q-value <= 0.01: 428", allResults[10]);
// Assert.AreEqual("All target peptides with q-value <= 0.01: 174", allResults[11]);
// Assert.AreEqual("All target protein groups with q-value <= 0.01 (1% FDR): 165", allResults[12]);
// Assert.AreEqual("TaGe_SA_A549_3_snip - Target PSMs with q-value <= 0.01: 214", allResults[14]);
// Assert.AreEqual("TaGe_SA_A549_3_snip - Target peptides with q-value <= 0.01: 174", allResults[15]);
// Assert.AreEqual("TaGe_SA_A549_3_snip - Target protein groups within 1 % FDR: 165", allResults[16]);
// Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target PSMs with q-value <= 0.01: 214", allResults[18]);
// Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target peptides with q-value <= 0.01: 174", allResults[19]);
// Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target protein groups within 1 % FDR: 165", allResults[20]);


// string resultsFile = Path.Combine(OutputDirectory, @"searchTask\results.txt");
// string[] results = File.ReadAllLines(resultsFile);

// Assert.AreEqual("All target PSMs with q-value <= 0.01: 428", results[5]);
// Assert.AreEqual("All target peptides with q-value <= 0.01: 174", results[6]);
// Assert.AreEqual("TaGe_SA_A549_3_snip - Target PSMs with q-value <= 0.01: 214", results[9]);
// Assert.AreEqual("TaGe_SA_A549_3_snip - Target peptides with q-value <= 0.01: 174", results[10]);
// Assert.AreEqual("TaGe_SA_A549_3_snip - Target protein groups within 1 % FDR: 165", results[11]);
// Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target PSMs with q-value <= 0.01: 214", results[13]);
// Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target peptides with q-value <= 0.01: 174", results[14]);
// Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target protein groups within 1 % FDR: 165", results[15]);

// property.SetValue(null, false);

// // Directory GlobalSetup
// if (Directory.Exists(ResultDirectory))
// Directory.Delete(ResultDirectory, true);
//}

//[Test]
//[NonParallelizable]
//public static void AllResultsAndResultsTxtContainsCorrectValues_PepQValue_BottomUp()
//{
// //override to be only used for unit tests in non-parallelizable format
// //must set to false at the end of this method
// var type = typeof(FdrAnalysisEngine);
// var property = type.GetProperty("QvalueThresholdOverride");
// property.SetValue(null, true);

// var ResultDirectory =
// Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PsmCountOverrideTest");

// // Directory GlobalSetup
// if (Directory.Exists(ResultDirectory))
// Directory.Delete(ResultDirectory, true);

// if (!Directory.Exists(ResultDirectory))
// Directory.CreateDirectory(ResultDirectory);

// string myFile1 = Path.Combine(TestContext.CurrentContext.TestDirectory,
// @"TestData\TaGe_SA_A549_3_snip.mzML");
// string myFile2 = Path.Combine(TestContext.CurrentContext.TestDirectory,
// @"TestData\TaGe_SA_A549_3_snip_2.mzML");
// string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory,
// @"TestData\TaGe_SA_A549_3_snip.fasta");

// var myTomlPath = Path.Combine(TestContext.CurrentContext.TestDirectory,
// @"TestData\Task2-SearchTaskconfig.toml");
// var searchTaskLoaded = Toml.ReadFile<SearchTask>(myTomlPath, MetaMorpheusTask.tomlConfig);
// searchTaskLoaded.CommonParameters.QValueCutoffForPepCalculation = 0.01;
// searchTaskLoaded.SearchParameters.WriteIndividualFiles = true;
// searchTaskLoaded.SearchParameters.WriteMzId = true;
// searchTaskLoaded.SearchParameters.WritePepXml = true;

// List<(string, MetaMorpheusTask)> taskList = new() { ("searchTask", searchTaskLoaded) };
// List<DbForTask> DatabaseList = new() { new DbForTask(myDatabase, false) };
// List<string> DataFileList = new() { myFile1, myFile2 };
// string OutputDirectory = Path.Combine(ResultDirectory, "BottomUpPepQValue");

// var e = new EverythingRunnerEngine(taskList, DataFileList, DatabaseList, OutputDirectory);

// e.Run();

// string allResultsFile = Path.Combine(OutputDirectory, "allResults.txt");
// string[] allResults = File.ReadAllLines(allResultsFile);

// // The new PEP calculation method improves things, so all these numbers are increasing as of (7/17/24)
// // There is a discrepancy between the number of All target peptides and individual file target peptides,
// // presumably due to the way protein inference is performed.
// Assert.AreEqual("All target PSMs with pep q-value <= 0.01: 382", allResults[10]);
// Assert.AreEqual("All target peptides with pep q-value <= 0.01: 153", allResults[11]);
// Assert.AreEqual("All target protein groups with q-value <= 0.01 (1% FDR): 140", allResults[12]);
// Assert.AreEqual("TaGe_SA_A549_3_snip - Target PSMs with pep q-value <= 0.01: 190", allResults[14]);
// Assert.AreEqual("TaGe_SA_A549_3_snip - Target peptides with pep q-value <= 0.01: 153", allResults[15]);
// Assert.AreEqual("TaGe_SA_A549_3_snip - Target protein groups within 1 % FDR: 140", allResults[16]);
// Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target PSMs with pep q-value <= 0.01: 190", allResults[18]);
// Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target peptides with pep q-value <= 0.01: 153", allResults[19]);
// Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target protein groups within 1 % FDR: 140", allResults[20]);


// string resultsFile = Path.Combine(OutputDirectory, @"searchTask\results.txt");
// string[] results = File.ReadAllLines(resultsFile);

// Assert.AreEqual("All target PSMs with pep q-value <= 0.01: 382", results[5]);
// Assert.AreEqual("All target peptides with pep q-value <= 0.01: 153", results[6]);
// Assert.AreEqual("All target protein groups with q-value <= 0.01 (1% FDR): 140", results[7]);
// Assert.AreEqual("TaGe_SA_A549_3_snip - Target PSMs with pep q-value <= 0.01: 190", results[9]);
// Assert.AreEqual("TaGe_SA_A549_3_snip - Target peptides with pep q-value <= 0.01: 153", results[10]);
// Assert.AreEqual("TaGe_SA_A549_3_snip - Target protein groups within 1 % FDR: 140", results[11]);
// Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target PSMs with pep q-value <= 0.01: 190", results[13]);
// Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target peptides with pep q-value <= 0.01: 153", results[14]);
// Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target protein groups within 1 % FDR: 140", results[15]);

// property.SetValue(null, false);

// // Directory GlobalSetup
// if (Directory.Exists(ResultDirectory))
// Directory.Delete(ResultDirectory, true);
//}

}
}
24 changes: 3 additions & 21 deletions MetaMorpheus/Test/PostSearchAnalysisTaskTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using EngineLayer.FdrAnalysis;
using NUnit.Framework;
using NUnit.Framework;
using Assert = NUnit.Framework.Legacy.ClassicAssert;

namespace Test
Expand All @@ -18,15 +17,8 @@ public static class PostSearchAnalysisTaskTests
public static Array GetTestCases() => Enum.GetValues(typeof(EverythingRunnerEngineTestCases));

[Test]
[NonParallelizable]
public static void AllResultsAndResultsTxtContainsCorrectValues_QValue_BottomUp()
{
//override to be only used for unit tests in non-parallelizable format
//must set to false at the end of this method
var type = typeof(FdrAnalysisEngine);
var property = type.GetProperty("QvalueThresholdOverride");
property.SetValue(null, true);

//First test that AllResults and Results display correct numbers of peptides and psms with q-value filter on
EverythingRunnerEngineTestCase.TryGetTestCase(EverythingRunnerEngineTestCases.BottomUpQValue, out var testCase);
string outputFolder = testCase.OutputDirectory;
Expand Down Expand Up @@ -58,7 +50,7 @@ public static void AllResultsAndResultsTxtContainsCorrectValues_QValue_BottomUp(
Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target PSMs with q-value <= 0.01: 214", results[13]);
Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target peptides with q-value <= 0.01: 174", results[14]);
Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target protein groups within 1 % FDR: 165", results[15]);

// Search TaGe_SA_A549_3_snip_2 by itself. The results from this should be identical to the file specific results above
// TaGe_SA_A549_3_snip_2 is searched twice. First with two files being searched simultaneously, then with TaGe_SA_A549_3_snip_2 by itself
// This allows us to compare the file specific results produced by in the two file search to the output
Expand All @@ -77,19 +69,11 @@ public static void AllResultsAndResultsTxtContainsCorrectValues_QValue_BottomUp(
Assert.AreEqual("All target PSMs with q-value <= 0.01: " + TaGe_SA_A549_3_snip_2ExpectedPsms, singleFileResults[5]);
Assert.AreEqual("All target peptides with q-value <= 0.01: " + TaGe_SA_A549_3_snip_2ExpectedPeptides, singleFileResults[6]);
Assert.AreEqual("All target protein groups with q-value <= 0.01 (1% FDR): 165", singleFileResults[7]);
property.SetValue(null, false);
}

[Test]
[NonParallelizable]
public static void AllResultsAndResultsTxtContainsCorrectValues_PepQValue_BottomUp()
{
//override to be only used for unit tests in non-parallelizable format
//must set to false at the end of this method
var type = typeof(FdrAnalysisEngine);
var property = type.GetProperty("QvalueThresholdOverride");
property.SetValue(null, true);

//First test that AllResults and Results display correct numbers of peptides and psms with pep q-value filter on
EverythingRunnerEngineTestCase.TryGetTestCase(EverythingRunnerEngineTestCases.BottomUpPepQValue, out var testCase);
string outputFolder = testCase.OutputDirectory;
Expand All @@ -116,7 +100,6 @@ public static void AllResultsAndResultsTxtContainsCorrectValues_PepQValue_Bottom
Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target PSMs with pep q-value <= 0.01: 190", results[13]);
Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target peptides with pep q-value <= 0.01: 153", results[14]);
Assert.AreEqual("TaGe_SA_A549_3_snip_2 - Target protein groups within 1 % FDR: 140", results[15]);
property.SetValue(null, false);
}

/// <summary>
Expand All @@ -126,10 +109,9 @@ public static void AllResultsAndResultsTxtContainsCorrectValues_PepQValue_Bottom
[TestCaseSource(nameof(GetTestCases))]
public static void AllResultTxtContainsCorrectNumberOfResultLines(EverythingRunnerEngineTestCases testCaseIdentifier)
{

var testCase = EverythingRunnerEngineTestCase.GetTestCase(testCaseIdentifier);

int expectedIndividualFileLines = testCase.DataFileList.Count == 1 || !testCase.WriteIndividualResults
int expectedIndividualFileLines = testCase.DataFileList.Count == 1 || !testCase.WriteIndividualResults
? 0 : testCase.DataFileList.Count;
int expectedSummaryLines = 1;
var allResultTxtLines = File.ReadAllLines(Path.Combine(testCase.OutputDirectory, @"allResults.txt"));
Expand Down
4 changes: 2 additions & 2 deletions MetaMorpheus/Test/SearchEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ public static void TestClassicSearchXcorrWithToml()
List<PsmFromTsv> parsedPsms = PsmTsvReader.ReadTsv(psmFile, out var warnings);

Assert.AreEqual(385, parsedPsms.Count); //total psm count
Assert.AreEqual(215, parsedPsms.Count(p => p.QValue < 0.01)); //psms with q-value < 0.01 as read from psmtsv, including decoys
Assert.AreEqual(218, parsedPsms.Count(p => p.QValue < 0.01)); //psms with q-value < 0.01 as read from psmtsv, including decoys
Assert.AreEqual(0, warnings.Count);

int countFromResultsTxt = Convert.ToInt32(File.ReadAllLines(Path.Combine(outputFolder, @"SearchTOML\results.txt")).ToList().FirstOrDefault(l=>l.Contains("All target")).Split(":")[1].Trim());
Assert.AreEqual(214, countFromResultsTxt);
Assert.AreEqual(216, countFromResultsTxt);
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion MetaMorpheus/Test/TestData/Task1-SearchTaskconfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ MaxModsForPeptide = 2
Protease = "trypsin"
SearchModeType = "Full"
FragmentationTerminus = "Both"
SpecificProtease = "trypsin"
SpecificProtease = "trypsin"
2 changes: 1 addition & 1 deletion MetaMorpheus/Test/TestData/Task2-SearchTaskconfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ MaxModsForPeptide = 2
Protease = "trypsin"
SearchModeType = "Full"
FragmentationTerminus = "Both"
SpecificProtease = "trypsin"
SpecificProtease = "trypsin"

0 comments on commit 2bfe86a

Please sign in to comment.