-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathfrmIsotopicAbundance.frm
1246 lines (1031 loc) · 43.8 KB
/
frmIsotopicAbundance.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
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
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
VERSION 5.00
Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "richtx32.ocx"
Begin VB.Form frmIsotopicDistribution
Caption = "Isotopic Distribution"
ClientHeight = 5205
ClientLeft = 60
ClientTop = 345
ClientWidth = 10830
HelpContextID = 3100
Icon = "frmIsotopicAbundance.frx":0000
LinkTopic = "Form1"
ScaleHeight = 5205
ScaleWidth = 10830
StartUpPosition = 3 'Windows Default
Tag = "15000"
Begin VB.CheckBox chkAddProtonChargeCarrier
Caption = "Add Proton"
Height = 255
Left = 3840
TabIndex = 32
Tag = "15100"
Top = 1200
Value = 1 'Checked
Width = 1695
End
Begin VB.TextBox txtChargeState
Height = 285
Left = 4920
TabIndex = 7
Text = "1"
Top = 915
Width = 615
End
Begin VB.Frame fraIonComparisonList
Caption = "Comparison List"
Height = 2175
Left = 5640
TabIndex = 22
Tag = "15195"
Top = 2880
Width = 4575
Begin VB.CheckBox chkComparisonListNormalize
Caption = "Normalize pasted ion list"
Height = 255
Left = 120
TabIndex = 31
Tag = "15105"
Top = 1000
Value = 1 'Checked
Width = 2295
End
Begin VB.CommandButton cmdComparisonListClear
Caption = "Clear list"
Height = 375
Left = 2880
TabIndex = 28
Tag = "15165"
Top = 1320
Width = 1455
End
Begin VB.CommandButton cmdComparisonListPaste
Caption = "Paste list of ions to plot"
Height = 375
Left = 120
TabIndex = 27
Tag = "15160"
Top = 1320
Width = 2535
End
Begin VB.ComboBox cboComparisonListPlotType
Height = 315
Left = 2040
Style = 2 'Dropdown List
TabIndex = 26
Tag = "15140"
Top = 630
Width = 2295
End
Begin VB.Label lblComparisonListDataPoints
Caption = "0"
Height = 255
Left = 2640
TabIndex = 30
Top = 1800
Width = 615
End
Begin VB.Label lblComparisonListDataPointsLabel
Caption = "Comparison list data points:"
Height = 255
Left = 120
TabIndex = 29
Tag = "15170"
Top = 1800
Width = 2415
End
Begin VB.Label lblComparisonListPlotColorLabel
BackStyle = 0 'Transparent
Caption = "Plot Data Color"
Height = 255
Left = 120
TabIndex = 23
Tag = "15120"
Top = 300
Width = 1935
End
Begin VB.Label lblComparisonListPlotColor
BackColor = &H000000FF&
BorderStyle = 1 'Fixed Single
Height = 255
Left = 2040
TabIndex = 24
Tag = "15125"
ToolTipText = "Click to change"
Top = 300
Width = 375
End
Begin VB.Label lblComparisonListPlotType
BackStyle = 0 'Transparent
Caption = "Plot Type"
Height = 255
Left = 120
TabIndex = 25
Tag = "15130"
Top = 660
Width = 1935
End
End
Begin VB.Frame fraPlotOptions
Caption = "Options"
Height = 2655
Left = 5640
TabIndex = 9
Tag = "15190"
Top = 120
Width = 4575
Begin VB.TextBox txtEffectiveResolutionMass
Height = 300
Left = 3000
TabIndex = 19
Text = "1000"
Top = 1770
Width = 855
End
Begin VB.TextBox txtEffectiveResolution
Height = 300
Left = 3000
TabIndex = 17
Text = "5000"
Top = 1440
Width = 855
End
Begin VB.TextBox txtGaussianQualityFactor
Height = 300
Left = 3000
TabIndex = 21
Text = "50"
Top = 2190
Width = 855
End
Begin VB.ComboBox cboPlotType
Height = 315
Left = 2040
Style = 2 'Dropdown List
TabIndex = 15
Tag = "15140"
Top = 960
Width = 2295
End
Begin VB.CheckBox chkPlotResults
Caption = "&Plot Results"
Height = 255
Left = 120
TabIndex = 10
Tag = "15100"
Top = 300
Value = 1 'Checked
Width = 1695
End
Begin VB.CheckBox chkAutoLabelPeaks
Caption = "&Auto-Label Peaks"
Height = 255
Left = 2040
TabIndex = 11
Tag = "15105"
Top = 300
Width = 2295
End
Begin VB.Label lblEffectiveResolutionMass
BackStyle = 0 'Transparent
Caption = "Effective Resolution M/Z"
Height = 255
Left = 120
TabIndex = 18
Tag = "15130"
Top = 1800
Width = 2655
End
Begin VB.Label lblEffectiveResolution
BackStyle = 0 'Transparent
Caption = "Effective Resolution"
Height = 255
Left = 120
TabIndex = 16
Tag = "15130"
Top = 1470
Width = 2655
End
Begin VB.Label lblGaussianQualityFactor
BackStyle = 0 'Transparent
Caption = "Gaussian Quality Factor"
Height = 255
Left = 120
TabIndex = 20
Tag = "15130"
Top = 2220
Width = 2655
End
Begin VB.Label lblPlotType
BackStyle = 0 'Transparent
Caption = "Plot Type"
Height = 255
Left = 120
TabIndex = 14
Tag = "15130"
Top = 990
Width = 1935
End
Begin VB.Label lblPlotColor
BackColor = &H00FF0000&
BorderStyle = 1 'Fixed Single
Height = 255
Left = 2040
TabIndex = 13
Tag = "15125"
ToolTipText = "Click to change"
Top = 630
Width = 375
End
Begin VB.Label lblPlotColorLabel
BackStyle = 0 'Transparent
Caption = "Plot Data Color"
Height = 255
Left = 120
TabIndex = 12
Tag = "15120"
Top = 630
Width = 1935
End
End
Begin VB.CommandButton cmdCopy
Caption = "Cop&y"
Height = 375
Left = 1320
TabIndex = 3
Tag = "10340"
Top = 840
Width = 1095
End
Begin RichTextLib.RichTextBox rtfFormula
Height = 495
Left = 1560
TabIndex = 1
Tag = "5050"
ToolTipText = "Type the molecular formula here."
Top = 120
Width = 3015
_ExtentX = 5318
_ExtentY = 873
_Version = 393217
MultiLine = 0 'False
TextRTF = $"frmIsotopicAbundance.frx":08CA
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "MS Sans Serif"
Size = 8.25
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
End
Begin VB.TextBox txtResults
BeginProperty Font
Name = "Courier"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 3255
Left = 120
Locked = -1 'True
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 8
Tag = "15150"
ToolTipText = "Isotopic distribution results"
Top = 1680
Width = 5415
End
Begin VB.CommandButton cmdCompute
Caption = "&Compute"
Default = -1 'True
Height = 375
Left = 120
TabIndex = 2
Tag = "15110"
Top = 840
Width = 1095
End
Begin VB.CommandButton cmdClose
Cancel = -1 'True
Caption = "Cl&ose"
Height = 375
Left = 2520
TabIndex = 4
Tag = "4000"
Top = 840
Width = 1095
End
Begin VB.Label lblChargeState
Alignment = 1 'Right Justify
Caption = "C&harge state:"
Height = 255
Left = 3480
TabIndex = 6
Tag = "15070"
Top = 930
Width = 1335
End
Begin VB.Label lblResults
Caption = "Results:"
Height = 255
Left = 120
TabIndex = 5
Tag = "15060"
Top = 1320
Width = 1455
End
Begin VB.Label lblFormula
Caption = "&Formula:"
Height = 255
Left = 120
TabIndex = 0
Tag = "15050"
Top = 240
Width = 1455
End
End
Attribute VB_Name = "frmIsotopicDistribution"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private WithEvents objSpectrum As CWSpectrumDLL.Spectrum
Attribute objSpectrum.VB_VarHelpID = -1
Private Const MAX_SERIES_COUNT = 2
Private Const GAUSSIAN_CONVERSION_DATACOUNT_WARNING_THRESHOLD = 1000
Private Enum ipmIsotopicPlotModeConstants
ipmSticksToZero = 0
ipmGaussian = 1
ipmContinuousData = 2 ' Used for raw, uncentered data
End Enum
Private Enum lcwfLastControlWithFocusConstants
lcwfFormula = 0
lcwfEffectiveResolution = 1
lcwfEffectiveResolutionMass = 2
lcwfGaussianQualityFactor = 3
lcwfChargeState = 4
End Enum
Private ConvolutedMSDataCount As Long
Private ConvolutedMSData2D() As Double ' 1-based array (since it is 1-based in the Dll)
Private ComparisonListDataCount As Long
Private ComparisonListXVals() As Double ' 0-based array
Private ComparisonListYVals() As Double ' 0-based array
Private CRCForPredictedSpectrumSaved As Double
Private CRCForComparisonIonListSaved As Double
Private mNeedToZoomOutFull As Boolean
Private mLastControlWithFocus As lcwfLastControlWithFocusConstants
Private mFormActivatedByUser As Boolean ' Set true the first time the user activates the form; always true from then on
' Used to prevent plotting the mass spectrum until after the user has activated the isotopic distribution form at least once
Private mUserWarnedLargeDataSetForGaussianConversion As Boolean
Private mDelayUpdatingPlot As Boolean
Private Sub ComparisonIonListClear()
ComparisonListDataCount = 0
ReDim ComparisonListXVals(0)
ReDim ComparisonListYVals(0)
UpdateComparisonListStatus
PlotIsotopicDistribution
End Sub
Private Sub ComparisonIonListPaste()
Dim strIonList As String, strLineWork As String
Dim blnAllowCommaDelimeter As Boolean
Dim lngCrLfLoc As Long, lngValuesToPopulate As Long
Dim lngIndex As Long, lngStartIndex As Long
Dim strDelimeter As String, intDelimeterLength As Integer
Dim strLeftChar As String, strDelimeterList As String
Dim dblParsedVals() As Double ' 0-based array
Dim intParseValCount As Integer
Dim dblMaximumIntensity As Double
On Error GoTo ComparisonIonListPasteErrorHandler
'' ' Warn user about replacing data
'' If Not QueryExistingIonsInList() Then Exit Sub
' Grab text from clipboard
strIonList = GetClipboardTextSmart()
If Len(strIonList) = 0 Then
MsgBox LookupMessage(980), vbInformation + vbOKOnly, LookupMessage(985)
Exit Sub
End If
' Determine if commas are used for the decimal point in this locale
If DetermineDecimalPoint() = "," Then
blnAllowCommaDelimeter = False
Else
blnAllowCommaDelimeter = True
End If
frmProgress.InitializeForm LookupMessage(990), 0, Len(strIonList)
frmProgress.ToggleAlwaysOnTop True
frmProgress.UpdateCurrentSubTask LookupMessage(1000)
' First Determine number of data points in strIonList
' This isn't necessary (while it is necessary in frmFragmentationModelling.PasteIonMatchList),
' but it doesn't take that much time and allows this code to be nearly identical to the frmFragmentationModelling code
' First look for the first occurrence of a valid delimeter
lngCrLfLoc = ParseStringFindCrlfIndex(strIonList, intDelimeterLength)
If lngCrLfLoc > 0 Then
' Record the first character of the delimeter (if vbCrLf, then recording vbCr), otherwise, recording just vbCr or just vbLf)
strDelimeter = Mid(strIonList, lngCrLfLoc, 1)
' Now determine the number of occurrences of the delimeter
lngValuesToPopulate = 0
For lngIndex = 1 To Len(strIonList)
If lngIndex Mod 500 = 0 Then
frmProgress.UpdateProgressBar lngIndex
If KeyPressAbortProcess > 1 Then Exit For
End If
If Mid(strIonList, lngIndex, 1) = strDelimeter Then
lngValuesToPopulate = lngValuesToPopulate + 1
End If
Next lngIndex
If lngValuesToPopulate > 1 And KeyPressAbortProcess = 0 Then
' Update frmProgress to use the correct progress bar size
frmProgress.InitializeForm LookupMessage(990), 0, lngValuesToPopulate
frmProgress.UpdateCurrentSubTask LookupMessage(1010)
End If
' Initialize IonMatchList
ComparisonListDataCount = 0
ReDim ComparisonListXVals(lngValuesToPopulate)
ReDim ComparisonListYVals(lngValuesToPopulate)
' Construct Delimeter List: Contains a space, Tab, and possibly comma
strDelimeterList = " " & vbTab & vbCr & vbLf
If blnAllowCommaDelimeter Then
strDelimeterList = strDelimeterList & ","
End If
' Initialize dblMaximumIntensity
dblMaximumIntensity = LowestValueForDoubleDataType
' Actually parse the data
' I process the list using the Mid() function since this is the fastest method
' However, Mid() becomes slower when the index value reaches 1000 or more (roughly)
' so I discard already-parsed data from strIonList every 1000 characters (approximately)
Do While Len(strIonList) > 0
lngStartIndex = 1
For lngIndex = 1 To Len(strIonList)
If lngIndex Mod 100 = 0 Then
frmProgress.UpdateProgressBar ComparisonListDataCount
If KeyPressAbortProcess > 1 Then Exit For
End If
If Mid(strIonList, lngIndex, 1) = strDelimeter Then
strLineWork = Mid(strIonList, lngStartIndex, lngIndex - 1)
If Len(strLineWork) > 0 Then
' Only parse if the first letter (trimmed) is a number (may start with - or +)
strLeftChar = Left(strLineWork, 1)
If IsNumeric(strLeftChar) Or strLeftChar = "-" Or strLeftChar = "+" Then
intParseValCount = ParseStringValuesDbl(strLineWork, dblParsedVals(), 2, strDelimeterList, , False, False, False)
If intParseValCount >= 2 Then
If dblParsedVals(0) <> 0 And dblParsedVals(0) <> 0 Then
If dblParsedVals(1) > dblMaximumIntensity Then
dblMaximumIntensity = dblParsedVals(1)
End If
ComparisonListXVals(ComparisonListDataCount) = dblParsedVals(0)
ComparisonListYVals(ComparisonListDataCount) = dblParsedVals(1)
ComparisonListDataCount = ComparisonListDataCount + 1
If ComparisonListDataCount > lngValuesToPopulate Then
' This shouldn't happen
Debug.Assert False
Exit Do
End If
End If
End If
End If
End If
lngStartIndex = lngIndex + intDelimeterLength
lngIndex = lngIndex + intDelimeterLength - 1
If lngIndex > 1000 Then
' Reduce the size of strIonList since the Mid() function gets slower with longer strings
strIonList = Mid(strIonList, lngIndex + 1)
lngIndex = 1
Exit For
End If
End If
Next lngIndex
If lngIndex > Len(strIonList) Then Exit Do
Loop
End If
frmProgress.HideForm
If ComparisonListDataCount > 0 And KeyPressAbortProcess = 0 Then
If dblMaximumIntensity <> 0 And cChkBox(chkComparisonListNormalize) Then
' Normalize the Comparison ion list to 100
For lngIndex = 0 To ComparisonListDataCount - 1
ComparisonListYVals(lngIndex) = ComparisonListYVals(lngIndex) / dblMaximumIntensity * 100
Next lngIndex
End If
PlotIsotopicDistribution False
Else
If KeyPressAbortProcess = 0 Then
MsgBox LookupMessage(1020), vbInformation + vbOKOnly, LookupMessage(985)
Else
MsgBox LookupMessage(940), vbInformation + vbOKOnly, LookupMessage(945)
End If
End If
UpdateComparisonListStatus
Exit Sub
ComparisonIonListPasteErrorHandler:
frmProgress.HideForm
UpdateComparisonListStatus
GeneralErrorHandler "frmIsotopicDistribution|ComparisonIonListPaste", Err.Number, Err.Description
End Sub
Private Sub CopyResults()
Clipboard.Clear
Clipboard.SetText txtResults, vbCFText
End Sub
Public Sub EnableDisablePlotUpdates(blnDisableUpdating As Boolean)
mDelayUpdatingPlot = blnDisableUpdating
If Not blnDisableUpdating Then
PlotIsotopicDistribution True
End If
End Sub
Private Sub PlotIsotopicDistribution(Optional blnIgnoreCRC As Boolean = False)
Dim lngIndex As Long
Static blnSeriesPlotModeInitialized(MAX_SERIES_COUNT) As Boolean
Static blnUpdatingPlot As Boolean
Dim PredictedSpectrumCRC As Double
Dim dblMassTimesIntensity As Double
Dim blnUpdatePlot As Boolean
Dim blnAllowResumeNextErrorHandling As Boolean
Dim dblXVals() As Double ' 0-based array
Dim dblYVals() As Double ' 0-based array
Dim lngDataCount As Long
Dim intSeriesNumber As Integer
Dim strLegendCaption As String
Dim eIsoPlotMode As ipmIsotopicPlotModeConstants
Dim lngPlotColor As Long
Dim eResponse As VbMsgBoxResult
Dim strMessage As String
Dim blnCursorVisibilitySaved As Boolean
Dim blnAutoHideCaptionsSaved As Boolean
If Not mFormActivatedByUser Or mDelayUpdatingPlot Then Exit Sub
On Error GoTo PlotIsotopicDistributionErrorHandler
blnAllowResumeNextErrorHandling = True
' Compute a CRC value for the current PredictedSpectrum() array and compare to the previously computed value
PredictedSpectrumCRC = 0
For lngIndex = 1 To ConvolutedMSDataCount
dblMassTimesIntensity = Abs((lngIndex) * ConvolutedMSData2D(lngIndex, 0) * ConvolutedMSData2D(lngIndex, 1))
If dblMassTimesIntensity > 0 Then
PredictedSpectrumCRC = PredictedSpectrumCRC + Log(dblMassTimesIntensity)
End If
Next lngIndex
' If the new CRC is different than the old one then re-plot the spectrun
If PredictedSpectrumCRC <> CRCForPredictedSpectrumSaved Then
CRCForPredictedSpectrumSaved = PredictedSpectrumCRC
blnUpdatePlot = True
End If
' Also compute a CRC value for the Comparison Ion List and compare to the previously computed value
PredictedSpectrumCRC = 0
For lngIndex = 0 To ComparisonListDataCount - 1
dblMassTimesIntensity = Abs(lngIndex * ComparisonListXVals(lngIndex) * ComparisonListYVals(lngIndex))
If dblMassTimesIntensity > 0 Then
PredictedSpectrumCRC = PredictedSpectrumCRC + Log(dblMassTimesIntensity)
End If
Next lngIndex
' If the new CRC is different than the old one then re-plot the spectrun
If PredictedSpectrumCRC <> CRCForComparisonIonListSaved Then
CRCForComparisonIonListSaved = PredictedSpectrumCRC
blnUpdatePlot = True
End If
If blnIgnoreCRC Then blnUpdatePlot = True
If Not blnUpdatePlot Then
Exit Sub
End If
If blnUpdatingPlot Then Exit Sub
blnUpdatingPlot = True
blnAllowResumeNextErrorHandling = False
objSpectrum.ShowSpectrum
' Hide the Cursor and disable auto-hiding of annotations
blnCursorVisibilitySaved = objSpectrum.GetCursorVisibility()
If blnCursorVisibilitySaved Then objSpectrum.SetCursorVisible False
blnAutoHideCaptionsSaved = objSpectrum.GetAnnotationDensityAutoHideCaptions()
If blnAutoHideCaptionsSaved Then objSpectrum.SetAnnotationDensityAutoHideCaptions False, False
If ConvolutedMSDataCount > 0 Then
lngDataCount = ConvolutedMSDataCount
ReDim dblXVals(0 To lngDataCount - 1)
ReDim dblYVals(0 To lngDataCount - 1)
' Now fill dblXVals() and dblYVals()
' ConvolutedMSData2D() is 1-based, but dblXVals() and dblYVals() are 0-based
For lngIndex = 1 To lngDataCount
dblXVals(lngIndex - 1) = ConvolutedMSData2D(lngIndex, 0)
dblYVals(lngIndex - 1) = ConvolutedMSData2D(lngIndex, 1)
Next lngIndex
Else
lngDataCount = 0
End If
' First plot the theoretical isotopic distribution
intSeriesNumber = 1
strLegendCaption = rtfFormula.Text
eIsoPlotMode = cboPlotType.ListIndex
lngPlotColor = lblPlotColor.BackColor
PlotIsotopicDistributionWork objSpectrum, intSeriesNumber, lngDataCount, dblXVals(), dblYVals(), strLegendCaption, blnSeriesPlotModeInitialized(), eIsoPlotMode, lngPlotColor
' Now plot the comparison ion list (will clear series 2 if list is empty)
intSeriesNumber = 2
strLegendCaption = "Comparison List"
eIsoPlotMode = cboComparisonListPlotType.ListIndex
lngPlotColor = lblComparisonListPlotColor.BackColor
' Need to copy the data from CaprisonListXVals() to dblXVals() since the Gaussian conversion operation changes the array
If ComparisonListDataCount > 0 Then
lngDataCount = ComparisonListDataCount
ReDim dblXVals(0 To UBound(ComparisonListXVals()))
dblXVals() = ComparisonListXVals()
dblYVals() = ComparisonListYVals()
Else
lngDataCount = 0
End If
' Check for large number of data points when Gaussian mode is enabled
If eIsoPlotMode = ipmGaussian And lngDataCount > GAUSSIAN_CONVERSION_DATACOUNT_WARNING_THRESHOLD Then
If Not mUserWarnedLargeDataSetForGaussianConversion Then
strMessage = LookupLanguageCaption(15300, "Warning, the ion comparison list contains a large number of data points. Do you really want to convert each point to a Gaussian curve?")
eResponse = MsgBox(strMessage, vbQuestion + vbYesNoCancel + vbDefaultButton2, LookupLanguageCaption(15305, "Large Data Point Count"))
If eResponse = vbYes Then
mUserWarnedLargeDataSetForGaussianConversion = True
ElseIf eResponse = vbCancel Then
lngDataCount = 0
Else
' Switch to Continuous Data mode
eIsoPlotMode = ipmContinuousData
cboComparisonListPlotType.ListIndex = eIsoPlotMode
End If
End If
End If
PlotIsotopicDistributionWork objSpectrum, intSeriesNumber, lngDataCount, dblXVals(), dblYVals(), strLegendCaption, blnSeriesPlotModeInitialized(), eIsoPlotMode, lngPlotColor
With objSpectrum
If mNeedToZoomOutFull Then
.ZoomOutFull
mNeedToZoomOutFull = False
End If
.SetCursorPosition 100, 0
' Auto-hiding of captions was disabled above; re-enable if necessary
.SetAnnotationDensityAutoHideCaptions blnAutoHideCaptionsSaved
' The cursor was hidden above; re-show it if necessary
If blnCursorVisibilitySaved Then
.SetCursorVisible True
End If
.SetSpectrumFormCurrentSeriesNumber 1
.SetCustomTicksXAxis 0, 0, True
.SetCustomTicksYAxis 0, 0, True
.ShowSpectrum
End With
' Return the focus back to this form (if possible)
On Error Resume Next
Select Case mLastControlWithFocus
Case lcwfFormula
rtfFormula.SetFocus
Case lcwfEffectiveResolution
txtEffectiveResolution.SetFocus
Case lcwfEffectiveResolutionMass
txtEffectiveResolutionMass.SetFocus
Case lcwfGaussianQualityFactor
txtGaussianQualityFactor.SetFocus
Case lcwfChargeState
txtChargeState.SetFocus
Case Else
Me.SetFocus
End Select
blnUpdatingPlot = False
Exit Sub
PlotIsotopicDistributionErrorHandler:
If blnAllowResumeNextErrorHandling Then
' Something is probably wrong with the CRC computation routines
Debug.Assert False
Resume Next
Else
GeneralErrorHandler "frmIsotopicDistribution|PlotIsotopicDistribution", Err.Number, Err.Description
End If
blnUpdatingPlot = False
End Sub
Private Sub PlotIsotopicDistributionWork(objThisCWSpectrum As CWSpectrumDLL.Spectrum, intSeriesNumber As Integer, lngDataCount As Long, dblXVals() As Double, dblYVals() As Double, strLegendCaption As String, blnSeriesPlotModeInitialized() As Boolean, eIsoPlotMode As ipmIsotopicPlotModeConstants, lngPlotColor As Long)
Dim lngResolution As Long, lngResolutionMass As Long
Dim lngQualityFactor As Long
Dim udtAutoLabelPeaksSettings As udtAutoLabelPeaksOptionsType
Dim dblMinimum As Double, dblMaximum As Double
Dim ePlotMode As pmPlotModeConstants
On Error GoTo PlotIsotopicDistributionWorkErrorHandler
If eIsoPlotMode = ipmGaussian Then
lngResolution = CLngSafe(txtEffectiveResolution)
lngResolutionMass = CLngSafe(txtEffectiveResolutionMass)
lngQualityFactor = CIntSafe(txtGaussianQualityFactor)
ValidateValueLng lngResolution, 1, 1000000000#, 5000
ValidateValueLng lngQualityFactor, 1, 75, 50
ValidateValueLng lngResolutionMass, 1, 1000000000#, 1000
' Note that dblXVals() and dblYVals() will be replaced with Gaussian representations of the peaks by the following function
ConvertStickDataToGaussian2DArray Me, dblXVals(), dblYVals(), lngDataCount, lngResolution, lngResolutionMass, CInt(lngQualityFactor)
End If
If eIsoPlotMode = ipmSticksToZero Then
ePlotMode = pmStickToZero
Else
ePlotMode = pmLines
End If
With objThisCWSpectrum
If .GetSeriesCount() < intSeriesNumber Then
.SetSeriesCount intSeriesNumber
End If
If Not blnSeriesPlotModeInitialized(intSeriesNumber) Then
.SetSeriesPlotMode intSeriesNumber, pmStickToZero, False
blnSeriesPlotModeInitialized(intSeriesNumber) = True
End If
.ClearData intSeriesNumber
If lngDataCount > 0 Then
' Normal data
.SetSeriesColor intSeriesNumber, lngPlotColor
.SetDataXvsY intSeriesNumber, dblXVals(), dblYVals(), lngDataCount, strLegendCaption
.SetSeriesPlotMode intSeriesNumber, ePlotMode, False
If cChkBox(chkAutoLabelPeaks) Then
udtAutoLabelPeaksSettings = .GetAutoLabelPeaksOptions()
udtAutoLabelPeaksSettings.DisplayXPos = True
udtAutoLabelPeaksSettings.IsContinuousData = (ePlotMode = pmLines)
.SetAutoLabelPeaksOptions udtAutoLabelPeaksSettings
.AutoLabelPeaks intSeriesNumber, udtAutoLabelPeaksSettings.DisplayXPos, udtAutoLabelPeaksSettings.DisplayYPos, udtAutoLabelPeaksSettings.CaptionAngle, udtAutoLabelPeaksSettings.IncludeArrow, udtAutoLabelPeaksSettings.HideInDenseRegions, udtAutoLabelPeaksSettings.PeakLabelCountMaximum
End If
.SetSpectrumFormCurrentSeriesNumber intSeriesNumber
.GetRangeX dblMinimum, dblMaximum
If dblXVals(0) < dblMinimum Or dblXVals(0) > dblMaximum Then mNeedToZoomOutFull = True
If dblXVals(lngDataCount - 1) < dblMinimum Or dblXVals(lngDataCount - 1) > dblMaximum Then mNeedToZoomOutFull = True
End If
End With
Exit Sub
PlotIsotopicDistributionWorkErrorHandler:
GeneralErrorHandler "frmIsotopicDistribution|PlotIsotopicDistributionWork", Err.Number, Err.Description
End Sub
Private Sub PositionFormControls()
Dim lngPreferredValue As Long
On Error GoTo PositionFormControlsErrorHandler
With fraPlotOptions
lngPreferredValue = Me.ScaleWidth - .Width - 120
If lngPreferredValue < 5500 Then lngPreferredValue = 5500
.Left = lngPreferredValue
End With
fraIonComparisonList.Left = fraPlotOptions.Left
rtfFormula.Width = fraPlotOptions.Left - rtfFormula.Left - 120
With txtResults
.Top = lblResults.Top + 360
.Left = 120
lngPreferredValue = fraPlotOptions.Left - .Left - 120
If lngPreferredValue < 2000 Then
' This shouldn't happen
Debug.Assert False
lngPreferredValue = 2000
End If
.Width = lngPreferredValue
lngPreferredValue = Me.ScaleHeight - .Top - 120
If lngPreferredValue < 1000 Then lngPreferredValue = 1000
.Height = lngPreferredValue
End With
lngPreferredValue = txtResults.Left + txtResults.Width - txtChargeState.Width
If lngPreferredValue < lblResults.Left + lblResults.Width + lblChargeState.Width Then
lngPreferredValue = lblResults.Left + lblResults.Width + lblChargeState.Width
End If
txtChargeState.Left = lngPreferredValue
lblChargeState.Left = txtChargeState.Left - lblChargeState.Width - 60
chkAddProtonChargeCarrier.Left = txtChargeState.Left - 1000
Exit Sub
PositionFormControlsErrorHandler:
Debug.Assert False
Resume Next
End Sub
Private Function QueryExistingIonsInList() As Boolean
Dim strMessage As String, eResponse As VbMsgBoxResult
If ComparisonListDataCount > 0 Then
strMessage = LookupMessage(910)
eResponse = MsgBox(strMessage, vbQuestion + vbYesNoCancel + vbDefaultButton3, LookupMessage(920))
If eResponse = vbYes Then
QueryExistingIonsInList = True
Else
QueryExistingIonsInList = False
End If
Else
QueryExistingIonsInList = True
End If
End Function
Public Sub ResetCWSpectrumOptions()
If cboComparisonListPlotType.ListIndex = ipmGaussian Then
objSpectrum.ResetOptionsToDefaults True, True, 2, pmLines
Else
objSpectrum.ResetOptionsToDefaults True, True, 2, pmStickToZero
End If
End Sub
Private Sub ResetPredictedSpectrumCRC()
CRCForPredictedSpectrumSaved = 0
End Sub
Public Sub SetFormActivated()
mFormActivatedByUser = True
End Sub
Public Sub SetNeedToZoomOutFull(blnEnable As Boolean)
mNeedToZoomOutFull = blnEnable
End Sub
Public Sub StartIsotopicDistributionCalcs(blnSetFocusOnTextbox As Boolean, Optional blnSetFocusOnChargeTextbox As Boolean = False)
Dim strResults As String, lngErrorID As Long
Dim strFormula As String
Dim strHeaderIsotopicAbundace As String, strHeaderMass As String
Dim strHeaderFraction As String, strHeaderIntensity As String
Dim blnAddProtonChargeCarrier As Boolean
Dim lngCursorPos As Long
Dim intChargeState As Integer
On Error GoTo StartIsotopicDistributionCalcsErrorHandler
strFormula = rtfFormula.Text
lngCursorPos = rtfFormula.SelStart
If Len(Trim(strFormula)) = 0 Then Exit Sub
RemoveHeightAdjustChar strFormula
Me.MousePointer = vbHourglass
If IsNumeric(txtChargeState) Then
intChargeState = Val(txtChargeState)
If intChargeState < 0 Then intChargeState = 1
If intChargeState >= 10000 Then intChargeState = 10000
Else
intChargeState = 1
End If
blnAddProtonChargeCarrier = cChkBox(chkAddProtonChargeCarrier)
strHeaderIsotopicAbundace = LookupLanguageCaption(15200, "Isotopic Abundances for")
If intChargeState = 0 Then
strHeaderMass = LookupLanguageCaption(15215, "Neutral Mass")
Else
strHeaderMass = LookupLanguageCaption(15210, "Mass/Charge")
End If
strHeaderFraction = LookupLanguageCaption(15220, "Fraction")
strHeaderIntensity = LookupLanguageCaption(15230, "Intensity")
' Make sure we're using isotopic masses
SwitchWeightMode emIsotopicMass
' Note: strFormula is passed ByRef
lngErrorID = objMwtWin.ComputeIsotopicAbundances(strFormula, intChargeState, strResults, ConvolutedMSData2D(), ConvolutedMSDataCount, strHeaderIsotopicAbundace, strHeaderMass, strHeaderFraction, strHeaderIntensity, blnAddProtonChargeCarrier)
If lngErrorID = 0 Then
' Update rtfFormula with the capitalized formula
rtfFormula = strFormula