Skip to content

Commit

Permalink
eliminate nunit legacy code (#2438)
Browse files Browse the repository at this point in the history
* lets try a little change

* k

* f

* tmt

* h

* thru parameter

* thru search engine tests

* thru stefan

* done cross your fingers
  • Loading branch information
trishorts authored Nov 13, 2024
1 parent 5463646 commit 14ef43d
Show file tree
Hide file tree
Showing 61 changed files with 1,480 additions and 1,565 deletions.
68 changes: 30 additions & 38 deletions MetaMorpheus/Test/AddCompIonsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
using EngineLayer.ModernSearch;
using MassSpectrometry;
using MzLibUtil;
using NUnit.Framework; using Assert = NUnit.Framework.Legacy.ClassicAssert;
using NUnit.Framework;
using Proteomics;
using Omics.Fragmentation;
using Proteomics.ProteolyticDigestion;
using Proteomics.RetentionTimePrediction;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down Expand Up @@ -70,16 +68,13 @@ public static void TestAddCompIonsClassic()
double scoreF = allPsmsArray[0].Score;

// Single search mode
Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length);
Assert.That(allPsmsArray.Length, Is.EqualTo(allPsmsArray2.Length));

// Single ms2 scan
Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length);

Assert.IsTrue(scoreT > 1);

Assert.AreEqual(allPsmsArray[0].ScanNumber, allPsmsArray2[0].ScanNumber);

Assert.IsTrue(scoreT == scoreF * 3 && scoreT > scoreF + 2);
Assert.That(allPsmsArray.Length, Is.EqualTo(allPsmsArray2.Length));
Assert.That(scoreT > 1);
Assert.That(allPsmsArray[0].ScanNumber, Is.EqualTo(allPsmsArray2[0].ScanNumber));
Assert.That(scoreT == scoreF * 3 && scoreT > scoreF + 2);
}

[Test]
Expand Down Expand Up @@ -145,18 +140,15 @@ public static void TestCompIons_ModernSearch()
new ModernSearchEngine(allPsmsArray2, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, withCompIons, fspComp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List<string>()).Run();

// Single search mode
Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length);
Assert.That(allPsmsArray.Length, Is.EqualTo(allPsmsArray2.Length));

// Single ms2 scan
Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length);
Assert.That(allPsmsArray.Length, Is.EqualTo(allPsmsArray2.Length));
Assert.That(allPsmsArray[0] != null);
Assert.That(allPsmsArray2[0] != null);

Assert.IsTrue(allPsmsArray2[0].Score > 1);

Assert.AreEqual(allPsmsArray[0].ScanNumber, allPsmsArray2[0].ScanNumber);

Assert.IsTrue(allPsmsArray2[0].Score <= allPsmsArray[0].Score * 2 && allPsmsArray2[0].Score > allPsmsArray[0].Score + 3);
Assert.That(allPsmsArray2[0].Score > 1);
Assert.That(allPsmsArray[0].ScanNumber, Is.EqualTo(allPsmsArray2[0].ScanNumber));
Assert.That(allPsmsArray2[0].Score <= allPsmsArray[0].Score * 2 && allPsmsArray2[0].Score > allPsmsArray[0].Score + 3);
ProteaseDictionary.Dictionary.Remove(protease.Name);
}

Expand Down Expand Up @@ -223,16 +215,16 @@ public static void TestCompIons_ETHCD_ModernSearch()
new ModernSearchEngine(allPsmsArray2, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, withCompIons, fspComp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List<string>()).Run();

// Single search mode
Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length);
Assert.That(allPsmsArray.Length, Is.EqualTo(allPsmsArray2.Length));

// Single ms2 scan
Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length);
Assert.That(allPsmsArray.Length, Is.EqualTo(allPsmsArray2.Length));
Assert.That(allPsmsArray[0] != null);
Assert.That(allPsmsArray2[0] != null);

Assert.IsTrue(allPsmsArray2[0].Score > 1);
Assert.That(allPsmsArray2[0].Score > 1);

