@@ -25,7 +25,7 @@ public class MetadataWriter
2525 private double maxMz = 0 ;
2626 private double minCharge = 100000000000000 ;
2727 private double maxCharge = 0 ;
28- private readonly Dictionary < string , int > msTypes = new Dictionary < string , int > ( ) ;
28+ private Dictionary < MSOrderType , int > msLevels = new Dictionary < MSOrderType , int > ( ) ;
2929 private readonly ICollection < CVTerm > fragmentationTypes = new HashSet < CVTerm > ( CVTerm . CvTermComparer ) ;
3030
3131 /// <summary>
@@ -57,14 +57,9 @@ public void WriteMetadata(IRawDataPlus rawFile, int firstScanNumber, int lastSca
5757 // Get the scan event for this scan number
5858 var scanEvent = rawFile . GetScanEventForScanNumber ( scanNumber ) ;
5959
60- // Keep track of the number of MS<MS level> spectra
61- if ( msTypes . ContainsKey ( scanFilter . MSOrder . ToString ( ) ) )
62- {
63- msTypes [ scanFilter . MSOrder . ToString ( ) ] += 1 ;
64- }
65- else
66- msTypes . Add ( scanFilter . MSOrder . ToString ( ) , 1 ) ;
67-
60+ // Get MS levels
61+ msLevels = WriterUtil . CountScanOrder ( rawFile ) ;
62+
6863 if ( time > maxTime )
6964 maxTime = time ;
7065 if ( time < minTime )
@@ -174,22 +169,17 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last
174169 rawFile . GetInstrumentData ( ) . HardwareVersion ) ) ;
175170 }
176171
177-
178-
179172 // MS Data
180- foreach ( KeyValuePair < string , int > entry in msTypes )
181- {
182- if ( entry . Key . Equals ( MSOrderType . Ms . ToString ( ) ) )
183- metadata . addMSData ( new CVTerm ( "PRIDE:0000481" , "PRIDE" , "Number of MS1 spectra" ,
184- entry . Value . ToString ( ) ) ) ;
185- if ( entry . Key . Equals ( MSOrderType . Ms2 . ToString ( ) ) )
186- metadata . addMSData ( new CVTerm ( "PRIDE:0000482" , "PRIDE" , "Number of MS2 spectra" ,
187- entry . Value . ToString ( ) ) ) ;
188- if ( entry . Key . Equals ( MSOrderType . Ms3 . ToString ( ) ) )
189- metadata . addMSData ( new CVTerm ( "PRIDE:0000483" , "PRIDE" , "Number of MS3 spectra" ,
190- entry . Value . ToString ( ) ) ) ;
191- }
192-
173+ if ( msLevels [ MSOrderType . Ms ] > 0 )
174+ metadata . addMSData ( new CVTerm ( "PRIDE:0000481" , "PRIDE" , "Number of MS1 spectra" ,
175+ msLevels [ MSOrderType . Ms ] . ToString ( ) ) ) ;
176+ if ( msLevels [ MSOrderType . Ms2 ] > 0 )
177+ metadata . addMSData ( new CVTerm ( "PRIDE:0000482" , "PRIDE" , "Number of MS1 spectra" ,
178+ msLevels [ MSOrderType . Ms2 ] . ToString ( ) ) ) ;
179+ if ( msLevels [ MSOrderType . Ms3 ] > 0 )
180+ metadata . addMSData ( new CVTerm ( "PRIDE:0000483" , "PRIDE" , "Number of MS1 spectra" ,
181+ msLevels [ MSOrderType . Ms3 ] . ToString ( ) ) ) ;
182+
193183 metadata . addMSData ( new CVTerm ( "PRIDE:0000472" , "PRIDE" , "MS min charge" ,
194184 minCharge . ToString ( CultureInfo . InvariantCulture ) ) ) ;
195185 metadata . addMSData ( new CVTerm ( "PRIDE:0000473" , "PRIDE" , "MS max charge" ,
@@ -369,16 +359,14 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la
369359 }
370360
371361 // MS Data
362+ //TODO other MS levels??
372363 output . Add ( "#MsData" ) ;
373- foreach ( KeyValuePair < string , int > entry in msTypes )
374- {
375- if ( entry . Key . Equals ( MSOrderType . Ms . ToString ( ) ) )
376- output . Add ( "Number of MS1 spectra=" + entry . Value ) ;
377- if ( entry . Key . Equals ( MSOrderType . Ms2 . ToString ( ) ) )
378- output . Add ( "Number of MS2 spectra=" + entry . Value ) ;
379- if ( entry . Key . Equals ( MSOrderType . Ms3 . ToString ( ) ) )
380- output . Add ( "Number of MS3 spectra=" + entry . Value ) ;
381- }
364+ if ( msLevels [ MSOrderType . Ms ] > 0 )
365+ output . Add ( "Number of MS1 spectra=" + msLevels [ MSOrderType . Ms ] ) ;
366+ if ( msLevels [ MSOrderType . Ms2 ] > 0 )
367+ output . Add ( "Number of MS2 spectra=" + msLevels [ MSOrderType . Ms2 ] ) ;
368+ if ( msLevels [ MSOrderType . Ms3 ] > 0 )
369+ output . Add ( "Number of MS3 spectra=" + msLevels [ MSOrderType . Ms3 ] ) ;
382370
383371 output . AddRange ( new List < string >
384372 {
0 commit comments