diff --git a/MetaMorpheus/EngineLayer/Gptmd/GptmdEngine.cs b/MetaMorpheus/EngineLayer/Gptmd/GptmdEngine.cs index f5482ad4d..d72a0a4a2 100644 --- a/MetaMorpheus/EngineLayer/Gptmd/GptmdEngine.cs +++ b/MetaMorpheus/EngineLayer/Gptmd/GptmdEngine.cs @@ -65,9 +65,9 @@ public static bool ModFits(Modification attemptToLocalize, IBioPolymer protein, protected override MetaMorpheusEngineResults RunSpecific() { - var modDict = new ConcurrentDictionary>>(); + var mergedDictionaries = new ConcurrentDictionary>>(); int modsAdded = 0; - + object lockObject = new object(); int maxThreadsPerFile = CommonParameters.MaxThreadsToUsePerFile; var psms = AllIdentifications.Where(b => b.FdrInfo.QValueNotch <= 0.05 && !b.IsDecoy).ToList(); if (psms.Any() == false) @@ -76,6 +76,7 @@ protected override MetaMorpheusEngineResults RunSpecific() } Parallel.ForEach(Partitioner.Create(0, psms.Count), new ParallelOptions() { MaxDegreeOfParallelism = maxThreadsPerFile }, (range) => { + var modDict = new ConcurrentDictionary>>(); for (int i = range.Item1; i < range.Item2; i++) { foreach (var pepWithSetMods in psms[i].BestMatchingBioPolymersWithSetMods.Select(v => v.Peptide as PeptideWithSetModifications)) @@ -173,10 +174,24 @@ protected override MetaMorpheusEngineResults RunSpecific() } } } + lock (lockObject) + { + foreach (var kvp in modDict) + { + mergedDictionaries.AddOrUpdate(kvp.Key, kvp.Value, (key, oldValue) => + { + foreach (var item in kvp.Value) + { + oldValue.Add(item); + } + return oldValue; + }); + } + } }); // Convert ConcurrentDictionary to Dictionary with HashSet - var finalModDictionary = modDict.ToDictionary( + var finalModDictionary = mergedDictionaries.ToDictionary( kvp => kvp.Key, kvp => new HashSet>(kvp.Value) );