@@ -151,6 +151,42 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
151151 cvRef = "MS" ,
152152 value = ""
153153 } ) ;
154+ //ion current chromatogram
155+ SerializeCvParam ( new CVParamType
156+ {
157+ accession = "MS:1000810" ,
158+ name = "ion current chromatogram" ,
159+ cvRef = "MS" ,
160+ value = ""
161+ } ) ;
162+
163+ //other detector data
164+ if ( ParseInput . AllDetectors )
165+ {
166+ //PDA spectrum
167+ if ( _rawFile . GetInstrumentCountOfType ( Device . Pda ) > 0 )
168+ {
169+ SerializeCvParam ( new CVParamType
170+ {
171+ accession = "MS:1000806" ,
172+ name = "absorption spectrum" ,
173+ cvRef = "MS" ,
174+ value = ""
175+ } ) ;
176+ }
177+
178+ //absorption chromatogram
179+ if ( _rawFile . GetInstrumentCountOfType ( Device . Pda ) > 0 || _rawFile . GetInstrumentCountOfType ( Device . UV ) > 0 )
180+ {
181+ SerializeCvParam ( new CVParamType
182+ {
183+ accession = "MS:1000812" ,
184+ name = "absorption chromatogram" ,
185+ cvRef = "MS" ,
186+ value = ""
187+ } ) ;
188+ }
189+ }
154190 _writer . WriteEndElement ( ) ; // fileContent
155191
156192 // sourceFileList
@@ -244,6 +280,19 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
244280 name = "Conversion to mzML" ,
245281 value = ""
246282 } ) ;
283+ if ( ! ParseInput . NoPeakPicking )
284+ {
285+ _writer . WriteStartElement ( "processingMethod" ) ;
286+ _writer . WriteAttributeString ( "order" , "1" ) ;
287+ _writer . WriteAttributeString ( "softwareRef" , "ThermoRawFileParser" ) ;
288+ SerializeCvParam ( new CVParamType
289+ {
290+ accession = "MS:1000035" ,
291+ cvRef = "MS" ,
292+ name = "peak picking" ,
293+ value = ""
294+ } ) ;
295+ }
247296 _writer . WriteEndElement ( ) ; // processingMethod
248297 _writer . WriteEndElement ( ) ; // dataProcessing
249298 _writer . WriteEndElement ( ) ; // dataProcessingList
@@ -257,7 +306,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
257306 _writer . WriteAttributeString ( "defaultSourceFileRef" , SourceFileId ) ;
258307 // spectrumList
259308 _writer . WriteStartElement ( "spectrumList" ) ;
260- _writer . WriteAttributeString ( "count" , _rawFile . RunHeaderEx . SpectraCount . ToString ( ) ) ;
309+ _writer . WriteAttributeString ( "count" , GetTotalScanNumber ( ) ) ;
261310 _writer . WriteAttributeString ( "defaultDataProcessingRef" , "ThermoRawFileParserProcessing" ) ;
262311
263312 serializer = _factory . CreateSerializer ( typeof ( SpectrumType ) ) ;
@@ -266,7 +315,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
266315 var index = 0 ;
267316 var lastScanProgress = 0 ;
268317
269- Log . Info ( "Processing " + ( lastScanNumber - firstScanNumber ) + " MS scans" ) ;
318+ Log . Info ( String . Format ( "Processing {0} MS scans" , + ( 1 + lastScanNumber - firstScanNumber ) ) ) ;
270319
271320 for ( var scanNumber = firstScanNumber ; scanNumber <= lastScanNumber ; scanNumber ++ )
272321 {
@@ -318,14 +367,14 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
318367 // PDA spectra
319368 if ( ParseInput . AllDetectors && _rawFile . GetInstrumentCountOfType ( Device . Pda ) > 0 )
320369 {
321- for ( int nrI = 0 ; nrI < _rawFile . GetInstrumentCountOfType ( Device . Pda ) ; nrI ++ )
370+ for ( int nrI = 1 ; nrI < _rawFile . GetInstrumentCountOfType ( Device . Pda ) + 1 ; nrI ++ )
322371 {
323- _rawFile . SelectInstrument ( Device . Pda , nrI + 1 ) ;
372+ _rawFile . SelectInstrument ( Device . Pda , nrI ) ;
324373 firstScanNumber = _rawFile . RunHeader . FirstSpectrum ;
325374 lastScanNumber = _rawFile . RunHeader . LastSpectrum ;
326375 lastScanProgress = 0 ;
327376
328- Log . Info ( "Processing " + ( lastScanNumber - firstScanNumber ) + " PDA scans from Device #" + ( nrI + 1 ) ) ;
377+ Log . Info ( String . Format ( "Processing {0} PDA scans from Device #{1}" , ( 1 + lastScanNumber - firstScanNumber ) , nrI ) ) ;
329378
330379 for ( var scanNumber = firstScanNumber ; scanNumber <= lastScanNumber ; scanNumber ++ )
331380 {
@@ -342,7 +391,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
342391 }
343392 }
344393
345- var spectrum = ConstructPDASpectrum ( scanNumber , nrI + 1 ) ;
394+ var spectrum = ConstructPDASpectrum ( scanNumber , nrI ) ;
346395 if ( spectrum != null )
347396 {
348397 spectrum . index = index . ToString ( ) ;
@@ -532,6 +581,32 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc
532581 }
533582 }
534583
584+ private string GetTotalScanNumber ( )
585+ {
586+ //save instrument that was selected last time
587+ var lastSelectedInstrument = _rawFile . SelectedInstrument ;
588+ var numScans = 0 ;
589+
590+ _rawFile . SelectInstrument ( Device . MS , 1 ) ;
591+
592+ numScans += 1 + _rawFile . RunHeader . LastSpectrum - _rawFile . RunHeader . FirstSpectrum ;
593+
594+ if ( ParseInput . AllDetectors )
595+ {
596+ for ( int nrI = 1 ; nrI < _rawFile . GetInstrumentCountOfType ( Device . Pda ) + 1 ; nrI ++ )
597+ {
598+ _rawFile . SelectInstrument ( Device . Pda , nrI ) ;
599+ numScans += 1 + _rawFile . RunHeader . LastSpectrum - _rawFile . RunHeader . FirstSpectrum ;
600+ }
601+ }
602+
603+ //return instrument to last selected one
604+ if ( lastSelectedInstrument != null )
605+ _rawFile . SelectInstrument ( lastSelectedInstrument . DeviceType , lastSelectedInstrument . InstrumentIndex ) ;
606+
607+ return numScans . ToString ( ) ;
608+ }
609+
535610 /// <summary>
536611 /// Populate the instrument configuration list
537612 /// </summary>
@@ -704,6 +779,8 @@ private List<ChromatogramType> ConstructChromatograms(int firstScanNumber, int l
704779 var chromatograms = new List < ChromatogramType > ( ) ;
705780
706781 //MS chromatograms
782+ //Reselect MS device
783+ _rawFile . SelectInstrument ( Device . MS , 1 ) ;
707784 // Define the settings for getting the Base Peak chromatogram
708785 var settings = new ChromatogramTraceSettings ( TraceType . BasePeak ) ;
709786
@@ -744,21 +821,22 @@ private List<ChromatogramType> ConstructChromatograms(int firstScanNumber, int l
744821
745822 }
746823
747- //UV chromatograms
824+ //Chromatograms from other devices: UV, PDA
748825 if ( ParseInput . AllDetectors )
749826 {
750- for ( int nrI = 0 ; nrI < _rawFile . GetInstrumentCountOfType ( Device . Pda ) ; nrI ++ )
827+ for ( int nrI = 1 ; nrI < _rawFile . GetInstrumentCountOfType ( Device . Pda ) + 1 ; nrI ++ )
751828 {
752- _rawFile . SelectInstrument ( Device . Pda , nrI + 1 ) ;
829+ _rawFile . SelectInstrument ( Device . Pda , nrI ) ;
753830
754- var settingsPDA = new ChromatogramTraceSettings ( TraceType . TotalAbsorbance ) ;
831+ var instData = _rawFile . GetInstrumentData ( ) ;
755832
756- var dataPDA = _rawFile . GetChromatogramData ( new IChromatogramSettings [ ] { settingsPDA } ,
757- - 1 , - 1 ) ;
833+ settings = new ChromatogramTraceSettings ( TraceType . TotalAbsorbance ) ;
758834
759- var tracePDA = ChromatogramSignal . FromChromatogramData ( dataPDA ) ;
835+ data = _rawFile . GetChromatogramData ( new IChromatogramSettings [ ] { settings } , - 1 , - 1 ) ;
760836
761- for ( var i = 0 ; i < tracePDA . Length ; i ++ )
837+ trace = ChromatogramSignal . FromChromatogramData ( data ) ;
838+
839+ for ( var i = 0 ; i < trace . Length ; i ++ )
762840 {
763841 // CV Data for Total Absorbance Chromatogram
764842 var chroType = new CVParamType
@@ -775,17 +853,115 @@ private List<ChromatogramType> ConstructChromatograms(int firstScanNumber, int l
775853 name = "intensity array" ,
776854 cvRef = "MS" ,
777855 unitName = "absorbance unit" ,
778- value = "" ,
856+ value = instData . Units . ToString ( ) ,
779857 unitCvRef = "UO" ,
780858 unitAccession = "UO:0000269"
781859 } ;
782860
783- var chromatogram = TraceToChromatogram ( tracePDA [ i ] , String . Format ( "PDA{0}_{1}" , nrI , i . ToString ( ) ) ,
784- chroType , intensType ) ;
861+ var chromatogram = TraceToChromatogram ( trace [ i ] ,
862+ String . Format ( "PDA#{0}_TotalAbsorbance_{1}" , nrI , i ) ,
863+ chroType , intensType ) ;
785864
786865 chromatograms . Add ( chromatogram ) ;
787866 }
788867 }
868+
869+ for ( int nrI = 1 ; nrI < _rawFile . GetInstrumentCountOfType ( Device . UV ) + 1 ; nrI ++ )
870+ {
871+ _rawFile . SelectInstrument ( Device . UV , nrI ) ;
872+
873+ var instData = _rawFile . GetInstrumentData ( ) ;
874+
875+ for ( int channel = 0 ; channel < instData . ChannelLabels . Length ; channel ++ )
876+ {
877+ var channelName = instData . ChannelLabels [ channel ] ;
878+
879+ settings = new ChromatogramTraceSettings ( TraceType . StartUVChromatogramTraces + channel + 1 ) ;
880+
881+ data = _rawFile . GetChromatogramData ( new IChromatogramSettings [ ] { settings } , - 1 , - 1 ) ;
882+
883+ trace = ChromatogramSignal . FromChromatogramData ( data ) ;
884+
885+ for ( var i = 0 ; i < trace . Length ; i ++ )
886+ {
887+ // CV Data for Absorbance Chromatogram
888+ var chroType = new CVParamType
889+ {
890+ accession = "MS:1000812" ,
891+ name = "absorption chromatogram" ,
892+ cvRef = "MS" ,
893+ value = ""
894+ } ;
895+
896+ var intensType = new CVParamType
897+ {
898+ accession = "MS:1000515" ,
899+ name = "intensity array" ,
900+ cvRef = "MS" ,
901+ unitName = "absorbance unit" ,
902+ value = instData . Units . ToString ( ) ,
903+ unitCvRef = "UO" ,
904+ unitAccession = "UO:0000269"
905+ } ;
906+
907+ var chromatogram = TraceToChromatogram ( trace [ i ] ,
908+ String . Format ( "UV#{0}_{1}_{2}" , nrI , channelName , i ) ,
909+ chroType , intensType ) ;
910+
911+ chromatograms . Add ( chromatogram ) ;
912+ }
913+ }
914+ }
915+
916+ for ( int nrI = 1 ; nrI < _rawFile . GetInstrumentCountOfType ( Device . Analog ) + 1 ; nrI ++ )
917+ {
918+ _rawFile . SelectInstrument ( Device . Analog , nrI ) ;
919+
920+ var instData = _rawFile . GetInstrumentData ( ) ;
921+
922+ for ( int channel = 0 ; channel < instData . ChannelLabels . Length ; channel ++ )
923+ {
924+ var channelName = instData . ChannelLabels [ channel ] ;
925+
926+ if ( channelName . ToLower ( ) . Contains ( "pressure" ) )
927+ {
928+ settings = new ChromatogramTraceSettings ( TraceType . StartPCA2DChromatogramTraces + channel + 1 ) ;
929+
930+ data = _rawFile . GetChromatogramData ( new IChromatogramSettings [ ] { settings } , - 1 , - 1 ) ;
931+
932+ trace = ChromatogramSignal . FromChromatogramData ( data ) ;
933+
934+ for ( var i = 0 ; i < trace . Length ; i ++ )
935+ {
936+ // CV Data for Absorbance Chromatogram
937+ var chroType = new CVParamType
938+ {
939+ accession = "MS:1003019" ,
940+ name = "pressure chromatogram" ,
941+ cvRef = "MS" ,
942+ value = ""
943+ } ;
944+
945+ var intensType = new CVParamType
946+ {
947+ accession = "MS:1000821" ,
948+ name = "pressure array" ,
949+ cvRef = "MS" ,
950+ unitName = "pressure unit" ,
951+ value = "" ,
952+ unitCvRef = "UO" ,
953+ unitAccession = "UO:0000109"
954+ } ;
955+
956+ var chromatogram = TraceToChromatogram ( trace [ i ] ,
957+ String . Format ( "AD#{0}_{1}_{2}" , nrI , channelName , i ) ,
958+ chroType , intensType ) ;
959+
960+ chromatograms . Add ( chromatogram ) ;
961+ }
962+ }
963+ }
964+ }
789965 }
790966
791967 return chromatograms ;
@@ -1295,7 +1471,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber)
12951471 // Set the spectrum default array length if necessary
12961472 if ( spectrum . defaultArrayLength == 0 )
12971473 {
1298- spectrum . defaultArrayLength = masses . Length ;
1474+ spectrum . defaultArrayLength = intensities . Length ;
12991475 }
13001476
13011477 var intensitiesBinaryData =
@@ -1377,17 +1553,7 @@ private SpectrumType ConstructPDASpectrum(int scanNumber, int instrumentNumber)
13771553 // Construct and set the scan list element of the spectrum
13781554 var scanListType = ConstructScanList ( scanNumber , scan ) ;
13791555 spectrum . scanList = scanListType ;
1380-
13811556
1382- // Total ion current
1383- spectrumCvParams . Add ( new CVParamType
1384- {
1385- name = "total ion current" ,
1386- accession = "MS:1000285" ,
1387- value = scan . ScanStatistics . TIC . ToString ( CultureInfo . InvariantCulture ) ,
1388- cvRef = "MS"
1389- } ) ;
1390-
13911557 //Scan data
13921558 double ? basePeakPosition = null ;
13931559 double ? basePeakIntensity = null ;
@@ -1845,7 +2011,8 @@ private PrecursorListType ConstructPrecursorList(IScanEventBase scanEvent, int?
18452011 }
18462012
18472013 /// <summary>
1848- /// Populate the scan list element
2014+ /// Populate the scan list element. Full version used for mass spectra,
2015+ /// having Scan Event, scan Filter etc
18492016 /// </summary>
18502017 /// <param name="scanNumber">the scan number</param>
18512018 /// <param name="scan">the scan object</param>
@@ -1973,6 +2140,13 @@ private ScanListType ConstructScanList(int scanNumber, Scan scan, IScanFilter sc
19732140 return scanList ;
19742141 }
19752142
2143+ /// <summary>
2144+ /// Populate the scan list element. Simple version used for PDA spectra,
2145+ /// without Scan Event and other parameters
2146+ /// </summary>
2147+ /// <param name="scanNumber">the scan number</param>
2148+ /// <param name="scan">the scan object</param>
2149+ /// <returns></returns>
19762150 private ScanListType ConstructScanList ( int scanNumber , Scan scan )
19772151 {
19782152 // Scan list
0 commit comments