diff --git a/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs b/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs index 7a241532e..ac07d9174 100644 --- a/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs +++ b/MetaMorpheus/EngineLayer/FdrAnalysis/FdrAnalysisEngine.cs @@ -1,9 +1,7 @@ using EngineLayer.CrosslinkSearch; using System; using System.Collections.Generic; -using System.IO; using System.Linq; -using System.Text.RegularExpressions; namespace EngineLayer.FdrAnalysis { @@ -14,7 +12,16 @@ public class FdrAnalysisEngine : MetaMorpheusEngine private readonly string AnalysisType; private readonly string OutputFolder; // used for storing PEP training models private readonly bool DoPEP; - + private readonly int PsmCountThresholdForInvertedQvalue = 1000; + /// + /// This is to be used only for unit testing. Threshold for q-value calculation is set to 1000 + /// However, many unit tests don't generate that many PSMs. Therefore, this property is used to override the threshold + /// to enable PEP calculation in unit tests with lower number of PSMs + /// + public static bool QvalueThresholdOverride // property + { + get; private set; + } public FdrAnalysisEngine(List psms, int massDiffAcceptorNumNotches, CommonParameters commonParameters, List<(string fileName, CommonParameters fileSpecificParameters)> fileSpecificParameters, List nestedIds, string analysisType = "PSM", bool doPEP = true, string outputFolder = null) : base(commonParameters, fileSpecificParameters, nestedIds) @@ -71,10 +78,10 @@ private void DoFalseDiscoveryRateAnalysis(FdrAnalysisResults myAnalysisResults) .Select(b => b.FirstOrDefault()) .ToList(); - if (psms.Count > 100 & DoPEP) + if ((psms.Count > PsmCountThresholdForInvertedQvalue || QvalueThresholdOverride) & DoPEP) { CalculateQValue(psms, peptideLevelCalculation: false, pepCalculation: false); - if (peptides.Count > 100 ) + if (peptides.Count > PsmCountThresholdForInvertedQvalue || QvalueThresholdOverride) { CalculateQValue(peptides, peptideLevelCalculation: true, pepCalculation: false); @@ -160,6 +167,7 @@ public void CalculateQValue(List psms, bool peptideLevelCalculati // Stop if canceled if (GlobalVariables.StopLoops) { break; } + // we have to keep track of q-values separately for each notch int notch = psm.Notch ?? MassDiffAcceptorNumNotches; if (psm.IsDecoy) { @@ -198,7 +206,8 @@ public void CalculateQValue(List psms, bool peptideLevelCalculati } else { - if(psms.Count < 100) + //the QValueThreshodOverride condition here can be problematic in unit tests. + if (psms.Count < PsmCountThresholdForInvertedQvalue && !QvalueThresholdOverride) { QValueTraditional(psms, peptideLevelAnalysis: peptideLevelCalculation); @@ -216,39 +225,49 @@ public void CalculateQValue(List psms, bool peptideLevelCalculati private void QValueTraditional(List psms, bool peptideLevelAnalysis) { double qValue = 0; - double qValueNotch = 0; + double[] qValueNotch = new double[MassDiffAcceptorNumNotches + 1]; + for (int i = 0; i < psms.Count; i++) { // Stop if canceled if (GlobalVariables.StopLoops) { break; } - + int notch = psms[i].Notch ?? MassDiffAcceptorNumNotches; qValue = Math.Max(qValue, psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoy / Math.Max(psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTarget, 1)); - qValueNotch = Math.Max(qValueNotch, psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoyNotch / Math.Max(psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTargetNotch, 1)); + qValueNotch[notch] = Math.Max(qValueNotch[notch], psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoyNotch / Math.Max(psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTargetNotch, 1)); psms[i].GetFdrInfo(peptideLevelAnalysis).QValue = Math.Min(qValue, 1); - psms[i].GetFdrInfo(peptideLevelAnalysis).QValueNotch = Math.Min(qValueNotch, 1); + psms[i].GetFdrInfo(peptideLevelAnalysis).QValueNotch = Math.Min(qValueNotch[notch], 1); } } - private static void QValueInverted(List psms, bool peptideLevelAnalysis) + private void QValueInverted(List psms, bool peptideLevelAnalysis) { + double[] qValueNotch = new double[MassDiffAcceptorNumNotches + 1]; + bool[] qValueNotchCalculated = new bool[MassDiffAcceptorNumNotches + 1]; 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; - double qValueNotch = (psms[0].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoyNotch + 1) / psms[0].GetFdrInfo(peptideLevelAnalysis).CumulativeTargetNotch; //Assign FDR values to PSMs for (int i = 0; i < psms.Count; i++) { // Stop if canceled if (GlobalVariables.StopLoops) { break; } + int notch = psms[i].Notch ?? MassDiffAcceptorNumNotches; + + // populate the highest q-Value for each notch + if (!qValueNotchCalculated[notch]) + { + qValueNotch[notch] = (psms[0].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoyNotch + 1) / psms[0].GetFdrInfo(peptideLevelAnalysis).CumulativeTargetNotch; + qValueNotchCalculated[notch] = true; + } qValue = Math.Min(qValue, (psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoy + 1) / Math.Max(psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTarget, 1)); - qValueNotch = Math.Min(qValueNotch, (psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoyNotch + 1) / Math.Max(psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTargetNotch, 1)); + qValueNotch[notch] = Math.Min(qValueNotch[notch], (psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeDecoyNotch + 1) / Math.Max(psms[i].GetFdrInfo(peptideLevelAnalysis).CumulativeTargetNotch, 1)); psms[i].GetFdrInfo(peptideLevelAnalysis).QValue = Math.Min(qValue, 1); - psms[i].GetFdrInfo(peptideLevelAnalysis).QValueNotch = Math.Min(qValueNotch, 1); + psms[i].GetFdrInfo(peptideLevelAnalysis).QValueNotch = Math.Min(qValueNotch[notch], 1); } psms.Reverse(); //we inverted the psms for this calculation. now we need to put them back into the original order } diff --git a/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs b/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs index d6881cfc4..56489e3bd 100644 --- a/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs +++ b/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs @@ -98,7 +98,7 @@ protected override MyTaskResults RunSpecific(string OutputFolder, List= NumRequiredPsms && acquisitionResults.Ms1List.Count >= NumRequiredMs1Datapoints && acquisitionResults.Ms2List.Count >= NumRequiredMs2Datapoints) + if (acquisitionResults.Psms.Count >= NumRequiredPsms && acquisitionResults.Ms1List.Count >= NumRequiredMs1Datapoints && acquisitionResults.Ms2List.Count >= NumRequiredMs2Datapoints) { // generate calibration function and shift data points @@ -200,8 +200,8 @@ private DataPointAquisitionResults GetDataAcquisitionResults(MsDataFile myMsData _ = new FdrAnalysisEngine(allPsms, searchMode.NumNotches, CommonParameters, FileSpecificParameters, new List { taskId, "Individual Spectra Files", fileNameWithoutExtension }, doPEP: false).Run(); - List goodIdentifications = allPsms.Where(b => - b.FdrInfo.QValueNotch < CalibrationParameters.QValueCutoffForCalibratingPSMs + List goodIdentifications = allPsms.Where(b => + b.FdrInfo.QValueNotch < CalibrationParameters.QValueCutoffForCalibratingPSMs && b.FullSequence != null && !b.IsDecoy).ToList(); diff --git a/MetaMorpheus/Test/EverythingRunnerEngineTestCase.cs b/MetaMorpheus/Test/EverythingRunnerEngineTestCase.cs index a907b3f5d..94fcd7de6 100644 --- a/MetaMorpheus/Test/EverythingRunnerEngineTestCase.cs +++ b/MetaMorpheus/Test/EverythingRunnerEngineTestCase.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; +using EngineLayer.FdrAnalysis; using Nett; using NUnit.Framework; using TaskLayer; @@ -59,13 +60,25 @@ internal EverythingRunnerEngineTestCase(EverythingRunnerEngineTestCases testCase WriteMzId = searchTask.SearchParameters.WriteMzId; } + public static Object myLock = new(); internal void Run() { if (Directory.Exists(OutputDirectory)) Directory.Delete(OutputDirectory, true); - var runner = new EverythingRunnerEngine(TaskList, DataFileList, DatabaseList, OutputDirectory); - runner.Run(); + lock (myLock) + { + System.Reflection.PropertyInfo property = null; + if (TestCase != EverythingRunnerEngineTestCases.TopDownQValue && TestCase != EverythingRunnerEngineTestCases.TopDownQValueSingle) + { + var type = typeof(FdrAnalysisEngine); + property = type.GetProperty("QvalueThresholdOverride"); + property.SetValue(null, true); + } + var runner = new EverythingRunnerEngine(TaskList, DataFileList, DatabaseList, OutputDirectory); + runner.Run(); + if (TestCase != EverythingRunnerEngineTestCases.TopDownQValue && TestCase != EverythingRunnerEngineTestCases.TopDownQValueSingle) property.SetValue(null, false); + } HasRun = true; } @@ -188,4 +201,3 @@ static EverythingRunnerEngineTestCase() } } - diff --git a/MetaMorpheus/Test/MatchIonsOfAllCharges.cs b/MetaMorpheus/Test/MatchIonsOfAllCharges.cs index 52ad3a44b..970500680 100644 --- a/MetaMorpheus/Test/MatchIonsOfAllCharges.cs +++ b/MetaMorpheus/Test/MatchIonsOfAllCharges.cs @@ -14,12 +14,10 @@ using System; using MassSpectrometry; using Nett; -using EngineLayer.Gptmd; using NUnit.Framework.Legacy; using Omics.Digestion; using Omics.Modifications; using Omics.SpectrumMatch; -using static System.Net.WebRequestMethods; namespace Test { @@ -421,11 +419,8 @@ public static void TestLibraryUpdate() string raw1 = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\TaGe_SA_HeLa_04_subset_longestSeq.mzML"); string raw2 = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\TaGe_SA_A549_3_snip.mzML"); string lib = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SpectralLibrarySearch\SpectralLibrary.msp"); - - string rawCopy = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SpectralLibrarySearch\UpdateLibrary\rawCopy.mzML"); System.IO.File.Copy(raw1, rawCopy); - EverythingRunnerEngine UpdateLibrary = new(new List<(string, MetaMorpheusTask)> { ("UpdateSpectraFileOutput", task) }, new List { raw1, raw2 }, new List { new DbForTask(lib, false), new DbForTask( db1,false), new DbForTask(db2, false) }, thisTaskOutputFolder); UpdateLibrary.Run(); @@ -483,7 +478,6 @@ public static void TestLibraryExistAfterGPTMDsearch() _ = Directory.CreateDirectory(thisTaskOutputFolder); SearchTask task = Toml.ReadFile(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SpectralLibrarySearch\SpectralSearchTask.toml"), MetaMorpheusTask.tomlConfig); - string db = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\hela_snip_for_unitTest.fasta"); string raw = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\TaGe_SA_HeLa_04_subset_longestSeq.mzML"); string lib = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SpectralLibrarySearch\SpectralLibrary.msp"); diff --git a/MetaMorpheus/Test/MetaDraw/MetaDrawTest.cs b/MetaMorpheus/Test/MetaDraw/MetaDrawTest.cs index 29c5b3686..427d62bf9 100644 --- a/MetaMorpheus/Test/MetaDraw/MetaDrawTest.cs +++ b/MetaMorpheus/Test/MetaDraw/MetaDrawTest.cs @@ -1028,8 +1028,6 @@ public static void MetaDraw_TestChimeraScanSpectrumDisplay() Directory.Delete(outputFolder, true); } - - [Test] public static void TestMetaDrawErrors() { @@ -1081,7 +1079,6 @@ public static void TestMetaDrawErrors() } [Test] - [NonParallelizable] public static void TestMetaDrawLoadingWithWeirdFileNames() { // test loading when the file has a periods, commas, spaces in the name diff --git a/MetaMorpheus/Test/MetaDraw/SpectrumMatchPlotTests.cs b/MetaMorpheus/Test/MetaDraw/SpectrumMatchPlotTests.cs index 2331545c0..b2741ab39 100644 --- a/MetaMorpheus/Test/MetaDraw/SpectrumMatchPlotTests.cs +++ b/MetaMorpheus/Test/MetaDraw/SpectrumMatchPlotTests.cs @@ -2,9 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using System.Threading; -using System.Threading.Tasks; using System.Windows.Controls; using EngineLayer; using GuiFunctions; @@ -31,6 +29,7 @@ public class SpectrumMatchPlotTests [OneTimeSetUp] public void Setup() { + outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"MetaDraw_PeakAnnotaitonTest"); string proteinDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\smalldb.fasta"); string spectraFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML"); diff --git a/MetaMorpheus/Test/PostSearchAnalysisTaskTests.cs b/MetaMorpheus/Test/PostSearchAnalysisTaskTests.cs index f01117297..f6b68a08a 100644 --- a/MetaMorpheus/Test/PostSearchAnalysisTaskTests.cs +++ b/MetaMorpheus/Test/PostSearchAnalysisTaskTests.cs @@ -2,7 +2,8 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; -using NUnit.Framework; using Assert = NUnit.Framework.Legacy.ClassicAssert; +using NUnit.Framework; +using Assert = NUnit.Framework.Legacy.ClassicAssert; namespace Test { @@ -49,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 @@ -110,7 +111,7 @@ public static void AllResultTxtContainsCorrectNumberOfResultLines(EverythingRunn { 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")); diff --git a/MetaMorpheus/Test/ProteinGroupTest.cs b/MetaMorpheus/Test/ProteinGroupTest.cs index 8df95e4e7..a1a1d0e5b 100644 --- a/MetaMorpheus/Test/ProteinGroupTest.cs +++ b/MetaMorpheus/Test/ProteinGroupTest.cs @@ -6,8 +6,6 @@ using Proteomics.ProteolyticDigestion; using MassSpectrometry; using Chemistry; -using EngineLayer.ClassicSearch; -using FlashLFQ; using TaskLayer; using ProteinGroup = EngineLayer.ProteinGroup; using System.IO; @@ -206,6 +204,7 @@ public static void TestModificationInfoListInProteinGroupsOutput() string mzmlName = @"TestData\PrunedDbSpectra.mzml"; string fastaName = @"TestData\DbForPrunedDb.fasta"; string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestPrunedGeneration"); + var engine = new EverythingRunnerEngine(taskList, new List { mzmlName }, new List { new DbForTask(fastaName, false) }, outputFolder); engine.Run(); string final = Path.Combine(MySetUpClass.outputFolder, "task2", "DbForPrunedDbGPTMDproteinPruned.xml"); diff --git a/MetaMorpheus/Test/QuantificationTest.cs b/MetaMorpheus/Test/QuantificationTest.cs index b004ec459..d0363872f 100644 --- a/MetaMorpheus/Test/QuantificationTest.cs +++ b/MetaMorpheus/Test/QuantificationTest.cs @@ -12,7 +12,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using Omics.Modifications; using TaskLayer; diff --git a/MetaMorpheus/Test/SearchEngineTests.cs b/MetaMorpheus/Test/SearchEngineTests.cs index fc4d3c62f..2d4bc2cbf 100644 --- a/MetaMorpheus/Test/SearchEngineTests.cs +++ b/MetaMorpheus/Test/SearchEngineTests.cs @@ -22,6 +22,7 @@ using TaskLayer; using UsefulProteomicsDatabases; using static Nett.TomlObjectFactory; +using EngineLayer.FdrAnalysis; namespace Test { @@ -66,8 +67,14 @@ public static void TestClassicSearchEngine() } [Test] + [NonParallelizable] public static void TestSearchEngineResultsPsmFromTsv() { + // only for unit test. must set to false at the end of each tests + var type = typeof(FdrAnalysisEngine); + var property = type.GetProperty("QvalueThresholdOverride"); + property.SetValue(null, true); + var myTomlPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\Task1-SearchTaskconfig.toml"); var searchTaskLoaded = Toml.ReadFile(myTomlPath, MetaMorpheusTask.tomlConfig); string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\TestConsistency"); @@ -116,6 +123,7 @@ public static void TestSearchEngineResultsPsmFromTsv() Assert.AreEqual("[2742 to 2761]", psm.StartAndEndResiduesInProtein); Assert.AreEqual(159644.25225, psm.TotalIonCurrent); Assert.AreEqual(0, psm.VariantCrossingIons.Count); + property.SetValue(null, false); } //tests a weird crash from ms2 scans that had experimental peaks but they were all removed from the xarray by XCorr processing @@ -145,11 +153,11 @@ public static void TestClassicSearchXcorrWithToml() List 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] @@ -548,7 +556,7 @@ public static void TestModernSearchEngineLowResOneRealSpectrum() List<(string fileName, CommonParameters fileSpecificParameters)> fsp = new List<(string fileName, CommonParameters fileSpecificParameters)> { ("filename", CommonParameters) }; - EngineLayer.FdrAnalysis.FdrAnalysisResults fdrResultsModernDelta = (EngineLayer.FdrAnalysis.FdrAnalysisResults)(new EngineLayer.FdrAnalysis.FdrAnalysisEngine(nonNullPsms, 1, CommonParameters, fsp, new List()).Run()); + FdrAnalysisResults fdrResultsModernDelta = (FdrAnalysisResults)(new FdrAnalysisEngine(nonNullPsms, 1, CommonParameters, fsp, new List()).Run()); // Single search mode Assert.AreEqual(12, allPsmsArray.Length); @@ -565,8 +573,15 @@ public static void TestModernSearchEngineLowResOneRealSpectrum() } [Test] + [NonParallelizable] public static void TestClassicSearchEngineLowResSimple() { + //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 origDataFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\TaGe_SA_A549_3_snip.mzML"); MyFileManager myFileManager = new MyFileManager(true); @@ -651,7 +666,7 @@ public static void TestClassicSearchEngineLowResSimple() var nonNullPsms = allPsmsArray.Where(p => p != null).ToList(); Assert.AreEqual(432, nonNullPsms.Count); //if you run the test separately, it will be 111 because mods won't have been read in a previous test... - EngineLayer.FdrAnalysis.FdrAnalysisResults fdrResultsModernDelta = (EngineLayer.FdrAnalysis.FdrAnalysisResults)(new EngineLayer.FdrAnalysis.FdrAnalysisEngine(nonNullPsms, 1, CommonParameters, fsp, new List()).Run()); + FdrAnalysisResults fdrResultsModernDelta = (FdrAnalysisResults)(new FdrAnalysisEngine(nonNullPsms, 1, CommonParameters, fsp, new List()).Run()); // Single search mode Assert.AreEqual(535, allPsmsArray.Length); @@ -660,11 +675,19 @@ public static void TestClassicSearchEngineLowResSimple() Assert.AreEqual(181, goodScore.Count()); Directory.Delete(outputFolder, true); + property.SetValue(null, false); } [Test] + [NonParallelizable] public static void TestModernSearchEngineLowResSimple() { + //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 origDataFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\TaGe_SA_A549_3_snip.mzML"); MyFileManager myFileManager = new MyFileManager(true); @@ -751,6 +774,7 @@ public static void TestModernSearchEngineLowResSimple() var goodScore = nonNullPsms.Where(p => p.FdrInfo.QValue <= 0.01).Select(s => s.Score).ToList(); Assert.AreEqual(181, goodScore.Count()); + property.SetValue(null, false); } [Test] diff --git a/MetaMorpheus/Test/SearchTaskTest.cs b/MetaMorpheus/Test/SearchTaskTest.cs index 221f0fb3c..88b06d1d4 100644 --- a/MetaMorpheus/Test/SearchTaskTest.cs +++ b/MetaMorpheus/Test/SearchTaskTest.cs @@ -1,19 +1,18 @@ using EngineLayer; using MassSpectrometry; using MzLibUtil; -using NUnit.Framework; using Assert = NUnit.Framework.Legacy.ClassicAssert; +using NUnit.Framework; +using Assert = NUnit.Framework.Legacy.ClassicAssert; using Proteomics; using Omics.Fragmentation; using Proteomics.ProteolyticDigestion; using System; using System.Collections.Generic; -using System.Globalization; using System.IO; using System.Linq; using Omics.Digestion; using Omics.Modifications; using TaskLayer; -using Org.BouncyCastle.Asn1.X509; namespace Test { @@ -88,6 +87,7 @@ public static void ParseSearchModeTest() [Test] public static void SemiSpecificFullAndSmallMatches() { + SearchTask searchTask = new SearchTask() { diff --git a/MetaMorpheus/Test/SilacTest.cs b/MetaMorpheus/Test/SilacTest.cs index bdfc70c27..ea3d0bac9 100644 --- a/MetaMorpheus/Test/SilacTest.cs +++ b/MetaMorpheus/Test/SilacTest.cs @@ -1,6 +1,7 @@ using EngineLayer; using MassSpectrometry; -using NUnit.Framework; using Assert = NUnit.Framework.Legacy.ClassicAssert; +using NUnit.Framework; +using Assert = NUnit.Framework.Legacy.ClassicAssert; using Proteomics; using Proteomics.AminoAcidPolymer; using Proteomics.ProteolyticDigestion; diff --git a/MetaMorpheus/Test/TestData/Task1-SearchTaskconfig.toml b/MetaMorpheus/Test/TestData/Task1-SearchTaskconfig.toml index 1b1b8022c..3f0189708 100644 --- a/MetaMorpheus/Test/TestData/Task1-SearchTaskconfig.toml +++ b/MetaMorpheus/Test/TestData/Task1-SearchTaskconfig.toml @@ -80,4 +80,4 @@ MaxModsForPeptide = 2 Protease = "trypsin" SearchModeType = "Full" FragmentationTerminus = "Both" -SpecificProtease = "trypsin" +SpecificProtease = "trypsin" \ No newline at end of file diff --git a/MetaMorpheus/Test/TestData/Task2-SearchTaskconfig.toml b/MetaMorpheus/Test/TestData/Task2-SearchTaskconfig.toml index 4045885e8..b89f45d45 100644 --- a/MetaMorpheus/Test/TestData/Task2-SearchTaskconfig.toml +++ b/MetaMorpheus/Test/TestData/Task2-SearchTaskconfig.toml @@ -80,4 +80,4 @@ MaxModsForPeptide = 2 Protease = "trypsin" SearchModeType = "Full" FragmentationTerminus = "Both" -SpecificProtease = "trypsin" +SpecificProtease = "trypsin" \ No newline at end of file diff --git a/MetaMorpheus/Test/TestOGlyco.cs b/MetaMorpheus/Test/TestOGlyco.cs index 886ab208a..1ecb85dca 100644 --- a/MetaMorpheus/Test/TestOGlyco.cs +++ b/MetaMorpheus/Test/TestOGlyco.cs @@ -17,11 +17,8 @@ using SpectralAveraging; using NUnit.Framework.Legacy; using Omics.Modifications; -using ThermoFisher.CommonCore.BackgroundSubtraction; using Easy.Common.Extensions; -using iText.IO.Font.Otf; using static Nett.TomlObjectFactory; -using Omics.SpectrumMatch; using TopDownProteomics; using MzLibUtil; @@ -32,7 +29,6 @@ public class TestOGlyco { private static GlycanBox[] OGlycanBoxes { get; set; } - [OneTimeSetUp] public static void Setup() { @@ -57,7 +53,6 @@ public static void OGlycanTest_GetGlycanBox_Decoy() var group_target = OGlycanBoxes_withDecoys.GroupBy(p => p.TargetDecoy == true); var group_decoy = OGlycanBoxes_withDecoys.GroupBy(p => p.TargetDecoy == false); Assert.That(group_target.Count() == group_decoy.Count()); - } [Test] @@ -117,14 +112,11 @@ public static void OGlycanTest_IsobaricCase() var glycanLevel_filterON = PsmTsvReader.ReadTsv(oGlycoPath, out var error) //load the PSMs data from the "csv file" and bulid the objects .Where(p => p.Ms2ScanNumber == 161 && p.BaseSeq == "HTSVQTTSSGSGPFTDVR").ToList()[0].GlycanLocalizationLevel; - Assert.That(glycanLevel_filterON == EngineLayer.GlycoSearch.LocalizationLevel.Level1); Directory.Delete(outputFolder, true); } - - [Test] public static void GlycoSpectralHeader() { @@ -201,7 +193,6 @@ public static void OGlycoTest_OGlycanChildIons() var testGlycanIons_smallGlycan = GlycanDatabase.OGlycanCompositionFragments(testKind_smallGlycan); - } [Test] @@ -487,7 +478,6 @@ public static void OGlycoTest_Localization2() } HashSet allPeaks = new HashSet(binsToSearch); - //Graph Localization LocalizationGraph localizationGraph = new LocalizationGraph(modPos, glycanBox, boxes, -1); @@ -911,7 +901,6 @@ public static void GlycoTestWithBadExperimentalDesignFile() Assert.That(errors[0].Contains("Condition \"condition1\" biorep 1 fraction 1 techrep 1 is missing!")); Assert.That(readIn.Count == 2); - new EverythingRunnerEngine(new List<(string, MetaMorpheusTask)> { ("Task", glycoSearchTask) }, new List { spectraFile1, spectraFile2 }, new List { db }, outputFolder).Run(); List expectedOutput = new() @@ -926,7 +915,6 @@ public static void GlycoTestWithBadExperimentalDesignFile() "seen_oglyco_localization.tsv" }; - List expectedIndividualFileOutput = new() { "171025_06subset_1_AllProteinGroups.tsv", @@ -1144,8 +1132,6 @@ public static void GlycoSearchIndividualFileFolderOutputTest() "2019_09_16_StcEmix_35trig_EThcD25_rep1_4999-5968seen_oglyco_localization.tsv" }; - - List output = Directory.GetFiles(outputFolder).Select(f => Path.GetFileName(f)).ToList(); List outputFolders = Directory.GetDirectories(outputFolder).ToList(); List individualOutputFolders = Directory.GetDirectories(outputFolders.FirstOrDefault()).ToList(); @@ -1213,8 +1199,6 @@ public static void NandO_GlycoSearchIndividualFileFolderOutputTest() "2019_09_16_StcEmix_35trig_EThcD25_rep1_4999-5968seen_no_glyco_localization.tsv" }; - - List output = Directory.GetFiles(outputFolder).Select(f => Path.GetFileName(f)).ToList(); List outputFolders = Directory.GetDirectories(outputFolder).ToList(); List individualOutputFolders = Directory.GetDirectories(outputFolders.FirstOrDefault()).ToList(); @@ -1336,7 +1320,6 @@ public static void TestGlycoQuant() Assert.That(!errors.Any()); Assert.That(readIn.Count == 2); - new EverythingRunnerEngine(new List<(string, MetaMorpheusTask)> { ("Task", glycoSearchTask) }, new List { spectraFile1, spectraFile2 }, new List { db }, outputFolder).Run(); List expectedOutput = new() @@ -1354,7 +1337,6 @@ public static void TestGlycoQuant() "seen_oglyco_localization.tsv" }; - List expectedIndividualFileOutput = new() { "171025_06subset_1_AllProteinGroups.tsv", @@ -1367,7 +1349,6 @@ public static void TestGlycoQuant() "171025_06subset_1seen_oglyco_localization.tsv", }; - string outputFolderWithTask = Path.Combine(outputFolder, "Task"); List output = Directory.GetFiles(outputFolderWithTask).Select(f => Path.GetFileName(f)).ToList(); List outputFolders = Directory.GetDirectories(outputFolderWithTask).ToList(); @@ -1416,7 +1397,6 @@ public static void TestGlycoQuant2() Assert.That(!errors.Any()); Assert.That(readIn.Count == 2); - new EverythingRunnerEngine(new List<(string, MetaMorpheusTask)> { ("Task", glycoSearchTask) }, new List { spectraFile1, spectraFile2 }, new List { db }, outputFolder).Run(); List expectedOutput = new() @@ -1433,7 +1413,6 @@ public static void TestGlycoQuant2() "seen_oglyco_localization.tsv" }; - List expectedIndividualFileOutput = new() { "171025_06subset_1_AllPSMs.psmtsv", @@ -1445,7 +1424,6 @@ public static void TestGlycoQuant2() "171025_06subset_1seen_oglyco_localization.tsv", }; - string outputFolderWithTask = Path.Combine(outputFolder, "Task"); List output = Directory.GetFiles(outputFolderWithTask).Select(f => Path.GetFileName(f)).ToList(); List outputFolders = Directory.GetDirectories(outputFolderWithTask).ToList(); diff --git a/MetaMorpheus/Test/TestPsm.cs b/MetaMorpheus/Test/TestPsm.cs index f3921c997..3a2c7546f 100644 --- a/MetaMorpheus/Test/TestPsm.cs +++ b/MetaMorpheus/Test/TestPsm.cs @@ -108,6 +108,7 @@ public static void TestQValueFilter() [Test] public static void TestPpmAndDaMassErrors() { + var variableModifications = new List(); var fixedModifications = new List(); var origDataFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\TaGe_SA_HeLa_04_subset_longestSeq.mzML"); diff --git a/MetaMorpheus/Test/TestToml.cs b/MetaMorpheus/Test/TestToml.cs index ed848c8d0..514b26018 100644 --- a/MetaMorpheus/Test/TestToml.cs +++ b/MetaMorpheus/Test/TestToml.cs @@ -1,11 +1,8 @@ -using Chemistry; -using EngineLayer; -using EngineLayer.ClassicSearch; +using EngineLayer; using MassSpectrometry; using MzLibUtil; using Nett; using NUnit.Framework; using Assert = NUnit.Framework.Legacy.ClassicAssert; -using Proteomics; using Proteomics.ProteolyticDigestion; using System.Collections.Generic; using System.IO; @@ -14,7 +11,6 @@ using Omics.Fragmentation; using SpectralAveraging; using TaskLayer; -using UsefulProteomicsDatabases; namespace Test { @@ -136,6 +132,7 @@ public static void TestTomlForSpecficFiles() [Test] public static void TestBadFileSpecificProtease() { + //this test checks for a catch statement (or some other handling) for file-specific toml loading //create a toml with a protease that doesn't exist in the protease.tsv dictionary string proteaseNotInDictionary = "aaa"; //arbitrary. If somebody adds a protease with this name, use a different name diff --git a/MetaMorpheus/Test/XLTest.cs b/MetaMorpheus/Test/XLTest.cs index 515dd1c43..de9c1a72d 100644 --- a/MetaMorpheus/Test/XLTest.cs +++ b/MetaMorpheus/Test/XLTest.cs @@ -366,8 +366,15 @@ public static void TestCsmSort() } [Test] + [NonParallelizable] public static void XlTest_MoreComprehensive() { + //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); + //Generate parameters var commonParameters = new CommonParameters(doPrecursorDeconvolution: false, dissociationType: DissociationType.HCD, scoreCutoff: 1, digestionParams: new DigestionParams(minPeptideLength: 5), precursorMassTolerance: new PpmTolerance(10), maxThreadsToUsePerFile: 1); @@ -749,7 +756,7 @@ public static void XlTest_MoreComprehensive() Assert.AreEqual(loopCsmPsmData.BetaIntensity, 0); Assert.That(loopCsmPsmData.ComplementaryIonCount, Is.EqualTo(3).Within(0.1)); Assert.That(loopCsmPsmData.DeltaScore, Is.EqualTo(8).Within(0.1)); - Assert.That(loopCsmPsmData.HydrophobicityZScore, Is.EqualTo(1).Within(0.1)); + Assert.That(loopCsmPsmData.HydrophobicityZScore, Is.EqualTo(9).Within(0.1)); Assert.That(loopCsmPsmData.Intensity, Is.EqualTo(1).Within(0.1)); Assert.AreEqual(loopCsmPsmData.IsDeadEnd, 0); Assert.AreEqual(loopCsmPsmData.IsInter, 0); @@ -822,11 +829,13 @@ public static void XlTest_MoreComprehensive() Assert.AreEqual(40, inter); Assert.AreEqual(49, intra); Assert.AreEqual(231, single); - Assert.AreEqual(8, loop); + Assert.AreEqual(0, loop); Assert.AreEqual(0, deadend); - Assert.AreEqual(61, deadendH2O); + Assert.AreEqual(0, deadendH2O); Assert.AreEqual(0, deadendNH2); Assert.AreEqual(0, deadendTris); + + property.SetValue(null, false); } [Test]