-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmDtaTxtFileBrowser.frm
475 lines (405 loc) · 16.5 KB
/
frmDtaTxtFileBrowser.frm
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
VERSION 5.00
Begin VB.Form frmDtaTxtFileBrowser
BorderStyle = 3 'Fixed Dialog
Caption = "_Dta.Txt File Browser"
ClientHeight = 1320
ClientLeft = 45
ClientTop = 360
ClientWidth = 10515
KeyPreview = -1 'True
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1320
ScaleWidth = 10515
ShowInTaskbar = 0 'False
StartUpPosition = 3 'Windows Default
Tag = "16000"
Begin VB.CommandButton cmdJumpToScan
Cancel = -1 'True
Caption = "&Jump to scan"
Height = 360
Left = 7560
TabIndex = 10
Tag = "16100"
ToolTipText = "Shortcut is Ctrl+J"
Top = 720
Width = 1275
End
Begin VB.CheckBox chkWindowStayOnTop
Caption = "&Keep Window On Top"
Height = 495
Left = 9000
TabIndex = 11
Tag = "16110"
Top = 120
Width = 1455
End
Begin VB.CommandButton cmdOK
Caption = "Cl&ose"
Height = 360
Left = 7560
TabIndex = 9
Tag = "4000"
Top = 240
Width = 1275
End
Begin VB.Frame fraDTATextOptions
Height = 1095
Left = 120
TabIndex = 0
Top = 120
Width = 7215
Begin VB.TextBox txtParentIonCharge
Height = 285
Left = 5400
Locked = -1 'True
TabIndex = 8
Top = 660
Width = 1455
End
Begin VB.TextBox txtParentIonMass
Height = 285
Left = 5400
Locked = -1 'True
TabIndex = 4
Top = 240
Width = 1455
End
Begin VB.ComboBox cboDTAScanNumber
Height = 315
Left = 1920
Style = 2 'Dropdown List
TabIndex = 2
Top = 240
Width = 1455
End
Begin VB.Label lblParentIonCharge
Caption = "Parent Ion Charge"
Height = 255
Left = 3600
TabIndex = 7
Tag = "16080"
Top = 660
Width = 1575
End
Begin VB.Label lblParentIonMH
Caption = "Parent Ion MH+"
Height = 255
Left = 3600
TabIndex = 3
Tag = "16070"
Top = 240
Width = 1575
End
Begin VB.Label lblScanNumberEndLabel
Caption = "Scan Number End"
Height = 255
Left = 120
TabIndex = 5
Tag = "16060"
Top = 660
Width = 1575
End
Begin VB.Label lblScanNumberEnd
Caption = "End Scan Number"
Height = 255
Left = 1920
TabIndex = 6
Top = 660
Width = 1455
End
Begin VB.Label lblDTAScanNumber
Caption = "Scan Number Start"
Height = 255
Left = 120
TabIndex = 1
Tag = "16050"
Top = 240
Width = 1575
End
End
End
Attribute VB_Name = "frmDtaTxtFileBrowser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Type udtSpectraType
ScanNumberStart As Long
ScanNumberEnd As Long
ParentIon As Double
ParentIonCharge As Integer
DataCount As Long
XVals() As Double
YVals() As Double
End Type
Private Type udtDtaTxtDataType
Initialized As Boolean
SpectraCount As Long
Spectra() As udtSpectraType
DtaTxtFilePath As String
End Type
Private mDtaTxtData As udtDtaTxtDataType
Public Function GetDataInitializedState() As Boolean
GetDataInitializedState = mDtaTxtData.Initialized
End Function
Public Sub JumpToScanNumber(Optional ByRef lngScanNumber As Long = 0)
' If lngScanNumber is greater than 0, then jumps directly to the given scan number
' Otherwise, shows an Input box to allow the user to type a scan number
' The scan number entered by the user is returned ByRef in lngScanNumber
Dim strFirstScan As String, strLastScan As String
Dim strScanNumber As String
Dim lngIndex As Long
Dim blnMatched As Boolean
If cboDTAScanNumber.ListCount < 1 Then
If lngScanNumber = 0 Then MsgBox "The scan list is empty; no scans to jump to.", vbInformation + vbOKOnly, "No Scans in Memory"
Exit Sub
End If
If lngScanNumber <= 0 Then
strFirstScan = cboDTAScanNumber.List(0)
strLastScan = cboDTAScanNumber.List(cboDTAScanNumber.ListCount - 1)
strScanNumber = InputBox("Enter the scan number to jump to (" & strFirstScan & " to " & strLastScan & "): ", "Jump to Scan", cboDTAScanNumber)
If IsNumeric(strScanNumber) Then
lngScanNumber = CLngSafe(strScanNumber)
With cboDTAScanNumber
If CLngSafe(.List(0)) > lngScanNumber Then
.ListIndex = 0
Else
For lngIndex = 0 To .ListCount - 1
If CLngSafe(.List(lngIndex)) >= lngScanNumber Then
.ListIndex = lngIndex
blnMatched = True
Exit For
End If
Next lngIndex
If Not blnMatched Then .ListIndex = .ListCount - 1
End If
End With
End If
End If
End Sub
Public Sub ReadDtaTxtFile(strFilePath As String)
Dim InFileNum As Integer
Dim lngDtaTxtSpectraDimCount As Long
Dim lngTotalByteCount As Long, lngTotalBytesRead As Long
Dim lngCurrentLineNumber As Long
Dim intParseCount As Integer, intIndex As Integer
Dim strParsedVals() As String
Dim lngDataDimCount As Long
Dim lngIndex As Long
Dim strLineIn As String
Dim blnSkipNextRead As Boolean
Dim lngScanNumberStart As Long
Dim lngScanNumberEnd As Long
Dim intChargeFromHeader As Integer
Dim dblParentIonMass As Double
Dim intChargeFromParentIon As Integer
Dim blnSkipThisScan As Boolean
Const SCAN_DELIMETER = "="
On Error GoTo ReadDtaTxtFileErrorHandler
' Initialize mDtaTxtData
With mDtaTxtData
.Initialized = True
.SpectraCount = 0
.DtaTxtFilePath = strFilePath
lngDtaTxtSpectraDimCount = 1000
ReDim .Spectra(lngDtaTxtSpectraDimCount)
End With
' Make sure the file exists
If Not FileExists(strFilePath) Then
mDtaTxtData.Initialized = False
Exit Sub
End If
InFileNum = FreeFile()
Open strFilePath For Input As #InFileNum
lngTotalByteCount = FileLen(strFilePath)
frmProgress.InitializeForm "Reading _Dta.Txt file", 0, lngTotalByteCount, True, False, True
lngTotalBytesRead = 0
lngCurrentLineNumber = 0
Do While Not EOF(InFileNum)
If blnSkipNextRead Then
blnSkipNextRead = False
Else
Line Input #InFileNum, strLineIn
strLineIn = Trim(strLineIn)
End If
lngCurrentLineNumber = lngCurrentLineNumber + 1
lngTotalBytesRead = lngTotalBytesRead + Len(strLineIn) + 2 ' Add 2 bytes to account for CrLf at end of line
If lngCurrentLineNumber Mod 1000 = 0 Then
' Only update the progress bar every 250 lines
frmProgress.UpdateProgressBar lngTotalBytesRead
If KeyPressAbortProcess > 1 Then Exit Do
End If
If Left(strLineIn, 1) = SCAN_DELIMETER Then
' Header line found
' Determine scan range and assigned charge
lngScanNumberStart = 0
lngScanNumberEnd = 0
intChargeFromHeader = 0
dblParentIonMass = 0
intChargeFromParentIon = 0
intParseCount = ParseString(strLineIn, strParsedVals(), 15, "." & Chr(34) & " ", "", False, False, False)
' Find the enry in strParsedVals() that contains dta
For intIndex = intParseCount - 1 To 0 Step -1
If LCase(strParsedVals(intIndex)) = "dta" Then
If intIndex >= 3 Then
Debug.Assert intIndex = 6
lngScanNumberStart = CLngSafe(strParsedVals(intIndex - 3))
lngScanNumberEnd = CLngSafe(strParsedVals(intIndex - 2))
intChargeFromHeader = CLngSafe(strParsedVals(intIndex - 1))
End If
Exit For
End If
Next intIndex
' Read next line to get Parent ion (as M+H) and charge
Line Input #InFileNum, strLineIn
lngCurrentLineNumber = lngCurrentLineNumber + 1
lngTotalBytesRead = lngTotalBytesRead + Len(strLineIn) + 2 ' Add 2 bytes to account for CrLf at end of line
intParseCount = ParseString(strLineIn, strParsedVals(), 3, " ", "", True, True, False)
If intParseCount >= 2 Then
dblParentIonMass = CDblSafe(strParsedVals(0))
intChargeFromParentIon = CIntSafe(strParsedVals(1))
If intChargeFromParentIon <> intChargeFromHeader Then
intChargeFromHeader = intChargeFromParentIon
End If
End If
With mDtaTxtData
' Check if this scan has the same values for lngScanNumberStart and lngScanNumberEnd as the previous one
blnSkipThisScan = False
If .SpectraCount > 0 Then
With .Spectra(.SpectraCount - 1)
If .ScanNumberStart = lngScanNumberStart And .ScanNumberEnd = lngScanNumberEnd Then
blnSkipThisScan = True
End If
End With
End If
If blnSkipThisScan Then
' Skip all of the lines for this scan by continuing to read data until a line
' a line is found that doesn't start with a number
blnSkipNextRead = False
Do While Not EOF(InFileNum)
Line Input #InFileNum, strLineIn
strLineIn = Trim(strLineIn)
If Not IsNumeric(Left(strLineIn, 1)) Then
blnSkipNextRead = True
Exit Do
Else
lngCurrentLineNumber = lngCurrentLineNumber + 1
lngTotalBytesRead = lngTotalBytesRead + Len(strLineIn) + 2 ' Add 2 bytes to account for CrLf at end of line
End If
Loop
Else
.SpectraCount = .SpectraCount + 1
If .SpectraCount >= lngDtaTxtSpectraDimCount Then
lngDtaTxtSpectraDimCount = lngDtaTxtSpectraDimCount + 1000
ReDim Preserve .Spectra(lngDtaTxtSpectraDimCount)
End If
With .Spectra(.SpectraCount - 1)
.ParentIon = dblParentIonMass
.ParentIonCharge = intChargeFromHeader
.ScanNumberStart = lngScanNumberStart
.ScanNumberEnd = lngScanNumberEnd
.DataCount = 0
lngDataDimCount = 0
ReDim .XVals(lngDataDimCount)
ReDim .YVals(lngDataDimCount)
End With
End If
End With
ElseIf IsNumeric(Left(strLineIn, 1)) Then
' Add to the most recent scan's data
intParseCount = ParseString(strLineIn, strParsedVals(), 3, " ", "", True, True, False)
If intParseCount >= 2 Then
With mDtaTxtData
If .SpectraCount > 0 Then
With .Spectra(.SpectraCount - 1)
.XVals(.DataCount) = Val(strParsedVals(0))
.YVals(.DataCount) = Val(strParsedVals(1))
.DataCount = .DataCount + 1
If .DataCount >= lngDataDimCount Then
lngDataDimCount = lngDataDimCount + 100
ReDim Preserve .XVals(lngDataDimCount)
ReDim Preserve .YVals(lngDataDimCount)
End If
End With
End If
End With
End If
End If
Loop
Close #InFileNum
With mDtaTxtData
cboDTAScanNumber.Clear
If .SpectraCount > 0 Then
For lngIndex = 0 To .SpectraCount - 1
cboDTAScanNumber.AddItem .Spectra(lngIndex).ScanNumberStart
Next lngIndex
cboDTAScanNumber.ListIndex = 0
.Initialized = True
Me.Show
Else
.Initialized = False
Me.Hide
End If
End With
frmProgress.HideForm
Exit Sub
ReadDtaTxtFileErrorHandler:
MsgBox "Error reading input file " & strFilePath & vbCrLf & Err.Description & vbCrLf & "Aborting.", vbExclamation + vbOKOnly, "Error"
frmProgress.HideForm
End Sub
Private Sub ShowDtaTextSpectrum()
Dim lngSelectedIndex As Long
If cboDTAScanNumber.ListIndex < 0 Then Exit Sub
lngSelectedIndex = cboDTAScanNumber.ListIndex
With mDtaTxtData
If .Initialized Then
With .Spectra(lngSelectedIndex)
frmFragmentationModelling.SetIonMatchList .XVals(), .YVals(), .DataCount, mDtaTxtData.DtaTxtFilePath, .ScanNumberStart, .ScanNumberEnd, .ParentIon, .ParentIonCharge
txtParentIonMass = .ParentIon
txtParentIonCharge = .ParentIonCharge
lblScanNumberEnd = .ScanNumberEnd
End With
End If
End With
On Error Resume Next
cboDTAScanNumber.SetFocus
End Sub
Public Sub ToggleAlwaysOnTop(blnStayOnTop As Boolean)
Static blnUpdating As Boolean
If blnUpdating Then Exit Sub
Me.ScaleMode = vbTwips
WindowStayOnTop Me.hwnd, blnStayOnTop, Me.ScaleX(Me.Left, vbTwips, vbPixels), Me.ScaleY(Me.Top, vbTwips, vbPixels), Me.ScaleX(Me.Width, vbTwips, vbPixels), Me.ScaleY(Me.Height, vbTwips, vbPixels)
blnUpdating = True
SetCheckBox chkWindowStayOnTop, blnStayOnTop
blnUpdating = False
End Sub
Private Sub cboDTAScanNumber_Click()
ShowDtaTextSpectrum
End Sub
Private Sub chkWindowStayOnTop_Click()
ToggleAlwaysOnTop cChkBox(chkWindowStayOnTop)
End Sub
Private Sub cmdJumpToScan_Click()
JumpToScanNumber
End Sub
Private Sub cmdOK_Click()
Me.Hide
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift Or vbCtrlMask Then
If KeyCode = vbKeyJ Then
JumpToScanNumber
End If
End If
End Sub
Private Sub Form_Load()
ToggleAlwaysOnTop False
SizeAndCenterWindow Me, cWindowBottomCenter, 10600, 1725
lblScanNumberEnd.Left = cboDTAScanNumber.Left + 60
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
QueryUnloadFormHandler Me, Cancel, UnloadMode
End Sub