-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUnused.cs
436 lines (348 loc) · 20.4 KB
/
Unused.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
Imports PRISM
Imports ThermoRawFileReader
Public Class clsUnused
Inherits clsMasicEventNotifier
''Private Sub FindMinimumPotentialPeakAreaInRegion(scanList As clsScanList, intParentIonIndexStart As Integer, intParentIonIndexEnd As Integer, ByRef udtSICPotentialAreaStatsForRegion As MASICPeakFinder.clsMASICPeakFinder.udtSICPotentialAreaStatsType)
'' ' This function finds the minimum potential peak area in the parent ions between
'' ' intParentIonIndexStart and intParentIonIndexEnd
'' ' However, the summed intensity is not used if the number of points >= .SICNoiseThresholdIntensity is less than MASICPeakFinder.clsMASICPeakFinder.MINIMUM_PEAK_WIDTH
'' Dim intParentIonIndex As Integer
'' Dim intIndex As Integer
'' With udtSICPotentialAreaStatsForRegion
'' .MinimumPotentialPeakArea = Double.MaxValue
'' .PeakCountBasisForMinimumPotentialArea = 0
'' End With
'' For intParentIonIndex = intParentIonIndexStart To intParentIonIndexEnd
'' With scanList.ParentIons(intParentIonIndex).SICStats.SICPotentialAreaStatsForPeak
'' If .MinimumPotentialPeakArea > 0 AndAlso .PeakCountBasisForMinimumPotentialArea >= MASICPeakFinder.clsMASICPeakFinder.MINIMUM_PEAK_WIDTH Then
'' If .PeakCountBasisForMinimumPotentialArea > udtSICPotentialAreaStatsForRegion.PeakCountBasisForMinimumPotentialArea Then
'' ' The non valid peak count value is larger than the one associated with the current
'' ' minimum potential peak area; update the minimum peak area to dblPotentialPeakArea
'' udtSICPotentialAreaStatsForRegion.MinimumPotentialPeakArea = .MinimumPotentialPeakArea
'' udtSICPotentialAreaStatsForRegion.PeakCountBasisForMinimumPotentialArea = .PeakCountBasisForMinimumPotentialArea
'' Else
'' If .MinimumPotentialPeakArea < udtSICPotentialAreaStatsForRegion.MinimumPotentialPeakArea AndAlso
'' .PeakCountBasisForMinimumPotentialArea >= udtSICPotentialAreaStatsForRegion.PeakCountBasisForMinimumPotentialArea Then
'' udtSICPotentialAreaStatsForRegion.MinimumPotentialPeakArea = .MinimumPotentialPeakArea
'' udtSICPotentialAreaStatsForRegion.PeakCountBasisForMinimumPotentialArea = .PeakCountBasisForMinimumPotentialArea
'' End If
'' End If
'' End If
'' End With
'' Next
'' If udtSICPotentialAreaStatsForRegion.MinimumPotentialPeakArea = Double.MaxValue Then
'' udtSICPotentialAreaStatsForRegion.MinimumPotentialPeakArea = 1
'' End If
''End Sub
''Private Function FindSICPeakAndAreaForParentIon(scanList As clsScanList, intParentIonIndex As Integer, ByRef udtSICDetails As clsSICStatsDetails, ByRef udtSmoothedYDataSubset As MASICPeakFinder.clsMASICPeakFinder.udtSmoothedYDataSubsetType, sicOptions As clsSICOptions) As Boolean
'' Const RECOMPUTE_NOISE_LEVEL As Boolean = True
'' Dim intSurveyScanIndex As Integer
'' Dim intDataIndex As Integer
'' Dim intIndexPointer As Integer
'' Dim intParentIonIndexStart As Integer
'' Dim intScanIndexObserved As Integer
'' Dim intScanDelta As Integer
'' Dim intFragScanNumber As Integer
'' Dim intAreaDataCount As Integer
'' Dim intAreaDataBaseIndex As Integer
'' Dim sngFWHMScanStart, sngFWHMScanEnd As Single
'' Dim udtSICPotentialAreaStatsForRegion As MASICPeakFinder.clsMASICPeakFinder.udtSICPotentialAreaStatsType
'' Dim sngMaxIntensityValueRawData As Single
'' Dim intSICScanNumbers() As Integer
'' Dim sngSICIntensities() As Single
'' Dim blnCustomSICPeak As Boolean
'' Dim blnSuccess As Boolean
'' Try
'' ' Determine the minimum potential peak area in the last 500 scans
'' intParentIonIndexStart = intParentIonIndex - 500
'' If intParentIonIndexStart < 0 Then intParentIonIndexStart = 0
'' FindMinimumPotentialPeakAreaInRegion(scanList, intParentIonIndexStart, intParentIonIndex, udtSICPotentialAreaStatsForRegion)
'' With scanList
'' With .ParentIons(intParentIonIndex)
'' intScanIndexObserved = .SurveyScanIndex
'' If intScanIndexObserved < 0 Then intScanIndexObserved = 0
'' blnCustomSICPeak = .CustomSICPeak
'' End With
'' If udtSICDetails.SICData Is Nothing OrElse udtSICDetails.SICDataCount = 0 Then
'' ' Either .SICData is nothing or no SIC data exists
'' ' Cannot find peaks for this parent ion
'' With .ParentIons(intParentIonIndex).SICStats
'' With .Peak
'' .IndexObserved = 0
'' .IndexBaseLeft = .IndexObserved
'' .IndexBaseRight = .IndexObserved
'' .IndexMax = .IndexObserved
'' End With
'' End With
'' Else
'' With .ParentIons(intParentIonIndex).SICStats
'' ' Record the index (of data in .SICData) that the parent ion mass was first observed
'' .Peak.ScanTypeForPeakIndices = eScanTypeConstants.SurveyScan
'' ' Search for intScanIndexObserved in udtSICDetails.SICScanIndices()
'' .Peak.IndexObserved = -1
'' For intSurveyScanIndex = 0 To udtSICDetails.SICDataCount - 1
'' If udtSICDetails.SICScanIndices(intSurveyScanIndex) = intScanIndexObserved Then
'' .Peak.IndexObserved = intSurveyScanIndex
'' Exit For
'' End If
'' Next
'' If .Peak.IndexObserved = -1 Then
'' ' Match wasn't found; this is unexpected
'' ReportError("Programming error: survey scan index not found", eMasicErrorCodes.FindSICPeaksError)
'' .Peak.IndexObserved = 0
'' End If
'' ' Populate intSICScanNumbers() with the scan numbers that the SICData corresponds to
'' ' At the same time, populate udtSICStats.SICDataScanIntervals with the scan intervals between each of the data points
'' If udtSICDetails.SICDataCount > udtSICDetails.SICDataScanIntervals.Length Then
'' ReDim udtSICDetails.SICDataScanIntervals(udtSICDetails.SICDataCount - 1)
'' End If
'' ReDim intSICScanNumbers(udtSICDetails.SICDataCount - 1)
'' For intSurveyScanIndex = 0 To udtSICDetails.SICDataCount - 1
'' intSICScanNumbers(intSurveyScanIndex) = scanList.SurveyScans(udtSICDetails.SICScanIndices(intSurveyScanIndex)).ScanNumber
'' If intSurveyScanIndex > 0 Then
'' intScanDelta = intSICScanNumbers(intSurveyScanIndex) - intSICScanNumbers(intSurveyScanIndex - 1)
'' udtSICDetails.SICDataScanIntervals(intSurveyScanIndex) = CByte(Math.Min(Byte.MaxValue, intScanDelta)) ' Make sure the Scan Interval is, at most, 255; it will typically be 1 or 4
'' End If
'' Next
'' ' Record the fragmentation scan number
'' intFragScanNumber = scanList.FragScans(scanList.ParentIons(intParentIonIndex).FragScanIndices(0)).ScanNumber
'' ' Determine the value for .ParentIonIntensity
'' blnSuccess = mMASICPeakFinder.ComputeParentIonIntensity(udtSICDetails.SICDataCount, intSICScanNumbers, udtSICDetails.SICData, .Peak, intFragScanNumber)
'' blnSuccess = mMASICPeakFinder.FindSICPeakAndArea(udtSICDetails.SICDataCount, intSICScanNumbers, udtSICDetails.SICData, .SICPotentialAreaStatsForPeak, .Peak,
'' udtSmoothedYDataSubset, sicOptions.SICPeakFinderOptions,
'' udtSICPotentialAreaStatsForRegion,
'' Not blnCustomSICPeak, scanList.SIMDataPresent, RECOMPUTE_NOISE_LEVEL)
'' If blnSuccess Then
'' ' Record the survey scan indices of the peak max, start, and end
'' ' Note that .ScanTypeForPeakIndices was set earlier in this function
'' .PeakScanIndexMax = udtSICDetails.SICScanIndices(.Peak.IndexMax)
'' .PeakScanIndexStart = udtSICDetails.SICScanIndices(.Peak.IndexBaseLeft)
'' .PeakScanIndexEnd = udtSICDetails.SICScanIndices(.Peak.IndexBaseRight)
'' Else
'' ' No peak found
'' .PeakScanIndexMax = udtSICDetails.SICScanIndices(.Peak.IndexMax)
'' .PeakScanIndexStart = .PeakScanIndexMax
'' .PeakScanIndexEnd = .PeakScanIndexMax
'' With .Peak
'' .MaxIntensityValue = udtSICDetails.SICData(.IndexMax)
'' .IndexBaseLeft = .IndexMax
'' .IndexBaseRight = .IndexMax
'' .FWHMScanWidth = 1
'' ' Assign the intensity of the peak at the observed maximum to the area
'' .Area = .MaxIntensityValue
'' .SignalToNoiseRatio = mMASICPeakFinder.ComputeSignalToNoise(.MaxIntensityValue, .BaselineNoiseStats.NoiseLevel)
'' End With
'' End If
'' End With
'' ' Update .OptimalPeakApexScanNumber
'' ' Note that a valid peak will typically have .IndexBaseLeft or .IndexBaseRight different from .IndexMax
'' With .ParentIons(intParentIonIndex)
'' .OptimalPeakApexScanNumber = scanList.SurveyScans(udtSICDetails.SICScanIndices(.SICStats.Peak.IndexMax)).ScanNumber
'' End With
'' End If
'' End With
'' blnSuccess = True
'' Catch ex As Exception
'' ReportError("Error finding SIC peaks and their areas", ex, eMasicErrorCodes.FindSICPeaksError)
'' blnSuccess = False
'' End Try
'' Return blnSuccess
''End Function
Private Function GetNextSurveyScanIndex(surveyScans As IList(Of clsScanInfo), intSurveyScanIndex As Integer) As Integer
' Returns the next adjacent survey scan index
' If the given survey scan is not a SIM scan, then simply returns the next index
' If the given survey scan is a SIM scan, then returns the next survey scan with the same .SIMIndex
' If no appropriate next survey scan index is found, then returns intSurveyScanIndex instead
Dim intNextSurveyScanIndex As Integer
Dim intSIMIndex As Integer
Try
If intSurveyScanIndex < surveyScans.Count - 1 AndAlso intSurveyScanIndex >= 0 Then
If surveyScans(intSurveyScanIndex).SIMScan Then
intSIMIndex = surveyScans(intSurveyScanIndex).SIMIndex
intNextSurveyScanIndex = intSurveyScanIndex + 1
Do While intNextSurveyScanIndex < surveyScans.Count
If surveyScans(intNextSurveyScanIndex).SIMIndex = intSIMIndex Then
Exit Do
Else
intNextSurveyScanIndex += 1
End If
Loop
If intNextSurveyScanIndex = surveyScans.Count Then
' Match was not found
intNextSurveyScanIndex = intSurveyScanIndex
End If
Return intNextSurveyScanIndex
Else
' Not a SIM Scan
Return intSurveyScanIndex + 1
End If
Else
' intSurveyScanIndex is the final survey scan or is less than 0
Return intSurveyScanIndex
End If
Catch ex As Exception
' Error occurred; simply return intSurveyScanIndex
Return intSurveyScanIndex
End Try
End Function
Private Function GetPreviousSurveyScanIndex(surveyScans As IList(Of clsScanInfo), intSurveyScanIndex As Integer) As Integer
' Returns the previous adjacent survey scan index
' If the given survey scan is not a SIM scan, then simply returns the previous index
' If the given survey scan is a SIM scan, then returns the previous survey scan with the same .SIMIndex
' If no appropriate next survey scan index is found, then returns intSurveyScanIndex instead
Dim intPreviousSurveyScanIndex As Integer
Dim intSIMIndex As Integer
Try
If intSurveyScanIndex > 0 AndAlso intSurveyScanIndex < surveyScans.Count Then
If surveyScans(intSurveyScanIndex).SIMScan Then
intSIMIndex = surveyScans(intSurveyScanIndex).SIMIndex
intPreviousSurveyScanIndex = intSurveyScanIndex - 1
Do While intPreviousSurveyScanIndex >= 0
If surveyScans(intPreviousSurveyScanIndex).SIMIndex = intSIMIndex Then
Exit Do
Else
intPreviousSurveyScanIndex -= 1
End If
Loop
If intPreviousSurveyScanIndex < 0 Then
' Match was not found
intPreviousSurveyScanIndex = intSurveyScanIndex
End If
Return intPreviousSurveyScanIndex
Else
' Not a SIM Scan
Return intSurveyScanIndex - 1
End If
Else
' intSurveyScanIndex is the first survey scan or is less than 0
Return intSurveyScanIndex
End If
Catch ex As Exception
' Error occurred; simply return intSurveyScanIndex
Return intSurveyScanIndex
End Try
End Function
Private Function GetScanTypeName(eScanType As clsScanList.eScanTypeConstants) As String
Select Case eScanType
Case clsScanList.eScanTypeConstants.SurveyScan
Return "survey scan"
Case clsScanList.eScanTypeConstants.FragScan
Return "frag scan"
Case Else
Return "unknown scan type"
End Select
End Function
Private Function InterpolateX(
ByRef sngInterpolatedXValue As Single,
X1 As Integer,
X2 As Integer,
Y1 As Single,
Y2 As Single,
sngTargetY As Single) As Boolean
' Checks if Y1 or Y2 is less than sngTargetY
' If it is, then determines the X value that corresponds to sngTargetY by interpolating the line between (X1, Y1) and (X2, Y2)
'
' Returns True if a match is found; otherwise, returns false
Dim sngDeltaY As Single
Dim sngFraction As Single
Dim intDeltaX As Integer
Dim sngTargetX As Single
If Y1 < sngTargetY OrElse Y2 < sngTargetY Then
If Y1 < sngTargetY AndAlso Y2 < sngTargetY Then
' Both of the Y values are less than sngTargetY
' We cannot interpolate
ReportError("This code should normally not be reached (clsMasic->InterpolateX)")
Return False
Else
sngDeltaY = Y2 - Y1 ' Yes, this is y-two minus y-one
sngFraction = (sngTargetY - Y1) / sngDeltaY
intDeltaX = X2 - X1 ' Yes, this is x-two minus x-one
sngTargetX = sngFraction * intDeltaX + X1
If Math.Abs(sngTargetX - X1) >= 0 AndAlso Math.Abs(sngTargetX - X2) >= 0 Then
sngInterpolatedXValue = sngTargetX
Return True
Else
ReportError("TargetX is not between X1 and X2; this shouldn't happen (clsMasic->InterpolateX)")
Return False
End If
End If
Else
Return False
End If
End Function
Private Function LookupRTByScanNumber(
scanList As IList(Of clsScanInfo),
intScanListCount As Integer,
intScanListArray() As Integer,
intScanNumberToFind As Integer) As Single
' intScanListArray() must be populated with the scan numbers in scanList() before calling this function
Dim intScanIndex As Integer
Dim intMatchIndex As Integer
Try
intMatchIndex = Array.IndexOf(intScanListArray, intScanNumberToFind)
If intMatchIndex < 0 Then
' Need to find the closest scan with this scan number
intMatchIndex = 0
For intScanIndex = 0 To intScanListCount - 1
If scanList(intScanIndex).ScanNumber <= intScanNumberToFind Then intMatchIndex = intScanIndex
Next
End If
Return scanList(intMatchIndex).ScanTime
Catch ex As Exception
' Ignore any errors that occur in this function
ReportError("Error in LookupRTByScanNumber", ex)
Return 0
End Try
End Function
Private Sub SaveBPIWork(
scanList As IList(Of clsScanInfo),
intScanCount As Integer,
strOutputFilePath As String,
blnSaveTIC As Boolean,
cColDelimiter As Char)
Dim srOutFile As StreamWriter
Dim intScanIndex As Integer
srOutFile = New StreamWriter(strOutputFilePath)
If blnSaveTIC Then
srOutFile.WriteLine("Time" & cColDelimiter & "TotalIonIntensity")
Else
srOutFile.WriteLine("Time" & cColDelimiter & "BasePeakIntensity" & cColDelimiter & "m/z")
End If
For intScanIndex = 0 To intScanCount - 1
With scanList(intScanIndex)
If blnSaveTIC Then
srOutFile.WriteLine(StringUtilities.DblToString(.ScanTime, 5) & cColDelimiter &
StringUtilities.DblToString(.TotalIonIntensity, 2))
Else
srOutFile.WriteLine(StringUtilities.DblToString(.ScanTime, 5) & cColDelimiter &
StringUtilities.DblToString(.BasePeakIonIntensity, 2) & cColDelimiter &
StringUtilities.DblToString(.BasePeakIonMZ, 4))
End If
End With
Next
srOutFile.Close()
End Sub
Private Function ValidateXRawAccessor() As Boolean
Static blnValidated As Boolean
Static blnValidationSaved As Boolean
If blnValidated Then
Return blnValidationSaved
End If
Try
Dim objXRawAccess As New XRawFileIO()
Dim isValid = objXRawAccess.IsMSFileReaderInstalled()
If isValid Then
blnValidationSaved = True
Return True
Else
ReportError("MSFileReader was not found; Thermo .raw files cannot be read. Download the MSFileReader installer " &
"by creating an account at https://thermo.flexnetoperations.com/control/thmo/login , " &
"then logging in and choosing 'Utility Software'")
Return False
End If
Catch ex As Exception
blnValidationSaved = False
Return False
End Try
End Function
End Class