-
Notifications
You must be signed in to change notification settings - Fork 4
/
frmMain.cs
2749 lines (2216 loc) · 120 KB
/
frmMain.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
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
using System;
using System.Collections.Generic;
// -------------------------------------------------------------------------------
// Written by Matthew Monroe for the Department of Energy (PNNL, Richland, WA)
// Program started October 11, 2003
// Copyright 2005, Battelle Memorial Institute. All Rights Reserved.
// E-mail: [email protected] or [email protected]
// Website: https://github.com/PNNL-Comp-Mass-Spec/ or https://www.pnnl.gov/integrative-omics
// -------------------------------------------------------------------------------
//
// Licensed under the 2-Clause BSD License; you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
// https://opensource.org/licenses/BSD-2-Clause
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using MASIC.Data;
using MASIC.DataInput;
using MASIC.Options;
using PRISM;
using PRISM.FileProcessor;
using PRISMDatabaseUtils;
using PRISMWin;
using ProgressFormNET;
using ShFolderBrowser.FolderBrowser;
namespace MASIC
{
/// <summary>
/// Main GUI window
/// </summary>
public partial class frmMain : Form
{
// ReSharper disable CommentTypo
// Ignore Spelling: Acet, Acq, Acetylated, amine, Checkbox, Combobox, CrLf, csv, Da, dpi, fracking frm, frmMain
// Ignore Spelling: Golay, immonium, iTraq, Lys, MASIC, mzml, Orbitrap Savitzky, Textbox
// ReSharper restore CommentTypo
/// <summary>
/// Constructor
/// </summary>
public frmMain()
{
// This call is required by the Windows Form Designer.
InitializeComponent();
// Add any initialization after the InitializeComponent() call
mCacheOptions = new SpectrumCacheOptions();
mDefaultCustomSICList = new List<CustomSICEntryType>();
mLogMessages = new List<string>();
mReporterIonIndexToModeMap = new Dictionary<int, ReporterIons.ReporterIonMassModeConstants>();
InitializeControls();
mMasic = new clsMASIC();
RegisterEvents(mMasic);
}
private const string XML_SETTINGS_FILE_NAME = "MASICParameters.xml";
private const string CUSTOM_SIC_VALUES_DATA_TABLE = "PeakMatchingThresholds";
private const string COL_NAME_MZ = "MZ";
private const string COL_NAME_MZ_TOLERANCE = "MZToleranceDa";
private const string COL_NAME_SCAN_CENTER = "Scan_Center";
private const string COL_NAME_SCAN_TOLERANCE = "Scan_Tolerance";
private const string COL_NAME_SCAN_COMMENT = "Scan_Comment";
private const string COL_NAME_CUSTOM_SIC_VALUE_ROW_ID = "UniqueRowID";
private struct CustomSICEntryType
{
public double MZ;
public float ScanCenter;
public string Comment;
}
private DataSet mCustomSICValuesDataset;
private readonly List<CustomSICEntryType> mDefaultCustomSICList;
private bool mWorking;
private string mXmlSettingsFilePath;
private string mPreferredInputFileExtension;
private readonly SpectrumCacheOptions mCacheOptions;
private bool mSuppressNoParentIonsError;
private bool mCompressMSSpectraData;
private bool mCompressMSMSSpectraData;
private double mCompressToleranceDivisorForDa;
private double mCompressToleranceDivisorForPPM;
private int mHeightAdjustForce;
private DateTime mHeightAdjustTime;
/// <summary>
/// Default instance of MASIC
/// </summary>
private readonly clsMASIC mMasic;
private frmProgress mProgressForm;
/// <summary>
/// Log messages, including warnings and errors, with the newest message at the top
/// </summary>
// ReSharper disable once CollectionNeverQueried.Local
private readonly List<string> mLogMessages;
private readonly Dictionary<int, ReporterIons.ReporterIonMassModeConstants> mReporterIonIndexToModeMap;
private ReporterIons.ReporterIonMassModeConstants SelectedReporterIonMode
{
get => GetSelectedReporterIonMode();
set
{
try
{
cboReporterIonMassMode.SelectedIndex = GetReporterIonIndexFromMode(value);
}
catch (Exception)
{
// Ignore errors here
}
}
}
private void AddCustomSICRow(
double mz,
double mzToleranceDa,
float scanOrAcqTimeCenter,
float scanOrAcqTimeTolerance,
string comment,
out bool existingRowFound)
{
existingRowFound = false;
foreach (DataRow myDataRow in mCustomSICValuesDataset.Tables[CUSTOM_SIC_VALUES_DATA_TABLE].Rows)
{
if (Math.Abs(double.Parse(myDataRow[0].ToString()) - mz) < float.Epsilon &&
Math.Abs(float.Parse(myDataRow[1].ToString()) - scanOrAcqTimeCenter) < float.Epsilon)
{
existingRowFound = true;
break;
}
}
comment ??= string.Empty;
if (!existingRowFound)
{
var newDataRow = mCustomSICValuesDataset.Tables[CUSTOM_SIC_VALUES_DATA_TABLE].NewRow();
newDataRow[0] = Math.Round(mz, 4);
newDataRow[1] = Math.Round(mzToleranceDa, 4);
newDataRow[2] = Math.Round(scanOrAcqTimeCenter, 6);
newDataRow[3] = Math.Round(scanOrAcqTimeTolerance, 6);
newDataRow[4] = comment;
mCustomSICValuesDataset.Tables[CUSTOM_SIC_VALUES_DATA_TABLE].Rows.Add(newDataRow);
}
}
private void AppendCustomSICListItem(double mz, float scanCenter, string comment)
{
var customSicEntryItem = new CustomSICEntryType
{
MZ = mz,
ScanCenter = scanCenter,
Comment = comment
};
mDefaultCustomSICList.Add(customSicEntryItem);
}
private void AppendReporterIonMassMode(ReporterIons.ReporterIonMassModeConstants reporterIonMassMode, string description)
{
cboReporterIonMassMode.Items.Add(description);
var currentIndex = cboReporterIonMassMode.Items.Count - 1;
// Add or update the value for key currentIndex
mReporterIonIndexToModeMap[currentIndex] = reporterIonMassMode;
}
private void AppendToLog(EventLogEntryType messageType, string message)
{
if (message.StartsWith("ProcessingStats") || message.StartsWith("Parameter file not specified"))
{
return;
}
string textToAppend;
var doEvents = false;
switch (messageType)
{
case EventLogEntryType.Error:
textToAppend = "Error: " + message;
tbsOptions.SelectTab(tbsOptions.TabCount - 1);
doEvents = true;
break;
case EventLogEntryType.Warning:
textToAppend = "Warning: " + message;
tbsOptions.SelectTab(tbsOptions.TabCount - 1);
doEvents = true;
break;
default:
// Includes Case EventLogEntryType.Information
textToAppend = message;
break;
}
mLogMessages.Insert(0, textToAppend);
txtLogMessages.AppendText(textToAppend + Environment.NewLine);
txtLogMessages.ScrollToCaret();
if (doEvents)
{
Application.DoEvents();
}
}
private void AutoPopulateCustomSICValues(bool confirmReplaceExistingResults)
{
GetCurrentCustomSICTolerances(out var defaultMZTolerance, out var defaultScanOrAcqTimeTolerance);
if (defaultScanOrAcqTimeTolerance > 1)
{
defaultScanOrAcqTimeTolerance = 0.6F;
}
if (ClearCustomSICList(confirmReplaceExistingResults))
{
// The default values use relative times, so make sure that mode is enabled
SetCustomSICToleranceType(CustomSICList.CustomSICScanTypeConstants.Relative);
txtCustomSICScanOrAcqTimeTolerance.Text = defaultScanOrAcqTimeTolerance.ToString(CultureInfo.InvariantCulture);
foreach (var item in mDefaultCustomSICList)
{
AddCustomSICRow(item.MZ, defaultMZTolerance, item.ScanCenter, defaultScanOrAcqTimeTolerance, item.Comment, out _);
}
}
}
private bool mUpdating;
private void CatchUnrequestedHeightChange()
{
if (mUpdating)
return;
if (mHeightAdjustForce == 0 || DateTime.UtcNow.Subtract(mHeightAdjustTime).TotalSeconds > 5.0)
return;
try
{
mUpdating = true;
Height = mHeightAdjustForce;
mHeightAdjustForce = 0;
mHeightAdjustTime = DateTime.Parse("1900-01-01");
}
catch (Exception)
{
// Ignore errors here
}
finally
{
mUpdating = false;
}
}
private void AutoToggleReporterIonStatsEnabled()
{
if (SelectedReporterIonMode == ReporterIons.ReporterIonMassModeConstants.CustomOrNone)
{
if (chkReporterIonStatsEnabled.Checked)
{
chkReporterIonStatsEnabled.Checked = false;
}
}
else if (!chkReporterIonStatsEnabled.Checked)
{
chkReporterIonStatsEnabled.Checked = true;
}
}
private void AutoToggleReporterIonStatsMode()
{
if (chkReporterIonStatsEnabled.Checked)
{
if (SelectedReporterIonMode == ReporterIons.ReporterIonMassModeConstants.CustomOrNone)
{
SelectedReporterIonMode = ReporterIons.ReporterIonMassModeConstants.ITraqFourMZ;
}
}
else if (SelectedReporterIonMode != ReporterIons.ReporterIonMassModeConstants.CustomOrNone)
{
SelectedReporterIonMode = ReporterIons.ReporterIonMassModeConstants.CustomOrNone;
}
}
private void ClearAllRangeFilters()
{
txtScanStart.Text = "0";
txtScanEnd.Text = "0";
txtTimeStart.Text = "0";
txtTimeEnd.Text = "0";
}
/// <summary>
/// Clear the custom SIC list
/// </summary>
/// <param name="confirmReplaceExistingResults"></param>
/// <returns>
/// True if the CUSTOM_SIC_VALUES_DATA_TABLE is empty or if it was cleared
/// False if the user is queried about clearing and they do not click Yes
/// </returns>
private bool ClearCustomSICList(bool confirmReplaceExistingResults)
{
if (mCustomSICValuesDataset.Tables[CUSTOM_SIC_VALUES_DATA_TABLE].Rows.Count == 0)
return true;
DialogResult result;
if (confirmReplaceExistingResults)
{
result = MessageBox.Show("Are you sure you want to clear the Custom SIC list?", "Clear Custom SICs", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
}
else
{
result = DialogResult.Yes;
}
if (result == DialogResult.Yes)
{
mCustomSICValuesDataset.Tables[CUSTOM_SIC_VALUES_DATA_TABLE].Rows.Clear();
return true;
}
return false;
}
private bool ConfirmPaths()
{
if (txtInputFilePath.TextLength == 0)
{
MessageBox.Show("Please define an input file path", "Missing Value", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txtInputFilePath.Focus();
return false;
}
if (txtOutputDirectoryPath.TextLength == 0)
{
MessageBox.Show("Please define an output directory path", "Missing Value", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
txtOutputDirectoryPath.Focus();
return false;
}
return true;
}
private string CStrSafe(object item)
{
try
{
if (item == null)
{
return string.Empty;
}
if (Convert.IsDBNull(item))
{
return string.Empty;
}
return Convert.ToString(item);
}
catch (Exception)
{
return string.Empty;
}
}
private void DefineDefaultCustomSICList()
{
mDefaultCustomSICList.Clear();
this.AppendCustomSICListItem(824.47422, 0.176F, "Pep-09");
this.AppendCustomSICListItem(412.74102, 0.176F, "Pep-09");
this.AppendCustomSICListItem(484.28137, 0.092F, "Pep-11");
this.AppendCustomSICListItem(459.27687, 0.368F, "Pep-14");
this.AppendCustomSICListItem(740.01082, 0.574F, "Pep-16");
this.AppendCustomSICListItem(762.51852, 0.642F, "Pep-26");
this.AppendCustomSICListItem(657.42992, 0.192F, "Pep-16_Partial");
this.AppendCustomSICListItem(900.59222, 0.4F, "Pep-26_PartialA");
this.AppendCustomSICListItem(640.43972, 0.4F, "Pep-26_PartialB");
}
private void DefineOverviewText()
{
var msg = new StringBuilder();
msg.Append("When Export All Spectra Data Points is enabled, a separate file is created containing the raw data points (scan number, m/z, and intensity), using the specified file format. ");
msg.Append("If Export MS/MS Spectra is enabled, the fragmentation spectra are included, in addition to the survey scan spectra (MS1 scans). ");
msg.Append("If MS/MS spectra are not included, one can optionally renumber the survey scan spectra so that they increase in steps of 1, regardless of the number of MS/MS scans between each survey scan. ");
msg.Append("The Minimum Intensity and Maximum Ion Count options allow you to limit the number of data points exported for each spectrum.");
lblRawDataExportOverview.Text = msg.ToString();
msg.Clear();
msg.Append("These options control how the selected ion chromatogram (SIC) is created for each parent ion mass or custom SIC search mass. ");
msg.Append("The data in the survey scan spectra (MS1 scans) are searched +/- the SIC Tolerance, looking forward and backward in time until ");
msg.Append("the intensity of the matching data 1) falls below the Intensity Threshold Fraction Max Peak value, 2) falls below the Intensity ");
msg.Append("Threshold Absolute Minimum, or 3) spans more than the Maximum Peak Width forward or backward limits defined.");
lblSICOptionsOverview.Text = msg.ToString();
msg.Clear();
msg.Append("When processing Thermo MRM data files, a file named _MRMSettings.txt will be created listing the ");
msg.Append("parent and daughter m/z values monitored via SRM. ");
msg.Append("You can optionally export detailed MRM intensity data using these options:");
lblMRMInfo.Text = msg.ToString();
msg.Clear();
msg.Append("Select a comma or tab delimited file to read custom SIC search values from, ");
msg.Append("or define them in the Custom SIC Values table below. If using the file, ");
msg.Append("allowed column names are: ").Append(CustomSICListReader.GetCustomMZFileColumnHeaders()).Append(". ");
msg.Append("Note: use " +
CustomSICListReader.CUSTOM_SIC_COLUMN_SCAN_TIME + " and " +
CustomSICListReader.CUSTOM_SIC_COLUMN_TIME_TOLERANCE + " only when specifying ");
msg.Append("acquisition time-based values. When doing so, do not include " +
CustomSICListReader.CUSTOM_SIC_COLUMN_SCAN_CENTER + " and " +
CustomSICListReader.CUSTOM_SIC_COLUMN_SCAN_TOLERANCE + ".");
txtCustomSICFileDescription.Text = msg.ToString();
}
private void EnableDisableControls()
{
var createSICsAndRawData = !chkSkipSICAndRawDataProcessing.Checked;
var msmsProcessingEnabled = !chkSkipMSMSProcessing.Checked;
var exportRawDataOnly = chkExportRawDataOnly.Checked && chkExportRawSpectraData.Checked;
chkSkipMSMSProcessing.Enabled = createSICsAndRawData;
chkExportRawDataOnly.Enabled = createSICsAndRawData && chkExportRawSpectraData.Checked;
fraExportAllSpectraDataPoints.Enabled = createSICsAndRawData;
fraSICNoiseThresholds.Enabled = createSICsAndRawData && !exportRawDataOnly;
fraPeakFindingOptions.Enabled = fraSICNoiseThresholds.Enabled;
fraSmoothingOptions.Enabled = fraSICNoiseThresholds.Enabled;
fraSICSearchThresholds.Enabled = fraSICNoiseThresholds.Enabled;
fraMassSpectraNoiseThresholds.Enabled = createSICsAndRawData;
fraBinningIntensityOptions.Enabled = createSICsAndRawData && msmsProcessingEnabled && !exportRawDataOnly;
fraBinningMZOptions.Enabled = fraBinningIntensityOptions.Enabled;
fraSpectrumSimilarityOptions.Enabled = fraBinningIntensityOptions.Enabled;
fraCustomSICControls.Enabled = createSICsAndRawData && !exportRawDataOnly;
dgCustomSICValues.Enabled = createSICsAndRawData && !exportRawDataOnly;
var rawExportEnabled = chkExportRawSpectraData.Checked;
cboExportRawDataFileFormat.Enabled = rawExportEnabled;
chkExportRawDataIncludeMSMS.Enabled = rawExportEnabled;
if (chkExportRawDataIncludeMSMS.Checked)
{
chkExportRawDataRenumberScans.Enabled = false;
}
else
{
chkExportRawDataRenumberScans.Enabled = rawExportEnabled;
}
txtExportRawDataSignalToNoiseRatioMinimum.Enabled = rawExportEnabled;
txtExportRawDataMaxIonCountPerScan.Enabled = rawExportEnabled;
txtExportRawDataIntensityMinimum.Enabled = rawExportEnabled;
if (cboSICNoiseThresholdMode.SelectedIndex == (int)MASICPeakFinder.clsMASICPeakFinder.NoiseThresholdModes.AbsoluteThreshold)
{
txtSICNoiseThresholdIntensity.Enabled = true;
txtSICNoiseFractionLowIntensityDataToAverage.Enabled = false;
}
else if (cboSICNoiseThresholdMode.SelectedIndex is
(int)MASICPeakFinder.clsMASICPeakFinder.NoiseThresholdModes.TrimmedMeanByAbundance or
(int)MASICPeakFinder.clsMASICPeakFinder.NoiseThresholdModes.TrimmedMeanByCount or
(int)MASICPeakFinder.clsMASICPeakFinder.NoiseThresholdModes.TrimmedMedianByAbundance)
{
txtSICNoiseThresholdIntensity.Enabled = false;
txtSICNoiseFractionLowIntensityDataToAverage.Enabled = true;
}
else
{
// Unknown mode; disable both
txtSICNoiseThresholdIntensity.Enabled = false;
txtSICNoiseFractionLowIntensityDataToAverage.Enabled = false;
}
txtButterworthSamplingFrequency.Enabled = optUseButterworthSmooth.Checked;
txtSavitzkyGolayFilterOrder.Enabled = optUseSavitzkyGolaySmooth.Checked;
if (cboMassSpectraNoiseThresholdMode.SelectedIndex == (int)MASICPeakFinder.clsMASICPeakFinder.NoiseThresholdModes.AbsoluteThreshold)
{
txtMassSpectraNoiseThresholdIntensity.Enabled = true;
txtMassSpectraNoiseFractionLowIntensityDataToAverage.Enabled = false;
txtMassSpectraNoiseMinimumSignalToNoiseRatio.Enabled = false;
}
else if (cboMassSpectraNoiseThresholdMode.SelectedIndex is
(int)MASICPeakFinder.clsMASICPeakFinder.NoiseThresholdModes.TrimmedMeanByAbundance or
(int)MASICPeakFinder.clsMASICPeakFinder.NoiseThresholdModes.TrimmedMeanByCount or
(int)MASICPeakFinder.clsMASICPeakFinder.NoiseThresholdModes.TrimmedMedianByAbundance)
{
txtMassSpectraNoiseThresholdIntensity.Enabled = false;
txtMassSpectraNoiseFractionLowIntensityDataToAverage.Enabled = true;
txtMassSpectraNoiseMinimumSignalToNoiseRatio.Enabled = true;
}
else
{
// Unknown mode; disable both
txtMassSpectraNoiseThresholdIntensity.Enabled = false;
txtMassSpectraNoiseFractionLowIntensityDataToAverage.Enabled = false;
txtMassSpectraNoiseMinimumSignalToNoiseRatio.Enabled = false;
}
chkSaveExtendedStatsFileIncludeFilterText.Enabled = chkSaveExtendedStatsFile.Checked;
chkSaveExtendedStatsFileIncludeStatusLog.Enabled = chkSaveExtendedStatsFile.Checked;
txtStatusLogKeyNameFilterList.Enabled = chkSaveExtendedStatsFile.Checked && chkSaveExtendedStatsFileIncludeStatusLog.Checked;
chkConsolidateConstantExtendedHeaderValues.Enabled = chkSaveExtendedStatsFile.Checked;
EnableDisableCustomSICValueGrid();
}
private void EnableDisableCustomSICValueGrid()
{
bool enableGrid;
if (txtCustomSICFileName.TextLength > 0)
{
enableGrid = false;
dgCustomSICValues.CaptionText = "Custom SIC Values will be read from the file defined above";
}
else
{
enableGrid = true;
dgCustomSICValues.CaptionText = "Custom SIC Values";
}
cmdPasteCustomSICList.Enabled = enableGrid;
cmdCustomSICValuesPopulate.Enabled = enableGrid;
cmdClearCustomSICList.Enabled = enableGrid;
dgCustomSICValues.Enabled = enableGrid;
}
private void frmMain_Resize(object sender, EventArgs e)
{
CatchUnrequestedHeightChange();
}
private void GetCurrentCustomSICTolerances(out double defaultMZTolerance, out float defaultScanOrAcqTimeTolerance)
{
try
{
defaultMZTolerance = double.Parse(txtSICTolerance.Text);
if (optSICTolerancePPM.Checked)
{
defaultMZTolerance = Utilities.PPMToMass(defaultMZTolerance, 1000);
}
}
catch (Exception)
{
defaultMZTolerance = 0.6;
}
try
{
defaultScanOrAcqTimeTolerance = float.Parse(txtCustomSICScanOrAcqTimeTolerance.Text);
}
catch (Exception)
{
defaultScanOrAcqTimeTolerance = 0;
}
}
private CustomSICList.CustomSICScanTypeConstants GetCustomSICScanToleranceType()
{
if (optCustomSICScanToleranceAbsolute.Checked)
{
return CustomSICList.CustomSICScanTypeConstants.Absolute;
}
if (optCustomSICScanToleranceRelative.Checked)
{
return CustomSICList.CustomSICScanTypeConstants.Relative;
}
if (optCustomSICScanToleranceAcqTime.Checked)
{
return CustomSICList.CustomSICScanTypeConstants.AcquisitionTime;
}
// Assume absolute
return CustomSICList.CustomSICScanTypeConstants.Absolute;
}
private int GetReporterIonIndexFromMode(ReporterIons.ReporterIonMassModeConstants reporterIonMassMode)
{
foreach (var item in mReporterIonIndexToModeMap)
{
if (item.Value == reporterIonMassMode)
{
return item.Key;
}
}
throw new InvalidEnumArgumentException("Dictionary mReporterIonIndexToModeMap is missing enum " + reporterIonMassMode);
}
private ReporterIons.ReporterIonMassModeConstants GetReporterIonModeFromIndex(int comboboxIndex)
{
if (mReporterIonIndexToModeMap.TryGetValue(comboboxIndex, out var reporterIonMassMode))
{
return reporterIonMassMode;
}
throw new Exception("Dictionary mReporterIonIndexToModeMap is missing index " + comboboxIndex);
}
private ReporterIons.ReporterIonMassModeConstants GetSelectedReporterIonMode()
{
return GetReporterIonModeFromIndex(cboReporterIonMassMode.SelectedIndex);
}
private string GetSettingsFilePath()
{
return ProcessFilesOrDirectoriesBase.GetSettingsFilePathLocal("MASIC", XML_SETTINGS_FILE_NAME);
}
private void IniFileLoadOptions(bool updateIOPaths)
{
// Prompts the user to select a file to load the options from
using var fileSelector = new OpenFileDialog
{
AddExtension = true,
CheckFileExists = true,
CheckPathExists = true,
DefaultExt = ".xml",
DereferenceLinks = true,
Multiselect = false,
ValidateNames = true,
Filter = "Settings files (*.xml)|*.xml|All files (*.*)|*.*",
FilterIndex = 1
};
var filePath = mXmlSettingsFilePath;
if (filePath.Length > 0)
{
try
{
fileSelector.InitialDirectory = Directory.GetParent(filePath)?.ToString();
}
catch
{
fileSelector.InitialDirectory = AppUtils.GetAppDirectoryPath();
}
}
else
{
fileSelector.InitialDirectory = AppUtils.GetAppDirectoryPath();
}
if (File.Exists(filePath))
{
fileSelector.FileName = Path.GetFileName(filePath);
}
fileSelector.Title = "Specify file to load options from";
var result = fileSelector.ShowDialog();
if (result == DialogResult.Cancel)
return;
if (fileSelector.FileName.Length > 0)
{
mXmlSettingsFilePath = fileSelector.FileName;
IniFileLoadOptions(mXmlSettingsFilePath, updateIOPaths);
}
}
private void IniFileLoadOptions(string filePath, bool updateIOPaths)
{
// Loads options from the given file
try
{
// Utilize the built-in LoadParameterFileSettings function, then call ResetToDefaults
var masicInstance = mMasic ?? new clsMASIC();
var success = masicInstance.LoadParameterFileSettings(filePath);
if (!success)
{
MessageBox.Show("LoadParameterFileSettings returned false for: " + Path.GetFileName(filePath), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
ResetToDefaults(false);
// Sleep for 100 msec, just to be safe
Thread.Sleep(100);
// Now load some custom options that aren't loaded by clsMASIC
var xmlFileReader = new XmlSettingsFileAccessor();
// Pass True to .LoadSettings() to turn off case sensitive matching
xmlFileReader.LoadSettings(filePath, false);
try
{
txtDatasetLookupFilePath.Text = xmlFileReader.GetParam(MASICOptions.XML_SECTION_DATABASE_SETTINGS, "DatasetLookupFilePath", txtDatasetLookupFilePath.Text);
try
{
if (!File.Exists(txtDatasetLookupFilePath.Text))
{
txtDatasetLookupFilePath.Text = string.Empty;
}
}
catch (Exception)
{
// Ignore any errors here
}
if (updateIOPaths)
{
txtInputFilePath.Text = xmlFileReader.GetParam(MASICOptions.XML_SECTION_IMPORT_OPTIONS, "InputFilePath", txtInputFilePath.Text);
}
Width = xmlFileReader.GetParam(MASICOptions.XML_SECTION_IMPORT_OPTIONS, "WindowWidth", Width);
Height = xmlFileReader.GetParam(MASICOptions.XML_SECTION_IMPORT_OPTIONS, "WindowHeight", Height);
// Uncomment to test DPI scaling
//var graphics = this.CreateGraphics();
//var dpiX = graphics.DpiX;
//var dpiY = graphics.DpiY;
//var savedWidth = xmlFileReader.GetParam(MASICOptions.XML_SECTION_IMPORT_OPTIONS, "WindowWidth", 0);
//var savedHeight = xmlFileReader.GetParam(MASICOptions.XML_SECTION_IMPORT_OPTIONS, "WindowHeight", 0);
//if (savedWidth > 0)
// Width = (int)Math.Floor(savedWidth * 96 / dpiX);
//if (savedHeight > 0)
// Height = (int)Math.Floor(savedHeight * 96 / dpiY);
if (updateIOPaths)
{
txtOutputDirectoryPath.Text = xmlFileReader.GetParam(MASICOptions.XML_SECTION_IMPORT_OPTIONS, "LastDirectory", txtOutputDirectoryPath.Text);
}
if (txtOutputDirectoryPath.TextLength == 0)
{
txtOutputDirectoryPath.Text = AppUtils.GetAppDirectoryPath();
}
mPreferredInputFileExtension = xmlFileReader.GetParam(MASICOptions.XML_SECTION_IMPORT_OPTIONS, "PreferredInputFileExtension", mPreferredInputFileExtension);
}
catch (Exception)
{
MessageBox.Show("Invalid parameter in settings file: " + Path.GetFileName(filePath), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch (Exception ex)
{
MessageBox.Show("Error loading settings from file: " + filePath + "; " + Environment.NewLine +
ex.Message + ";" + Environment.NewLine, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void IniFileSaveDefaultOptions()
{
var response = MessageBox.Show("Save the current options as defaults?", "Save Defaults", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (response == DialogResult.Yes)
{
IniFileSaveOptions(GetSettingsFilePath(), false);
}
}
private void IniFileSaveOptions()
{
// Prompts the user to select a file to load the options from
using var fileSelector = new SaveFileDialog
{
AddExtension = true,
CheckFileExists = false,
CheckPathExists = true,
DefaultExt = ".xml",
DereferenceLinks = true,
OverwritePrompt = true,
ValidateNames = true,
Filter = "Settings files (*.xml)|*.xml|All files (*.*)|*.*",
FilterIndex = 1
};
var filePath = mXmlSettingsFilePath;
if (filePath.Length > 0)
{
try
{
fileSelector.InitialDirectory = Directory.GetParent(filePath)?.ToString();
}
catch
{
fileSelector.InitialDirectory = AppUtils.GetAppDirectoryPath();
}
}
else
{
fileSelector.InitialDirectory = AppUtils.GetAppDirectoryPath();
}
if (File.Exists(filePath))
{
fileSelector.FileName = Path.GetFileName(filePath);
}
fileSelector.Title = "Specify file to save options to";
var result = fileSelector.ShowDialog();
if (result == DialogResult.Cancel)
return;
if (fileSelector.FileName.Length > 0)
{
mXmlSettingsFilePath = fileSelector.FileName;
IniFileSaveOptions(mXmlSettingsFilePath, false);
}
}
private void IniFileSaveOptions(string filePath, bool saveWindowDimensionsOnly = false)
{
try
{
if (!saveWindowDimensionsOnly)
{
UpdateMasicSettings(mMasic);
mMasic.Options.SaveParameterFileSettings(filePath);
// Sleep for 100 msec, just to be safe
Thread.Sleep(100);
}
// Pass True to .LoadSettings() here so that newly made Xml files will have the correct capitalization
var xmlFileReader = new XmlSettingsFileAccessor();
xmlFileReader.LoadSettings(filePath, true);
try
{
if (!saveWindowDimensionsOnly)
{
try
{
if (File.Exists(txtDatasetLookupFilePath.Text))
{
xmlFileReader.SetParam(MASICOptions.XML_SECTION_DATABASE_SETTINGS, "DatasetLookupFilePath", txtDatasetLookupFilePath.Text);
}
}
catch (Exception)
{
// Ignore any errors here
}
xmlFileReader.SetParam(MASICOptions.XML_SECTION_IMPORT_OPTIONS, "InputFilePath", txtInputFilePath.Text);
}
xmlFileReader.SetParam(MASICOptions.XML_SECTION_IMPORT_OPTIONS, "LastDirectory", txtOutputDirectoryPath.Text);
xmlFileReader.SetParam(MASICOptions.XML_SECTION_IMPORT_OPTIONS, "PreferredInputFileExtension", mPreferredInputFileExtension);
xmlFileReader.SetParam(MASICOptions.XML_SECTION_IMPORT_OPTIONS, "WindowWidth", Width);
xmlFileReader.SetParam(MASICOptions.XML_SECTION_IMPORT_OPTIONS, "WindowHeight", Height);
}
catch (Exception)
{
MessageBox.Show("Error storing parameter in settings file: " + Path.GetFileName(filePath), "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
xmlFileReader.SaveSettings();
}
catch (Exception ex)
{
ConsoleMsgUtils.ShowWarning("Error saving settings to file: " + filePath);
ConsoleMsgUtils.ShowWarning(ex.Message);
MessageBox.Show("Error saving settings to file: " + filePath, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void InitializeControls()
{
DefineDefaultCustomSICList();
PopulateComboBoxes();
InitializeCustomSICDataGrid();
DefineOverviewText();
mXmlSettingsFilePath = GetSettingsFilePath();
ProcessFilesOrDirectoriesBase.CreateSettingsFileIfMissing(mXmlSettingsFilePath);
mPreferredInputFileExtension = ".Raw";
mHeightAdjustForce = 0;
mHeightAdjustTime = DateTime.Parse("1900-01-01");
IniFileLoadOptions(mXmlSettingsFilePath, true);
SetToolTips();
}
private void InitializeCustomSICDataGrid()
{
// Make the Peak Matching Thresholds data table
var customSICValues = new DataTable(CUSTOM_SIC_VALUES_DATA_TABLE);
// Add the columns to the data table
DataTableUtils.AppendColumnDoubleToTable(customSICValues, COL_NAME_MZ);
DataTableUtils.AppendColumnDoubleToTable(customSICValues, COL_NAME_MZ_TOLERANCE);
DataTableUtils.AppendColumnDoubleToTable(customSICValues, COL_NAME_SCAN_CENTER);
DataTableUtils.AppendColumnDoubleToTable(customSICValues, COL_NAME_SCAN_TOLERANCE);
DataTableUtils.AppendColumnStringToTable(customSICValues, COL_NAME_SCAN_COMMENT, string.Empty);
DataTableUtils.AppendColumnIntegerToTable(customSICValues, COL_NAME_CUSTOM_SIC_VALUE_ROW_ID, 0, true, true);
var primaryKeyColumn = new[] { customSICValues.Columns[COL_NAME_CUSTOM_SIC_VALUE_ROW_ID] };
customSICValues.PrimaryKey = primaryKeyColumn;
// Instantiate the dataset
mCustomSICValuesDataset = new DataSet(CUSTOM_SIC_VALUES_DATA_TABLE);
// Add the new DataTable to the DataSet.
mCustomSICValuesDataset.Tables.Add(customSICValues);
// Bind the DataSet to the DataGrid
dgCustomSICValues.DataSource = mCustomSICValuesDataset;
dgCustomSICValues.DataMember = CUSTOM_SIC_VALUES_DATA_TABLE;
// Update the grid's table style
UpdateCustomSICDataGridTableStyle();
// Populate the table
AutoPopulateCustomSICValues(false);
}
private void PasteCustomSICValues(bool clearList)
{
var lineDelimiters = new[] { '\r', '\n' };
// Examine the clipboard contents
var clipboardData = Clipboard.GetDataObject();
if (clipboardData == null)
{
return;
}
if (!clipboardData.GetDataPresent(DataFormats.StringFormat, true))
{
return;
}
var data = Convert.ToString(clipboardData.GetData(DataFormats.StringFormat, true));
// Split data on carriage return or line feed characters
// Lines that end in CrLf will give two separate lines; one with the text, and one blank; that's OK
var dataLines = data.Split(lineDelimiters, 50000);
if (dataLines.Length == 0)
{
return;
}