diff --git a/MetaMorpheus/EngineLayer/Calibration/CalibrationEngine.cs b/MetaMorpheus/EngineLayer/Calibration/CalibrationEngine.cs index 35c838a37..9f52e3b2d 100644 --- a/MetaMorpheus/EngineLayer/Calibration/CalibrationEngine.cs +++ b/MetaMorpheus/EngineLayer/Calibration/CalibrationEngine.cs @@ -63,12 +63,6 @@ protected override MetaMorpheusEngineResults RunSpecific() //generate new scans MsDataScan[] calibratedScans = new MsDataScan[originalScans.Count]; - //hard copy original scans - for (int i = 0; i < originalScans.Count; i++) - { - calibratedScans[i] = originalScans[i]; - } - //apply a smoothing function, so that outlier scans aren't wildly shifted double[] ms1SmoothedErrors = SmoothErrors(ms1RelativeErrors); double[] ms2SmoothedErrors = new double[ms2RelativeErrors.Length]; diff --git a/MetaMorpheus/EngineLayer/Calibration/DataPointAcquisitionEngine.cs b/MetaMorpheus/EngineLayer/Calibration/DataPointAcquisitionEngine.cs index 021b1a86e..d7111459a 100644 --- a/MetaMorpheus/EngineLayer/Calibration/DataPointAcquisitionEngine.cs +++ b/MetaMorpheus/EngineLayer/Calibration/DataPointAcquisitionEngine.cs @@ -236,6 +236,9 @@ private static List SearchMS2Spectrum(Ms2ScanWithSpecificMass double theoreticalMass = matchedIon.NeutralTheoreticalProduct.NeutralMass; //get envelopes that match var envelopesThatMatch = isotopicEnvelopes.Where(x => ms2Tolerance.Within(x.MonoisotopicMass, theoreticalMass)).OrderBy(x => Math.Abs(x.MonoisotopicMass - theoreticalMass)).ToList(); + + if(envelopesThatMatch.Count == 0) + continue; //only allow one envelope per charge state bool[] chargeStateFound = new bool[envelopesThatMatch.Max(x => x.Charge) + 1]; diff --git a/MetaMorpheus/EngineLayer/Calibration/DataPointAquisitionResults.cs b/MetaMorpheus/EngineLayer/Calibration/DataPointAquisitionResults.cs index 8aaf2f9fc..d22975a95 100644 --- a/MetaMorpheus/EngineLayer/Calibration/DataPointAquisitionResults.cs +++ b/MetaMorpheus/EngineLayer/Calibration/DataPointAquisitionResults.cs @@ -7,6 +7,9 @@ namespace EngineLayer.Calibration { + /// + /// Returns PSMs that can be used for calibration based on tolerance limits passed from the calibration task + /// public class DataPointAquisitionResults : MetaMorpheusEngineResults { public DataPointAquisitionResults( @@ -27,19 +30,9 @@ public DataPointAquisitionResults( var ms1Range = Ms1List.Select(b => b.ExperimentalMz - b.TheoreticalMz).ToArray(); var ms2Range = Ms2List.Select(b => b.ExperimentalMz - b.TheoreticalMz).ToArray(); - Ms1InfoTh = new Tuple(ArrayStatistics.Mean(ms1Range), ArrayStatistics.StandardDeviation(ms1Range)); - Ms2InfoTh = new Tuple(ArrayStatistics.Mean(ms2Range), ArrayStatistics.StandardDeviation(ms2Range)); - var ms1PpmRange = Ms1List.Select(b => (b.ExperimentalMz - b.TheoreticalMz) / b.TheoreticalMz).ToArray(); var ms2PpmRange = Ms2List.Select(b => (b.ExperimentalMz - b.TheoreticalMz) / b.TheoreticalMz).ToArray(); - Ms1InfoPpm = new Tuple(ArrayStatistics.Mean(ms1PpmRange), ArrayStatistics.StandardDeviation(ms1PpmRange)); - Ms2InfoPpm = new Tuple(ArrayStatistics.Mean(ms2PpmRange), ArrayStatistics.StandardDeviation(ms2PpmRange)); - - NumMs1MassChargeCombinationsConsidered = numMs1MassChargeCombinationsConsidered; - NumMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks = numMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks; - NumMs2MassChargeCombinationsConsidered = numMs2MassChargeCombinationsConsidered; - NumMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks = numMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks; var precursorErrors = psms.Select(p => (p.ScanPrecursorMass - p.BioPolymerWithSetModsMonoisotopicMass.Value) / p.BioPolymerWithSetModsMonoisotopicMass.Value * 1e6).ToList(); PsmPrecursorIqrPpmError = precursorErrors.InterquartileRange(); @@ -50,16 +43,6 @@ public DataPointAquisitionResults( PsmProductMedianPpmError = productErrors.Median(); } - public Tuple Ms1InfoTh { get; } - public Tuple Ms2InfoTh { get; } - public Tuple Ms1InfoPpm { get; } - public Tuple Ms2InfoPpm { get; } - - public int NumMs1MassChargeCombinationsConsidered { get; } - public int NumMs1MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks { get; } - public int NumMs2MassChargeCombinationsConsidered { get; } - public int NumMs2MassChargeCombinationsThatAreIgnoredBecauseOfTooManyPeaks { get; } - public List Ms1List { get; } public List Ms2List { get; } @@ -69,8 +52,6 @@ public DataPointAquisitionResults( public readonly double PsmProductIqrPpmError; public readonly List Psms; - public int Count { get { return Ms1List.Count + Ms2List.Count; } } - public override string ToString() { var sb = new StringBuilder(); diff --git a/MetaMorpheus/GUI/MainWindow.xaml.cs b/MetaMorpheus/GUI/MainWindow.xaml.cs index db8f7bd28..515344905 100644 --- a/MetaMorpheus/GUI/MainWindow.xaml.cs +++ b/MetaMorpheus/GUI/MainWindow.xaml.cs @@ -27,7 +27,7 @@ namespace MetaMorpheusGUI /// public partial class MainWindow : Window { - private readonly ObservableCollection SpectraFiles = new ObservableCollection(); + private readonly ObservableCollection SpectraFiles = new ObservableCollection(); private ObservableCollection ProteinDatabases = new ObservableCollection(); private readonly ObservableCollection PreRunTasks = new ObservableCollection(); private readonly ObservableCollection SelectedSpectraFiles = new ObservableCollection(); diff --git a/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs b/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs index 362418ff6..d6881cfc4 100644 --- a/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs +++ b/MetaMorpheus/TaskLayer/CalibrationTask/CalibrationTask.cs @@ -7,7 +7,6 @@ using MzLibUtil; using Nett; using Proteomics; -using Omics.Fragmentation; using System; using System.Collections.Generic; using System.IO; @@ -23,8 +22,6 @@ public class CalibrationTask : MetaMorpheusTask public CalibrationTask() : base(MyTask.Calibrate) { CommonParameters = new CommonParameters( - productMassTolerance: new PpmTolerance(25), - precursorMassTolerance: new PpmTolerance(15), trimMsMsPeaks: false, doPrecursorDeconvolution: false ); @@ -33,7 +30,12 @@ public CalibrationTask() : base(MyTask.Calibrate) } public CalibrationParameters CalibrationParameters { get; set; } - + private readonly int NumRequiredPsms = 20; + private readonly int NumRequiredMs1Datapoints = 50; + private readonly int NumRequiredMs2Datapoints = 100; + double MaxPrecursorTolerance = 40; + double MaxProductTolerance = 150; + public const string CalibSuffix = "-calib"; protected override MyTaskResults RunSpecific(string OutputFolder, List dbFilenameList, List currentRawFileList, string taskId, FileSpecificParameters[] fileSettingsList) { LoadModifications(taskId, out var variableModifications, out var fixedModifications, out var localizeableModificationTypes); @@ -68,13 +70,14 @@ protected override MyTaskResults RunSpecific(string OutputFolder, List unsuccessfullyCalibratedFilePaths = new List(); + // re-write experimental design (if it has been defined) with new calibrated file names + string assumedPathToExperDesign = Directory.GetParent(currentRawFileList.First()).FullName; + assumedPathToExperDesign = Path.Combine(assumedPathToExperDesign, GlobalVariables.ExperimentalDesignFileName); for (int spectraFileIndex = 0; spectraFileIndex < currentRawFileList.Count; spectraFileIndex++) { if (GlobalVariables.StopLoops) { break; } - bool couldNotFindEnoughDatapoints = false; - // get filename stuff string originalUncalibratedFilePath = currentRawFileList[spectraFileIndex]; string originalUncalibratedFilenameWithoutExtension = Path.GetFileNameWithoutExtension(originalUncalibratedFilePath); @@ -94,164 +97,83 @@ protected override MyTaskResults RunSpecific(string OutputFolder, List { taskId, "Individual Spectra Files" }); DataPointAquisitionResults acquisitionResults = null; - for (int i = 1; i <= 5; i++) + acquisitionResults = GetDataAcquisitionResults(myMsDataFile, originalUncalibratedFilePath, variableModifications, fixedModifications, proteinList, taskId, combinedParams, new PpmTolerance(MaxPrecursorTolerance), new PpmTolerance(MaxProductTolerance)); + if(acquisitionResults.Psms.Count >= NumRequiredPsms && acquisitionResults.Ms1List.Count >= NumRequiredMs1Datapoints && acquisitionResults.Ms2List.Count >= NumRequiredMs2Datapoints) { - acquisitionResults = GetDataAcquisitionResults(myMsDataFile, originalUncalibratedFilePath, variableModifications, fixedModifications, proteinList, taskId, combinedParams, combinedParams.PrecursorMassTolerance, combinedParams.ProductMassTolerance); - - // enough data points to calibrate? - if (acquisitionResults.Psms.Count >= NumRequiredPsms && acquisitionResults.Ms1List.Count > NumRequiredMs1Datapoints && acquisitionResults.Ms2List.Count > NumRequiredMs2Datapoints) - { - break; - } - - if (i == 1) // failed round 1 - { - combinedParams.PrecursorMassTolerance = new PpmTolerance(20); - combinedParams.ProductMassTolerance = new PpmTolerance(50); - } - else if (i == 2) // failed round 2 - { - combinedParams.PrecursorMassTolerance = new PpmTolerance(30); - combinedParams.ProductMassTolerance = new PpmTolerance(100); - } - else if (i == 3) // failed round 3 - { - combinedParams.PrecursorMassTolerance = new PpmTolerance(40); - combinedParams.ProductMassTolerance = new PpmTolerance(150); - } - else // failed round 4 - { - if (acquisitionResults.Psms.Count < NumRequiredPsms) - { - Warn("Calibration failure! Could not find enough high-quality PSMs. Required " + NumRequiredPsms + ", saw " + acquisitionResults.Psms.Count); - } - if (acquisitionResults.Ms1List.Count < NumRequiredMs1Datapoints) - { - Warn("Calibration failure! Could not find enough MS1 datapoints. Required " + NumRequiredMs1Datapoints + ", saw " + acquisitionResults.Ms1List.Count); - } - if (acquisitionResults.Ms2List.Count < NumRequiredMs2Datapoints) - { - Warn("Calibration failure! Could not find enough MS2 datapoints. Required " + NumRequiredMs2Datapoints + ", saw " + acquisitionResults.Ms2List.Count); - } - - couldNotFindEnoughDatapoints = true; - FinishedDataFile(originalUncalibratedFilePath, new List { taskId, "Individual Spectra Files", originalUncalibratedFilePath }); - break; - } - - Warn("Could not find enough PSMs to calibrate with; opening up tolerances to " + - Math.Round(combinedParams.PrecursorMassTolerance.Value, 2) + " ppm precursor and " + - Math.Round(combinedParams.ProductMassTolerance.Value, 2) + " ppm product"); - } - - if (couldNotFindEnoughDatapoints) - { - unsuccessfullyCalibratedFilePaths.Add(Path.GetFileNameWithoutExtension(currentRawFileList[spectraFileIndex])); - ReportProgress(new ProgressEventArgs(100, "Failed to calibrate!", new List { taskId, "Individual Spectra Files", originalUncalibratedFilenameWithoutExtension })); - continue; - } - // stats before calibration - int prevPsmCount = acquisitionResults.Psms.Count; - double preCalibrationPrecursorErrorIqr = acquisitionResults.PsmPrecursorIqrPpmError; - double preCalibrationProductErrorIqr = acquisitionResults.PsmProductIqrPpmError; + // generate calibration function and shift data points + Status("Calibrating...", new List { taskId, "Individual Spectra Files" }); + CalibrationEngine engine = new(myMsDataFile, acquisitionResults, combinedParams, FileSpecificParameters, new List { taskId, "Individual Spectra Files", originalUncalibratedFilenameWithoutExtension }); + _ = engine.Run(); - // generate calibration function and shift data points - Status("Calibrating...", new List { taskId, "Individual Spectra Files" }); - CalibrationEngine engine = new(myMsDataFile, acquisitionResults, combinedParams, FileSpecificParameters, new List { taskId, "Individual Spectra Files", originalUncalibratedFilenameWithoutExtension }); - _ = engine.Run(); + //update file + myMsDataFile = engine.CalibratedDataFile; - //update file - myMsDataFile = engine.CalibratedDataFile; + // write the calibrated mzML file + myMsDataFile.ExportAsMzML(calibratedFilePath, CalibrationParameters.WriteIndexedMzml); + myFileManager.DoneWithFile(originalUncalibratedFilePath); - // do another search to evaluate calibration results - Status("Post-calibration search...", new List { taskId, "Individual Spectra Files" }); - acquisitionResults = GetDataAcquisitionResults(myMsDataFile, originalUncalibratedFilePath, variableModifications, fixedModifications, proteinList, taskId, combinedParams, combinedParams.PrecursorMassTolerance, combinedParams.ProductMassTolerance); + // write toml settings for the calibrated file + string newTomlFileName = Path.Combine(OutputFolder, originalUncalibratedFilenameWithoutExtension + CalibSuffix + ".toml"); - //generate calibration function and shift data points AGAIN because it's fast and contributes new data - Status("Calibrating...", new List { taskId, "Individual Spectra Files" }); - engine = new CalibrationEngine(myMsDataFile, acquisitionResults, combinedParams, FileSpecificParameters, new List { taskId, "Individual Spectra Files", originalUncalibratedFilenameWithoutExtension }); - _ = engine.Run(); + FileSpecificParameters fileSpecificParams = new(); - //update file - myMsDataFile = engine.CalibratedDataFile; - - // write the calibrated mzML file - myMsDataFile.ExportAsMzML(calibratedFilePath, CalibrationParameters.WriteIndexedMzml); - myFileManager.DoneWithFile(originalUncalibratedFilePath); - - // stats after calibration - int postCalibrationPsmCount = acquisitionResults.Psms.Count; - double postCalibrationPrecursorErrorIqr = acquisitionResults.PsmPrecursorIqrPpmError; - double postCalibrationProductErrorIqr = acquisitionResults.PsmProductIqrPpmError; + // carry over file-specific parameters from the uncalibrated file to the calibrated one + if (fileSettingsList[spectraFileIndex] != null) + { + fileSpecificParams = fileSettingsList[spectraFileIndex].Clone(); + } - // did the data improve? (not used for anything yet...) - bool improvement = ImprovGlobal(preCalibrationPrecursorErrorIqr, preCalibrationProductErrorIqr, prevPsmCount, postCalibrationPsmCount, postCalibrationPrecursorErrorIqr, postCalibrationProductErrorIqr); + //suggest 4 * interquartile range as the ppm tolerance + fileSpecificParams.PrecursorMassTolerance = new PpmTolerance((4.0 * acquisitionResults.PsmPrecursorIqrPpmError) + Math.Abs(acquisitionResults.PsmPrecursorMedianPpmError)); + fileSpecificParams.ProductMassTolerance = new PpmTolerance((4.0 * acquisitionResults.PsmProductIqrPpmError) + Math.Abs(acquisitionResults.PsmProductMedianPpmError)); - // write toml settings for the calibrated file - string newTomlFileName = Path.Combine(OutputFolder, originalUncalibratedFilenameWithoutExtension + CalibSuffix + ".toml"); + Toml.WriteFile(fileSpecificParams, newTomlFileName, tomlConfig); - FileSpecificParameters fileSpecificParams = new(); + FinishedWritingFile(newTomlFileName, new List { taskId, "Individual Spectra Files", originalUncalibratedFilenameWithoutExtension }); - // carry over file-specific parameters from the uncalibrated file to the calibrated one - if (fileSettingsList[spectraFileIndex] != null) + // finished calibrating this file + FinishedWritingFile(calibratedFilePath, new List { taskId, "Individual Spectra Files", originalUncalibratedFilenameWithoutExtension }); + MyTaskResults.NewSpectra.Add(calibratedFilePath); + MyTaskResults.NewFileSpecificTomls.Add(newTomlFileName); + FinishedDataFile(originalUncalibratedFilePath, new List { taskId, "Individual Spectra Files", originalUncalibratedFilePath }); + ReportProgress(new ProgressEventArgs(100, "Done!", new List { taskId, "Individual Spectra Files", originalUncalibratedFilenameWithoutExtension })); + } + else { - fileSpecificParams = fileSettingsList[spectraFileIndex].Clone(); + unsuccessfullyCalibratedFilePaths.Add(originalUncalibratedFilePath); + // provide a message indicating why we couldn't calibrate + CalibrationWarnMessage(acquisitionResults); + FinishedDataFile(originalUncalibratedFilePath, new List { taskId, "Individual Spectra Files", originalUncalibratedFilePath }); + ReportProgress(new ProgressEventArgs(100, "Done!", new List { taskId, "Individual Spectra Files", originalUncalibratedFilenameWithoutExtension })); + continue; } - - //suggest 4 * interquartile range as the ppm tolerance - fileSpecificParams.PrecursorMassTolerance = new PpmTolerance((4.0 * postCalibrationPrecursorErrorIqr) + Math.Abs(acquisitionResults.PsmPrecursorMedianPpmError)); - fileSpecificParams.ProductMassTolerance = new PpmTolerance((4.0 * postCalibrationProductErrorIqr) + Math.Abs(acquisitionResults.PsmProductMedianPpmError)); - - Toml.WriteFile(fileSpecificParams, newTomlFileName, tomlConfig); - - FinishedWritingFile(newTomlFileName, new List { taskId, "Individual Spectra Files", originalUncalibratedFilenameWithoutExtension }); - - // finished calibrating this file - FinishedWritingFile(calibratedFilePath, new List { taskId, "Individual Spectra Files", originalUncalibratedFilenameWithoutExtension }); - MyTaskResults.NewSpectra.Add(calibratedFilePath); - MyTaskResults.NewFileSpecificTomls.Add(newTomlFileName); - FinishedDataFile(originalUncalibratedFilePath, new List { taskId, "Individual Spectra Files", originalUncalibratedFilePath }); - ReportProgress(new ProgressEventArgs(100, "Done!", new List { taskId, "Individual Spectra Files", originalUncalibratedFilenameWithoutExtension })); } - - // re-write experimental design (if it has been defined) with new calibrated file names - string assumedPathToExperDesign = Directory.GetParent(currentRawFileList.First()).FullName; - assumedPathToExperDesign = Path.Combine(assumedPathToExperDesign, GlobalVariables.ExperimentalDesignFileName); - if (File.Exists(assumedPathToExperDesign)) { WriteNewExperimentalDesignFile(assumedPathToExperDesign, OutputFolder, currentRawFileList, unsuccessfullyCalibratedFilePaths); } - // finished calibrating all files for the task ReportProgress(new ProgressEventArgs(100, "Done!", new List { taskId, "Individual Spectra Files" })); return MyTaskResults; } - private readonly int NumRequiredPsms = 20; - private readonly int NumRequiredMs1Datapoints = 50; - private readonly int NumRequiredMs2Datapoints = 100; - public const string CalibSuffix = "-calib"; - - private static bool ImprovGlobal(double prevPrecTol, double prevProdTol, int prevPsmCount, int thisRoundPsmCount, double thisRoundPrecTol, double thisRoundProdTol) + private void CalibrationWarnMessage(DataPointAquisitionResults acquisitionResults) { - if (thisRoundPsmCount > prevPsmCount) + // provide a message indicating why we couldn't calibrate + if (acquisitionResults.Psms.Count < NumRequiredPsms) { - return true; + Warn("Calibration failure! Could not find enough high-quality PSMs. Required " + NumRequiredPsms + ", saw " + acquisitionResults.Psms.Count); } - - double precRatio = thisRoundPrecTol / prevPrecTol; - double prodRatio = thisRoundProdTol / prevProdTol; - - if (thisRoundPsmCount == prevPsmCount) + else if (acquisitionResults.Ms1List.Count < NumRequiredMs1Datapoints) { - return precRatio + prodRatio < 2; // Take any improvement in ratios + Warn("Calibration failure! Could not find enough MS1 datapoints. Required " + NumRequiredMs1Datapoints + ", saw " + acquisitionResults.Ms1List.Count); + } + else if (acquisitionResults.Ms2List.Count < NumRequiredMs2Datapoints) + { + Warn("Calibration failure! Could not find enough MS2 datapoints. Required " + NumRequiredMs2Datapoints + ", saw " + acquisitionResults.Ms2List.Count); } - - var countRatio = (double)thisRoundPsmCount / prevPsmCount; - return countRatio > 0.9 && precRatio + prodRatio < 1.8; } private DataPointAquisitionResults GetDataAcquisitionResults(MsDataFile myMsDataFile, string currentDataFile, List variableModifications, List fixedModifications, List proteinList, string taskId, CommonParameters combinedParameters, Tolerance initPrecTol, Tolerance initProdTol) diff --git a/MetaMorpheus/Test/CalibrationTests.cs b/MetaMorpheus/Test/CalibrationTests.cs index a69900d1f..da347a548 100644 --- a/MetaMorpheus/Test/CalibrationTests.cs +++ b/MetaMorpheus/Test/CalibrationTests.cs @@ -1,20 +1,12 @@ -using Easy.Common.Extensions; -using EngineLayer; -using EngineLayer.Calibration; +using EngineLayer; using FlashLFQ; using MassSpectrometry; using NUnit.Framework; using Assert = NUnit.Framework.Legacy.ClassicAssert; -using System; using System.Collections.Generic; -using System.ComponentModel; using System.IO; using System.Linq; -using System.Reflection; using System.Text.RegularExpressions; using TaskLayer; -using ThermoFisher.CommonCore.Data; -using ThermoFisher.CommonCore.Data.Business; -using static iText.StyledXmlParser.Jsoup.Select.Evaluator; namespace Test { @@ -76,6 +68,41 @@ public static void ExperimentalDesignCalibrationTest(string nonCalibratedFile) Directory.Delete(unitTestFolder, true); } + [Test] + public static void CalibrationTestNoPsms() + { + // set up directories + string unitTestFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"ExperimentalDesignCalibrationTest"); + string outputFolder = Path.Combine(unitTestFolder, @"TaskOutput"); + Directory.CreateDirectory(unitTestFolder); + Directory.CreateDirectory(outputFolder); + + // set up original spectra file (input to calibration) + string nonCalibratedFilePath = Path.Combine(unitTestFolder, "filename1.mzML"); + File.Copy(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML"), nonCalibratedFilePath, true); + + // protein db for a non-matching organism + string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\gapdh.fa"); + + // set up original experimental design (input to calibration) + SpectraFileInfo fileInfo = new(nonCalibratedFilePath, "condition", 0, 0, 0); + _ = ExperimentalDesign.WriteExperimentalDesignToFile(new List { fileInfo }); + + // run calibration + CalibrationTask calibrationTask = new(); + calibrationTask.RunTask(outputFolder, new List { new DbForTask(myDatabase, false) }, new List { nonCalibratedFilePath }, "test"); + + // test new experimental design written by calibration + var newExpDesignPath = Path.Combine(outputFolder, @"ExperimentalDesign.tsv"); + string expectedCalibratedFileName = Path.GetFileNameWithoutExtension(nonCalibratedFilePath) + "-calib.mzML"; + var expectedCalibratedFilePath = Path.Combine(outputFolder, expectedCalibratedFileName); + var newExperDesign = ExperimentalDesign.ReadExperimentalDesign(newExpDesignPath, new List { expectedCalibratedFilePath }, out var errors); + + Assert.That(errors.Any()); + + // clean up + Directory.Delete(unitTestFolder, true); + } [Test] public static void CalibrationTestLowRes() @@ -146,6 +173,49 @@ public static void ExperimentalDesignCalibrationAndSearch(string nonCalibratedFi Directory.Delete(unitTestFolder, true); } + [Test] + public static void ExperimentalDesignCalibrationAndSearchWithOneCalibratibleAndOneNoncalibratible() + { + // set up output directories + string unitTestFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"ExperimentalDesignCalibrationAndSearch"); + string outputFolder = Path.Combine(unitTestFolder, @"TaskOutput"); + Directory.CreateDirectory(unitTestFolder); + Directory.CreateDirectory(outputFolder); + + // set up original spectra file (input to calibration) + string nonCalibratedFilePathOne = Path.Combine(unitTestFolder, "filename1.mzML"); + File.Copy(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML"), nonCalibratedFilePathOne, true); + string nonCalibratedFilePathTwo = Path.Combine(unitTestFolder, "filename2.mzML"); + File.Copy(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\TaGe_SA_A549_3_snip.mzML"), nonCalibratedFilePathTwo, true); + + // set up original experimental design (input to calibration) + SpectraFileInfo fileInfoOne = new(nonCalibratedFilePathOne, "condition1", 0, 0, 0); + SpectraFileInfo fileInfoTwo = new(nonCalibratedFilePathTwo, "condition2", 0, 0, 0); + _ = ExperimentalDesign.WriteExperimentalDesignToFile(new List { fileInfoOne, fileInfoTwo }); + + // set up tasks (calibration + search) + CalibrationTask calibrationTask = new CalibrationTask(); + SearchTask searchTask = new SearchTask(); + + // protein db + string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\smalldb.fasta"); + + // run the tasks + EverythingRunnerEngine a = new EverythingRunnerEngine( + new List<(string, MetaMorpheusTask)> { ("", calibrationTask), ("", searchTask) }, + new List { nonCalibratedFilePathOne, nonCalibratedFilePathTwo }, + new List { new DbForTask(myDatabase, false) }, + outputFolder); + + a.Run(); + + // test to see if quantification ran correctly + Assert.That(File.Exists(Path.Combine(outputFolder, @"ExperimentalDesign.tsv"))); + + // clean up + Directory.Delete(unitTestFolder, true); + } + [Test] [TestCase("ExpDesFileNotFound","small.mzML", "Experimental design file not found!")] [TestCase("WrongNumberOfCells", "small.mzML", "Error: The experimental design was not formatted correctly. Expected 5 cells, but found 4 on line 2")] diff --git a/MetaMorpheus/Test/Test.csproj b/MetaMorpheus/Test/Test.csproj index e46489a22..f3152baf7 100644 --- a/MetaMorpheus/Test/Test.csproj +++ b/MetaMorpheus/Test/Test.csproj @@ -343,6 +343,9 @@ Always + + Always + Always diff --git a/MetaMorpheus/Test/TestData/SmallCalibratible_Yeast.toml b/MetaMorpheus/Test/TestData/SmallCalibratible_Yeast.toml new file mode 100644 index 000000000..261479cd5 --- /dev/null +++ b/MetaMorpheus/Test/TestData/SmallCalibratible_Yeast.toml @@ -0,0 +1 @@ +Protease = "trypsin"