-
Notifications
You must be signed in to change notification settings - Fork 3
/
frmDAnTE.Main.cs
404 lines (324 loc) · 12.9 KB
/
frmDAnTE.Main.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;
using DAnTE.Properties;
using DAnTE.Tools;
namespace DAnTE.Inferno
{
/// <summary>
/// Main DAnTE form
/// </summary>
public partial class frmDAnTE : Form
{
#region Other Variables
public const string PROGRAM_DATE = "January 31, 2019";
public const int SUGGESTED_DATASETS_TO_SELECT = 30;
public const int MAX_DATASETS_TO_SELECT = 60;
public const int MAX_DATASETS_TO_SELECT_CPU_INTENSIVE = 30;
private IContainer components;
// Tab Page controls
private TabControl mtabControlData;
// Tab controls for Expressions
private TabPage ctltabPage;
private readonly frmShowProgress mfrmShowProgress;
// ReSharper disable once NotAccessedField.Local
// Used by HandleFileOpenCompleted in Inferno\Events\frmDAnTE.FileIOEvents.cs
private List<string> mDataSetNames = new List<string>();
private string[] mstrArrProteins;
private string[] mstrArrMassTags;
// File path of the loaded data, but also used when loading a protein info file or factors file
private string mstrLoadedfileName;
// File path of the session (.dnt) file
private string mSessionFile;
private readonly Timer mAutoLoadTimer;
private bool mAutoLoadSessionFile;
private DateTime mAutoLoadScheduledTime;
// This is a linux-style path that is used by R to save .png files
// For example: C:/Users/username/AppData/Roaming/Inferno/_temp.png
private string mRTempFilePath = "";
private clsRconnect mRConnector;
private string mstrFldgTitle;
private enmDataType mDataSetType = enmDataType.ESET;
private static frmDAnTE m_frmDAnTE;
private readonly BackgroundWorker m_BackgroundWorker;
private frmDAnTEmdi m_frmDAnTEmdi;
private ToolStripMenuItem mnuItemMissFilt;
private ToolStripMenuItem mnuItemFC;
private ToolStripMenuItem ctxtMnuItemFilter;
private ToolStripSeparator toolStripSeparator13;
private readonly Dictionary<string, clsDatasetTreeNode> mhtDatasets =
new Dictionary<string, clsDatasetTreeNode>();
private readonly Dictionary<string, string> mhtAnalysisObjects = new Dictionary<string, string>();
private readonly List<clsAnalysisObject> marrAnalysisObjects = new List<clsAnalysisObject>();
private ToolStripMenuItem mnuItemVenn;
private int mintFilterTblNum;
#endregion
#region Form Constructor
public frmDAnTE()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
Settings.Default.SessionFileName = null;
Settings.Default.Save();
if (IsMdiChild)
{
//ToolStripManager.Merge(this.mtoolStripDAnTE, "mtoolStripMDI");
mtoolStripDAnTE.Visible = false;
}
mAutoLoadTimer = new Timer
{
Interval = 250,
Enabled = true
};
mAutoLoadTimer.Tick += mAutoLoadTimer_Tick;
mfrmShowProgress = new frmShowProgress();
//Threading -----------------------------------
m_BackgroundWorker = new BackgroundWorker();
}
#endregion
#region Private methods
public static frmDAnTE GetChildInstance()
{
//if not created yet, Create an instance
if (m_frmDAnTE == null || m_frmDAnTE.IsDisposed)
m_frmDAnTE = new frmDAnTE();
// Return the instance
return m_frmDAnTE;
}
private DataGridViewSelectedRowCollection GetSelectedRows(DataGridView currGrid)
{
var selectedRows = currGrid.SelectedRows;
if (selectedRows.Count < 1)
{
var rowIndicesAdded = new SortedSet<int>();
// Make a list of the rows with selected cells
foreach (DataGridViewCell selectedCell in currGrid.SelectedCells)
{
if (rowIndicesAdded.Contains(selectedCell.RowIndex))
continue;
rowIndicesAdded.Add(selectedCell.RowIndex);
}
// Auto select the rows
foreach (var rowIndex in rowIndicesAdded)
{
currGrid.Rows[rowIndex].Selected = true;
}
selectedRows = currGrid.SelectedRows;
}
return selectedRows;
}
private bool ValidateExpressionsLoaded(string currentTask)
{
if (!mhtDatasets.ContainsKey("Expressions"))
{
MessageBox.Show("'Expressions' table not found; cannot " + currentTask, "Error");
return false;
}
return true;
}
private bool ValidateFactorsDefined(string currentTask)
{
if (!mhtDatasets.ContainsKey("Factors"))
{
MessageBox.Show(
"Factors must be defined in order to " + currentTask + ". See Define Factors in the Grouping menu.",
"Factors not defined");
return false;
}
return true;
}
private bool ValidateIsPlotTable(clsDatasetTreeNode mclsSelected, int minimumColCount = 1)
{
if (!mclsSelected.mblIsPlottable)
{
MessageBox.Show(
"Table '" + mclsSelected.mstrDataText +
"' does not contain data that can be plotted. Please select a different table from the list",
"Invalid table");
return false;
}
if (minimumColCount > 1 && mclsSelected.mDTable.Columns.Count < minimumColCount)
{
MessageBox.Show(
"Table '" + mclsSelected.mstrDataText + "' cannot be plotted; it must have at least " +
minimumColCount + " columns of data", "Not enough columns");
return false;
}
return true;
}
private bool ValidateNodeIsSelected(clsDatasetTreeNode selectedNode)
{
if (selectedNode == null)
{
MessageBox.Show("Data not loaded (or data table not selected)", "Nothing to do", MessageBoxButtons.OK,
MessageBoxIcon.Information);
return false;
}
return true;
}
private bool ValidateDataMatrixTableSelected(clsDatasetTreeNode mclsSelected, bool checkColumnCount = false)
{
if (mclsSelected == null)
{
MessageBox.Show("Please select a numeric data table from the list", "Invalid table");
return false;
}
if (mclsSelected.mDTable == null)
{
MessageBox.Show("Please select a numeric data table from the list", "Invalid table");
return false;
}
if (!mclsSelected.mblIsNumeric)
{
MessageBox.Show(
"Table '" + mclsSelected.mstrDataText +
"' does not contain a matrix of numeric data. Please select a different table from the list",
"Invalid table");
return false;
}
if (checkColumnCount)
{
var numCols = mclsSelected.mDTable.Columns.Count - 1;
if (numCols <= 0)
{
MessageBox.Show("Table '" + mclsSelected.mstrDataText + "' must have at least 2 columns of data",
"Invalid table");
return false;
}
}
return true;
}
#endregion
#region Event handlers --------------
private void OnLoad_event(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(mSessionFile))
{
return;
}
mAutoLoadSessionFile = true;
mAutoLoadScheduledTime = DateTime.UtcNow.AddMilliseconds(250);
}
private void OnClosed_event(object sender, EventArgs e)
{
ToolStripManager.RevertMerge("mtoolStripMDI");
}
/// <summary>
/// What to do when an item from the treeview control is selected
/// </summary>
private void ctlTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Button == MouseButtons.Right)
ctlTreeView.SelectedNode = ctlTreeView.GetNodeAt(e.X, e.Y);
NodeSelect(e.Node);
}
private void ctlTreeView_AfterSelect(object sender, TreeViewEventArgs e)
{
NodeSelect(e.Node);
}
private void Form_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.All;
else
e.Effect = DragDropEffects.None;
}
/// <summary>
/// User dropped a file into a empty window
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form_DragDrop(object sender, DragEventArgs e)
{
var s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
if (s.Length > 1)
MessageBox.Show("Only one file at a time!", "One file please...",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
else
{
var fExt = Path.GetExtension(s[0]);
var fileTypeError = string.IsNullOrEmpty(fExt);
if (!fileTypeError)
{
if (fExt.Equals(".dnt", StringComparison.CurrentCultureIgnoreCase))
{
OpenSessionCheckExisting(s[0], USE_THREADED_LOAD);
}
else if (fExt.Equals(".csv", StringComparison.CurrentCultureIgnoreCase))
{
mDataSetType = enmDataType.ESET;
OpenExpressionFile(s[0]);
}
else
{
fileTypeError = true;
}
}
if (fileTypeError)
{
MessageBox.Show("Only .dnt or .csv files can be opened via drag/drop here", "Unsupported file type",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
Help.ShowHelp(this, mhelpProviderDAnTE.HelpNamespace);
}
#endregion
#region Properties
public clsRconnect RConnector
{
set => mRConnector = value;
}
public string RTempFilePath
{
set => mRTempFilePath = value;
}
public frmDAnTEmdi ParentInstance
{
set => m_frmDAnTEmdi = value;
}
public ToolStrip ToolStripDAnTE => mtoolStripDAnTE;
public string Title
{
get => Text;
set => Text = value;
}
public string SessionFile
{
set => mSessionFile = value;
}
#endregion
#region Event Handlers
void mAutoLoadTimer_Tick(object sender, EventArgs e)
{
if (!mAutoLoadSessionFile || DateTime.UtcNow <= mAutoLoadScheduledTime)
{
return;
}
mAutoLoadSessionFile = false;
mAutoLoadTimer.Enabled = false;
SessionFileOpenNonThreaded(mSessionFile);
}
private void frmDAnTE_Activated(object sender, EventArgs e)
{
if (IsMdiChild)
{
mnuStripDAnTE.Visible = false;
mtoolStripDAnTE.Visible = false;
var mp = (frmDAnTEmdi)Application.OpenForms["frmDAnTEmdi"];
if (mp != null)
{
ToolStripManager.RevertMerge(mp.mToolStripMDI); //toolstrip reference to parent toolstrip
ToolStripManager.Merge(mtoolStripDAnTE, mp.mToolStripMDI);
}
}
}
#endregion
}
}