diff --git a/mzLib/Readers/SearchResults/PsmFromTsvFile.cs b/mzLib/Readers/SearchResults/PsmFromTsvFile.cs index 5b1dbf482..74dfcf953 100644 --- a/mzLib/Readers/SearchResults/PsmFromTsvFile.cs +++ b/mzLib/Readers/SearchResults/PsmFromTsvFile.cs @@ -4,7 +4,7 @@ namespace Readers; public class PsmFromTsvFile : ResultFile, IResultFile { - public override SupportedFileType FileType { get; } + public override SupportedFileType FileType => SupportedFileType.psmtsv; public override Software Software { get; set; } /// @@ -12,10 +12,7 @@ public class PsmFromTsvFile : ResultFile, IResultFile /// public PsmFromTsvFile() : base() { } - public PsmFromTsvFile(string filePath) : base(filePath, Software.MetaMorpheus) - { - - } + public PsmFromTsvFile(string filePath) : base(filePath, Software.MetaMorpheus) { } public override void LoadResults() { diff --git a/mzLib/Readers/SearchResults/SpectrumMatchFromTsvFile.cs b/mzLib/Readers/SearchResults/SpectrumMatchFromTsvFile.cs index 65e597bc7..c5282edfa 100644 --- a/mzLib/Readers/SearchResults/SpectrumMatchFromTsvFile.cs +++ b/mzLib/Readers/SearchResults/SpectrumMatchFromTsvFile.cs @@ -4,7 +4,7 @@ namespace Readers; public class SpectrumMatchFromTsvFile : ResultFile, IResultFile { - public override SupportedFileType FileType { get; } + public override SupportedFileType FileType => FilePath.ParseFileType(); public override Software Software { get; set; } /// @@ -12,10 +12,7 @@ public class SpectrumMatchFromTsvFile : ResultFile, IResul /// public SpectrumMatchFromTsvFile() : base() { } - public SpectrumMatchFromTsvFile(string filePath) : base(filePath, Software.MetaMorpheus) - { - - } + public SpectrumMatchFromTsvFile(string filePath) : base(filePath, Software.MetaMorpheus) { } public override void LoadResults() { diff --git a/mzLib/Test/FileReadingTests/TestPsmFromTsv.cs b/mzLib/Test/FileReadingTests/TestPsmFromTsv.cs index 6cfe00e15..be4323885 100644 --- a/mzLib/Test/FileReadingTests/TestPsmFromTsv.cs +++ b/mzLib/Test/FileReadingTests/TestPsmFromTsv.cs @@ -273,5 +273,56 @@ public static void TestSimpleToLibrarySpectrum() Assert.That(librarySpectrumWithNeutralLoss.Contains("WaterLoss")); } + + [Test] + [TestCase("FileReader - PsmFromTsv")] + [TestCase("FileReader - SpectrumMatchFromTsv")] + [TestCase("File Construction - PsmFromTsv")] + [TestCase("File Construction - SpectrumMatchFromTsv")] + public static void TestPsmFiles(string fileLoadingType) + { + string psmTsvPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"FileReadingTests\SearchResults\TDGPTMDSearchResults.psmtsv"); + List psms = SpectrumMatchTsvReader.ReadPsmTsv(psmTsvPath, out var warnings); + Assert.That(warnings.Count == 2); + + IResultFile loadedFile = null; + switch (fileLoadingType) + { + case "FileReader - PsmFromTsv": + var file = FileReader.ReadFile(psmTsvPath); + file.LoadResults(); + Assert.That(file.Results.Count == psms.Count); + loadedFile = file; + break; + + case "FileReader - SpectrumMatchFromTsv": + var file2 = FileReader.ReadFile(psmTsvPath); + file2.LoadResults(); + Assert.That(file2.Results.Count == psms.Count); + loadedFile = file2; + break; + + case "File Construction - PsmFromTsv": + var file3 = new PsmFromTsvFile(psmTsvPath); + file3.LoadResults(); + Assert.That(file3.Results.Count == psms.Count); + loadedFile = file3; + break; + + case "File Construction - SpectrumMatchFromTsv": + var file4 = new SpectrumMatchFromTsvFile(psmTsvPath); + file4.LoadResults(); + Assert.That(file4.Results.Count == psms.Count); + loadedFile = file4; + break; + + default: + Assert.Fail(); + break; + } + + Assert.That(loadedFile.FileType == SupportedFileType.psmtsv); + Assert.Throws(() => { loadedFile.WriteResults(""); }); + } } }