Assert.AreEqual(allPsmsArray[0].ScanNumber, allPsmsArray2[0].ScanNumber);
Assert.That(allPsmsArray[0].ScanNumber, Is.EqualTo(allPsmsArray2[0].ScanNumber));
Assert.That(allPsmsArray2[0].Score, Is.EqualTo(7.007).Within(0.001));
ProteaseDictionary.Dictionary.Remove(protease.Name);
}
Expand Down Expand Up @@ -300,17 +292,17 @@ public static void TestCompIons_LowCID_ModernSearch()
new ModernSearchEngine(allPsmsArray2, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, withCompIons, fspComp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List<string>()).Run();

// Single search mode
Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length);
Assert.That(allPsmsArray.Length, Is.EqualTo(allPsmsArray2.Length));

// Single ms2 scan
Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length);
Assert.That(allPsmsArray.Length, Is.EqualTo(allPsmsArray2.Length));
Assert.That(allPsmsArray[0] != null);
Assert.That(allPsmsArray2[0] != null);

Assert.IsTrue(allPsmsArray2[0].Score > 1);
Assert.That(allPsmsArray2[0].Score > 1);

Assert.AreEqual(allPsmsArray[0].ScanNumber, allPsmsArray2[0].ScanNumber);
Assert.IsTrue(allPsmsArray2[0].Score <= allPsmsArray[0].Score * 2 && allPsmsArray2[0].Score > allPsmsArray[0].Score + 2);
Assert.That(allPsmsArray[0].ScanNumber, Is.EqualTo(allPsmsArray2[0].ScanNumber));
Assert.That(allPsmsArray2[0].Score <= allPsmsArray[0].Score * 2 && allPsmsArray2[0].Score > allPsmsArray[0].Score + 2);
ProteaseDictionary.Dictionary.Remove(protease.Name);
}

Expand Down Expand Up @@ -340,7 +332,7 @@ public static void TestCompIons_MatchIonsScore()
double localizedScore = MetaMorpheusEngine.CalculatePeptideScore(scan, matchedIons);
double scoreNormal = MetaMorpheusEngine.CalculatePeptideScore(scan, matchedIons);
double scoreComp = MetaMorpheusEngine.CalculatePeptideScore(scan, matchedCompIons);
Assert.IsTrue(scoreNormal * 2 == scoreComp && scoreComp > scoreNormal + 1);
Assert.That(scoreNormal * 2 == scoreComp && scoreComp > scoreNormal + 1);
}

[Test]
Expand All @@ -367,23 +359,23 @@ public static void TestCompIons_MatchIons()
//MetaMorpheusEngine.MatchIons(t.GetOneBasedScan(2), productMassTolerance, sorted_theoretical_product_masses_for_this_peptide, matchedIonSeriesF, matchedIonMassesF, matchedDaErrorF, matchedPpmErrorF, matchedIonIntensityF, precursorMass, ProductType.B, false);

//Test the number of series is doubled
Assert.IsTrue(matchedIonSeriesT.Count == matchedIonSeriesF.Count * 2);
Assert.That(matchedIonSeriesT.Count == matchedIonSeriesF.Count * 2);
//Test the number of ions is doubled
Assert.IsTrue(matchedIonMassesT.Count == matchedIonMassesF.Count * 2);
Assert.That(matchedIonMassesT.Count == matchedIonMassesF.Count * 2);
//Test the number of da errors is doubled
Assert.IsTrue(matchedDaErrorT.Count == matchedDaErrorF.Count * 2);
Assert.That(matchedDaErrorT.Count == matchedDaErrorF.Count * 2);
//test the number of ppm errors is doubled
Assert.IsTrue(matchedPpmErrorT.Count == matchedPpmErrorF.Count * 2);
Assert.That(matchedPpmErrorT.Count == matchedPpmErrorF.Count * 2);
//test the number of the intensity values is doubled
Assert.IsTrue(matchedIonIntensityT.Count == matchedIonIntensityF.Count * 2);
Assert.That(matchedIonIntensityT.Count == matchedIonIntensityF.Count * 2);
foreach (double d in matchedDaErrorF)
{
Assert.IsTrue(d <= 0.01);
Assert.That(d <= 0.01);
}

foreach (double d in matchedDaErrorT)
{
Assert.IsTrue(d <= 0.01);
Assert.That(d <= 0.01);
}
}

