Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stability Update #2455

Merged
merged 28 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a5af17c
Minor
Alexander-Sol Dec 23, 2024
734c014
idk
Alexander-Sol Jan 6, 2025
032574c
idk
Alexander-Sol Jan 7, 2025
bbd779f
Changed resolveAmbiguity method to order BPWSM and eliminate ambiguou…
Alexander-Sol Jan 7, 2025
44a6beb
Deleted unused changes
Alexander-Sol Jan 7, 2025
95f5344
Minor
Alexander-Sol Jan 7, 2025
34ea722
Probably not very good
Alexander-Sol Jan 8, 2025
0653bd8
Added XL Test
Alexander-Sol Jan 9, 2025
891df52
Deleted reproducibility test that showed different DB = different pep…
Alexander-Sol Jan 9, 2025
09fb710
Merge branch 'master' into RaceConditions
trishorts Jan 17, 2025
82ce0a1
Merge branch 'master' into RaceConditions
nbollis Jan 23, 2025
95c53a4
Fixed locks in DataPointAcquiEngine
Alexander-Sol Jan 29, 2025
ebf2cba
Merge branch 'RaceConditions' of https://github.com/Alexander-Sol/Met…
Alexander-Sol Jan 29, 2025
63b3471
Removed unintended changes
Alexander-Sol Jan 29, 2025
8833d48
Merge branch 'master' into RaceConditions
nbollis Jan 31, 2025
315cdb5
Merge branch 'master' into RaceConditions
nbollis Feb 3, 2025
d2e1e48
Merge branch 'master' into RaceConditions
nbollis Feb 3, 2025
9e7ea6c
undid unneccessary change
Alexander-Sol Feb 3, 2025
5d84eb2
Merge branch 'master' into RaceConditions
nbollis Feb 4, 2025
7179fcc
Merge branch 'master' into RaceConditions
nbollis Feb 4, 2025
f136897
Added comment to xlsm ResolveAllAmbiguities
Alexander-Sol Feb 4, 2025
718c1c1
Merge branch 'RaceConditions' of https://github.com/Alexander-Sol/Met…
Alexander-Sol Feb 4, 2025
aa7ad26
Deleted XL resolve
Alexander-Sol Feb 5, 2025
54d7189
reverted changes to psmtsvwriter and spectralmatch
Alexander-Sol Feb 5, 2025
6c4289c
reverted unintended changes
Alexander-Sol Feb 5, 2025
036a9ea
reverted unintended changes
Alexander-Sol Feb 5, 2025
0201420
revert
Alexander-Sol Feb 5, 2025
bfec019
Merge branch 'master' into RaceConditions
trishorts Feb 5, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public DataPointAcquisitionEngine(
MinMS1isotopicPeaksNeededForConfirmedIdentification = minMS1isotopicPeaksNeededForConfirmedIdentification;
}

private readonly object _ms1Lock = new();
private readonly object _ms2Lock = new();

