@@ -232,6 +232,10 @@ public FlashLfqResults Run()
232232 QuantifyIsobaricPeaks ( ) ;
233233 _results . IsobaricPeptideDict = IsobaricPeptideDict ;
234234 AddIsoPeaks ( ) ;
235+ foreach ( var file in _results . SpectraFiles )
236+ {
237+ RunErrorChecking ( file ) ;
238+ }
235239 }
236240 IsoTrackerIsRunning = false ;
237241
@@ -831,8 +835,14 @@ private MbrScorer BuildMbrScorer(List<ChromatographicPeak> acceptorFileIdentifie
831835 . ToList ( ) ;
832836 double medianAcceptorLogIntensity = acceptorFileLogIntensities . Median ( ) ;
833837 Normal logIntensityDistribution = new Normal ( acceptorFileLogIntensities . Median ( ) , acceptorFileLogIntensities . InterquartileRange ( ) / 1.36 ) ;
834-
835- return new MbrScorer ( apexToAcceptorFilePeakDict , acceptorFileIdentifiedPeaks , ppmDistribution , logIntensityDistribution ) ;
838+ try // if the constructor fails, we don't want to crash the program
839+ {
840+ return new MbrScorer ( apexToAcceptorFilePeakDict , acceptorFileIdentifiedPeaks , ppmDistribution , logIntensityDistribution ) ;
841+ }
842+ catch
843+ {
844+ return null ;
845+ }
836846 }
837847
838848 /// <summary>
@@ -1354,6 +1364,12 @@ private void RunErrorChecking(SpectraFileInfo spectraFile)
13541364 {
13551365 if ( PeptideModifiedSequencesToQuantify . Contains ( storedPeak . Identifications . First ( ) . ModifiedSequence ) )
13561366 {
1367+ // if the try peak is merge into stored peaks, the try peak should be labeled as MSMSAmbiguousPeakfinding and then the intensity should be set as 0 in the peptide result
1368+ if ( tryPeak . DetectionType == DetectionType . IsoTrack_MSMS ||
1369+ tryPeak . DetectionType == DetectionType . IsoTrack_MBR )
1370+ {
1371+ tryPeak . DetectionType = DetectionType . MSMSAmbiguousPeakfinding ;
1372+ }
13571373 storedPeak . MergeFeatureWith ( tryPeak , FlashParams . Integrate ) ;
13581374 }
13591375 else
@@ -2009,7 +2025,7 @@ internal void CollectChromPeakInRuns(PeakRegion sharedPeak, List<Chromatographic
20092025 double peakStart = sharedPeak . StartRT ;
20102026 double PeakEnd = sharedPeak . EndRT ;
20112027 bool isMBR = false ;
2012- DetectionType detectionType = DetectionType . MSMS ;
2028+ DetectionType detectionType = DetectionType . IsoTrack_MSMS ;
20132029
20142030 // Check is there any Id in the XIC within the time window.
20152031 // Yes: use the Id from the same file. No: use the Id from other file, then set the detection type property as MBR.
@@ -2033,7 +2049,7 @@ internal void CollectChromPeakInRuns(PeakRegion sharedPeak, List<Chromatographic
20332049
20342050 break ;
20352051 case 1 : // If there is one Id from the same file in the time window, then detectionType should be MSMS.
2036- detectionType = DetectionType . MSMS ;
2052+ detectionType = DetectionType . IsoTrack_MSMS ;
20372053 break ;
20382054 case > 1 : // If there are more than one Id from the same file in the time window, then detectionType should be IsoTrack_Ambiguous.
20392055 detectionType = DetectionType . IsoTrack_Ambiguous ;
@@ -2119,24 +2135,37 @@ internal ChromatographicPeak FindChromPeak(Tuple<double, double, double> rtInfo,
21192135 /// </summary>
21202136 internal void AddIsoPeaks ( )
21212137 {
2122-
21232138 foreach ( var fileInfo in SpectraFileInfoList )
21242139 {
2125- var allChromPeaksInFile = IsobaricPeptideDict
2140+ var allIsoTrackerPeaksInFile = IsobaricPeptideDict
21262141 . SelectMany ( p => p . Value )
21272142 . SelectMany ( p => p . Value )
21282143 . Where ( peak => peak != null && peak . SpectraFileInfo . Equals ( fileInfo ) )
21292144 . ToList ( ) ;
2130- //remove the repeated peaks from FlashLFQ with the same identification list
2131- foreach ( var peak in allChromPeaksInFile )
2145+
2146+ //remove the repeated peaks from FlashLFQ with the same identification list, the priority is IsoTrack > MSMS
2147+ foreach ( var peak in allIsoTrackerPeaksInFile )
21322148 {
21332149 _results . Peaks [ fileInfo ] . RemoveAll ( p => IDsEqual ( p . Identifications , peak . Identifications ) ) ;
21342150 }
21352151
21362152 // Add the peaks into the result dictionary, and remove the duplicated peaks.
2137- _results . Peaks [ fileInfo ] . AddRange ( allChromPeaksInFile ) ;
2153+ // And we choice the IsoTrack_MSMS as the priority.
2154+ _results . Peaks [ fileInfo ] . AddRange ( allIsoTrackerPeaksInFile ) ;
21382155 _results . Peaks [ fileInfo ] = _results . Peaks [ fileInfo ]
2139- . DistinctBy ( peak => new { peak . ApexRetentionTime , peak . SpectraFileInfo , peak . Identifications . First ( ) . BaseSequence } ) . ToList ( ) ;
2156+ . GroupBy ( peak => new { peak . ApexRetentionTime , peak . SpectraFileInfo , peak . Identifications . First ( ) . BaseSequence } )
2157+ . Select ( group =>
2158+ {
2159+ // Prioritize IsoTrack_MSMS over other detection types
2160+ var prioritizedPeak = group
2161+ . OrderByDescending ( p => p . DetectionType == DetectionType . IsoTrack_MSMS )
2162+ . ThenByDescending ( p => p . DetectionType == DetectionType . IsoTrack_MBR )
2163+ . ThenByDescending ( p => p . DetectionType == DetectionType . IsoTrack_Ambiguous )
2164+ . ThenByDescending ( p => p . DetectionType == DetectionType . MSMS )
2165+ . First ( ) ;
2166+ return prioritizedPeak ;
2167+ } )
2168+ . ToList ( ) ;
21402169 }
21412170 }
21422171
0 commit comments