-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWindowHCSAnalyzer.cs
4087 lines (3271 loc) · 183 KB
/
WindowHCSAnalyzer.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
#region Version Header
/************************************************************************
* $Id: Window.cs, 177+1 2010/10/20 08:28:39 HongKee $
* $Description: Plugin Template for IM 3.0 $
* $Author: HongKee $
* $Date: 2010/10/20 08:28:39 $
* $Revision: 177+1 $
/************************************************************************/
#endregion
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms.DataVisualization.Charting;
using LibPlateAnalysis;
using weka.core;
using System.IO;
using HCSAnalyzer.jp.genome.soap;
using HCSAnalyzer.Forms;
using HCSAnalyzer.Controls;
using System.Reflection;
using System.Collections;
using HCSAnalyzer.Classes;
using System.Resources;
using HCSPlugin;
using HCSAnalyzer.Forms.FormsForOptions;
using HCSAnalyzer.Forms.FormsForDRCAnalysis;
//////////////////////////////////////////////////////////////////////////
// If you want to change Menu & Name of plugin
// Go to "Properties->Resources" in Solution Explorer
// Change Menu & Name
//
// You can also use your own Painter & Mouse event handler
//
//////////////////////////////////////////////////////////////////////////
namespace HCSAnalyzer
{
public partial class HCSAnalyzer : Form
{
Boolean bHaveMouse;
static cScreening CompleteScreening;
FormConsole MyConsole;
PlatesListForm PlateListWindow;
cGlobalInfo GlobalInfo;
public HCSAnalyzer()
{
InitializeComponent();
ToolTip toolTip1 = new ToolTip();
// Set up the delays for the ToolTip.
toolTip1.AutoPopDelay = 5000;
toolTip1.InitialDelay = 1000;
toolTip1.ReshowDelay = 500;
toolTip1.ShowAlways = true;
// Set up the ToolTip text for the Button and Checkbox.
toolTip1.SetToolTip(this.radioButtonDimRedUnsupervised, "Unsupervised feature selection.\nThese approaches use all the active wells as data for the dimensionality reduction.");
toolTip1.SetToolTip(this.radioButtonDimRedSupervised, "Supervised feature selection.\nThese approaches have learning porcess based on the well classes except for the neutral class.");
comboBoxMethodForCorrection.SelectedIndex = 0;
comboBoxClusteringMethod.SelectedIndex = 0;
comboBoxCLassificationMethod.SelectedIndex = 0;
comboBoxNeutralClassForClassif.SelectedIndex = 2;
comboBoxReduceDimSingleClass.SelectedIndex = 0;
comboBoxReduceDimMultiClass.SelectedIndex = 0;
comboBoxDimReductionNeutralClass.SelectedIndex = 2;
comboBoxMethodForNormalization.SelectedIndex = 1;
comboBoxNormalizationNegativeCtrl.SelectedIndex = 1;
comboBoxNormalizationPositiveCtrl.SelectedIndex = 0;
comboBoxRejectionNegativeCtrl.SelectedIndex = 1;
comboBoxRejectionPositiveCtrl.SelectedIndex = 0;
comboBoxRejection.SelectedIndex = 0;
buttonReduceDim.Focus();
buttonReduceDim.Select();
}
private void HCSAnalyzer_Load(object sender, EventArgs e)
{
GlobalInfo = new cGlobalInfo(CompleteScreening);
GlobalInfo.OptionsWindow.Visible = false;
GlobalInfo.ComboForSelectedDesc = this.comboBoxDescriptorToDisplay;
GlobalInfo.CheckedListBoxForDescActive = this.checkedListBoxActiveDescriptors;
//new Kitware.VTK.RenderWindowControl novelRender = new RenderWindowControl
GlobalInfo.renderWindowControlForVTK = null;//renderWindowControlForVTK;
MyConsole = new FormConsole();
MyConsole.Visible = false;
PlateListWindow = new PlatesListForm();
GlobalInfo.PlateListWindow = PlateListWindow;
GlobalInfo.panelForPlate = this.panelForPlate;
comboBoxClass.SelectedIndex = 1;
}
#region Math Tools
public double std(double[] input)
{
double var = 0f, mean = Mean(input);
foreach (double f in input) var += (f - mean) * (f - mean);
return Math.Sqrt(var / (double)(input.Length - 1));
}
public double Variance(double[] input)
{
double var = 0f, mean = Mean(input);
foreach (double f in input) var += (f - mean) * (f - mean);
return var / (double)(input.Length - 1);
}
public double Mean(double[] input)
{
double mean = 0f;
foreach (double f in input) mean += f;
return mean / (double)input.Length;
}
private double[] CreateGauss(double p, double p_2, int p_3)
{
double[] Gauss = new double[p_3];
for (int x = 0; x < p_3; x++)
{
Gauss[x] = Math.Exp(-((x - p) * (x - p)) / (2 * p_2 * p_2));
}
return Gauss;
}
private List<double[]> CreateHistogram(double[] data, double Bin)
{
List<double[]> ToReturn = new List<double[]>();
//float max = math.Max(data);
if (data.Length == 0) return ToReturn;
double Max = data[0];
double Min = data[0];
for (int Idx = 1; Idx < data.Length; Idx++)
{
if (data[Idx] > Max) Max = data[Idx];
if (data[Idx] < Min) Min = data[Idx];
}
double step = (Max - Min) / Bin;
int HistoSize = (int)((Max - Min) / step) + 1;
double[] axeX = new double[HistoSize];
for (int i = 0; i < HistoSize; i++)
{
axeX[i] = Min + i * step;
}
ToReturn.Add(axeX);
double[] histogram = new double[HistoSize];
//double RealPos = Min;
int PosHisto;
foreach (double f in data)
{
PosHisto = (int)((f - Min) / step);
if ((PosHisto >= 0) && (PosHisto < HistoSize))
histogram[PosHisto]++;
}
ToReturn.Add(histogram);
return ToReturn;
}
public double[] MeanCenteringStdStandarization(double[] input)
{
double mean = Mean(input);
double Stdev = std(input);
double[] OutPut = new double[input.Length];
for (int i = 0; i < input.Length; i++)
OutPut[i] = input[i] - mean;
for (int i = 0; i < input.Length; i++)
OutPut[i] = OutPut[i] / Stdev;
return OutPut;
}
public double Anderson_Darling(double[] tab)
{
double A = 0;
double Mean1 = Mean(tab);
double STD = std(tab);
double[] norm = new double[tab.Length];
for (int i = 0; i < tab.Length; i++)
norm[i] = (tab[i] - Mean1) / STD;
return A = Asquare(norm);
}
public double Asquare(double[] data)
{
double A = 0;
double Mean1 = Mean(data);
double varianceb = Math.Sqrt(2 * Variance(data));
double err = 0;
int cpt = 0;
for (int i = 0; i < data.Length; i++)
{
cpt++;
err += ((2 * cpt - 1) * (Math.Log(CDF(data[i], Mean1, varianceb)) + Math.Log(1 - CDF(data[data.Length - 1 - i], Mean1, varianceb))));
}
A = -data.Length - err / data.Length;
return A;
}
public double CDF(double Y, double mu, double varb)
{
double Res = 0;
Res = 0.5 * (1 + alglib.errorfunction((Y - mu) / (varb)));
return Res;
}
#endregion
#region User Interface Functions
private void tabControlMain_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
e.Effect = DragDropEffects.Move;
else
e.Effect = DragDropEffects.None;
}
private void tabControlMain_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
if (files[0].Remove(0, files[0].Length - 4) == ".csv")
{
LoadCSVAssay(files, false);
UpdateUIAfterLoading();
}
}
return;
}
#region Descriptor List UI management
private void checkedListBoxActiveDescriptors_MouseDown(object sender, MouseEventArgs e)
{
if ((e.Button != System.Windows.Forms.MouseButtons.Right) || (CompleteScreening == null)) return;
ContextMenuStrip contextMenuStripActorPicker = new ContextMenuStrip();
ToolStripMenuItem UnselectItem = new ToolStripMenuItem("Unselect all");
UnselectItem.Click += new System.EventHandler(this.UnselectItem);
ToolStripMenuItem SelectAllItem = new ToolStripMenuItem("Select all");
SelectAllItem.Click += new System.EventHandler(this.SelectAllItem);
ToolStripMenuItem ConcentrationToDescriptorItem = new ToolStripMenuItem("Concentration to descriptor");
ConcentrationToDescriptorItem.Click += new System.EventHandler(this.ConcentrationToDescriptorItem);
ToolStripMenuItem ColumnToDescriptorItem = new ToolStripMenuItem("Column to descriptor");
ColumnToDescriptorItem.Click += new System.EventHandler(this.ColumnToDescriptorItem);
ToolStripMenuItem RowToDescriptorItem = new ToolStripMenuItem("Row to descriptor");
RowToDescriptorItem.Click += new System.EventHandler(this.RowToDescriptorItem);
ToolStripMenuItem ToolStripConvertMenuItems = new ToolStripMenuItem("Convert");
ToolStripConvertMenuItems.DropDownItems.Add(ConcentrationToDescriptorItem);
ToolStripConvertMenuItems.DropDownItems.Add(ColumnToDescriptorItem);
ToolStripConvertMenuItems.DropDownItems.Add(RowToDescriptorItem);
ToolStripSeparator SepratorStrip = new ToolStripSeparator();
Point locationOnForm = checkedListBoxActiveDescriptors.FindForm().PointToClient(Control.MousePosition);
int VertPos = locationOnForm.Y - 163;
int ItemHeight = checkedListBoxActiveDescriptors.GetItemHeight(0);
int IdxItem = VertPos / ItemHeight;
if ((IdxItem < CompleteScreening.ListDescriptors.Count) && ((IdxItem >= 0)))
{
ToolStripMenuItem ToolStripMenuItems = new ToolStripMenuItem(CompleteScreening.ListDescriptors[IdxItem].GetName());
ToolStripMenuItem InfoDescItem = new ToolStripMenuItem("Info");
IntToTransfer = IdxItem;
InfoDescItem.Click += new System.EventHandler(this.InfoDescItem);
ToolStripMenuItems.DropDownItems.Add(InfoDescItem);
if (CompleteScreening.ListDescriptors.Count >= 2)
{
ToolStripMenuItem RemoveDescItem = new ToolStripMenuItem("Remove");
RemoveDescItem.Click += new System.EventHandler(this.RemoveDescItem);
ToolStripMenuItems.DropDownItems.Add(RemoveDescItem);
}
if (CompleteScreening.ListDescriptors[IntToTransfer].GetBinNumber() > 1)
{
ToolStripMenuItem SplitDescItem = new ToolStripMenuItem("Split");
SplitDescItem.Click += new System.EventHandler(this.SplitDescItem);
ToolStripMenuItems.DropDownItems.Add(SplitDescItem);
}
contextMenuStripActorPicker.Items.AddRange(new ToolStripItem[] { UnselectItem, SelectAllItem, ToolStripConvertMenuItems, ToolStripMenuItems });
}
else
{
contextMenuStripActorPicker.Items.AddRange(new ToolStripItem[] { UnselectItem, SelectAllItem, ToolStripConvertMenuItems });
}
contextMenuStripActorPicker.Show(Control.MousePosition);
}
static int IntToTransfer;
void RemoveDescItem(object sender, EventArgs e)
{
System.Windows.Forms.DialogResult ResWin = MessageBox.Show("By applying this process, the selected descriptor will be definitively removed from this analysis ! Proceed ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (ResWin == System.Windows.Forms.DialogResult.No) return;
CompleteScreening.ListDescriptors.RemoveDesc(CompleteScreening.ListDescriptors[IntToTransfer], CompleteScreening);
//CompleteScreening.UpDatePlateListWithFullAvailablePlate();
for (int idxP = 0; idxP < CompleteScreening.ListPlatesActive.Count; idxP++)
CompleteScreening.ListPlatesActive[idxP].UpDataMinMax();
CompleteScreening.GetCurrentDisplayPlate().DisplayDistribution(CompleteScreening.ListDescriptors.CurrentSelectedDescriptor, false);
}
void InfoDescItem(object sender, EventArgs e)
{
CompleteScreening.ListDescriptors[IntToTransfer].WindowDescriptorInfo.ShowDialog();
CompleteScreening.ListDescriptors.UpDateDisplay();
}
void UnselectItem(object sender, EventArgs e)
{
for (int i = 0; i < checkedListBoxActiveDescriptors.Items.Count; i++)
CompleteScreening.ListDescriptors.SetItemState(i, false);
RefreshInfoScreeningRichBox();
}
void SelectAllItem(object sender, EventArgs e)
{
for (int i = 0; i < checkedListBoxActiveDescriptors.Items.Count; i++)
CompleteScreening.ListDescriptors.SetItemState(i, true);
RefreshInfoScreeningRichBox();
}
private void ConcentrationToDescriptorItem(object sender, EventArgs e)
{
cDescriptorsType ConcentrationType = new cDescriptorsType("Concentration", true, 1);
CompleteScreening.ListDescriptors.AddNew(ConcentrationType);
foreach (cPlate TmpPlate in CompleteScreening.ListPlatesAvailable)
{
foreach (cWell Tmpwell in TmpPlate.ListActiveWells)
{
List<cDescriptor> LDesc = new List<cDescriptor>();
cDescriptor NewDesc = new cDescriptor(Tmpwell.Concentration, ConcentrationType,CompleteScreening);
LDesc.Add(NewDesc);
Tmpwell.AddDescriptors(LDesc);
}
}
CompleteScreening.ListDescriptors.UpDateDisplay();
CompleteScreening.UpDatePlateListWithFullAvailablePlate();
for (int idxP = 0; idxP < CompleteScreening.ListPlatesActive.Count; idxP++)
CompleteScreening.ListPlatesActive[idxP].UpDataMinMax();
StartingUpDateUI();
}
private void ColumnToDescriptorItem(object sender, EventArgs e)
{
cDescriptorsType ColumnType = new cDescriptorsType("Column", true, 1);
CompleteScreening.ListDescriptors.AddNew(ColumnType);
foreach (cPlate TmpPlate in CompleteScreening.ListPlatesAvailable)
{
foreach (cWell Tmpwell in TmpPlate.ListActiveWells)
{
List<cDescriptor> LDesc = new List<cDescriptor>();
cDescriptor NewDesc = new cDescriptor(Tmpwell.GetPosX(), ColumnType, CompleteScreening);
LDesc.Add(NewDesc);
Tmpwell.AddDescriptors(LDesc);
}
}
CompleteScreening.ListDescriptors.UpDateDisplay();
CompleteScreening.UpDatePlateListWithFullAvailablePlate();
for (int idxP = 0; idxP < CompleteScreening.ListPlatesActive.Count; idxP++)
CompleteScreening.ListPlatesActive[idxP].UpDataMinMax();
StartingUpDateUI();
}
private void RowToDescriptorItem(object sender, EventArgs e)
{
cDescriptorsType RowType = new cDescriptorsType("Row", true, 1);
CompleteScreening.ListDescriptors.AddNew(RowType);
foreach (cPlate TmpPlate in CompleteScreening.ListPlatesAvailable)
{
foreach (cWell Tmpwell in TmpPlate.ListActiveWells)
{
List<cDescriptor> LDesc = new List<cDescriptor>();
cDescriptor NewDesc = new cDescriptor(Tmpwell.GetPosY(), RowType, CompleteScreening);
LDesc.Add(NewDesc);
Tmpwell.AddDescriptors(LDesc);
}
}
CompleteScreening.ListDescriptors.UpDateDisplay();
CompleteScreening.UpDatePlateListWithFullAvailablePlate();
for (int idxP = 0; idxP < CompleteScreening.ListPlatesActive.Count; idxP++)
CompleteScreening.ListPlatesActive[idxP].UpDataMinMax();
StartingUpDateUI();
}
private void SplitDescItem(object sender, EventArgs e)
{
int NumBin = CompleteScreening.ListDescriptors[IntToTransfer].GetBinNumber();
// first we update the descriptor
for (int i = 0; i < NumBin; i++)
CompleteScreening.ListDescriptors.AddNew(new cDescriptorsType(CompleteScreening.ListDescriptors[IntToTransfer].GetName() + "_" + i, true, 1));
foreach (cPlate TmpPlate in CompleteScreening.ListPlatesAvailable)
{
foreach (cWell Tmpwell in TmpPlate.ListActiveWells)
{
List<cDescriptor> LDesc = new List<cDescriptor>();
for (int i = 0; i < NumBin; i++)
{
cDescriptor NewDesc = new cDescriptor(Tmpwell.ListDescriptors[IntToTransfer].Getvalue(i), CompleteScreening.ListDescriptors[i + IntToTransfer + 1],CompleteScreening);
LDesc.Add(NewDesc);
}
Tmpwell.AddDescriptors(LDesc);
}
}
CompleteScreening.ListDescriptors.UpDateDisplay();
CompleteScreening.UpDatePlateListWithFullAvailablePlate();
for (int idxP = 0; idxP < CompleteScreening.ListPlatesActive.Count; idxP++)
CompleteScreening.ListPlatesActive[idxP].UpDataMinMax();
StartingUpDateUI();
}
#endregion
private void clearToolStripMenuItem1_Click(object sender, EventArgs e)
{
GlobalInfo.CurrentRichTextBox.Clear();
}
private void buttonClearConsole_Click(object sender, EventArgs e)
{
GlobalInfo.CurrentRichTextBox.Clear();
}
private void distributionToolStripMenuItem_Click(object sender, EventArgs e)
{
DisplayHistogram(false);
}
private void checkBoxApplyToAllPlates_CheckedChanged(object sender, EventArgs e)
{
if (checkBoxApplyToAllPlates.Checked)
this.Cursor = Cursors.Default;
else
this.Cursor = Cursors.Cross;
if (CompleteScreening == null) return;
CompleteScreening.IsSelectionApplyToAllPlates = checkBoxApplyToAllPlates.Checked;
}
private void comboBoxClass_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
if (e.Index > 0)
{
SolidBrush BrushForColor = new SolidBrush(GlobalInfo.GetColor(e.Index - 1));
e.Graphics.FillRectangle(BrushForColor, e.Bounds.X + 1, e.Bounds.Y + 1, 10, 10);
}
e.Graphics.DrawString(comboBoxClass.Items[e.Index].ToString(), comboBoxClass.Font,
System.Drawing.Brushes.Black, new RectangleF(e.Bounds.X + 15, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
e.DrawFocusRectangle();
}
/// <summary>
/// Zoom Out function
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSizeDecrease_Click(object sender, EventArgs e)
{
if (CompleteScreening == null) return;
CompleteScreening.GlobalInfo.ChangeSize(0.8f);
CompleteScreening.GetCurrentDisplayPlate().DisplayDistribution(CompleteScreening.ListDescriptors.CurrentSelectedDescriptor, false);
}
/// <summary>
/// Zoom In function
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSizeIncrease_Click(object sender, EventArgs e)
{
if (CompleteScreening == null) return;
CompleteScreening.GlobalInfo.ChangeSize(1.2f);
CompleteScreening.GetCurrentDisplayPlate().DisplayDistribution(CompleteScreening.ListDescriptors.CurrentSelectedDescriptor, false);
}
/// <summary>
/// Change the slection mode (global or local)
/// </summary>
/// <param name="OnlyOnSelected">True: single plate selection; False: entiere screen selection</param>
private void GlobalSelection(bool OnlyOnSelected)
{
if (CompleteScreening == null) return;
if (CompleteScreening.GetSelectionType() == -2) return;
for (int col = 0; col < CompleteScreening.Columns; col++)
for (int row = 0; row < CompleteScreening.Rows; row++)
{
if (CompleteScreening.IsSelectionApplyToAllPlates)
{
int NumberOfPlates = CompleteScreening.ListPlatesActive.Count;
for (int PlateIdx = 0; PlateIdx < NumberOfPlates; PlateIdx++)
{
cPlate CurrentPlateToProcess = CompleteScreening.ListPlatesActive.GetPlate(PlateIdx);
cWell TmpWell = CurrentPlateToProcess.GetWell(col, row, OnlyOnSelected);
if (TmpWell == null) continue;
if (CompleteScreening.GetSelectionType() == -1)
TmpWell.SetAsNoneSelected();
else
TmpWell.SetClass(CompleteScreening.GetSelectionType());
}
}
else
{
cWell TmpWell = CompleteScreening.GetCurrentDisplayPlate().GetWell(col, row, OnlyOnSelected);
if (TmpWell != null)
{
if (CompleteScreening.GetSelectionType() == -1) TmpWell.SetAsNoneSelected();
else
TmpWell.SetClass(CompleteScreening.GetSelectionType());
}
}
}
CompleteScreening.GetCurrentDisplayPlate().UpdateNumberOfClass();
}
/// <summary>
/// Switch to global selection
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonGlobalOnlySelected_Click(object sender, EventArgs e)
{
GlobalSelection(true);
}
/// <summary>
/// Manage the event related to the active plate selection combo list
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripcomboBoxPlateList_SelectedIndexChanged(object sender, EventArgs e)
{
CompleteScreening.CurrentDisplayPlateIdx = this.toolStripcomboBoxPlateList.SelectedIndex;
if (CompleteScreening.CurrentDisplayPlateIdx == -1) return;
CompleteScreening.GetCurrentDisplayPlate().DisplayDistribution(CompleteScreening.ListDescriptors.CurrentSelectedDescriptor, false);
}
/// <summary>
/// Manage the event related to Class selection control
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void comboBoxClass_SelectedIndexChanged(object sender, EventArgs e)
{
if (CompleteScreening == null) return;
CompleteScreening.SetSelectionType(comboBoxClass.SelectedIndex - 1);
CompleteScreening.GetCurrentDisplayPlate().UpdateNumberOfClass();
}
/// <summary>
/// set all the well of the current plate to "unselected" mode
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
for (int col = 0; col < CompleteScreening.Columns; col++)
for (int row = 0; row < CompleteScreening.Rows; row++)
{
cWell TmpWell = CompleteScreening.ListPlatesActive.GetPlate(CompleteScreening.CurrentDisplayPlateIdx).GetWell(col, row, false);
if (TmpWell != null) TmpWell.SetAsNoneSelected();
}
}
private void checkedListBoxDescriptorActive_SelectedIndexChanged(object sender, EventArgs e)
{
if (CompleteScreening.CurrentDisplayPlateIdx == -1) return;
for (int idxDesc = 0; idxDesc < CompleteScreening.ListDescriptors.Count; idxDesc++)
CompleteScreening.ListDescriptors[idxDesc].SetActiveState(false);
for (int IdxDesc = 0; IdxDesc < checkedListBoxActiveDescriptors.CheckedItems.Count; IdxDesc++)
CompleteScreening.ListDescriptors[checkedListBoxActiveDescriptors.CheckedIndices[IdxDesc]].SetActiveState(true);
RefreshInfoScreeningRichBox();
return;
}
private void comboBoxDescriptorToDisplay_SelectedIndexChanged(object sender, EventArgs e)
{
CompleteScreening.ListDescriptors.CurrentSelectedDescriptor = (int)comboBoxDescriptorToDisplay.SelectedIndex;
if (!checkBoxDisplayClasses.Checked)
CompleteScreening.GetCurrentDisplayPlate().DisplayDistribution(CompleteScreening.ListDescriptors.CurrentSelectedDescriptor, false);
}
private void StartingUpDateUI()
{
MyConsole = new FormConsole();
GlobalInfo.CurrentRichTextBox = this.MyConsole.richTextBoxConsole;
CompleteScreening.ListDescriptors.CurrentSelectedDescriptor = 0;
CompleteScreening.CurrentDisplayPlateIdx = 0;
CompleteScreening.LabelForClass = this.labelNumClasses;
CompleteScreening.LabelForMin = this.labelMin;
CompleteScreening.LabelForMax = this.labelMax;
CompleteScreening.PanelForLUT = this.panelForLUT;
CompleteScreening.PanelForPlate = this.panelForPlate;
// CompleteScreening.ListDescriptors = new cListDescriptors(this.checkedListBoxActiveDescriptors, comboBoxDescriptorToDisplay);
PlateListWindow.listBoxPlateNameToProcess.Items.Clear();
PlateListWindow.listBoxAvaliableListPlates.Items.Clear();
// CompleteScreening.ListBoxSelectedPlates = PlateListWindow.listBoxPlateNameToProcess;
this.toolStripcomboBoxPlateList.Items.Clear();
CompleteScreening.IsSelectionApplyToAllPlates = checkBoxApplyToAllPlates.Checked;
GlobalInfo.CurrentScreen = CompleteScreening;
}
private void panelForLUT_Paint(object sender, PaintEventArgs e)
{
if ((CompleteScreening == null) || (CompleteScreening.ListPlatesAvailable.Count == 0) || (CompleteScreening.ISLoading))
return;
CompleteScreening.GetCurrentDisplayPlate().DisplayLUT(CompleteScreening.ListDescriptors.CurrentSelectedDescriptor);
}
private void dataGridViewForQualityControl_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if ((e.ColumnIndex == -1) || (e.RowIndex == -1)) return;
String PlateName = (string)dataGridViewForQualityControl.Rows[e.RowIndex].Cells[0].Value;
String DescName = (string)dataGridViewForQualityControl.Rows[e.RowIndex].Cells[1].Value;
tabControlMain.SelectedTab = tabPageDistribution;
int PosPlate = this.toolStripcomboBoxPlateList.FindStringExact(PlateName);
this.toolStripcomboBoxPlateList.SelectedIndex = PosPlate;
CompleteScreening.CurrentDisplayPlateIdx = this.toolStripcomboBoxPlateList.SelectedIndex;
int PosDesc = this.comboBoxDescriptorToDisplay.FindStringExact(DescName);
comboBoxDescriptorToDisplay.SelectedIndex = PosDesc;
CompleteScreening.ListDescriptors.CurrentSelectedDescriptor = (int)comboBoxDescriptorToDisplay.SelectedIndex;
CompleteScreening.GetCurrentDisplayPlate().DisplayDistribution(CompleteScreening.ListDescriptors.CurrentSelectedDescriptor, false);
}
private void comboBoxDimReductionNeutralClass_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
SolidBrush BrushForColor = new SolidBrush(GlobalInfo.GetColor(e.Index));
e.Graphics.FillRectangle(BrushForColor, e.Bounds.X + 1, e.Bounds.Y + 1, 10, 10);
e.Graphics.DrawString(comboBoxDimReductionNeutralClass.Items[e.Index].ToString(), comboBoxDimReductionNeutralClass.Font,
System.Drawing.Brushes.Black, new RectangleF(e.Bounds.X + 15, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
e.DrawFocusRectangle();
}
private void comboBoxNeutralClassForClassif_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
SolidBrush BrushForColor = new SolidBrush(GlobalInfo.GetColor(e.Index));
e.Graphics.FillRectangle(BrushForColor, e.Bounds.X + 1, e.Bounds.Y + 1, 10, 10);
e.Graphics.DrawString(comboBoxNeutralClassForClassif.Items[e.Index].ToString(), comboBoxNeutralClassForClassif.Font,
System.Drawing.Brushes.Black, new RectangleF(e.Bounds.X + 15, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
e.DrawFocusRectangle();
}
private void panelForPlate_Paint(object sender, PaintEventArgs e)
{
if ((CompleteScreening == null) || (CompleteScreening.ListPlatesAvailable.Count == 0) || (CompleteScreening.ISLoading))
return;
float SizeFont = GlobalInfo.SizeHistoHeight / 2;
int Gutter = (int)GlobalInfo.OptionsWindow.numericUpDownGutter.Value;
Graphics g = CompleteScreening.PanelForPlate.CreateGraphics();
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
g.Clear(CompleteScreening.PanelForPlate.BackColor);
int ScrollShiftY = panelForPlate.VerticalScroll.Value;
int ScrollShiftX = panelForPlate.HorizontalScroll.Value;
for (int i = 1; i <= CompleteScreening.Columns; i++)
g.DrawString(i.ToString(), new Font("Arial", SizeFont), Brushes.White, new PointF((GlobalInfo.SizeHistoWidth + Gutter) * (i - 1) + (GlobalInfo.SizeHistoWidth + Gutter) / 4
- (i.ToString().Length - 1) * (GlobalInfo.SizeHistoWidth + Gutter) / 8 + GlobalInfo.ShiftX - ScrollShiftX, -ScrollShiftY));
for (int j = 1; j <= CompleteScreening.Rows; j++)
{
if (GlobalInfo.OptionsWindow.radioButtonWellPosModeDouble.Checked)
g.DrawString(j.ToString(), new Font("Arial", SizeFont), Brushes.White, new PointF(-ScrollShiftX, (GlobalInfo.SizeHistoHeight + Gutter) * (j - 1) + GlobalInfo.ShiftY - ScrollShiftY));
else
g.DrawString(GlobalInfo.ConvertIntPosToStringPos(j), new Font("Arial", SizeFont), Brushes.White, new PointF(-ScrollShiftX, (GlobalInfo.SizeHistoHeight + Gutter) * (j - 1) + GlobalInfo.ShiftY - ScrollShiftY));
}
}
private void UpdateUIAfterLoading()
{
if (comboBoxDescriptorToDisplay.Items.Count >= 1)
{
pluginsToolStripMenuItem.Enabled = true;
exportToolStripMenuItem.Enabled = true;
appendDescriptorsToolStripMenuItem.Enabled = true;
linkToolStripMenuItem.Enabled = true;
copyAverageValuesToolStripMenuItem1.Enabled = true;
copyClassesToolStripMenuItem.Enabled = true;
swapClassesToolStripMenuItem.Enabled = true;
applySelectionToScreenToolStripMenuItem.Enabled = true;
visualizationToolStripMenuItem.Enabled = true;
qualityControlsToolStripMenuItem1.Enabled = true;
buttonReduceDim.Enabled = true;
visualizationToolStripMenuItemPCA.Enabled = true;
qualityControlToolStripMenuItem.Enabled = true;
buttonQualityControl.Enabled = true;
buttonCorrectionPlateByPlate.Enabled = true;
buttonRejectPlates.Enabled = true;
buttonNormalize.Enabled = true;
buttonCluster.Enabled = true;
buttonStartClassification.Enabled = true;
buttonExport.Enabled = true;
platesManagerToolStripMenuItem.Enabled = true;
doseResponseManagerToolStripMenuItem.Enabled = true;
toolStripMenuItemGeneAnalysis.Enabled = true;
dRCAnalysisToolStripMenuItem.Enabled = true;
dRCAnalysisToolStripMenuItem1.Enabled = true;
CompleteScreening.ISLoading = false;
comboBoxDescriptorToDisplay.SelectedIndex = 0;
string NamePlate = PlateListWindow.listBoxAvaliableListPlates.Items[0].ToString();
toolStripcomboBoxPlateList.Text = NamePlate + " ";
}
}
public void RefreshInfoScreeningRichBox()
{
if (tabControlMain.SelectedTab.Name != "tabPageExport") return;
richTextBoxForScreeningInformation.Clear();
if (CompleteScreening == null) return;
string Tmp = "Plate dimensions: " + CompleteScreening.Columns + " x " + CompleteScreening.Rows + "\n\n\n";
richTextBoxForScreeningInformation.AppendText(Tmp);
Tmp = "Number of plates: " + CompleteScreening.ListPlatesActive.Count + " (/ " + CompleteScreening.ListPlatesAvailable.Count + ")\n\n";
int TotalWells = 0;
for (int PlateIdx = 1; PlateIdx <= CompleteScreening.ListPlatesActive.Count; PlateIdx++)
{
cPlate CurrentPlateToProcess = CompleteScreening.ListPlatesActive.GetPlate(PlateIdx - 1);
Tmp += "Plate " + PlateIdx + " :\t" + CurrentPlateToProcess.Name + "\n";
Tmp += "\t" + CurrentPlateToProcess.GetNumberOfActiveWells() + " active wells / " + CurrentPlateToProcess.GetNumberOfClasses() + " classes.\n";
TotalWells += CurrentPlateToProcess.GetNumberOfActiveWells();
}
richTextBoxForScreeningInformation.AppendText(Tmp + "\n");
Tmp = "Number of active wells: " + TotalWells;
richTextBoxForScreeningInformation.AppendText(Tmp + "\n\n");
Tmp = "Number of active descriptors: " + CompleteScreening.GetNumberOfActiveDescriptor() + " (/ " + CompleteScreening.ListDescriptors.Count + ")\n\n";
for (int Desc = 1; Desc <= CompleteScreening.ListDescriptors.Count; Desc++)
{
if (CompleteScreening.ListDescriptors[Desc - 1].IsActive() == false) continue;
Tmp += "Descriptor " + Desc + " :\t" + CompleteScreening.ListDescriptors[Desc - 1].GetName() + "\n";
}
richTextBoxForScreeningInformation.AppendText(Tmp + "\n");
}
private void tabControlMain_SelectedIndexChanged(object sender, EventArgs e)
{
RefreshInfoScreeningRichBox();
}
private void checkBoxDisplayClasses_CheckedChanged(object sender, EventArgs e)
{
if (CompleteScreening == null) return;
CompleteScreening.GlobalInfo.IsDisplayClassOnly = checkBoxDisplayClasses.Checked;
CompleteScreening.GetCurrentDisplayPlate().DisplayDistribution(CompleteScreening.ListDescriptors.CurrentSelectedDescriptor, false);
}
// Convert and normalize the points and draw the reversible frame.
private void MyDrawReversibleRectangle(Point p1, Point p2)
{
Rectangle rc = new Rectangle();
// Convert the points to screen coordinates.
p1 = PointToScreen(p1);
//p1.X += tabControlMain.Location.X;
//p1.Y += tabControlMain.Location.Y;
p2 = PointToScreen(p2);
//p2.X += tabControlMain.Location.X;
//p2.Y += tabControlMain.Location.Y;
// Normalize the rectangle.
if (p1.X < p2.X)
{
rc.X = p1.X;
rc.Width = p2.X - p1.X;
}
else
{
rc.X = p2.X;
rc.Width = p1.X - p2.X;
}
if (p1.Y < p2.Y)
{
rc.Y = p1.Y;
rc.Height = p2.Y - p1.Y;
}
else
{
rc.Y = p2.Y;
rc.Height = p1.Y - p2.Y;
}
// Draw the reversible frame.
ControlPaint.DrawReversibleFrame(rc, Color.Red, FrameStyle.Dashed);
}
private void panelForPlate_MouseWheel(object sender, MouseEventArgs e)
{
// Update the drawing based upon the mouse wheel scrolling.
if (CompleteScreening == null) return;
int numberOfTextLinesToMove = e.Delta * SystemInformation.MouseWheelScrollLines / 120;
if (numberOfTextLinesToMove > 0)
CompleteScreening.GlobalInfo.ChangeSize(numberOfTextLinesToMove);
else
CompleteScreening.GlobalInfo.ChangeSize(1.0f / (-1 * numberOfTextLinesToMove));
CompleteScreening.GetCurrentDisplayPlate().DisplayDistribution(CompleteScreening.ListDescriptors.CurrentSelectedDescriptor, false);
}
private void panelForPlate_MouseDown(object sender, MouseEventArgs e)
{
if (CompleteScreening == null) return;
// if (GlobalInfo.WindowForDRCDesign.Visible) return;
// Make a note that we "have the mouse".
bHaveMouse = true;
// Store the "starting point" for this rubber-band rectangle.
CompleteScreening.ptOriginal.X = e.X + panelForPlate.Location.X + 10;
CompleteScreening.ptOriginal.Y = e.Y + panelForPlate.Location.Y + 76;
// Special value lets us know that no previous
// rectangle needs to be erased.
CompleteScreening.ptLast.X = -1;
CompleteScreening.ptLast.Y = -1;
}
private void panelForPlate_MouseMove(object sender, MouseEventArgs e)
{
if (CompleteScreening == null) return;
// if (GlobalInfo.WindowForDRCDesign.Visible) return;
Point ptCurrent = new Point(e.X + panelForPlate.Location.X + 10, e.Y + panelForPlate.Location.Y + 76);
// If we "have the mouse", then we draw our lines.
if (bHaveMouse)
{
// If we have drawn previously, draw again in
// that spot to remove the lines.
if (CompleteScreening.ptLast.X != -1)
{
MyDrawReversibleRectangle(CompleteScreening.ptOriginal, CompleteScreening.ptLast);
}
// Update last point.
CompleteScreening.ptLast = ptCurrent;
// Draw new lines.
MyDrawReversibleRectangle(CompleteScreening.ptOriginal, ptCurrent);
}
}
private void panelForPlate_MouseUp(object sender, MouseEventArgs e)
{
if (CompleteScreening == null) return;
// if (GlobalInfo.WindowForDRCDesign.Visible) return;
// Set internal flag to know we no longer "have the mouse".
bHaveMouse = false;
// If we have drawn previously, draw again in that spot
// to remove the lines.
if (CompleteScreening.ptLast.X != -1)
{
Point ptCurrent = new Point(e.X + panelForPlate.Location.X + 10, e.Y + panelForPlate.Location.Y + 76);
MyDrawReversibleRectangle(CompleteScreening.ptOriginal, CompleteScreening.ptLast);
if (!GlobalInfo.WindowForDRCDesign.Visible)
CompleteScreening.GetCurrentDisplayPlate().UpDateWellsSelection();
else
{
int PosMouseXMax = CompleteScreening.ptLast.X;
int PosMouseXMin = CompleteScreening.ptOriginal.X;
if (CompleteScreening.ptOriginal.X > PosMouseXMax)
{
PosMouseXMax = CompleteScreening.ptOriginal.X;
PosMouseXMin = CompleteScreening.ptLast.X;
}
int PosMouseYMax = CompleteScreening.ptLast.Y;
int PosMouseYMin = CompleteScreening.ptOriginal.Y;
if (CompleteScreening.ptOriginal.Y > PosMouseYMax)
{
PosMouseYMax = CompleteScreening.ptOriginal.Y;
PosMouseYMin = CompleteScreening.ptLast.Y;
}
//List<cWell> ListWellSelected = new List<cWell>();
GlobalInfo.WindowForDRCDesign.ListWells = new List<cWell>();
for (int j = 0; j < CompleteScreening.Rows; j++)
for (int i = 0; i < CompleteScreening.Columns; i++)
{
cWell TempWell = CompleteScreening.GetCurrentDisplayPlate().GetWell(i, j, false);
if (TempWell == null) continue;
int PWellX = (int)((TempWell.GetPosX() + 1) * (CompleteScreening.GlobalInfo.SizeHistoWidth + (int)GlobalInfo.OptionsWindow.numericUpDownGutter.Value));// - 2*ParentScreening.GlobalInfo.ShiftX);
int PWellY = (int)((TempWell.GetPosY() + 1) * (CompleteScreening.GlobalInfo.SizeHistoHeight + (int)GlobalInfo.OptionsWindow.numericUpDownGutter.Value) + +(int)((int)GlobalInfo.OptionsWindow.numericUpDownGutter.Value * 2.5) + 60);// (int)ParentScreening.GlobalInfo.OptionsWindow.numericUpDownShiftY.Value);
if ((PWellX > PosMouseXMin) && (PWellX < PosMouseXMax) && (PWellY > PosMouseYMin) && (PWellY < PosMouseYMax))
{
GlobalInfo.WindowForDRCDesign.ListWells.Add(TempWell);
}
}