protected override MetaMorpheusEngineResults RunSpecific()
{
Status("Extracting data points:");
Expand All @@ -52,9 +55,6 @@ protected override MetaMorpheusEngineResults RunSpecific()
List<LabeledDataPoint> Ms1List = new List<LabeledDataPoint>();
List<LabeledDataPoint> Ms2List = new List<LabeledDataPoint>();

object lockObj = new object();
object lockObj2 = new object();

int maxThreadsPerFile = CommonParameters.MaxThreadsToUsePerFile;
int[] threads = Enumerable.Range(0, maxThreadsPerFile).ToArray();
Parallel.ForEach(threads, (matchIndex) =>
Expand Down Expand Up @@ -85,7 +85,7 @@ protected override MetaMorpheusEngineResults RunSpecific()

List<LabeledDataPoint> ms2tuple = SearchMS2Spectrum(GoodScans[matchIndex], identification, ProductMassTolerance);

lock (lockObj2)
lock (_ms2Lock)
{
Ms2List.AddRange(ms2tuple);
}
Expand All @@ -102,7 +102,7 @@ protected override MetaMorpheusEngineResults RunSpecific()

var ms1tupleForward = SearchMS1Spectra(theoreticalMasses, theoreticalIntensities, ms2scanNumber, 1, peptideCharge, identification);

lock (lockObj)
lock (_ms1Lock)
{
Ms1List.AddRange(ms1tupleBack.Item1);
numMs1MassChargeCombinationsConsidered += ms1tupleBack.Item2;
Expand Down
4 changes: 3 additions & 1 deletion MetaMorpheus/EngineLayer/FdrAnalysis/SpectralMatchGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public static List<SpectralMatchGroup> GroupByBaseSequence(List<SpectralMatch> s
/// </summary>
public IEnumerable<SpectralMatch> GetBestMatches()
{
return SpectralMatches.GroupBy(p => p.FullSequence).Select(g => g.MaxBy(p => p));
return SpectralMatches
.GroupBy(p => p.FullSequence)
.Select(g => g.MaxBy(p => p));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion MetaMorpheus/TaskLayer/MetaMorpheusTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@
{
MetaMorpheusEngine.FinishedSingleEngineHandler -= SingleEngineHandlerInTask;
var resultsFileName = Path.Combine(output_folder, "results.txt");
e.Data.Add("folder", output_folder);
e.Data.Add("folder", output_folder);

Check warning on line 583 in MetaMorpheus/TaskLayer/MetaMorpheusTask.cs

View check run for this annotation

Codecov / codecov/patch

MetaMorpheus/TaskLayer/MetaMorpheusTask.cs#L583

Added line #L583 was not covered by tests
using (StreamWriter file = new StreamWriter(resultsFileName))
{
file.WriteLine(GlobalVariables.MetaMorpheusVersion.Equals("1.0.0.0") ? "MetaMorpheus: Not a release version" : "MetaMorpheus: version " + GlobalVariables.MetaMorpheusVersion);
Expand Down
23 changes: 9 additions & 14 deletions MetaMorpheus/TaskLayer/MyFileManager.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
using EngineLayer;
using MassSpectrometry;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using Readers;
using System.Reflection.Metadata.Ecma335;

namespace TaskLayer
{
public class MyFileManager
{
private readonly bool DisposeOfFileWhenDone;
private readonly Dictionary<string, MsDataFile> MyMsDataFiles = new Dictionary<string, MsDataFile>();
private readonly object FileLoadingLock = new object();
private readonly ConcurrentDictionary<string, MsDataFile> MyMsDataFiles = new ConcurrentDictionary<string, MsDataFile>();

public MyFileManager(bool disposeOfFileWhenDone)
{
Expand All @@ -23,7 +24,7 @@ public MyFileManager(bool disposeOfFileWhenDone)

public bool SeeIfOpen(string path)
{
return (MyMsDataFiles.ContainsKey(path) && MyMsDataFiles[path] != null);
return MyMsDataFiles.TryGetValue(path, out var file);
}

public MsDataFile LoadFile(string origDataFile, CommonParameters commonParameters)
Expand All @@ -42,25 +43,19 @@ public MsDataFile LoadFile(string origDataFile, CommonParameters commonParameter
filter = null;
}

if (MyMsDataFiles.TryGetValue(origDataFile, out MsDataFile value) && value != null)
{
if (MyMsDataFiles.TryGetValue(origDataFile, out MsDataFile value))
return value;
}

// By now know that need to load this file!!!
lock (FileLoadingLock) // Lock because reading is sequential
{
MyMsDataFiles[origDataFile] = MsDataFileReader.GetDataFile(origDataFile)
.LoadAllStaticData(filter, commonParameters.MaxThreadsToUsePerFile);
return MyMsDataFiles[origDataFile];
}
return MyMsDataFiles.GetOrAdd(origDataFile,
MsDataFileReader.GetDataFile(origDataFile).LoadAllStaticData(filter, commonParameters.MaxThreadsToUsePerFile));
}

internal void DoneWithFile(string origDataFile)
{
if (DisposeOfFileWhenDone)
{
MyMsDataFiles[origDataFile] = null;
// This would only return false if the file was not in the dictionary
MyMsDataFiles.TryRemove(origDataFile, out var file);
}
}

Expand Down
7 changes: 4 additions & 3 deletions MetaMorpheus/TaskLayer/SearchTask/SearchTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ public static MassDiffAcceptor GetMassDiffAcceptor(Tolerance precursorMassTolera
}
}

protected override MyTaskResults RunSpecific(string OutputFolder, List<DbForTask> dbFilenameList, List<string> currentRawFileList, string taskId, FileSpecificParameters[] fileSettingsList)
protected override MyTaskResults RunSpecific(string OutputFolder, List<DbForTask> dbFilenameList, List<string> currentRawFileList, string taskId,
FileSpecificParameters[] fileSettingsList)
{
MyFileManager myFileManager = new MyFileManager(SearchParameters.DisposeOfFileWhenDone);
var fileSpecificCommonParams = fileSettingsList.Select(b => SetAllFileSpecificCommonParams(CommonParameters, b));

// start loading first spectra file in the background
Task<MsDataFile> nextFileLoadingTask = new(() => myFileManager.LoadFile(currentRawFileList[0], SetAllFileSpecificCommonParams(CommonParameters, fileSettingsList[0])));
string fileToLoad = currentRawFileList[0];
Task<MsDataFile> nextFileLoadingTask = new(() => myFileManager.LoadFile(fileToLoad, SetAllFileSpecificCommonParams(CommonParameters, fileSettingsList[0])));
nextFileLoadingTask.Start();


if (SearchParameters.DoLabelFreeQuantification)
{
Expand Down
10 changes: 10 additions & 0 deletions MetaMorpheus/Test/EverythingRunnerEngineTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,22 @@ static EverythingRunnerEngineTestCase()
string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory,
@"TestData\TaGe_SA_A549_3_snip.fasta");
searchTaskLoaded.CommonParameters.QValueCutoffForPepCalculation = 0.01;

// Bottom-up Q-value Test Case
_cases.Add(EverythingRunnerEngineTestCases.BottomUpQValue,
new EverythingRunnerEngineTestCase(EverythingRunnerEngineTestCases.BottomUpQValue,
new List<(string, MetaMorpheusTask)> { ("postSearchAnalysisTaskTestOutput", searchTaskLoaded) },
new List<string> { myFile1, myFile2 }, new List<DbForTask> { new DbForTask(myDatabase, false) },
false));

// Bottom-up Q-value Single File Test Case
_cases.Add(EverythingRunnerEngineTestCases.BottomUpQValueSingle,
new EverythingRunnerEngineTestCase(EverythingRunnerEngineTestCases.BottomUpQValueSingle,
new List<(string, MetaMorpheusTask)> { ("postSearchAnalysisTaskTestOutput", searchTaskLoaded) },
new List<string> { myFile2 },
new List<DbForTask> { new DbForTask(myDatabase, false) }, false));

// Bottom-up Q-value No Individual Files Write MzId Test Case
searchTaskLoaded = Toml.ReadFile<SearchTask>(myTomlPath, MetaMorpheusTask.tomlConfig);
searchTaskLoaded.SearchParameters.WriteIndividualFiles = false;
searchTaskLoaded.SearchParameters.WriteMzId = true;
Expand All @@ -161,6 +166,7 @@ static EverythingRunnerEngineTestCase()
new List<string> { myFile1, myFile2 }, new List<DbForTask> { new DbForTask(myDatabase, false) },
false));

// Bottom-up Q-value No Individual Files Write PepXml Test Case
searchTaskLoaded = Toml.ReadFile<SearchTask>(myTomlPath, MetaMorpheusTask.tomlConfig);
searchTaskLoaded.SearchParameters.WriteIndividualFiles = false;
searchTaskLoaded.SearchParameters.WriteMzId = false;
Expand All @@ -171,6 +177,7 @@ static EverythingRunnerEngineTestCase()
new List<string> { myFile1, myFile2 }, new List<DbForTask> { new DbForTask(myDatabase, false) },
false));

// Bottom-up Pep Q-value Test Case
myTomlPath = Path.Combine(TestContext.CurrentContext.TestDirectory,
@"TestData\Task2-SearchTaskconfig.toml");
searchTaskLoaded = Toml.ReadFile<SearchTask>(myTomlPath, MetaMorpheusTask.tomlConfig);
Expand All @@ -181,6 +188,7 @@ static EverythingRunnerEngineTestCase()
new List<string> { myFile1, myFile2 }, new List<DbForTask> { new DbForTask(myDatabase, false) },
false));

// Top-down Q-value Test Case
myTomlPath = Path.Combine(TestContext.CurrentContext.TestDirectory,
@"TopDownTestData\TopDownSearchToml.toml");
searchTaskLoaded = Toml.ReadFile<SearchTask>(myTomlPath, MetaMorpheusTask.tomlConfig);
Expand All @@ -192,6 +200,8 @@ static EverythingRunnerEngineTestCase()
new List<(string, MetaMorpheusTask)> { ("postSearchAnalysisTaskTestOutput", searchTaskLoaded) },
new List<string> { myFile1, myFile2 }, new List<DbForTask> { new DbForTask(myDatabase, false) },
true));

// Top-down Q-value Single File Test Case
_cases.Add(EverythingRunnerEngineTestCases.TopDownQValueSingle,
new EverythingRunnerEngineTestCase(EverythingRunnerEngineTestCases.TopDownQValueSingle,
new List<(string, MetaMorpheusTask)> { ("postSearchAnalysisTaskTestOutput", searchTaskLoaded) },
Expand Down
1 change: 1 addition & 0 deletions MetaMorpheus/Test/XLSearchOutputTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static void WriteXlSpectralLibraryTest()
string myFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"XlTestData\2017-11-21_XL_DSSO_Ribosome_RT60min_28800-28898.mzML");
string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"XlTestData\RibosomeGO.fasta");

if (Directory.Exists(outputFolder)) Directory.Delete(outputFolder, true);
Directory.CreateDirectory(outputFolder);

XLSearchTask xLSearch = new XLSearchTask
Expand Down
9 changes: 9 additions & 0 deletions MetaMorpheus/Test/XLTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,15 @@ public static void TestCsmSort()
Assert.That(csmListList.Select(c => c.First().XLTotalScore).ToList(), Is.EquivalentTo(new List<double> { 43d, 33d }));
Assert.That(csmListList.Select(c => c.First().BaseSequence).ToList(), Is.EquivalentTo(new List<string> { "LEDITPEP", "VPEPTIDE" }));
Assert.That(csmListList.Select(c => c.First().BetaPeptide.BaseSequence).ToList(), Is.EquivalentTo(new List<string> { "VEDI", "APEP" }));


Protein protForwardAsDecoy = new Protein(sequence: "VPEPTIDELPEPTIDEAPEPTIDE", accession: "DECOY", isDecoy: true);
PeptideWithSetModifications pwsmV_D = new PeptideWithSetModifications(protForwardAsDecoy, new DigestionParams(), 1, 8, CleavageSpecificity.Full, "VPEPTIDE", 0, mod, 0, null);

csmOne.AddOrReplace(pwsmV_D, 3, 0, true, new List<MatchedFragmentIon>(), 0);
csmOne.ResolveAllAmbiguities();
Assert.That(csmOne.BestMatchingBioPolymersWithSetMods.Count() == 1);
Assert.That(!csmOne.BestMatchingBioPolymersWithSetMods.First().Peptide.Parent.IsDecoy);
}

[Test]
Expand Down
Loading