|
5 | 5 | using log4net; |
6 | 6 | using ThermoFisher.CommonCore.Data; |
7 | 7 | using ThermoFisher.CommonCore.Data.Business; |
| 8 | +using ThermoFisher.CommonCore.Data.FilterEnums; |
8 | 9 | using ThermoFisher.CommonCore.Data.Interfaces; |
9 | 10 |
|
10 | 11 | namespace ThermoRawFileParser.Writer |
@@ -176,49 +177,57 @@ public static IReaction GetReaction(IScanEvent scanEvent, int scanNumber) |
176 | 177 | } |
177 | 178 |
|
178 | 179 | /// <summary> |
179 | | - /// Calculate the precursor peak intensity. |
| 180 | + /// Calculate the precursor peak intensity (similar to modern MSConvert). |
| 181 | + /// Sum intensities of all peaks in the isolation window. |
180 | 182 | /// </summary> |
181 | 183 | /// <param name="rawFile">the RAW file object</param> |
182 | 184 | /// <param name="precursorScanNumber">the precursor scan number</param> |
183 | 185 | /// <param name="precursorMass">the precursor mass</param> |
| 186 | + /// <param name="isolationWidth">the isolation width</param> |
| 187 | + /// <param name="useProfile">profile/centroid switch</param> |
184 | 188 | protected static double? CalculatePrecursorPeakIntensity(IRawDataPlus rawFile, int precursorScanNumber, |
185 | | - double precursorMass) |
| 189 | + double precursorMass, double? isolationWidth, bool useProfile) |
186 | 190 | { |
187 | | - double? precursorIntensity = null; |
188 | | - double tolerance; |
| 191 | + double precursorIntensity = 0; |
| 192 | + double halfWidth = isolationWidth is null || isolationWidth == 0 ? 0 : DefaultIsolationWindowLowerOffset; // that is how it is made in MSConvert (why?) |
189 | 193 |
|
190 | 194 | // Get the precursor scan from the RAW file |
191 | 195 | var scan = Scan.FromFile(rawFile, precursorScanNumber); |
192 | 196 |
|
193 | | - //Select centroid stream if it exists, otherwise use profile one |
194 | 197 | double[] masses; |
195 | 198 | double[] intensities; |
196 | 199 |
|
197 | | - if (scan.HasCentroidStream) |
198 | | - { |
199 | | - masses = scan.CentroidScan.Masses; |
200 | | - intensities = scan.CentroidScan.Intensities; |
201 | | - tolerance = 0.01; //high resolution scan |
202 | | - } |
203 | | - else |
| 200 | + if (useProfile) |
204 | 201 | { |
205 | 202 | masses = scan.SegmentedScan.Positions; |
206 | 203 | intensities = scan.SegmentedScan.Intensities; |
207 | | - tolerance = 0.5; //low resolution scan |
208 | 204 | } |
209 | | - |
210 | | - //find closest peak in a stream |
211 | | - var bestDelta = tolerance; |
212 | | - for (var i = 0; i < masses.Length; i++) |
| 205 | + else |
213 | 206 | { |
214 | | - var delta = precursorMass - masses[i]; |
215 | | - if (Math.Abs(delta) < bestDelta) |
| 207 | + //use centroids if they exist, otherwise perform centroiding |
| 208 | + if (scan.HasCentroidStream) |
| 209 | + { |
| 210 | + masses = scan.CentroidScan.Masses; |
| 211 | + intensities = scan.CentroidScan.Intensities; |
| 212 | + } |
| 213 | + else |
216 | 214 | { |
217 | | - bestDelta = delta; |
218 | | - precursorIntensity = intensities[i]; |
| 215 | + var scanEvent = rawFile.GetScanEventForScanNumber(precursorScanNumber); |
| 216 | + var centroidedScan = scanEvent.ScanData == ScanDataType.Profile //only centroid profile spectra |
| 217 | + ? Scan.ToCentroid(scan).SegmentedScan |
| 218 | + : scan.SegmentedScan; |
| 219 | + |
| 220 | + masses = centroidedScan.Positions; |
| 221 | + intensities = centroidedScan.Intensities; |
219 | 222 | } |
| 223 | + } |
| 224 | + |
| 225 | + var index = masses.FastBinarySearch(precursorMass - halfWidth); //set index to the first peak inside isolation window |
220 | 226 |
|
221 | | - if (delta < -1 * tolerance) break; |
| 227 | + while (index > 0 && index < masses.Length && masses[index] < precursorMass + halfWidth) //negative index means value was not found |
| 228 | + { |
| 229 | + precursorIntensity += intensities[index]; |
| 230 | + index++; |
222 | 231 | } |
223 | 232 |
|
224 | 233 | return precursorIntensity; |
|
0 commit comments