Expand Down Expand Up @@ -460,8 +452,8 @@ public static void AddCompIonsMzOutput()
//A fix was introduced to save a "fake" m/z for the added ion
foreach(MatchedFragmentIon ion in matchedIons)
{
Assert.IsTrue(ion.NeutralTheoreticalProduct.NeutralMass < ion.Mz);
Assert.IsTrue(ion.NeutralTheoreticalProduct.NeutralMass + 2 > ion.Mz);
Assert.That(ion.NeutralTheoreticalProduct.NeutralMass < ion.Mz);
Assert.That(ion.NeutralTheoreticalProduct.NeutralMass + 2 > ion.Mz);
}

}
Expand Down
55 changes: 27 additions & 28 deletions MetaMorpheus/Test/AmbiguityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
using EngineLayer;
using EngineLayer.ClassicSearch;
using MzLibUtil;
using NUnit.Framework; using Assert = NUnit.Framework.Legacy.ClassicAssert;
using NUnit.Framework;
using Proteomics;
using Omics.Fragmentation;
using Proteomics.ProteolyticDigestion;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -65,12 +64,12 @@ public static void TestResolveAmbiguities()
new ClassicSearchEngine(allPsmsArray_withOutAmbiguity, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
proteinList, searchModes, CommonParameters_f, fsp_f, null, new List<string>(), writeSpectralLibrary).Run(); //report all ambiguity FALSE

Assert.AreEqual("QQQ", allPsmsArray_withAmbiguity[0].BaseSequence);
Assert.AreEqual("QQQ", allPsmsArray_withOutAmbiguity[0].BaseSequence);
Assert.IsTrue(allPsmsArray_withAmbiguity[0].ParentLength == null);
Assert.IsTrue(allPsmsArray_withOutAmbiguity[0].ParentLength != null);
Assert.IsTrue(allPsmsArray_withAmbiguity[0].OneBasedStartResidue == null);
Assert.IsTrue(allPsmsArray_withOutAmbiguity[0].OneBasedStartResidue != null);
Assert.That(allPsmsArray_withAmbiguity[0].BaseSequence, Is.EqualTo("QQQ"));
Assert.That(allPsmsArray_withOutAmbiguity[0].BaseSequence, Is.EqualTo("QQQ"));
Assert.That(allPsmsArray_withAmbiguity[0].ParentLength == null);
Assert.That(allPsmsArray_withOutAmbiguity[0].ParentLength != null);
Assert.That(allPsmsArray_withAmbiguity[0].OneBasedStartResidue == null);
Assert.That(allPsmsArray_withOutAmbiguity[0].OneBasedStartResidue != null);
}

[Test]
Expand Down Expand Up @@ -104,8 +103,8 @@ public static void TestContaminantAmbiguity()

var headerSplits = SpectralMatch.GetTabSeparatedHeader().Split('\t');
string[] splitLine = psmLine.Split('\t');
Assert.IsTrue(splitLine[Array.IndexOf(headerSplits, PsmTsvHeader.Contaminant)].Equals("N|Y")); //column "Contaminant"
Assert.IsTrue(splitLine[Array.IndexOf(headerSplits, PsmTsvHeader.DecoyContaminantTarget)].Equals("T|C")); //column "Decoy/Contaminant/Target"
Assert.That(splitLine[Array.IndexOf(headerSplits, PsmTsvHeader.Contaminant)].Equals("N|Y")); //column "Contaminant"
Assert.That(splitLine[Array.IndexOf(headerSplits, PsmTsvHeader.DecoyContaminantTarget)].Equals("T|C")); //column "Decoy/Contaminant/Target"


//KEEP ONLY TARGET
Expand All @@ -123,8 +122,8 @@ public static void TestContaminantAmbiguity()
//check that the psm file shows it's both a target and a contaminant
psmLine = File.ReadAllLines(Path.Combine(outputFolder, "task1", "AllPSMs.psmtsv"))[1];
splitLine = psmLine.Split('\t');
Assert.IsTrue(splitLine[Array.IndexOf(headerSplits, PsmTsvHeader.Contaminant)].Equals("N")); //column "Contaminant"
Assert.IsTrue(splitLine[Array.IndexOf(headerSplits, PsmTsvHeader.DecoyContaminantTarget)].Equals("T")); //column "Decoy/Contaminant/Target"
Assert.That(splitLine[Array.IndexOf(headerSplits, PsmTsvHeader.Contaminant)].Equals("N")); //column "Contaminant"
Assert.That(splitLine[Array.IndexOf(headerSplits, PsmTsvHeader.DecoyContaminantTarget)].Equals("T")); //column "Decoy/Contaminant/Target"


