@@ -1309,44 +1309,51 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
13091309 }
13101310 else //try getting it from the scan filter
13111311 {
1312- var parts = Regex . Split ( result . Groups [ 1 ] . Value , " " ) ;
1313-
1314- //find the position of the first (from the end) precursor with a different mass
1315- //to account for possible supplementary activations written in the filter
1316- var lastIonMass = parts . Last ( ) . Split ( '@' ) . First ( ) ;
1317- int last = parts . Length ;
1318- while ( last > 0 &&
1319- parts [ last - 1 ] . Split ( '@' ) . First ( ) == lastIonMass )
1320- {
1321- last -- ;
1322- }
1323-
1324- string parentFilter = String . Join ( " " , parts . Take ( last ) ) ;
1325- if ( _precursorScanNumbers . ContainsKey ( parentFilter ) )
1326- {
1327- _precursorScanNumber = _precursorScanNumbers [ parentFilter ] ;
1328- }
1312+ _precursorScanNumber = GetParentFromScanString ( result . Groups [ 1 ] . Value ) ;
13291313 }
13301314
13311315 if ( _precursorScanNumber > 0 )
13321316 {
1333-
1317+
13341318 try
13351319 {
1320+ try //since there is no direct way to get the number of reactions available, it is necessary to try and fail
1321+ {
1322+ scanEvent . GetReaction ( _precursorTree [ _precursorScanNumber ] . ReactionCount ) ;
1323+ }
1324+ catch ( ArgumentOutOfRangeException ex )
1325+ {
1326+ Log . Debug ( $ "Using Tribrid decision tree fix for scan# { scanNumber } ") ;
1327+ //Is it a decision tree scheduled scan on tribrid?
1328+ if ( msLevel == _precursorTree [ _precursorScanNumber ] . MSLevel )
1329+ {
1330+ _precursorScanNumber = GetParentFromScanString ( result . Groups [ 1 ] . Value ) ;
1331+ }
1332+ else
1333+ {
1334+ throw new RawFileParserException (
1335+ $ "Tribrid decision tree fix failed - cannot get reaction# { _precursorTree [ _precursorScanNumber ] . ReactionCount } from { scanEvent . ToString ( ) } ",
1336+ ex ) ;
1337+ }
1338+ }
1339+
13361340 // Construct and set the precursor list element of the spectrum
13371341 spectrum . precursorList =
13381342 ConstructPrecursorList ( _precursorScanNumber , scanEvent , charge , monoisotopicMz , isolationWidth ,
13391343 SPSMasses , out var reactionCount ) ;
13401344
13411345 //save precursor information for later reference
1342- _precursorTree [ scanNumber ] = new PrecursorInfo ( _precursorScanNumber , reactionCount , spectrum . precursorList . precursor ) ;
1346+ _precursorTree [ scanNumber ] = new PrecursorInfo ( _precursorScanNumber , msLevel , reactionCount , spectrum . precursorList . precursor ) ;
13431347 }
1344- catch ( RawFileParserException e )
1348+ catch ( Exception e )
13451349 {
1346- Log . Warn ( $ "Failed creating precursor list for scan# { scanNumber } ; { e . Message } ; precursor information for this and dependent scans will be empty") ;
1350+ var extra = ( e . InnerException is null ) ? "" : $ "\n { e . InnerException . StackTrace } ";
1351+
1352+ Log . Warn ( $ "Failed creating precursor list for scan# { scanNumber } - precursor information for this and dependent scans will be empty\n Exception details:{ e . Message } \n { e . StackTrace } \n { extra } ") ;
13471353 ParseInput . NewWarn ( ) ;
13481354
1349- _precursorTree [ scanNumber ] = new PrecursorInfo ( _precursorScanNumber , 0 , new PrecursorType [ 0 ] ) ;
1355+ _precursorTree [ scanNumber ] = new PrecursorInfo ( _precursorScanNumber , 1 , 0 , new PrecursorType [ 0 ] ) ;
1356+
13501357 }
13511358
13521359 }
@@ -2151,21 +2158,15 @@ private PrecursorListType ConstructPrecursorList(int precursorScanNumber, IScanE
21512158 IReaction reaction = null ;
21522159 var precursorMz = 0.0 ;
21532160 reactionCount = prevPrecursors . ReactionCount ;
2154- try
2155- {
2156- spectrumRef = ConstructSpectrumTitle ( ( int ) Device . MS , 1 , precursorScanNumber ) ;
2157- reaction = scanEvent . GetReaction ( reactionCount ) ;
2158-
2159- precursorMz = reaction . PrecursorMass ;
21602161
2161- //if isolation width was not found in the trailer, try to get one from the reaction
2162- if ( isolationWidth == null ) isolationWidth = reaction . IsolationWidth ;
2163- }
2164- catch ( ArgumentOutOfRangeException )
2165- {
2166- throw new RawFileParserException ( $ "Cannot get reaction at index { reactionCount } from { scanEvent . ToString ( ) } ") ;
2167- }
2162+ spectrumRef = ConstructSpectrumTitle ( ( int ) Device . MS , 1 , precursorScanNumber ) ;
2163+ reaction = scanEvent . GetReaction ( reactionCount ) ;
2164+
2165+ precursorMz = reaction . PrecursorMass ;
21682166
2167+ //if isolation width was not found in the trailer, try to get one from the reaction
2168+ if ( isolationWidth == null ) isolationWidth = reaction . IsolationWidth ;
2169+
21692170 var precursor = new PrecursorType
21702171 {
21712172 selectedIonList =
@@ -2423,6 +2424,30 @@ private PrecursorListType ConstructPrecursorList(int precursorScanNumber, IScanE
24232424
24242425 }
24252426
2427+ private int GetParentFromScanString ( string scanString )
2428+ {
2429+ var result = _filterStringIsolationMzPattern . Match ( scanString ) ;
2430+ var parts = Regex . Split ( result . Groups [ 1 ] . Value , " " ) ;
2431+
2432+ //find the position of the first (from the end) precursor with a different mass
2433+ //to account for possible supplementary activations written in the filter
2434+ var lastIonMass = parts . Last ( ) . Split ( '@' ) . First ( ) ;
2435+ int last = parts . Length ;
2436+ while ( last > 0 &&
2437+ parts [ last - 1 ] . Split ( '@' ) . First ( ) == lastIonMass )
2438+ {
2439+ last -- ;
2440+ }
2441+
2442+ string parentFilter = String . Join ( " " , parts . Take ( last ) ) ;
2443+ if ( _precursorScanNumbers . ContainsKey ( parentFilter ) )
2444+ {
2445+ return _precursorScanNumbers [ parentFilter ] ;
2446+ }
2447+
2448+ return - 1 ; //unsuccessful parsing
2449+ }
2450+
24262451 /// <summary>
24272452 /// Populate the scan list element. Full version used for mass spectra,
24282453 /// having Scan Event, scan Filter etc
0 commit comments