private void NegativeBasedNormalization() { System.Windows.Forms.DialogResult Res = MessageBox.Show("By applying this process, data will be definitively modified ! Proceed ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (Res == System.Windows.Forms.DialogResult.No) return; richTextBoxInfoForNormalization.Clear(); int NumberOfPlates = CompleteScreening.ListPlatesActive.Count; int NumberOfProcessedPlates = 0; // loop on all the plate for (int PlateIdx = 0; PlateIdx < NumberOfPlates; PlateIdx++) { cPlate CurrentPlateToProcess = CompleteScreening.ListPlatesActive.GetPlate(CompleteScreening.ListPlatesActive[PlateIdx].Name); // GlobalInfo.ConsoleWriteLine("Plate: " + CurrentPlateToProcess.Name); if (CurrentPlateToProcess.GetNumberOfWellOfClass(comboBoxNormalizationNegativeCtrl.SelectedIndex) == 0) { richTextBoxInfoForNormalization.AppendText("\n"+ CurrentPlateToProcess.Name + " does not contain well of the selected class. Plate skipped."); continue; } cExtendedList Neg = new cExtendedList(); int NumDesc = CompleteScreening.ListDescriptors.Count; cWell TempWell; // loop on all the desciptors for (int Desc = 0; Desc < NumDesc; Desc++) { Neg.Clear(); if (CompleteScreening.ListDescriptors[Desc].IsActive() == false) continue; for (int row = 0; row < CompleteScreening.Rows; row++) for (int col = 0; col < CompleteScreening.Columns; col++) { TempWell = CurrentPlateToProcess.GetWell(col, row, true); if (TempWell == null) continue; if (TempWell.GetClass() == comboBoxNormalizationNegativeCtrl.SelectedIndex) Neg.Add(TempWell.ListDescriptors[Desc].GetValue()); } double CurrentMean = Neg.Mean(); GlobalInfo.ConsoleWriteLine(CompleteScreening.ListDescriptors[Desc].GetName() + ", average = " + CurrentMean); if (CurrentMean == 0) { richTextBoxInfoForNormalization.AppendText("\n" + CurrentPlateToProcess.Name + " / " + CompleteScreening.ListDescriptors[Desc].GetName() + " average is null!\n"); richTextBoxInfoForNormalization.AppendText("\nNormalization skipped."); continue; } for (int row = 0; row < CompleteScreening.Rows; row++) for (int col = 0; col < CompleteScreening.Columns; col++) { TempWell = CurrentPlateToProcess.GetWell(col, row, true); if (TempWell == null) continue; for (int i = 0; i < TempWell.ListDescriptors[Desc].GetAssociatedType().GetBinNumber(); i++) { double Val = TempWell.ListDescriptors[Desc].Getvalue(i); Val /= CurrentMean; TempWell.ListDescriptors[Desc].SetHistoValues(i,Val*100); } TempWell.ListDescriptors[Desc].UpDateDescriptorStatistics(); } CurrentPlateToProcess.UpDataMinMax(); } richTextBoxInfoForNormalization.AppendText("\n" + CurrentPlateToProcess.Name + " successfully normalized."); NumberOfProcessedPlates++; } richTextBoxInfoForNormalization.AppendText("\n" + NumberOfProcessedPlates + " / " + NumberOfPlates + " successfully normalized."); }
private SimpleForm BuildCV(int Desc, int Class) { cExtendedList ListValue = new cExtendedList(); // List<double> Neg = new List<double>(); List<cSimpleSignature> CVFactorList = new List<cSimpleSignature>(); cWell TempWell; int NumberOfPlates = CompleteScreening.ListPlatesActive.Count; // loop on all the plate for (int PlateIdx = 0; PlateIdx < NumberOfPlates; PlateIdx++) { cPlate CurrentPlateToProcess = CompleteScreening.ListPlatesActive.GetPlate(CompleteScreening.ListPlatesActive[PlateIdx].Name); ListValue.Clear(); for (int row = 0; row < CompleteScreening.Rows; row++) for (int col = 0; col < CompleteScreening.Columns; col++) { TempWell = CurrentPlateToProcess.GetWell(col, row, true); if (TempWell == null) continue; else { if (TempWell.GetClass() == Class) ListValue.Add(TempWell.ListDescriptors[Desc].GetValue()); } } double CVScore = ListValue.Std() / ListValue.Mean(); GlobalInfo.ConsoleWriteLine(CurrentPlateToProcess.Name + ", Coeff. of Variation = " + CVScore); cSimpleSignature TmpDesc = new cSimpleSignature(CurrentPlateToProcess.Name, CVScore); CVFactorList.Add(TmpDesc); } Series CurrentSeries = new Series(); CurrentSeries.ChartType = SeriesChartType.Column; CurrentSeries.ShadowOffset = 1; Series SeriesLine = new Series(); SeriesLine.Name = "SeriesLine"; SeriesLine.ShadowOffset = 1; SeriesLine.ChartType = SeriesChartType.Line; int RealIdx = 0; for (int IdxValue = 0; IdxValue < CVFactorList.Count; IdxValue++) { if (CVFactorList[IdxValue].AverageValue.ToString() == "NaN") continue; CurrentSeries.Points.Add(CVFactorList[IdxValue].AverageValue); CurrentSeries.Points[RealIdx].Label = string.Format("{0:0.###}", CVFactorList[IdxValue].AverageValue); CurrentSeries.Points[RealIdx].Font = new Font("Arial", 10); CurrentSeries.Points[RealIdx].ToolTip = CVFactorList[IdxValue].Name; CurrentSeries.Points[RealIdx].AxisLabel = CVFactorList[IdxValue].Name; CurrentSeries.Points[RealIdx].Color = CompleteScreening.GlobalInfo.GetColor(Class); SeriesLine.Points.Add(CVFactorList[IdxValue].AverageValue); SeriesLine.Points[RealIdx].BorderColor = Color.Black; SeriesLine.Points[RealIdx].MarkerStyle = MarkerStyle.Circle; SeriesLine.Points[RealIdx].MarkerSize = 4; RealIdx++; } SimpleForm NewWindow = new SimpleForm(); int thisWidth = 200 * RealIdx; if (thisWidth > (int)GlobalInfo.OptionsWindow.numericUpDownMaximumWidth.Value) thisWidth = (int)GlobalInfo.OptionsWindow.numericUpDownMaximumWidth.Value; NewWindow.Width = thisWidth; NewWindow.Height = 400; NewWindow.Text = "Coeff. of Variation"; ChartArea CurrentChartArea = new ChartArea(); CurrentChartArea.BorderColor = Color.Black; CurrentChartArea.AxisX.Interval = 1; NewWindow.chartForSimpleForm.Series.Add(CurrentSeries); NewWindow.chartForSimpleForm.Series.Add(SeriesLine); CurrentChartArea.AxisX.IsLabelAutoFit = true; NewWindow.chartForSimpleForm.ChartAreas.Add(CurrentChartArea); // CurrentChartArea.Axes[1].Maximum = 2; CurrentChartArea.Axes[1].IsMarksNextToAxis = true; CurrentChartArea.Axes[0].MajorGrid.Enabled = false; CurrentChartArea.Axes[1].MajorGrid.Enabled = false; NewWindow.chartForSimpleForm.TextAntiAliasingQuality = TextAntiAliasingQuality.High; CurrentChartArea.BackGradientStyle = GradientStyle.TopBottom; CurrentChartArea.BackColor = CompleteScreening.GlobalInfo.OptionsWindow.panel1.BackColor; CurrentChartArea.BackSecondaryColor = Color.White; Title CurrentTitle = new Title(CompleteScreening.ListDescriptors[Desc].GetName() + " Coeff. of Variation"); CurrentTitle.Font = new System.Drawing.Font("Arial", 11, FontStyle.Bold); NewWindow.chartForSimpleForm.Titles.Add(CurrentTitle); return NewWindow; }
/// <summary> /// This function displays the evolution of the average value of a certain descriptor through the plates, for a specified class /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void descriptorEvolutionToolStripMenuItem_Click(object sender, EventArgs e) { if (CompleteScreening == null) return; FormClassification WindowClassification = new FormClassification(CompleteScreening); WindowClassification.label1.Text = "Class"; WindowClassification.Text = CompleteScreening.ListDescriptors[CompleteScreening.ListDescriptors.CurrentSelectedDescriptor].GetName() + " evolution"; WindowClassification.buttonClassification.Text = "Display"; if (WindowClassification.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; int SelectedClass = WindowClassification.comboBoxForNeutralClass.SelectedIndex; cExtendedList ListValuePerWell = new cExtendedList(); List<cDescriptor> List_Averages = new List<cDescriptor>(); cWell TempWell; int Desc = this.comboBoxDescriptorToDisplay.SelectedIndex; int NumberOfPlates = CompleteScreening.ListPlatesActive.Count; Series CurrentSeries = new Series(); CurrentSeries.Name = "Series1"; CurrentSeries.ChartType = SeriesChartType.ErrorBar; CurrentSeries.ShadowOffset = 1; Series SeriesLine = new Series(); SeriesLine.Name = "SeriesLine"; SeriesLine.ShadowOffset = 1; SeriesLine.ChartType = SeriesChartType.Line; int RealPlateIdx = 0; // loop on all the plates for (int PlateIdx = 0; PlateIdx < NumberOfPlates; PlateIdx++) { cPlate CurrentPlateToProcess = CompleteScreening.ListPlatesActive.GetPlate(CompleteScreening.ListPlatesActive[PlateIdx].Name); ListValuePerWell.Clear(); for (int row = 0; row < CompleteScreening.Rows; row++) for (int col = 0; col < CompleteScreening.Columns; col++) { TempWell = CurrentPlateToProcess.GetWell(col, row, true); if (TempWell == null) continue; else { if (TempWell.GetClass() == SelectedClass) { double Val = TempWell.ListDescriptors[Desc].GetValue(); if (double.IsNaN(Val)) continue; ListValuePerWell.Add(Val); } } } if (ListValuePerWell.Count >= 1) { DataPoint CurrentPt = new DataPoint(); CurrentPt.XValue = RealPlateIdx; double[] Values = new double[3]; Values[0] = ListValuePerWell.Mean(); double Std = ListValuePerWell.Std(); if (double.IsInfinity(Std) || (double.IsNaN(Std))) Std = 0; Values[1] = Values[0] - Std; Values[2] = Values[0] + Std; CurrentPt.YValues = Values;//ListValuePerWell.ToArray(); CurrentSeries.Points.Add(CurrentPt); CurrentSeries.Points[RealPlateIdx].AxisLabel = CurrentPlateToProcess.Name; CurrentSeries.Points[RealPlateIdx].Font = new Font("Arial", 8); CurrentSeries.Points[RealPlateIdx].Color = CompleteScreening.GlobalInfo.GetColor(SelectedClass); SeriesLine.Points.AddXY(RealPlateIdx, Values[0]); SeriesLine.Points[RealPlateIdx].ToolTip = "Plate name: " + CurrentPlateToProcess.Name + "\nAverage: " + string.Format("{0:0.###}", Values[0]) + "\nStdev: " + string.Format("{0:0.###}", Std); SeriesLine.Points[RealPlateIdx].Font = new Font("Arial", 8); SeriesLine.Points[RealPlateIdx].BorderColor = Color.Black; SeriesLine.Points[RealPlateIdx].MarkerStyle = MarkerStyle.Circle; SeriesLine.Points[RealPlateIdx].MarkerSize = 8; RealPlateIdx++; } } SimpleForm NewWindow = new SimpleForm(CompleteScreening); int thisWidth = 200 * SeriesLine.Points.Count; if (thisWidth > 1500) thisWidth = 1500; NewWindow.Width = thisWidth; NewWindow.Height = 400; ChartArea CurrentChartArea = new ChartArea(); CurrentChartArea.BorderColor = Color.Black; NewWindow.chartForSimpleForm.ChartAreas.Add(CurrentChartArea); CurrentChartArea.AxisX.Interval = 1; CurrentChartArea.Axes[1].IsMarksNextToAxis = true; CurrentChartArea.Axes[1].Title = CompleteScreening.ListDescriptors[CompleteScreening.ListDescriptors.CurrentSelectedDescriptor].GetName(); CurrentChartArea.Axes[0].MajorGrid.Enabled = false; CurrentChartArea.Axes[1].MajorGrid.Enabled = false; NewWindow.chartForSimpleForm.TextAntiAliasingQuality = TextAntiAliasingQuality.High; CurrentChartArea.BackGradientStyle = GradientStyle.TopBottom; CurrentChartArea.BackColor = CompleteScreening.GlobalInfo.OptionsWindow.panel1.BackColor; CurrentChartArea.BackSecondaryColor = Color.White; CurrentSeries["BoxPlotWhiskerPercentile"] = "false"; CurrentSeries["BoxPlotShowMedian"] = "false"; CurrentSeries["BoxPlotWhiskerPercentile"] = "false"; CurrentSeries["BoxPlotShowAverage"] = "false"; CurrentSeries["BoxPlotPercentile"] = "false"; CurrentChartArea.AxisX.IsLabelAutoFit = true; NewWindow.chartForSimpleForm.Series.Add(CurrentSeries); NewWindow.chartForSimpleForm.Series.Add(SeriesLine); Title CurrentTitle = new Title("Class " + SelectedClass + " " + CurrentChartArea.Axes[1].Title + " evolution"); NewWindow.chartForSimpleForm.Titles.Add(CurrentTitle); NewWindow.chartForSimpleForm.Titles[0].Font = new Font("Arial", 9); NewWindow.Show(); NewWindow.chartForSimpleForm.Update(); NewWindow.chartForSimpleForm.Show(); NewWindow.Controls.AddRange(new System.Windows.Forms.Control[] { NewWindow.chartForSimpleForm }); return; }
private void StandardNormalization() { System.Windows.Forms.DialogResult Res = MessageBox.Show("By applying this process, data will be definitively modified ! Proceed ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (Res == System.Windows.Forms.DialogResult.No) return; richTextBoxInfoForNormalization.Clear(); int NumberOfPlates = cGlobalInfo.CurrentScreening.ListPlatesActive.Count; int NumberOfProcessedPlates = 0; // loop on all the plate for (int PlateIdx = 0; PlateIdx < NumberOfPlates; PlateIdx++) { cPlate CurrentPlateToProcess = cGlobalInfo.CurrentScreening.ListPlatesActive.GetPlate(PlateIdx); if (CurrentPlateToProcess.GetNumberOfWellOfClass(comboBoxNormalizationNegativeCtrl.SelectedIndex) < 2) { richTextBoxInfoForNormalization.AppendText("\n" + CurrentPlateToProcess.GetName() + " does not contain enough well of the selected class. Plate skipped."); continue; } // GlobalInfo.ConsoleWriteLine("Plate: " + CurrentPlateToProcess.Name); cExtendedList Neg = new cExtendedList(); int NumDesc = cGlobalInfo.CurrentScreening.ListDescriptors.Count; cWell TempWell; // loop on all the desciptors for (int Desc = 0; Desc < NumDesc; Desc++) { if (cGlobalInfo.CurrentScreening.ListDescriptors[Desc].IsConnectedToDatabase == true) { cGlobalInfo.ConsoleWriteLine("Cell by cell normalization not implemented yet. " + cGlobalInfo.CurrentScreening.ListDescriptors[Desc].GetName() + " skipped"); continue; } Neg.Clear(); if (cGlobalInfo.CurrentScreening.ListDescriptors[Desc].IsActive() == false) continue; for (int row = 0; row < cGlobalInfo.CurrentScreening.Rows; row++) for (int col = 0; col < cGlobalInfo.CurrentScreening.Columns; col++) { TempWell = CurrentPlateToProcess.GetWell(col, row, true); if (TempWell == null) continue; if (TempWell.GetCurrentClassIdx() == comboBoxNormalizationNegativeCtrl.SelectedIndex) Neg.Add(TempWell.ListSignatures[Desc].GetValue()); } double CurrentMean = Neg.Mean(); double CurrentStd = Neg.Std(); if (CurrentStd == 0.0) { richTextBoxInfoForNormalization.AppendText("\n" + CurrentPlateToProcess.GetName() + " - " + cGlobalInfo.CurrentScreening.ListDescriptors[Desc].GetName() + ", Standard deviation = 0, process cancelled"); goto NEXTPLATE; } cGlobalInfo.ConsoleWriteLine(cGlobalInfo.CurrentScreening.ListDescriptors[Desc].GetName() + ", average = " + CurrentMean); for (int row = 0; row < cGlobalInfo.CurrentScreening.Rows; row++) for (int col = 0; col < cGlobalInfo.CurrentScreening.Columns; col++) { TempWell = CurrentPlateToProcess.GetWell(col, row, true); if (TempWell == null) continue; // for (int i = 0; i < TempWell.ListDescriptors[Desc].GetAssociatedType().GetBinNumber(); i++) { double Value = TempWell.ListSignatures[Desc].GetValue() - CurrentMean; TempWell.ListSignatures[Desc].SetHistoValues(Value / CurrentStd); } TempWell.ListSignatures[Desc].UpDateDescriptorStatistics(); } CurrentPlateToProcess.UpDataMinMax(); } richTextBoxInfoForNormalization.AppendText("\n" + CurrentPlateToProcess.GetName() + " successfully normalized."); NumberOfProcessedPlates++; NEXTPLATE: ; } richTextBoxInfoForNormalization.AppendText("\n" + NumberOfProcessedPlates + " / " + NumberOfPlates + " successfully normalized."); }
private void NegativePositiveBasedNormalization() { System.Windows.Forms.DialogResult Res = MessageBox.Show("By applying this process, data will be definitively modified ! Proceed ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (Res == System.Windows.Forms.DialogResult.No) return; richTextBoxInfoForNormalization.Clear(); int NumberOfPlates = cGlobalInfo.CurrentScreening.ListPlatesActive.Count; int NumberOfProcessedPlates = 0; // loop on all the plate for (int PlateIdx = 0; PlateIdx < NumberOfPlates; PlateIdx++) { cPlate CurrentPlateToProcess = cGlobalInfo.CurrentScreening.ListPlatesActive.GetPlate(cGlobalInfo.CurrentScreening.ListPlatesActive[PlateIdx].GetName()); // GlobalInfo.ConsoleWriteLine("Plate: " + CurrentPlateToProcess.Name); if ((CurrentPlateToProcess.GetNumberOfWellOfClass(comboBoxNormalizationNegativeCtrl.SelectedIndex)==0)||((CurrentPlateToProcess.GetNumberOfWellOfClass(comboBoxNormalizationPositiveCtrl.SelectedIndex)==0))) { richTextBoxInfoForNormalization.AppendText("\n" + CurrentPlateToProcess.GetName() + " does not contain well of the selected classes. Plate skipped."); continue; } cExtendedList Neg = new cExtendedList(); cExtendedList Pos = new cExtendedList(); int NumDesc = cGlobalInfo.CurrentScreening.ListDescriptors.Count; cWell TempWell; // loop on all the desciptors for (int Desc = 0; Desc < NumDesc; Desc++) { Neg.Clear(); if (cGlobalInfo.CurrentScreening.ListDescriptors[Desc].IsActive() == false) continue; if (cGlobalInfo.CurrentScreening.ListDescriptors[Desc].IsConnectedToDatabase == true) { cGlobalInfo.ConsoleWriteLine("Cell by cell normalization not implemented yet. "+ cGlobalInfo.CurrentScreening.ListDescriptors[Desc].GetName() + " skipped"); continue; } for (int row = 0; row < cGlobalInfo.CurrentScreening.Rows; row++) for (int col = 0; col < cGlobalInfo.CurrentScreening.Columns; col++) { TempWell = CurrentPlateToProcess.GetWell(col, row, true); if (TempWell == null) continue; if (TempWell.GetCurrentClassIdx() == comboBoxNormalizationPositiveCtrl.SelectedIndex) Pos.Add(TempWell.ListSignatures[Desc].GetValue()); if (TempWell.GetCurrentClassIdx() == comboBoxNormalizationNegativeCtrl.SelectedIndex) Neg.Add(TempWell.ListSignatures[Desc].GetValue()); } double CurrentMeanNeg = Neg.Mean(); double CurrentMeanPos = Pos.Mean(); if (CurrentMeanNeg == CurrentMeanPos) { cGlobalInfo.ConsoleWriteLine("Negative and positive are similar, no normalization operated on " + cGlobalInfo.CurrentScreening.ListDescriptors[Desc].GetName()); continue; } double Denominator = (Math.Abs(CurrentMeanPos - CurrentMeanNeg)); for (int row = 0; row < cGlobalInfo.CurrentScreening.Rows; row++) for (int col = 0; col < cGlobalInfo.CurrentScreening.Columns; col++) { TempWell = CurrentPlateToProcess.GetWell(col, row, true); if (TempWell == null) continue; //for (int i = 0; i < TempWell.ListDescriptors[Desc].GetAssociatedType().GetBinNumber(); i++) { double CurrValue = TempWell.ListSignatures[Desc].GetValue(); TempWell.ListSignatures[Desc].SetHistoValues((CurrValue - CurrentMeanNeg) / Denominator); //TempWell.ListDescriptors[Desc].Histogram.SetYvalues((CurrValue - CurrentMeanNeg) / Denominator,0); } //TempWell.ListDescriptors[Desc].Histogram. TempWell.ListSignatures[Desc].UpDateDescriptorStatistics(); } CurrentPlateToProcess.UpDataMinMax(); } richTextBoxInfoForNormalization.AppendText("\n" + CurrentPlateToProcess.GetName() + " successfully normalized."); NumberOfProcessedPlates++; } richTextBoxInfoForNormalization.AppendText("\n" + NumberOfProcessedPlates + " / " + NumberOfPlates + " successfully normalized."); }
/// <summary> /// compute the diffusion maps from Iteration = 0 to Iteration = NumIterations /// </summary> /// <param name="NumIterations">Maximum number of iterations</param> private void ComputeDiffusionMaps(int NumIterations) { DiffusionMaps = new List<double[,]>(); DiffusionMapsMeans = new List<double>(); DiffusionMapsStdev = new List<double>(); double[,] CurrentMap = new double[cGlobalInfo.CurrentScreening.Columns + 2, cGlobalInfo.CurrentScreening.Rows + 2]; double[,] NextMap = new double[cGlobalInfo.CurrentScreening.Columns + 2, cGlobalInfo.CurrentScreening.Rows + 2]; Array.Copy(Mask, CurrentMap, Mask.Length); double[,] CurrentMapWithoutBorders0 = new double[cGlobalInfo.CurrentScreening.Columns, cGlobalInfo.CurrentScreening.Rows]; for (int X = 0; X < cGlobalInfo.CurrentScreening.Columns; X++) for (int Y = 0; Y < cGlobalInfo.CurrentScreening.Rows; Y++) CurrentMapWithoutBorders0[X, Y] = CurrentMap[X + 1, Y + 1]; DiffusionMaps.Add(CurrentMapWithoutBorders0); cExtendedList ValueList = new cExtendedList(); for (int it = 0; it < NumIterations; it++) { DiffusionLaplacianFunction(CurrentMap, NextMap, cGlobalInfo.CurrentScreening.Columns + 2, cGlobalInfo.CurrentScreening.Rows + 2); ValueList.Clear(); double[,] CurrentMapWithoutBorders = new double[cGlobalInfo.CurrentScreening.Columns, cGlobalInfo.CurrentScreening.Rows]; for (int X = 0; X < cGlobalInfo.CurrentScreening.Columns; X++) for (int Y = 0; Y < cGlobalInfo.CurrentScreening.Rows; Y++) { CurrentMapWithoutBorders[X, Y] = NextMap[X + 1, Y + 1]; ValueList.Add(CurrentMapWithoutBorders[X, Y]); } DiffusionMaps.Add(CurrentMapWithoutBorders); DiffusionMapsMeans.Add(ValueList.Mean()); DiffusionMapsStdev.Add(ValueList.Std()); Array.Copy(NextMap, CurrentMap, CurrentMap.Length); } return; }