//KEEP ONLY CONTAMINANT
Expand All @@ -142,8 +141,8 @@ public static void TestContaminantAmbiguity()
//check that the psm file shows it's both a target and a contaminant
psmLine = File.ReadAllLines(Path.Combine(outputFolder, "task1", "AllPSMs.psmtsv"))[1];
splitLine = psmLine.Split('\t');
Assert.IsTrue(splitLine[Array.IndexOf(headerSplits, PsmTsvHeader.Contaminant)].Equals("Y")); //column "Contaminant"
Assert.IsTrue(splitLine[Array.IndexOf(headerSplits, PsmTsvHeader.DecoyContaminantTarget)].Equals("C")); //column "Decoy/Contaminant/Target"
Assert.That(splitLine[Array.IndexOf(headerSplits, PsmTsvHeader.Contaminant)].Equals("Y")); //column "Contaminant"
Assert.That(splitLine[Array.IndexOf(headerSplits, PsmTsvHeader.DecoyContaminantTarget)].Equals("C")); //column "Decoy/Contaminant/Target"


Directory.Delete(outputFolder, true);
Expand All @@ -161,21 +160,21 @@ public static void TestDatabaseSanitizationPrioritizesXml()
Protein xmlProtein = new Protein("APEPTIDE", "Test", oneBasedModifications: new Dictionary<int, List<Modification>> { { 1, new List<Modification> { mod } } });
List<Protein> proteins = new List<Protein> { fastaProtein, xmlProtein };
SanitizeProteinDatabase(proteins, TargetContaminantAmbiguity.RemoveTarget);
Assert.IsTrue(proteins.Count == 1);
Assert.IsTrue(proteins.First().OneBasedPossibleLocalizedModifications.Count != 0);
Assert.That(proteins.Count == 1);
Assert.That(proteins.First().OneBasedPossibleLocalizedModifications.Count != 0);

//reverse order and try again
proteins = new List<Protein> { xmlProtein, fastaProtein };
SanitizeProteinDatabase(proteins, TargetContaminantAmbiguity.RemoveTarget);
Assert.IsTrue(proteins.Count == 1);
Assert.IsTrue(proteins.First().OneBasedPossibleLocalizedModifications.Count != 0);
Assert.That(proteins.Count == 1);
Assert.That(proteins.First().OneBasedPossibleLocalizedModifications.Count != 0);

//same with no mods
xmlProtein = new Protein("APEPTIDE", "Test", proteolysisProducts: new List<ProteolysisProduct> { new ProteolysisProduct(1, 3, "zrWuzHere") });
proteins = new List<Protein> { xmlProtein, fastaProtein };
SanitizeProteinDatabase(proteins, TargetContaminantAmbiguity.RemoveTarget);
Assert.IsTrue(proteins.Count == 1);
Assert.IsTrue(proteins.First().ProteolysisProducts.Count() != 0);
Assert.That(proteins.Count == 1);
Assert.That(proteins.First().ProteolysisProducts.Count() != 0);
}

[Test]
Expand All @@ -189,17 +188,17 @@ public static void TestDatabaseSanitizationRemovesDecoys()
Protein cDecoyProtein = new Protein("AEDITPEP", "DECOY_Test");
List<Protein> proteins = new List<Protein> { targetProtein, contaminantProtein, tDecoyProtein, cDecoyProtein }; //two decoys, one for target, one for contaminant
SanitizeProteinDatabase(proteins, TargetContaminantAmbiguity.RemoveContaminant);
Assert.IsTrue(proteins.Count == 2);
Assert.IsTrue(!proteins[0].IsContaminant); //forward is target
Assert.IsTrue(proteins[0].OneBasedPossibleLocalizedModifications.Count == 1);
Assert.IsTrue(proteins[1].OneBasedPossibleLocalizedModifications.Count == 1);
Assert.That(proteins.Count == 2);
Assert.That(!proteins[0].IsContaminant); //forward is target
Assert.That(proteins[0].OneBasedPossibleLocalizedModifications.Count == 1);
Assert.That(proteins[1].OneBasedPossibleLocalizedModifications.Count == 1);

