private void zscoreSinglePlateToolStripMenuItem_Click(object sender, EventArgs e) { List<double> Pos = new List<double>(); List<double> Neg = new List<double>(); List<cSimpleSignature> ZFactorList = new List<cSimpleSignature>(); int NumDesc = CompleteScreening.ListDescriptors.Count; cWell TempWell; // loop on all the desciptors for (int Desc = 0; Desc < NumDesc; Desc++) { Pos.Clear(); 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 = CompleteScreening.GetCurrentDisplayPlate().GetWell(col, row, true); if (TempWell == null) continue; else { if (TempWell.GetClass() == 0) Pos.Add(TempWell.ListDescriptors[Desc].GetValue()); if (TempWell.GetClass() == 1) Neg.Add(TempWell.ListDescriptors[Desc].GetValue()); } } if (Pos.Count < 3) { MessageBox.Show("No or not enough positive controls !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (Neg.Count < 3) { MessageBox.Show("No or not enough negative controls !", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } double ZScore = 1 - 3 * (std(Pos.ToArray()) + std(Neg.ToArray())) / (Math.Abs(Mean(Pos.ToArray()) - Mean(Neg.ToArray()))); GlobalInfo.ConsoleWriteLine(CompleteScreening.ListDescriptors[Desc].GetName() + ", Z-Score = " + ZScore); cSimpleSignature TmpDesc = new cSimpleSignature(CompleteScreening.ListDescriptors[Desc].GetName(), ZScore); ZFactorList.Add(TmpDesc); } ZFactorList.Sort(delegate(cSimpleSignature p1, cSimpleSignature p2) { return p1.AverageValue.CompareTo(p2.AverageValue); }); 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 < ZFactorList.Count; IdxValue++) { if (double.IsNaN(ZFactorList[IdxValue].AverageValue)) continue; if (double.IsInfinity(ZFactorList[IdxValue].AverageValue)) continue; CurrentSeries.Points.Add(ZFactorList[IdxValue].AverageValue); CurrentSeries.Points[RealIdx].Label = string.Format("{0:0.###}", ZFactorList[IdxValue].AverageValue); CurrentSeries.Points[RealIdx].Font = new Font("Arial", 10); CurrentSeries.Points[RealIdx].ToolTip = ZFactorList[IdxValue].Name; CurrentSeries.Points[RealIdx].AxisLabel = ZFactorList[IdxValue].Name; SeriesLine.Points.Add(ZFactorList[IdxValue].AverageValue); SeriesLine.Points[RealIdx].BorderColor = Color.Black; SeriesLine.Points[RealIdx].MarkerStyle = MarkerStyle.Circle; SeriesLine.Points[RealIdx].MarkerSize = 4; RealIdx++; } SimpleForm NewWindow = new SimpleForm(CompleteScreening); 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 = "Z-factors"; 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.GetCurrentDisplayPlate().Name + " Z-factors"); CurrentTitle.Font = new System.Drawing.Font("Arial", 11, FontStyle.Bold); NewWindow.chartForSimpleForm.Titles.Add(CurrentTitle); NewWindow.Show(); NewWindow.chartForSimpleForm.Update(); NewWindow.chartForSimpleForm.Show(); NewWindow.Controls.AddRange(new System.Windows.Forms.Control[] { NewWindow.chartForSimpleForm }); }
private SimpleForm BuildSSMD(int Desc) { List<double> Pos = new List<double>(); List<double> Neg = new List<double>(); List<cSimpleSignature> ZFactorList = 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); Pos.Clear(); Neg.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() == 0) Pos.Add(TempWell.ListDescriptors[Desc].GetValue()); if (TempWell.GetClass() == 1) Neg.Add(TempWell.ListDescriptors[Desc].GetValue()); } } double SSMDScore = (Mean(Pos.ToArray()) - Mean(Neg.ToArray())) / Math.Sqrt(std(Pos.ToArray()) * std(Pos.ToArray()) + std(Neg.ToArray()) * std(Neg.ToArray())); GlobalInfo.ConsoleWriteLine(CurrentPlateToProcess.Name + ", SSMD = " + SSMDScore); //cDescriptor TmpDesc = new cDescriptor(SSMDScore, CurrentPlateToProcess.Name); cSimpleSignature TmpDesc = new cSimpleSignature(CurrentPlateToProcess.Name, SSMDScore); ZFactorList.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 < ZFactorList.Count; IdxValue++) { if (ZFactorList[IdxValue].AverageValue.ToString() == "NaN") continue; CurrentSeries.Points.Add(ZFactorList[IdxValue].AverageValue); CurrentSeries.Points[RealIdx].Label = string.Format("{0:0.###}", ZFactorList[IdxValue].AverageValue); CurrentSeries.Points[RealIdx].Font = new Font("Arial", 10); CurrentSeries.Points[RealIdx].ToolTip = ZFactorList[IdxValue].Name; CurrentSeries.Points[RealIdx].AxisLabel = ZFactorList[IdxValue].Name; SeriesLine.Points.Add(ZFactorList[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 = "SSMD"; 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() + " SSMD"); CurrentTitle.Font = new System.Drawing.Font("Arial", 11, FontStyle.Bold); NewWindow.chartForSimpleForm.Titles.Add(CurrentTitle); return NewWindow; }
private void buttonRejectPlates_Click(object sender, EventArgs e) { if (CompleteScreening == null) return; List<double> Pos = new List<double>(); List<double> Neg = new List<double>(); List<cSimpleSignature> ZFactorList = new List<cSimpleSignature>(); cWell TempWell; int Desc = this.comboBoxDescriptorToDisplay.SelectedIndex; 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); Pos.Clear(); Neg.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() == comboBoxRejectionPositiveCtrl.SelectedIndex) Pos.Add(TempWell.ListDescriptors[Desc].GetValue()); if (TempWell.GetClass() == comboBoxRejectionNegativeCtrl.SelectedIndex) Neg.Add(TempWell.ListDescriptors[Desc].GetValue()); } } if (Pos.Count < 3) { richTextBoxInformationRejection.AppendText("\nPlate: " + CurrentPlateToProcess.Name + ". No or not enough positive controls !"); continue; } if (Neg.Count < 3) { richTextBoxInformationRejection.AppendText("\nPlate: " + CurrentPlateToProcess.Name + ". No or not enough negative controls !"); continue; } double ZScore = 1 - 3 * (std(Pos.ToArray()) + std(Neg.ToArray())) / (Math.Abs(Mean(Pos.ToArray()) - Mean(Neg.ToArray()))); if (double.IsNaN(ZScore)) { richTextBoxInformationRejection.AppendText("\nFailed to estimate Z' factor on plate " + CurrentPlateToProcess.Name + " => rejected"); } cSimpleSignature TmpDesc = new cSimpleSignature(CurrentPlateToProcess.Name, ZScore); ZFactorList.Add(TmpDesc); } int NumDesc = CompleteScreening.ListDescriptors.Count; int PlateRejected = 0; richTextBoxInformationRejection.Clear(); richTextBoxInformationRejection.AppendText("\nDescriptor: "+CompleteScreening.ListDescriptors[Desc].GetName()+"\n"); foreach (cSimpleSignature TmpZFactor in ZFactorList) { if (TmpZFactor.AverageValue <= (float)numericUpDownRejectionThreshold.Value) PlateRejected++; } if (PlateRejected == ZFactorList.Count) { MessageBox.Show("By applying such rejection scheme, all the plates would be removed.\n", "Process cancelled !", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } PlateRejected = 0; foreach (cSimpleSignature TmpZFactor in ZFactorList) { richTextBoxInformationRejection.AppendText("\n" + TmpZFactor.Name + ": Z' factor = " + TmpZFactor.AverageValue.ToString("N3")); if (TmpZFactor.AverageValue <= (float)numericUpDownRejectionThreshold.Value) { richTextBoxInformationRejection.AppendText(" <= " + (float)numericUpDownRejectionThreshold.Value + " => rejected!"); CompleteScreening.ListPlatesActive.Remove(CompleteScreening.ListPlatesAvailable.GetPlate(ZFactorList[PlateRejected].Name)); toolStripcomboBoxPlateList.Items.Remove(ZFactorList[PlateRejected].Name); } else { richTextBoxInformationRejection.AppendText(" > " + (float)numericUpDownRejectionThreshold.Value + " => preserved!"); } PlateRejected++; } RefreshInfoScreeningRichBox(); CompleteScreening.CurrentDisplayPlateIdx = 0; if(toolStripcomboBoxPlateList.Items.Count>0) toolStripcomboBoxPlateList.SelectedIndex = 0; CompleteScreening.GetCurrentDisplayPlate().DisplayDistribution(CompleteScreening.ListDescriptors.CurrentSelectedDescriptor, false); }