@@ -56,14 +56,12 @@ public List<ProxiSpectrum> Retrieve()
5656 foreach ( var scanNumber in queryParameters . scanNumbers )
5757 {
5858 var proxiSpectrum = new ProxiSpectrum ( ) ;
59- double monoisotopicMz = 0.0 ;
59+
6060 try
6161 {
6262 // Get each scan from the RAW file
6363 var scan = Scan . FromFile ( rawFile , scanNumber ) ;
6464
65- // Check to see if the RAW file contains label (high-res) data and if it is present
66- // then look for any data that is out of order
6765 var time = rawFile . RetentionTimeFromScanNumber ( scanNumber ) ;
6866
6967 // Get the scan filter for this scan number
@@ -86,36 +84,32 @@ public List<ProxiSpectrum> Retrieve()
8684 value : ( ( int ) scanFilter . MSOrder ) . ToString ( CultureInfo . InvariantCulture ) ) ;
8785
8886 // trailer extra data list
89- var trailerData = rawFile . GetTrailerExtraInformation ( scanNumber ) ;
90- var charge = 0 ;
91- var isolationWidth = 0.0 ;
92- for ( var i = 0 ; i < trailerData . Length ; i ++ )
87+ //TODO Switch to Trailer object; check for empty trailerst
88+ ScanTrailer trailerData ;
89+ try
9390 {
94- if ( trailerData . Labels [ i ] == "Ion Injection Time (ms):" )
95- {
96- proxiSpectrum . AddAttribute ( accession : "MS:10000927" , name : "ion injection time" ,
97- value : trailerData . Values [ i ] , cvGroup : cvGroup . ToString ( ) ) ;
98- proxiSpectrum . AddAttribute ( accession : "UO:0000028" , name : "millisecond" ,
99- cvGroup : cvGroup . ToString ( ) ) ;
100- cvGroup ++ ;
101- }
102-
103- if ( trailerData . Labels [ i ] == "Charge State:" )
104- {
105- charge = Convert . ToInt32 ( trailerData . Values [ i ] ) ;
106- }
91+ trailerData = new ScanTrailer ( rawFile . GetTrailerExtraInformation ( scanNumber ) ) ;
92+ }
93+ catch ( Exception ex )
94+ {
95+ Log . WarnFormat ( "Cannot load trailer infromation for scan {0} due to following exception\n {1}" , scanNumber , ex . Message ) ;
96+ queryParameters . NewWarn ( ) ;
97+ trailerData = new ScanTrailer ( ) ;
98+ }
10799
108- if ( trailerData . Labels [ i ] == "Monoisotopic M/Z:" )
109- {
110- monoisotopicMz = double . Parse ( trailerData . Values [ i ] , NumberStyles . Any ,
111- CultureInfo . CurrentCulture ) ;
112- }
100+ int ? charge = trailerData . AsPositiveInt ( "Charge State:" ) ;
101+ double ? monoisotopicMz = trailerData . AsDouble ( "Monoisotopic M/Z:" ) ;
102+ double ? ionInjectionTime = trailerData . AsDouble ( "Ion Injection Time (ms):" ) ;
103+ double ? isolationWidth = trailerData . AsDouble ( "MS" + ( int ) scanFilter . MSOrder + " Isolation Width:" ) ;
113104
114- if ( trailerData . Labels [ i ] == "MS" + ( int ) scanFilter . MSOrder + " Isolation Width:" )
115- {
116- isolationWidth = double . Parse ( trailerData . Values [ i ] , NumberStyles . Any ,
117- CultureInfo . CurrentCulture ) ;
118- }
105+ //injection time
106+ if ( ionInjectionTime != null )
107+ {
108+ proxiSpectrum . AddAttribute ( accession : "MS:10000927" , name : "ion injection time" ,
109+ value : ionInjectionTime . ToString ( ) , cvGroup : cvGroup . ToString ( ) ) ;
110+ proxiSpectrum . AddAttribute ( accession : "UO:0000028" , name : "millisecond" ,
111+ cvGroup : cvGroup . ToString ( ) ) ;
112+ cvGroup ++ ;
119113 }
120114
121115 if ( reaction != null )
@@ -130,13 +124,13 @@ public List<ProxiSpectrum> Retrieve()
130124 value : selectedIonMz . ToString ( CultureInfo . InvariantCulture ) ) ;
131125
132126 // Store the isolation window information
133- var isolationHalfWidth = isolationWidth / 2 ;
127+ var offset = isolationWidth . Value / 2 + reaction . IsolationWidthOffset ;
134128 proxiSpectrum . AddAttribute ( accession : "MS:1000828" ,
135129 name : "isolation window lower offset" ,
136- value : isolationHalfWidth . ToString ( CultureInfo . InvariantCulture ) ) ;
130+ value : ( isolationWidth . Value - offset ) . ToString ( ) ) ;
137131 proxiSpectrum . AddAttribute ( accession : "MS:1000829" ,
138132 name : "isolation window upper offset" ,
139- value : isolationHalfWidth . ToString ( CultureInfo . InvariantCulture ) ) ;
133+ value : offset . ToString ( ) ) ;
140134 }
141135
142136 // scan polarity
@@ -152,13 +146,19 @@ public List<ProxiSpectrum> Retrieve()
152146 }
153147
154148 // charge state
155- proxiSpectrum . AddAttribute ( accession : "MS:10000041" , name : "charge state" ,
156- value : charge . ToString ( CultureInfo . InvariantCulture ) ) ;
149+ if ( charge != null )
150+ {
151+ proxiSpectrum . AddAttribute ( accession : "MS:10000041" , name : "charge state" ,
152+ value : charge . ToString ( ) ) ;
153+ }
157154
158155 // write the filter string
159156 proxiSpectrum . AddAttribute ( accession : "MS:10000512" , name : "filter string" ,
160157 value : scanEvent . ToString ( ) ) ;
161158
159+ double [ ] masses = null ;
160+ double [ ] intensities = null ;
161+
162162 if ( ! queryParameters . noPeakPicking ) // centroiding requested
163163 {
164164 // check if the scan has a centroid stream
@@ -169,8 +169,8 @@ public List<ProxiSpectrum> Retrieve()
169169 proxiSpectrum . AddAttribute ( accession : "MS:1000525" , name : "spectrum representation" ,
170170 value : "centroid spectrum" , valueAccession : "MS:1000127" ) ;
171171
172- proxiSpectrum . AddMz ( scan . CentroidScan . Masses ) ;
173- proxiSpectrum . AddIntensities ( scan . CentroidScan . Intensities ) ;
172+ masses = scan . CentroidScan . Masses ;
173+ intensities = scan . CentroidScan . Intensities ;
174174 }
175175 }
176176 else // otherwise take the low res segmented data
@@ -185,8 +185,8 @@ public List<ProxiSpectrum> Retrieve()
185185 proxiSpectrum . AddAttribute ( accession : "MS:1000525" , name : "spectrum representation" ,
186186 value : "centroid spectrum" , valueAccession : "MS:1000127" ) ;
187187
188- proxiSpectrum . AddMz ( segmentedScan . Positions ) ;
189- proxiSpectrum . AddIntensities ( segmentedScan . Intensities ) ;
188+ masses = segmentedScan . Positions ;
189+ intensities = segmentedScan . Intensities ;
190190 }
191191 }
192192 }
@@ -209,18 +209,27 @@ public List<ProxiSpectrum> Retrieve()
209209 break ;
210210 }
211211
212- proxiSpectrum . AddMz ( scan . SegmentedScan . Positions ) ;
213- proxiSpectrum . AddIntensities ( scan . SegmentedScan . Intensities ) ;
212+ masses = scan . SegmentedScan . Positions ;
213+ intensities = scan . SegmentedScan . Intensities ;
214214 }
215215 }
216216
217+ if ( masses != null && intensities != null )
218+ {
219+ Array . Sort ( masses , intensities ) ;
220+
221+ proxiSpectrum . AddMz ( masses ) ;
222+ proxiSpectrum . AddIntensities ( intensities ) ;
223+ }
224+
217225 resultList . Add ( proxiSpectrum ) ;
218226 }
219227 catch ( Exception ex )
220228 {
221229 if ( ex . GetBaseException ( ) is IndexOutOfRangeException )
222230 {
223- // ignore
231+ Log . WarnFormat ( "Spectrum #{0} outside of file boundries" , scanNumber ) ;
232+ queryParameters . NewWarn ( ) ;
224233 }
225234 else
226235 {
0 commit comments