proteins = new List<Protein> { targetProtein, contaminantProtein, tDecoyProtein, cDecoyProtein }; //two decoys, one for target, one for contaminant
SanitizeProteinDatabase(proteins, TargetContaminantAmbiguity.RemoveTarget);
Assert.IsTrue(proteins.Count == 2);
Assert.IsTrue(proteins[0].IsContaminant); //forward is contaminant
Assert.IsTrue(proteins[0].OneBasedPossibleLocalizedModifications.Count == 0); //contaminant doesn't have mods
Assert.IsTrue(proteins[1].OneBasedPossibleLocalizedModifications.Count == 1); //would be cool if this was 0 and we could keep the correct decoy, but kind of an edge case
Assert.That(proteins.Count == 2);
Assert.That(proteins[0].IsContaminant); //forward is contaminant
Assert.That(proteins[0].OneBasedPossibleLocalizedModifications.Count == 0); //contaminant doesn't have mods
Assert.That(proteins[1].OneBasedPossibleLocalizedModifications.Count == 1); //would be cool if this was 0 and we could keep the correct decoy, but kind of an edge case
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions MetaMorpheus/Test/AnalysisEngineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using EngineLayer.HistogramAnalysis;
using MassSpectrometry;
using MzLibUtil;
using NUnit.Framework; using Assert = NUnit.Framework.Legacy.ClassicAssert;
using NUnit.Framework;
using Proteomics;
using Omics.Fragmentation;
using Proteomics.ProteolyticDigestion;
Expand Down Expand Up @@ -60,17 +60,17 @@ public static void TestAnalysisEngineTests()
HashSet<PeptideWithSetModifications> value1 = new HashSet<PeptideWithSetModifications> { modPep };
PeptideWithSetModifications compactPeptide1 = value1.First();

Assert.AreEqual("QQQ", value1.First().BaseSequence);
Assert.That(value1.First().BaseSequence, Is.EqualTo("QQQ"));
var modPep2 = proteinList.First().Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).First();
HashSet<PeptideWithSetModifications> value2 = new HashSet<PeptideWithSetModifications> { modPep2 };
PeptideWithSetModifications compactPeptide2 = value2.First();

Assert.AreEqual("MNNNK", value2.First().BaseSequence);
Assert.That(value2.First().BaseSequence, Is.EqualTo("MNNNK"));

var modPep3 = proteinList.First().Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[1];
HashSet<PeptideWithSetModifications> value3 = new HashSet<PeptideWithSetModifications> { modPep3 };
PeptideWithSetModifications compactPeptide3 = value3.First();
Assert.AreEqual("NNNK", value3.First().BaseSequence);
Assert.That(value3.First().BaseSequence, Is.EqualTo("NNNK"));


Ms2ScanWithSpecificMass scanA = new Ms2ScanWithSpecificMass(new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 2, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 1, null), 1, 1, null, new CommonParameters());
Expand All @@ -94,7 +94,7 @@ public static void TestAnalysisEngineTests()

Action<BinTreeStructure, string> action1 = (BinTreeStructure l, string s) =>
{
Assert.AreEqual(1, l.FinalBins.Count);
Assert.That(l.FinalBins.Count, Is.EqualTo(1));
};

FdrAnalysisEngine engine = new FdrAnalysisEngine(newPsms, searchMode.NumNotches, CommonParameters, fsp, new List<string> { "ff" });
Expand Down
6 changes: 1 addition & 5 deletions MetaMorpheus/Test/AveragingGuiComponentsTest.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using GuiFunctions;
using NUnit.Framework; using Assert = NUnit.Framework.Legacy.ClassicAssert;
using NUnit.Framework;
using SpectralAveraging;

namespace Test
Expand Down
4 changes: 1 addition & 3 deletions MetaMorpheus/Test/AveragingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
using System.Linq;
using EngineLayer;
using FlashLFQ;
using GuiFunctions;
using MassSpectrometry;
using NUnit.Framework; using Assert = NUnit.Framework.Legacy.ClassicAssert;
using Readers;
using NUnit.Framework;
using SpectralAveraging;
using TaskLayer;
using Mzml = IO.MzML.Mzml;
Expand Down
Loading

0 comments on commit 14ef43d

Please sign in to comment.