-
Notifications
You must be signed in to change notification settings - Fork 4
/
MRMProcessing.cs
755 lines (630 loc) · 31.8 KB
/
MRMProcessing.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
using System;
using System.Collections.Generic;
using System.IO;
using MASIC.Data;
using MASIC.DataOutput;
using MASIC.Options;
using MASICPeakFinder;
using PRISM;
using ThermoRawFileReader;
namespace MASIC
{
/// <summary>
/// MRM processing class
/// </summary>
public class MRMProcessing : MasicEventNotifier
{
// Ignore Spelling: crosstab, MASIC, mrm, srm
private struct SRMListType
{
public double ParentIonMZ;
public double CentralMass;
public override string ToString()
{
return "m/z " + ParentIonMZ.ToString("0.00");
}
}
private readonly MASICOptions mOptions;
private readonly DataAggregation mDataAggregation;
private readonly DataOutput.DataOutput mDataOutputHandler;
/// <summary>
/// Constructor
/// </summary>
public MRMProcessing(MASICOptions masicOptions, DataOutput.DataOutput dataOutputHandler)
{
mOptions = masicOptions;
mDataAggregation = new DataAggregation();
RegisterEvents(mDataAggregation);
mDataOutputHandler = dataOutputHandler;
}
private string ConstructSRMMapKey(SRMListType srmEntry)
{
return ConstructSRMMapKey(srmEntry.ParentIonMZ, srmEntry.CentralMass);
}
private string ConstructSRMMapKey(double parentIonMZ, double centralMass)
{
return parentIonMZ.ToString("0.000") + "_to_" + centralMass.ToString("0.000");
}
private bool DetermineMRMSettings(
ScanList scanList,
out List<MRMScanInfo> mrmSettings,
out List<SRMListType> srmList)
{
// Returns true if this dataset has MRM data and if it is parsed successfully
// Returns false if the dataset does not have MRM data, or if an error occurs
mrmSettings = new List<MRMScanInfo>(200);
srmList = new List<SRMListType>(600); // Assume there are 3 fragmentation masses for each parent mass
try
{
var mrmDataPresent = false;
UpdateProgress(0, "Determining MRM settings");
// Initialize the tracking arrays
var mrmHashToIndexMap = new Dictionary<string, MRMScanInfo>();
// Construct a list of the MRM search values used
foreach (var fragScan in scanList.FragScans)
{
if (fragScan.MRMScanType == MRMScanTypeConstants.SRM)
{
mrmDataPresent = true;
// See if this MRM spec is already in mrmSettings
var mrmInfoHash = GenerateMRMInfoHash(fragScan.MRMScanInfo);
if (!mrmHashToIndexMap.TryGetValue(mrmInfoHash, out var mrmInfoForHash))
{
mrmInfoForHash = DuplicateMRMInfo(fragScan.MRMScanInfo);
mrmInfoForHash.ScanCount = 1;
mrmInfoForHash.ParentIonInfoIndex = fragScan.FragScanInfo.ParentIonInfoIndex;
mrmSettings.Add(mrmInfoForHash);
mrmHashToIndexMap.Add(mrmInfoHash, mrmInfoForHash);
// Append the new entries to srmList
for (var mrmMassIndex = 0; mrmMassIndex < mrmInfoForHash.MRMMassCount; mrmMassIndex++)
{
// Add this new transition to srmList() only if not already present
var matchFound = false;
foreach (var srmItem in srmList)
{
if (MRMParentDaughterMatch(srmItem, mrmInfoForHash, mrmMassIndex))
{
matchFound = true;
break;
}
}
if (!matchFound)
{
// Entry is not yet present; add it
var newSRMItem = new SRMListType
{
ParentIonMZ = mrmInfoForHash.ParentIonMZ,
CentralMass = mrmInfoForHash.MRMMassList[mrmMassIndex].CentralMass
};
srmList.Add(newSRMItem);
}
}
}
else
{
mrmInfoForHash.ScanCount++;
}
}
}
// Resize the lists to their contents
mrmSettings.Capacity = mrmSettings.Count;
srmList.Capacity = srmList.Count;
return mrmDataPresent;
}
catch (Exception ex)
{
ReportError("Error determining the MRM settings", ex, clsMASIC.MasicErrorCodes.OutputFileWriteError);
return false;
}
}
/// <summary>
/// Duplicate MRM info, overriding the parent ion m/z using parentIonMZ
/// </summary>
/// <param name="sourceInfo"></param>
/// <param name="parentIonMZ"></param>
public static MRMScanInfo DuplicateMRMInfo(
MRMInfo sourceInfo,
double parentIonMZ)
{
var targetInfo = new MRMScanInfo
{
ParentIonMZ = parentIonMZ,
MRMMassCount = sourceInfo.MRMMassList.Count,
ScanCount = 0,
ParentIonInfoIndex = -1,
};
if (sourceInfo.MRMMassList == null)
{
targetInfo.MRMMassList = new List<MRMMassRangeType>();
}
else
{
targetInfo.MRMMassList = new List<MRMMassRangeType>(sourceInfo.MRMMassList.Count);
targetInfo.MRMMassList.AddRange(sourceInfo.MRMMassList);
}
return targetInfo;
}
/// <summary>
/// Duplicate MRM info
/// </summary>
/// <param name="sourceInfo"></param>
private MRMScanInfo DuplicateMRMInfo(MRMScanInfo sourceInfo)
{
var targetInfo = new MRMScanInfo
{
ParentIonMZ = sourceInfo.ParentIonMZ,
MRMMassCount = sourceInfo.MRMMassCount,
ScanCount = sourceInfo.ScanCount,
ParentIonInfoIndex = sourceInfo.ParentIonInfoIndex,
};
if (sourceInfo.MRMMassList == null)
{
targetInfo.MRMMassList = new List<MRMMassRangeType>();
}
else
{
targetInfo.MRMMassList = new List<MRMMassRangeType>(sourceInfo.MRMMassList.Count);
targetInfo.MRMMassList.AddRange(sourceInfo.MRMMassList);
}
return targetInfo;
}
/// <summary>
/// Export MRM data to disk
/// </summary>
/// <param name="scanList"></param>
/// <param name="spectraCache"></param>
/// <param name="inputFileName"></param>
/// <param name="outputDirectoryPath"></param>
public bool ExportMRMDataToDisk(
ScanList scanList,
SpectraCache spectraCache,
string inputFileName,
string outputDirectoryPath)
{
if (!DetermineMRMSettings(scanList, out var mrmSettings, out var srmList))
{
return false;
}
return ExportMRMDataToDisk(scanList, spectraCache, mrmSettings, srmList, inputFileName, outputDirectoryPath);
}
/// <summary>
/// Export MRM data to disk
/// </summary>
/// <param name="scanList"></param>
/// <param name="spectraCache"></param>
/// <param name="mrmSettings"></param>
/// <param name="srmList"></param>
/// <param name="inputFileName"></param>
/// <param name="outputDirectoryPath"></param>
/// <returns>True if the MRM data is successfully written to disk, or if the mrmSettings list is empty</returns>
private bool ExportMRMDataToDisk(
ScanList scanList,
SpectraCache spectraCache,
IReadOnlyList<MRMScanInfo> mrmSettings,
IReadOnlyList<SRMListType> srmList,
string inputFileName,
string outputDirectoryPath)
{
const char TAB_DELIMITER = '\t';
StreamWriter dataWriter = null;
StreamWriter crosstabWriter = null;
bool success;
try
{
// Only write this data if 1 or more fragmentation spectra are of type SRM
if (mrmSettings == null || mrmSettings.Count == 0)
{
return true;
}
UpdateProgress(0, "Exporting MRM data");
// Write out the MRM Settings
var mrmSettingsFilePath = DataOutput.DataOutput.ConstructOutputFilePath(
inputFileName, outputDirectoryPath, DataOutput.DataOutput.OutputFileTypeConstants.MRMSettingsFile);
using var settingsWriter = new StreamWriter(mrmSettingsFilePath);
settingsWriter.WriteLine(mDataOutputHandler.GetHeadersForOutputFile(scanList, DataOutput.DataOutput.OutputFileTypeConstants.MRMSettingsFile));
var dataColumns = new List<string>(7);
for (var mrmInfoIndex = 0; mrmInfoIndex < mrmSettings.Count; mrmInfoIndex++)
{
var mrmSetting = mrmSettings[mrmInfoIndex];
for (var mrmMassIndex = 0; mrmMassIndex < mrmSetting.MRMMassCount; mrmMassIndex++)
{
dataColumns.Clear();
dataColumns.Add(mrmInfoIndex.ToString());
dataColumns.Add(mrmSetting.ParentIonMZ.ToString("0.000"));
dataColumns.Add(mrmSetting.MRMMassList[mrmMassIndex].CentralMass.ToString("0.000"));
dataColumns.Add(mrmSetting.MRMMassList[mrmMassIndex].StartMass.ToString("0.000"));
dataColumns.Add(mrmSetting.MRMMassList[mrmMassIndex].EndMass.ToString("0.000"));
dataColumns.Add(mrmSetting.ScanCount.ToString());
settingsWriter.WriteLine(string.Join(TAB_DELIMITER.ToString(), dataColumns));
}
}
if (mOptions.WriteMRMDataList || mOptions.WriteMRMIntensityCrosstab)
{
// Populate srmKeyToIndexMap
var srmKeyToIndexMap = new Dictionary<string, int>();
for (var srmIndex = 0; srmIndex < srmList.Count; srmIndex++)
{
srmKeyToIndexMap.Add(ConstructSRMMapKey(srmList[srmIndex]), srmIndex);
}
if (mOptions.WriteMRMDataList)
{
// Write out the raw MRM Data
var dataFilePath = DataOutput.DataOutput.ConstructOutputFilePath(inputFileName, outputDirectoryPath, DataOutput.DataOutput.OutputFileTypeConstants.MRMDatafile);
dataWriter = new StreamWriter(dataFilePath);
// Write the file headers
dataWriter.WriteLine(mDataOutputHandler.GetHeadersForOutputFile(scanList, DataOutput.DataOutput.OutputFileTypeConstants.MRMDatafile));
}
if (mOptions.WriteMRMIntensityCrosstab)
{
// Write out the raw MRM Data
var crosstabFilePath = DataOutput.DataOutput.ConstructOutputFilePath(inputFileName, outputDirectoryPath, DataOutput.DataOutput.OutputFileTypeConstants.MRMCrosstabFile);
crosstabWriter = new StreamWriter(crosstabFilePath);
// Initialize the crosstab header variable using the data in srmList()
var headerNames = new List<string>(srmList.Count + 2)
{
"Scan_First",
"ScanTime"
};
foreach (var srmEntry in srmList)
{
headerNames.Add(ConstructSRMMapKey(srmEntry));
}
crosstabWriter.WriteLine(string.Join(TAB_DELIMITER.ToString(), headerNames));
}
var scanFirst = int.MinValue;
float scanTimeFirst = 0;
var srmIndexLast = 0;
var crosstabColumnValue = new double[srmList.Count];
var crosstabColumnFlag = new bool[srmList.Count];
// For scanIndex = 0 To scanList.FragScanCount - 1
foreach (var fragScan in scanList.FragScans)
{
if (fragScan.MRMScanType != MRMScanTypeConstants.SRM)
{
continue;
}
if (scanFirst == int.MinValue)
{
scanFirst = fragScan.ScanNumber;
scanTimeFirst = fragScan.ScanTime;
}
// Look for each of the m/z values specified in fragScan.MRMScanInfo.MRMMassList
for (var mrmMassIndex = 0; mrmMassIndex < fragScan.MRMScanInfo.MRMMassCount; mrmMassIndex++)
{
// Find the maximum value between fragScan.StartMass and fragScan.EndMass
// Need to define a tolerance to account for numeric rounding artifacts in the variables
var mzStart = fragScan.MRMScanInfo.MRMMassList[mrmMassIndex].StartMass;
var mzEnd = fragScan.MRMScanInfo.MRMMassList[mrmMassIndex].EndMass;
var mrmToleranceHalfWidth = Math.Round((mzEnd - mzStart) / 2, 6);
if (mrmToleranceHalfWidth < 0.001)
{
mrmToleranceHalfWidth = 0.001;
}
var matchFound = mDataAggregation.FindMaxValueInMZRange(
spectraCache, fragScan,
mzStart - mrmToleranceHalfWidth,
mzEnd + mrmToleranceHalfWidth,
out _, out var matchIntensity);
if (mOptions.WriteMRMDataList)
{
dataColumns.Clear();
dataColumns.Add(fragScan.ScanNumber.ToString());
dataColumns.Add(fragScan.MRMScanInfo.ParentIonMZ.ToString("0.000"));
if (matchFound)
{
dataColumns.Add(fragScan.MRMScanInfo.MRMMassList[mrmMassIndex].CentralMass.ToString("0.000"));
dataColumns.Add(matchIntensity.ToString("0.000"));
}
else
{
dataColumns.Add(fragScan.MRMScanInfo.MRMMassList[mrmMassIndex].CentralMass.ToString("0.000"));
dataColumns.Add("0");
}
dataWriter?.WriteLine(string.Join(TAB_DELIMITER.ToString(), dataColumns));
}
if (!mOptions.WriteMRMIntensityCrosstab)
continue;
var srmMapKey = ConstructSRMMapKey(fragScan.MRMScanInfo.ParentIonMZ, fragScan.MRMScanInfo.MRMMassList[mrmMassIndex].CentralMass);
// Use srmKeyToIndexMap to determine the appropriate column index for srmMapKey
if (srmKeyToIndexMap.TryGetValue(srmMapKey, out var srmIndex))
{
if (crosstabColumnFlag[srmIndex] ||
srmIndex == 0 && srmIndexLast == srmList.Count - 1)
{
// Either the column is already populated, or the SRMIndex has cycled back to zero
// Write out the current crosstab line and reset the crosstab column arrays
ExportMRMDataWriteLine(crosstabWriter, scanFirst, scanTimeFirst,
crosstabColumnValue,
crosstabColumnFlag,
TAB_DELIMITER, true);
scanFirst = fragScan.ScanNumber;
scanTimeFirst = fragScan.ScanTime;
}
if (matchFound)
{
crosstabColumnValue[srmIndex] = matchIntensity;
}
crosstabColumnFlag[srmIndex] = true;
srmIndexLast = srmIndex;
}
else
{
// Unknown combination of parent ion m/z and daughter m/z; this is unexpected
// We won't write this entry out
}
}
UpdateCacheStats(spectraCache);
if (mOptions.AbortProcessing)
{
break;
}
}
if (mOptions.WriteMRMIntensityCrosstab)
{
// Write out any remaining crosstab values
ExportMRMDataWriteLine(crosstabWriter, scanFirst, scanTimeFirst, crosstabColumnValue, crosstabColumnFlag, TAB_DELIMITER, false);
}
}
success = true;
}
catch (Exception ex)
{
ReportError("Error writing the SRM data to disk", ex, clsMASIC.MasicErrorCodes.OutputFileWriteError);
success = false;
}
finally
{
dataWriter?.Close();
crosstabWriter?.Close();
}
return success;
}
/// <summary>
/// Write one line to the export file
/// </summary>
/// <param name="writer"></param>
/// <param name="scanFirst"></param>
/// <param name="scanTimeFirst"></param>
/// <param name="crosstabColumnValue"></param>
/// <param name="crosstabColumnFlag"></param>
/// <param name="delimiter"></param>
/// <param name="forceWrite">If false, only write out the line if 1 or more columns is non-zero</param>
private void ExportMRMDataWriteLine(
TextWriter writer,
int scanFirst,
float scanTimeFirst,
IList<double> crosstabColumnValue,
IList<bool> crosstabColumnFlag,
char delimiter,
bool forceWrite)
{
var nonZeroCount = 0;
var dataColumns = new List<string>(crosstabColumnValue.Count + 2)
{
scanFirst.ToString(),
StringUtilities.DblToString(scanTimeFirst, 5)
};
// Construct a tab-delimited list of the values
// At the same time, clear the arrays
for (var index = 0; index < crosstabColumnValue.Count; index++)
{
if (crosstabColumnValue[index] > 0)
{
dataColumns.Add(crosstabColumnValue[index].ToString("0.000"));
nonZeroCount++;
}
else
{
dataColumns.Add("0");
}
crosstabColumnValue[index] = 0;
crosstabColumnFlag[index] = false;
}
if (nonZeroCount > 0 || forceWrite)
{
writer.WriteLine(string.Join(delimiter.ToString(), dataColumns));
}
}
private string GenerateMRMInfoHash(MRMScanInfo mrmScanInfo)
{
var hashValue = mrmScanInfo.ParentIonMZ + "_" + mrmScanInfo.MRMMassCount;
for (var index = 0; index < mrmScanInfo.MRMMassCount; index++)
{
hashValue += "_" +
mrmScanInfo.MRMMassList[index].CentralMass.ToString("0.000") + "_" +
mrmScanInfo.MRMMassList[index].StartMass.ToString("0.000") + "_" +
mrmScanInfo.MRMMassList[index].EndMass.ToString("0.000");
}
return hashValue;
}
private bool MRMParentDaughterMatch(
SRMListType udtSRMListEntry,
MRMScanInfo mrmSettingsEntry,
int mrmMassIndex)
{
return MRMParentDaughterMatch(
udtSRMListEntry.ParentIonMZ,
udtSRMListEntry.CentralMass,
mrmSettingsEntry.ParentIonMZ,
mrmSettingsEntry.MRMMassList[mrmMassIndex].CentralMass);
}
private bool MRMParentDaughterMatch(
double parentIonMZ1,
double mrmDaughterMZ1,
double parentIonMZ2,
double mrmDaughterMZ2)
{
const double COMPARISON_TOLERANCE = 0.01;
return Math.Abs(parentIonMZ1 - parentIonMZ2) <= COMPARISON_TOLERANCE &&
Math.Abs(mrmDaughterMZ1 - mrmDaughterMZ2) <= COMPARISON_TOLERANCE;
}
/// <summary>
/// Process MRM data
/// </summary>
/// <param name="scanList"></param>
/// <param name="spectraCache"></param>
/// <param name="sicProcessor"></param>
/// <param name="xmlResultsWriter"></param>
/// <param name="peakFinder"></param>
/// <param name="parentIonsProcessed"></param>
public bool ProcessMRMList(
ScanList scanList,
SpectraCache spectraCache,
SICProcessing sicProcessor,
XMLResultsWriter xmlResultsWriter,
clsMASICPeakFinder peakFinder,
ref int parentIonsProcessed)
{
try
{
// Initialize sicDetails
var sicDetails = new SICDetails();
sicDetails.Reset();
sicDetails.SICScanType = ScanList.ScanTypeConstants.FragScan;
for (var parentIonIndex = 0; parentIonIndex < scanList.ParentIons.Count; parentIonIndex++)
{
if (scanList.ParentIons[parentIonIndex].MRMDaughterMZ <= 0)
{
continue;
}
// Step 1: Create the SIC for this MRM Parent/Daughter pair
var parentIonMZ = scanList.ParentIons[parentIonIndex].MZ;
var mrmDaughterMZ = scanList.ParentIons[parentIonIndex].MRMDaughterMZ;
var searchToleranceHalfWidth = scanList.ParentIons[parentIonIndex].MRMToleranceHalfWidth;
// Reset SICData
sicDetails.SICData.Clear();
// Step through the fragmentation spectra, finding those that have matching parent and daughter ion m/z values
for (var scanIndex = 0; scanIndex < scanList.FragScans.Count; scanIndex++)
{
if (scanList.FragScans[scanIndex].MRMScanType != MRMScanTypeConstants.SRM)
{
continue;
}
var fragScan = scanList.FragScans[scanIndex];
var useScan = false;
for (var mrmMassIndex = 0; mrmMassIndex < fragScan.MRMScanInfo.MRMMassCount; mrmMassIndex++)
{
if (MRMParentDaughterMatch(
fragScan.MRMScanInfo.ParentIonMZ,
fragScan.MRMScanInfo.MRMMassList[mrmMassIndex].CentralMass,
parentIonMZ, mrmDaughterMZ))
{
useScan = true;
break;
}
}
if (!useScan)
continue;
// Include this scan in the SIC for this parent ion
mDataAggregation.FindMaxValueInMZRange(
spectraCache,
scanList.FragScans[scanIndex],
mrmDaughterMZ - searchToleranceHalfWidth,
mrmDaughterMZ + searchToleranceHalfWidth,
out var closestMZ,
out var matchIntensity);
sicDetails.AddData(fragScan.ScanNumber, matchIntensity, closestMZ, scanIndex);
}
// Step 2: Find the largest peak in the SIC
// Compute the noise level; the noise level may change with increasing index number if the background is increasing for a given m/z
var success = peakFinder.ComputeDualTrimmedNoiseLevelTTest(
sicDetails.SICIntensities, 0,
sicDetails.SICDataCount - 1,
mOptions.SICOptions.SICPeakFinderOptions.
SICBaselineNoiseOptions,
out var noiseStatsSegments);
if (!success)
{
SetLocalErrorCode(clsMASIC.MasicErrorCodes.FindSICPeaksError, true);
return false;
}
// Initialize the peak
scanList.ParentIons[parentIonIndex].SICStats.Peak = new SICStatsPeak();
// Find the data point with the maximum intensity
double maximumIntensity = 0;
scanList.ParentIons[parentIonIndex].SICStats.Peak.IndexObserved = 0;
for (var scanIndex = 0; scanIndex < sicDetails.SICDataCount; scanIndex++)
{
var intensity = sicDetails.SICIntensities[scanIndex];
if (intensity > maximumIntensity)
{
maximumIntensity = intensity;
scanList.ParentIons[parentIonIndex].SICStats.Peak.IndexObserved = scanIndex;
}
}
// Compute the minimum potential peak area in the entire SIC, populating potentialAreaStatsInFullSIC
peakFinder.FindPotentialPeakArea(
sicDetails.SICData,
out var potentialAreaStatsInFullSIC,
mOptions.SICOptions.SICPeakFinderOptions);
// Update .BaselineNoiseStats in scanList.ParentIons(parentIonIndex).SICStats.Peak
scanList.ParentIons[parentIonIndex].SICStats.Peak.BaselineNoiseStats = peakFinder.LookupNoiseStatsUsingSegments(
scanList.ParentIons[parentIonIndex].SICStats.Peak.IndexObserved,
noiseStatsSegments);
var parentIon = scanList.ParentIons[parentIonIndex];
// Clear potentialAreaStatsForPeak
parentIon.SICStats.SICPotentialAreaStatsForPeak = new SICPotentialAreaStats();
var peakIsValid = peakFinder.FindSICPeakAndArea(
sicDetails.SICData,
out var potentialAreaStatsForPeakOut,
parentIon.SICStats.Peak, out var smoothedYDataSubset,
mOptions.SICOptions.SICPeakFinderOptions,
potentialAreaStatsInFullSIC, false,
scanList.SIMDataPresent, false);
parentIon.SICStats.SICPotentialAreaStatsForPeak = potentialAreaStatsForPeakOut;
sicProcessor.StorePeakInParentIon(
scanList, parentIonIndex, sicDetails,
parentIon.SICStats.SICPotentialAreaStatsForPeak,
parentIon.SICStats.Peak, peakIsValid);
// Step 3: store the results
// Possibly save the stats for this SIC to the SICData file
mDataOutputHandler.SaveSICDataToText(mOptions.SICOptions, scanList, parentIonIndex, sicDetails);
// Save the stats for this SIC to the XML file
xmlResultsWriter.SaveDataToXML(
scanList, parentIonIndex, sicDetails,
smoothedYDataSubset, mDataOutputHandler);
parentIonsProcessed++;
// ---------------------------------------------------------
// Update progress
// ---------------------------------------------------------
try
{
if (scanList.ParentIons.Count > 1)
{
UpdateProgress((short)(parentIonsProcessed / (double)(scanList.ParentIons.Count - 1) * 100));
}
else
{
UpdateProgress(0);
}
UpdateCacheStats(spectraCache);
if (mOptions.AbortProcessing)
{
scanList.ProcessingIncomplete = true;
break;
}
if (parentIonsProcessed % 100 == 0)
{
if (DateTime.UtcNow.Subtract(mOptions.LastParentIonProcessingLogTime).TotalSeconds >= 10 || parentIonsProcessed % 500 == 0)
{
ReportMessage("Parent Ions Processed: " + parentIonsProcessed);
Console.Write(".");
mOptions.LastParentIonProcessingLogTime = DateTime.UtcNow;
}
}
}
catch (Exception ex)
{
ReportError("Error updating progress", ex, clsMASIC.MasicErrorCodes.CreateSICsError);
}
}
return true;
}
catch (Exception ex)
{
ReportError("Error creating SICs for MRM spectra", ex, clsMASIC.MasicErrorCodes.CreateSICsError);
return false;
}
}
}
}