@@ -41,39 +41,62 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
4141 // Get the scan event for this scan number
4242 var scanEvent = rawFile . GetScanEventForScanNumber ( scanNumber ) ;
4343
44+ IReaction reaction = null ;
45+
4446 switch ( scanFilter . MSOrder )
4547 {
4648 case MSOrderType . Ms :
4749 // Keep track of scan number for precursor reference
4850 _precursorScanNumber = scanNumber ;
4951 break ;
5052 case MSOrderType . Ms2 :
53+ try
54+ {
55+ reaction = scanEvent . GetReaction ( 0 ) ;
56+ }
57+ catch ( ArgumentOutOfRangeException exception )
58+ {
59+ Log . Warn ( "No reaction found for scan " + scanNumber ) ;
60+ }
61+
62+ goto default ;
63+ case MSOrderType . Ms3 :
5164 {
65+ try
66+ {
67+ reaction = scanEvent . GetReaction ( 1 ) ;
68+ }
69+ catch ( ArgumentOutOfRangeException exception )
70+ {
71+ Log . Warn ( "No reaction found for scan " + scanNumber ) ;
72+ }
73+
74+ goto default ;
75+ }
76+ default :
5277 if ( scanEvent . ScanData == ScanDataType . Centroid ||
5378 ( scanEvent . ScanData == ScanDataType . Profile &&
54- ( scan . HasCentroidStream || ParseInput . OutputFormat != OutputFormat . MGFNoProfileData ) ) )
79+ ( scan . HasCentroidStream ||
80+ ParseInput . OutputFormat != OutputFormat . MGFNoProfileData ) ) )
5581 {
5682 Writer . WriteLine ( "BEGIN IONS" ) ;
5783 Writer . WriteLine ( $ "TITLE={ ConstructSpectrumTitle ( scanNumber ) } ") ;
5884 Writer . WriteLine ( $ "SCANS={ scanNumber } ") ;
59- Writer . WriteLine ( $ "RTINSECONDS={ ( time * 60 ) . ToString ( CultureInfo . InvariantCulture ) } ") ;
60- // Get the reaction information for the first precursor
61- try
85+ Writer . WriteLine (
86+ $ "RTINSECONDS={ ( time * 60 ) . ToString ( CultureInfo . InvariantCulture ) } ") ;
87+
88+ if ( reaction != null )
6289 {
63- var reaction = scanEvent . GetReaction ( 0 ) ;
6490 var precursorMass = reaction . PrecursorMass ;
6591 Writer . WriteLine ( "PEPMASS=" +
66- precursorMass . ToString ( "0.0000000" , CultureInfo . InvariantCulture ) ) ;
92+ precursorMass . ToString ( "0.0000000" ,
93+ CultureInfo . InvariantCulture ) ) ;
6794 //var precursorIntensity = 0.0;
6895 //GetPrecursorIntensity(rawFile, _precursorScanNumber, precursorMass);
6996 //Writer.WriteLine(precursorIntensity != null
7097 // ? $"PEPMASS={precursorMass:F7} {precursorIntensity}"
7198 // : $"PEPMASS={precursorMass:F7}");
7299 }
73- catch ( ArgumentOutOfRangeException exception )
74- {
75- Log . Warn ( "No reaction found for scan " + scanNumber ) ;
76- }
77100
78101 // trailer extra data list
79102 var trailerData = rawFile . GetTrailerExtraInformation ( scanNumber ) ;
@@ -132,7 +155,6 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
132155 }
133156
134157 break ;
135- }
136158 }
137159 }
138160 }
0 commit comments