From 7309ae790df040fdd1ab007b1c2abe87267f6908 Mon Sep 17 00:00:00 2001 From: Yuki Matsuzawa Date: Sat, 22 Aug 2026 09:02:56 +0900 Subject: [PATCH] Optimize MS2 value peak extraction Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- src/MSDIAL5/MsdialCore/Utility/DataAccess.cs | 24 +++----------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/MSDIAL5/MsdialCore/Utility/DataAccess.cs b/src/MSDIAL5/MsdialCore/Utility/DataAccess.cs index bf8cccd0d..f351b381e 100644 --- a/src/MSDIAL5/MsdialCore/Utility/DataAccess.cs +++ b/src/MSDIAL5/MsdialCore/Utility/DataAccess.cs @@ -332,10 +332,7 @@ public static List GetMs2ValuePeaks(IDataProvider provider, double int startScanID, int endScanID, IReadOnlyList pMzValues, ParameterBase param, AcquisitionType acquisitionType, double targetCE = -1, ChromXType type = ChromXType.RT, ChromXUnit unit = ChromXUnit.Min) { - var counter = 0; - var arrayLength = GetTargetArrayLength(provider, startScanID, endScanID, precursorMz, targetCE, param, acquisitionType); - var valuePeakArrayList = new List(pMzValues.Count); - valuePeakArrayList.AddRange(pMzValues.Select(_ => new ValuePeak[arrayLength])); + var valuePeakLists = pMzValues.Select(_ => new List()).ToArray(); for (int i = startScanID; i <= endScanID; i++) { var spec = provider.LoadMsSpectrumFromIndex(i); @@ -348,27 +345,12 @@ public static List GetMs2ValuePeaks(IDataProvider provider, double var intensities = RetrieveIntensitiesFromMzValues(pMzValues, spec.Spectrum, param.CentroidMs2Tolerance); for (int j = 0; j < pMzValues.Count; j++) { - valuePeakArrayList[j][counter] = new ValuePeak(id, chromX, pMzValues[j], intensities[j]); + valuePeakLists[j].Add(new ValuePeak(id, chromX, pMzValues[j], intensities[j])); } - counter++; - } - } - } - return valuePeakArrayList; - } - - private static int GetTargetArrayLength(IDataProvider provider, int startScanID, int endScanID, double precursorMz, double targetCE, ParameterBase param, AcquisitionType type) { - var counter = 0; - for (int i = startScanID; i <= endScanID; i++) { - var spec = provider.LoadMsSpectrumFromIndex(i); - if (spec.MsLevel == 2 && spec.Precursor != null) { - if (targetCE >= 0 && spec.CollisionEnergy >= 0 && Math.Abs(targetCE - spec.CollisionEnergy) > 1) continue; // for AIF mode - if (IsInMassWindow(precursorMz, spec, param.CentroidMs1Tolerance, type)) { - counter++; } } } - return counter; + return valuePeakLists.Select(peaks => peaks.ToArray()).ToList(); } public static double[] RetrieveIntensitiesFromMzValues(