From 0d5c6914fe5f8bdddcbf18d7bf37eda2cf216eab Mon Sep 17 00:00:00 2001 From: "DESKTOP-382ETUR\\Hiroshi Tsugawa" Date: Sun, 8 Feb 2026 23:41:32 +0900 Subject: [PATCH] modified the source code to exclude duplicated metabolite info. --- .../Algorithm/Alignment/SpotAction.cs | 10 ++--- .../MsdialGcMsApi/Algorithm/Annotation.cs | 41 ++++++++++++++++++- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/MSDIAL5/MsdialCore/Algorithm/Alignment/SpotAction.cs b/src/MSDIAL5/MsdialCore/Algorithm/Alignment/SpotAction.cs index 9b8ee3f03..b53ab3a2a 100644 --- a/src/MSDIAL5/MsdialCore/Algorithm/Alignment/SpotAction.cs +++ b/src/MSDIAL5/MsdialCore/Algorithm/Alignment/SpotAction.cs @@ -30,7 +30,7 @@ public MatchResultAnnotationDeduplicator(IMatchResultEvaluator spots) { - var spotList = spots.Where(n => n.IsReferenceMatched(_evaluator)).OrderByDescending(spot => spot.MatchResults.Representative.LibraryID).ToList(); + var spotList = spots.Where(n => n.IsReferenceMatched(_evaluator) && !n.Name.StartsWith("Putative")).OrderByDescending(spot => spot.MatchResults.Representative.LibraryID).ToList(); var currentPeakId = 0; var currentLibraryId = spotList[currentPeakId].MatchResults.Representative.LibraryID; @@ -56,7 +56,7 @@ public void Process(IEnumerable spots) { // by InChIKey spotList = spots - .Where(n => n.IsReferenceMatched(_evaluator)) + .Where(n => n.IsReferenceMatched(_evaluator) && !n.Name.StartsWith("Putative")) .Where(n => !string.IsNullOrEmpty(n.MatchResults?.Representative?.InChIKey) && n.MatchResults.Representative.InChIKey.Length > 1) .OrderByDescending(spot => spot.MatchResults.Representative.InChIKey) .ToList(); @@ -83,7 +83,7 @@ public void Process(IEnumerable spots) { // by Name spotList = spots - .Where(n => n.IsReferenceMatched(_evaluator)) + .Where(n => n.IsReferenceMatched(_evaluator) && !n.Name.StartsWith("Putative")) .Where(n => !n.MatchResults.Representative.Name.IsEmptyOrNull()) .OrderByDescending(spot => spot.MatchResults.Representative.Name) .ToList(); @@ -110,8 +110,8 @@ public void Process(IEnumerable spots) { } static void ChangeAnnotationToLowScore(AlignmentSpotProperty spot) { - spot.MatchResults.Representative.IsReferenceMatched = false; - spot.Name = "putative: " + spot.Name; + //spot.MatchResults.Representative.IsReferenceMatched = false; + spot.Name = "Putative: " + spot.Name; } } diff --git a/src/MSDIAL5/MsdialGcMsApi/Algorithm/Annotation.cs b/src/MSDIAL5/MsdialGcMsApi/Algorithm/Annotation.cs index 264876960..918ca0587 100644 --- a/src/MSDIAL5/MsdialGcMsApi/Algorithm/Annotation.cs +++ b/src/MSDIAL5/MsdialGcMsApi/Algorithm/Annotation.cs @@ -52,7 +52,7 @@ public AnnotatedMSDecResult[] MainProcess(IReadOnlyList ms1DecResul var features = new AnnotatedMSDecResult[ms1DecResults.Count]; if (_parameter.OnlyReportTopHitInMspSearch) { - var used = new HashSet(); + var used = new HashSet(new MoleculeMsReferenceEqualityComparer()); foreach (var (container, i) in containers.WithIndex().OrderByDescending(p => p.Item1.Representative.TotalScore)) { if (container.Representative is MsScanMatchResult topHit && !topHit.IsUnknown) { ms1DecResults[i].MspIDs.AddRange(containers[i].MatchResults.OrderByDescending(r => r.TotalScore).Select(r => r.LibraryID)); @@ -99,4 +99,43 @@ public AnnotatedMSDecResult[] MainProcess(IReadOnlyList ms1DecResul return ms1DecResults.Select(r => new AnnotatedMSDecResult(r, new MsScanMatchResultContainer())).ToArray(); } } + + public class MoleculeMsReferenceEqualityComparer : IEqualityComparer { + public bool Equals(MoleculeMsReference x, MoleculeMsReference y) { + if (ReferenceEquals(x, y)) return true; + if (x is null || y is null) return false; + + if (!string.IsNullOrEmpty(x.InChIKey) && !string.IsNullOrEmpty(y.InChIKey)) { + if (x.InChIKey == y.InChIKey) return true; + } + + if (x.ScanID != 0 && y.ScanID != 0 && x.ScanID == y.ScanID) { + return true; + } + + if (!string.IsNullOrEmpty(x.Name) && !string.IsNullOrEmpty(y.Name)) { + if (x.Name.ToLower() == y.Name.ToLower()) return true; + } + + return false; + } + + public int GetHashCode(MoleculeMsReference obj) { + if (obj is null) return 0; + + if (!string.IsNullOrEmpty(obj.InChIKey)) { + return obj.InChIKey.GetHashCode(); + } + + if (obj.ScanID != 0) { + return obj.ScanID.GetHashCode(); + } + + if (!string.IsNullOrEmpty(obj.Name)) { + return obj.Name.ToLower().GetHashCode(); + } + + return 0; + } + } }