// protected Size SizeHisto = new System.Drawing.Size(10, 5); public cWell(cWell NewWell) { this.PosX = NewWell.PosX; this.PosY = NewWell.PosY; this.ListDescriptors = NewWell.ListDescriptors; this.Parent = NewWell.Parent; this.AssociatedChart = NewWell.AssociatedChart; this.AssociatedPlate = NewWell.AssociatedPlate; this.CurrentColor = this.Parent.GlobalInfo.GetColor(ClassForClassif); }
public void DrawSignature() { if (ListWells == null) return; g = this.panelForDesignDisplay.CreateGraphics(); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; g.Clear(Color.White); int SizeWell = 8; CurrBrush = new SolidBrush(Color.Fuchsia); PosXMin = int.MaxValue; PosYMin = int.MaxValue; PosXMax = int.MinValue; PosYMax = int.MinValue; foreach (cWell TmpWell in ListWells) { if (TmpWell == null) continue; AssociatedPlate = TmpWell.AssociatedPlate; if (TmpWell.GetPosX() > PosXMax) PosXMax = TmpWell.GetPosX(); if (TmpWell.GetPosY() > PosYMax) PosYMax = TmpWell.GetPosY(); if (TmpWell.GetPosX() < PosXMin) PosXMin = TmpWell.GetPosX(); if (TmpWell.GetPosY() < PosYMin) PosYMin = TmpWell.GetPosY(); } if (AssociatedPlate == null) return; int SizeX = PosXMax - PosXMin + 1; int SizeY = PosYMax - PosYMin + 1; if (this.radioButtonOrientationLine.Checked) { this.numericUpDownConcentrationNumber.Value = (decimal)SizeX; this.numericUpDownReplication.Value = (decimal)SizeY; if (PosXMin > PosXMax) return; TemplateRegion = new cDRC_Region(AssociatedPlate, (int)this.numericUpDownConcentrationNumber.Value, (int)this.numericUpDownReplication.Value, PosXMin, PosYMin, true); } else { this.numericUpDownConcentrationNumber.Value = (decimal)SizeY; this.numericUpDownReplication.Value = (decimal)SizeX; if (PosXMin > PosXMax) return; TemplateRegion = new cDRC_Region(AssociatedPlate, (int)this.numericUpDownConcentrationNumber.Value, (int)this.numericUpDownReplication.Value, PosXMin, PosYMin, false); } DrawSingleRegion(0, 0, 0); for (int j = 1; j <= AssociatedPlate.ParentScreening.Columns + 1; j++) g.DrawLine(new Pen(Color.Black), new Point(j * SizeWell, SizeWell), new Point(j * SizeWell, (AssociatedPlate.ParentScreening.Rows + 1) * SizeWell)); for (int i = 1; i <= AssociatedPlate.ParentScreening.Rows + 1; i++) g.DrawLine(new Pen(Color.Black), new Point(SizeWell, i * SizeWell), new Point((AssociatedPlate.ParentScreening.Columns + 1) * SizeWell, i * SizeWell)); }
public cDBConnection(cPlate Plate, string SQLFileDBName) { AssociatedPlate = Plate; if (Plate.DBConnection == null) this.SQLFileDBName = SQLFileDBName; else this.SQLFileDBName = Plate.DBConnection.SQLFileDBName; if (this.OpenConnection() == false) this.IsSucceed = false; }
public cWell(List<cDescriptor> ListDesc, int Col, int Row, cScreening screenParent, cPlate CurrentPlate) { this.Parent = screenParent; this.AssociatedPlate = CurrentPlate; this.ListDescriptors = new List<cDescriptor>(); this.ListDescriptors = ListDesc; this.PosX = Col; this.PosY = Row; this.CurrentColor = this.Parent.GlobalInfo.GetColor(ClassForClassif); }
//public cWell(cWell NewWell) //{ // this.PosX = NewWell.PosX; // this.PosY = NewWell.PosY; // this.ListDescriptors = NewWell.ListDescriptors; // this.Parent = NewWell.Parent; // this.AssociatedChart = NewWell.AssociatedChart; // this.AssociatedPlate = NewWell.AssociatedPlate; // this.CurrentColor = this.Parent.GlobalInfo.GetColor(ClassForClassif); //} public cWell(cDescriptor Desc, int Col, int Row, cScreening screenParent, cPlate CurrentPlate) { this.CellNumber = -1; this.Parent = screenParent; this.AssociatedPlate = CurrentPlate; this.ListDescriptors = new List<cDescriptor>(); List<cDescriptor> TmpListDescriptors = new List<cDescriptor>(); TmpListDescriptors.Add(Desc); this.AddDescriptors(TmpListDescriptors); this.PosX = Col; this.PosY = Row; this.CurrentColor = this.Parent.GlobalInfo.GetColor(ClassForClassif); }
public cWell(cSignature Desc, int Col, int Row, cScreening screenParent, cPlate CurrentPlate) { //Parent = screenParent; this.AssociatedPlate = CurrentPlate; this.ListSignatures = new cListSignature(); this.ListSignatures.Add(Desc); this.PosX = Col; this.PosY = Row; // this.CurrentColor = this.cGlobalInfo.ListClasses[ClassForClassif].ColourForDisplay; Desc.AssociatedWell = this; // this.ListClass.Add(this.InitialClass); this.ListProperties = new cListWellProperty(this); this.ListProperties.UpdateValueByName("Well Class", 2); }
private void hitsDistributionMapToolStripMenuItem_Click(object sender, EventArgs e) { if (cGlobalInfo.CurrentScreening == null) return; List<cPanelForDisplayArray> ListPlates = new List<cPanelForDisplayArray>(); foreach (cPlate CurrentPlate in cGlobalInfo.CurrentScreening.ListPlatesActive) { ListPlates.Add(new FormToDisplayPlate(CurrentPlate)); } cWindowToDisplayEntireScreening WindowToDisplayArray = new cWindowToDisplayEntireScreening(ListPlates, cGlobalInfo.CurrentScreening.ListDescriptors[cGlobalInfo.CurrentScreening.ListDescriptors.CurrentSelectedDescriptorIdx].GetName(), 6); WindowToDisplayArray.checkBoxDisplayClasses.Checked = true; WindowToDisplayArray.Text = "Generate Hits Distribution Maps"; WindowToDisplayArray.Show(); System.Windows.Forms.DialogResult ResWin = MessageBox.Show("By applying this process, the current screening will be entirely updated ! Proceed ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (ResWin == System.Windows.Forms.DialogResult.No) { WindowToDisplayArray.Close(); return; } WindowToDisplayArray.Close(); if (cGlobalInfo.CurrentScreening != null) cGlobalInfo.CurrentScreening.Close3DView(); // CompleteScreening.ListDescriptors.RemoveDesc(CompleteScreening.ListDescriptors[IntToTransfer], CompleteScreening); cScreening MergedScreening = new cScreening("Class Screen"); MergedScreening.PanelForPlate = this.panelForPlate; MergedScreening.Rows = cGlobalInfo.CurrentScreening.Rows; MergedScreening.Columns = cGlobalInfo.CurrentScreening.Columns; MergedScreening.ListPlatesAvailable = new cListPlates(); // create the descriptor MergedScreening.ListDescriptors.Clean(); List<cDescriptorType> ListDescType = new List<cDescriptorType>(); List<int[][]> Values = new List<int[][]>(); for (int i = 0; i < cGlobalInfo.ListWellClasses.Count; i++) { cDescriptorType DescClass = new cDescriptorType("Class_" + i, true, 1); ListDescType.Add(DescClass); MergedScreening.ListDescriptors.AddNew(DescClass); int[][] TMpVal = new int[MergedScreening.Columns][]; for (int ii = 0; ii < MergedScreening.Columns; ii++) TMpVal[ii] = new int[MergedScreening.Rows]; Values.Add(TMpVal); } MergedScreening.ListDescriptors.CurrentSelectedDescriptorIdx = 0; foreach (cPlate CurrentPlate in cGlobalInfo.CurrentScreening.ListPlatesActive) { foreach (cWell TmpWell in CurrentPlate.ListActiveWells) { int Class = TmpWell.GetCurrentClassIdx(); if (Class >= 0) Values[Class][TmpWell.GetPosX() - 1][TmpWell.GetPosY() - 1]++; } } cPlate NewPlate = new cPlate(cGlobalInfo.CurrentScreening.GetName(), MergedScreening); for (int X = 0; X < cGlobalInfo.CurrentScreening.Columns; X++) for (int Y = 0; Y < cGlobalInfo.CurrentScreening.Rows; Y++) { cListSignature LDesc = new cListSignature(); for (int i = 0; i < cGlobalInfo.ListWellClasses.Count; i++) { cSignature Desc = new cSignature(Values[i][X][Y], ListDescType[i], cGlobalInfo.CurrentScreening); LDesc.Add(Desc); } cWell NewWell = new cWell(LDesc, X + 1, Y + 1, MergedScreening, NewPlate); // NewWell.SetCpdName("Well [" + (X + 1) + ":" + (Y + 1) + "]"); NewPlate.AddWell(NewWell); } // check if the plate exist already MergedScreening.AddPlate(NewPlate); MergedScreening.ListPlatesActive = new cListPlates(); cGlobalInfo.WindowHCSAnalyzer.toolStripcomboBoxPlateList.Items.Clear(); for (int i = 0; i < MergedScreening.ListPlatesAvailable.Count; i++) { MergedScreening.ListPlatesActive.Add(MergedScreening.ListPlatesAvailable[i]); cGlobalInfo.WindowHCSAnalyzer.toolStripcomboBoxPlateList.Items.Add(NewPlate.GetName()); } cGlobalInfo.CurrentScreening.ListDescriptors = MergedScreening.ListDescriptors; cGlobalInfo.CurrentScreening.ListPlatesAvailable = MergedScreening.ListPlatesAvailable; cGlobalInfo.CurrentScreening.ListPlatesActive = MergedScreening.ListPlatesActive; cGlobalInfo.CurrentScreening.UpDatePlateListWithFullAvailablePlate(); for (int idxP = 0; idxP < cGlobalInfo.CurrentScreening.ListPlatesActive.Count; idxP++) cGlobalInfo.CurrentScreening.ListPlatesActive[idxP].UpDataMinMax(); cGlobalInfo.CurrentScreening.CurrentDisplayPlateIdx = 0; cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate().DisplayDistribution(cGlobalInfo.CurrentScreening.ListDescriptors.GetActiveDescriptor(), true); ListPlates = new List<cPanelForDisplayArray>(); for (int DescIdx = 0; DescIdx < cGlobalInfo.CurrentScreening.ListDescriptors.Count; DescIdx++) { if (cGlobalInfo.CurrentScreening.ListDescriptors[DescIdx].IsActive()) ListPlates.Add(new FormToDisplayDescriptorPlate(cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate(), cGlobalInfo.CurrentScreening, DescIdx)); } cWindowToDisplayEntireDescriptors WindowToDisplayDesc = new cWindowToDisplayEntireDescriptors(ListPlates, cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate().GetName(), cGlobalInfo.ListWellClasses.Count); WindowToDisplayDesc.checkBoxGlobalNormalization.Checked = true; WindowToDisplayDesc.Show(); }
/// <summary> /// K - Mean clustering procedure /// </summary> /// <param name="Classes"></param> /// <param name="PlateToProcess"></param> /// <returns></returns> private bool KMeans(int Classes, cPlate PlateToProcess) { int NumWell = PlateToProcess.GetNumberOfActiveWells(); int Numdesc = CompleteScreening.GetNumberOfActiveDescriptor(); double[,] DataForKMeans = new double[NumWell, Numdesc]; int IdxDesc = 0; for (int desc = 0; desc < CompleteScreening.ListDescriptors.Count; desc++) { if (CompleteScreening.ListDescriptors[desc].IsActive() == false) continue; List<double> CurrentDesc = new List<double>(); double[] NormDesc = null; for (int IdxValue = 0; IdxValue < CompleteScreening.Columns; IdxValue++) for (int IdxValue0 = 0; IdxValue0 < CompleteScreening.Rows; IdxValue0++) { cWell TmpWell = PlateToProcess.GetWell(IdxValue, IdxValue0, true); if (TmpWell != null) CurrentDesc.Add(TmpWell.ListDescriptors[desc].GetValue()); } if (CurrentDesc.Count == 0) continue; NormDesc = MeanCenteringStdStandarization(CurrentDesc.ToArray()); for (int row = 0; row < NumWell; row++) DataForKMeans[row, IdxDesc] = NormDesc[row]; IdxDesc++; } int Info; double[,] CenterPos; int[] ClusterIndx; try { alglib.kmeansgenerate(DataForKMeans, NumWell, Numdesc, Classes, 10, out Info, out CenterPos, out ClusterIndx); int Idx = 0; for (int IdxValue = 0; IdxValue < CompleteScreening.Columns; IdxValue++) for (int IdxValue0 = 0; IdxValue0 < CompleteScreening.Rows; IdxValue0++) { cWell TmpWell = PlateToProcess.GetWell(IdxValue, IdxValue0, true); if (TmpWell != null) { if (ClusterIndx[Idx] == -1) TmpWell.SetAsNoneSelected(); else TmpWell.SetClass(ClusterIndx[Idx]); Idx++; } } } catch { richTextBoxInfoClustering.AppendText("\nPlate: " + PlateToProcess.Name + " skipped: data corrupted (check your descriptor data validity)."); //MessageBox.Show("Check the data validity", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } return true; }
private void buttonGenerate_Click(object sender, EventArgs e) { if (MessageBox.Show("This process will generate a new screening and delete the current one. Are you sure?", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != System.Windows.Forms.DialogResult.OK) return; // Now Let's write the CSV file //string FilePath = "c:\\test.csv"; //System.IO.StreamWriter file = new System.IO.StreamWriter(FilePath); //file.WriteLine("PlateName,WellPosition,ImageNumbers"); //foreach (var itemPlate in MainScreenDico) //{ // foreach (var itemWell in itemPlate.Value) // { // string Line = itemPlate.Key.ToString()+","+itemWell.Key.ToString()+","+itemWell.Value; // file.WriteLine(Line); // } //} //file.Close(); // return; // if (this.CurrentScreening == null) string[] ForNames = this.textBoxImageRoot.Text.Split('\\'); cGlobalInfo.CurrentScreening = new cScreening(ForNames[ForNames.Length - 1]); cGlobalInfo.CurrentScreening.Columns = 24; cGlobalInfo.CurrentScreening.Rows = 16; cGlobalInfo.CurrentScreening.ListDescriptors.Clean(); cGlobalInfo.CurrentScreening.ListDescriptors.AddNew(new cDescriptorType("ImageNumbers", true, 1)); foreach (var itemPlate in MainScreenDico) { cPlate CurrentPlate = cGlobalInfo.CurrentScreening.GetPlateIfNameIsContainIn(itemPlate.Key); if (CurrentPlate == null) { CurrentPlate = new cPlate(itemPlate.Key, cGlobalInfo.CurrentScreening); cGlobalInfo.CurrentScreening.AddPlate(CurrentPlate); } else { this.richTextBoxReport.AppendText("----------- Error ----------\nPlate " + itemPlate.Key + " has already been processed. Plate skipped !\n"); continue; } foreach (var itemWell in itemPlate.Value) { cListSignature LDesc = new cListSignature(); cSignature CurrentDescriptor = new cSignature((double)(int)itemWell.Value, cGlobalInfo.CurrentScreening.ListDescriptors[0/* + ShiftIdx*/], cGlobalInfo.CurrentScreening); LDesc.Add(CurrentDescriptor); int[] Pos = new int[2]; Pos = cGlobalInfo.WindowHCSAnalyzer.ConvertPosition(itemWell.Key.ToString()); cWell CurrentWell = new cWell(LDesc, Pos[0], Pos[1], cGlobalInfo.CurrentScreening, CurrentPlate); CurrentPlate.AddWell(CurrentWell); } } cGlobalInfo.CurrentScreening.UpDatePlateListWithFullAvailablePlate(); foreach (var item in cGlobalInfo.CurrentScreening.ListPlatesActive) item.UpDataMinMax(); cGlobalInfo.WindowHCSAnalyzer.StartingUpDateUI(); cGlobalInfo.WindowHCSAnalyzer.toolStripcomboBoxPlateList.Items.Clear(); for (int IdxPlate = 0; IdxPlate < cGlobalInfo.CurrentScreening.ListPlatesActive.Count; IdxPlate++) { string Name = cGlobalInfo.CurrentScreening.ListPlatesActive.GetPlate(IdxPlate).GetName(); cGlobalInfo.WindowHCSAnalyzer.toolStripcomboBoxPlateList.Items.Add(Name); cGlobalInfo.WindowHCSAnalyzer.PlateListWindow.listBoxPlateNameToProcess.Items.Add(Name); cGlobalInfo.WindowHCSAnalyzer.PlateListWindow.listBoxAvaliableListPlates.Items.Add(Name); cGlobalInfo.CurrentScreening.ListPlatesActive.GetPlate(IdxPlate).UpDataMinMax(); } cGlobalInfo.CurrentScreening.CurrentDisplayPlateIdx = 0; cGlobalInfo.CurrentScreening.SetSelectionType(cGlobalInfo.WindowHCSAnalyzer.comboBoxClass.SelectedIndex - 1); cGlobalInfo.CurrentScreening.ListDescriptors.CurrentSelectedDescriptorIdx = 0; cGlobalInfo.WindowHCSAnalyzer.UpdateUIAfterLoading(); // now Image Analysis // first create a descriptor for each readout cDescriptorType TmpDescType = new cDescriptorType("Total_Intensity_0", true, 1); cGlobalInfo.CurrentScreening.ListDescriptors.AddNew(TmpDescType); //FormForPlateDimensions PlateDim = new FormForPlateDimensions(); //PlateDim.checkBoxAddCellNumber.Visible = true; //PlateDim.checkBoxIsOmitFirstColumn.Visible = true; //PlateDim.labelHisto.Visible = true; //PlateDim.numericUpDownHistoSize.Visible = true; FormForDoubleProgress WindowProgress = new FormForDoubleProgress(); WindowProgress.Show(); WindowProgress.progressBarPlate.Maximum = cGlobalInfo.CurrentScreening.ListPlatesAvailable.Count; WindowProgress.progressBarPlate.Value = 0; WindowProgress.progressBarPlate.Refresh(); int IdxPlateProg = 0; foreach (cPlate TmpPlate in cGlobalInfo.CurrentScreening.ListPlatesAvailable) { WindowProgress.progressBarPlate.Value++; WindowProgress.progressBarPlate.Refresh(); WindowProgress.labelPlateIdx.Text = (IdxPlateProg + 1) + " / " + cGlobalInfo.CurrentScreening.ListPlatesAvailable.Count; WindowProgress.progressBarWell.Value = 0; WindowProgress.progressBarWell.Maximum = TmpPlate.ListWells.Count; #region modif //List<cImageMetaInfo> ListImageMetaInfo = new List<cImageMetaInfo>(); //string Pathds = this.textBoxImageRoot.Text; //string XMLFile = Pathds+"\\"+ TmpPlate.GetName()+"\\MeasurementDetail.mrf"; //int NumberOfChannels = (int)this.numericUpDownChannelNumber.Value; //List<string> ListFiles = Directory.GetFiles(Pathds + "\\" + TmpPlate.GetName(), "*C0*.tif", SearchOption.AllDirectories).ToList(); //ListFiles.Sort(); //OrderBy(q=>q).ToList(); //if (File.Exists(XMLFile)) //{ // XmlDocument xmlDoc = new XmlDocument(); // xmlDoc.Load(XMLFile); // for (int Channel = 0; Channel < NumberOfChannels; Channel++) // { // //string FinalName = ListChannels[Channel]; // cImageMetaInfo TmpMetaInfo = new cImageMetaInfo(); // //TmpMetaInfo.FileName = FinalName; // TmpMetaInfo.Name = xmlDoc.ChildNodes[1].ChildNodes[1].Attributes["bts:Ch"].Value;//ListChannelNames[Channel]; // TmpMetaInfo.ResolutionX = double.Parse(xmlDoc.ChildNodes[1].ChildNodes[1].Attributes["bts:HorizontalPixelDimension"].Value);//1; // TmpMetaInfo.ResolutionY = double.Parse(xmlDoc.ChildNodes[1].ChildNodes[1].Attributes["bts:VerticalPixelDimension"].Value);//1; // TmpMetaInfo.ResolutionZ = 1; // ListImageMetaInfo.Add(TmpMetaInfo); // } //} //else //{ // for (int Channel = 0; Channel < NumberOfChannels; Channel++) // { // //string FinalName = ListChannels[Channel]; // cImageMetaInfo TmpMetaInfo = new cImageMetaInfo(); // //TmpMetaInfo.FileName = FinalName; // // TmpMetaInfo.Name = ListChannelNames[Channel]; // TmpMetaInfo.ResolutionX = 1; // TmpMetaInfo.ResolutionY = 1; // TmpMetaInfo.ResolutionZ = 1; // ListImageMetaInfo.Add(TmpMetaInfo); // } //} #endregion int IdxWell = 0; foreach (cWell TmpWell in TmpPlate.ListWells) { WindowProgress.labelWellIdx.Text = (IdxWell + 1) + " / " + TmpPlate.ListWells.Count; WindowProgress.progressBarWell.Value = IdxWell + 1; WindowProgress.progressBarWell.Refresh(); WindowProgress.Refresh(); int NumberOfFieldProcessed = 0; double AverageValue = 0; for (int IdxField = 0; IdxField < this.numericUpDownFieldNumber.Value; IdxField++) { //var watch = Stopwatch.StartNew(); cGetImageFromWells IFW = new cGetImageFromWells(); IFW.SetInputData(new cListWells(TmpWell)); IFW.ListProperties.FindByName("Field").SetNewValue(IdxField); IFW.Run(); cImage TmpImage = IFW.GetOutPut(); //watch.Stop(); //cGlobalInfo.WindowHCSAnalyzer.richTextBoxConsole.AppendText("IFW = "+watch.ElapsedMilliseconds + "\n"); if ((TmpImage == null) || (TmpImage.GetNumChannels() == 0)) { cGlobalInfo.WindowHCSAnalyzer.richTextBoxConsole.AppendText("Error while loading [Plate] " + TmpPlate.GetName() + " [Well] " + TmpWell.GetPos() + " [Field] " + IdxField + "\n"); continue; } else { AverageValue = 25; //TmpImage.SingleChannelImage[0].Data.Sum(); } IFW.GetOutPut().Dispose(); //GC.Collect(); NumberOfFieldProcessed++; } if (NumberOfFieldProcessed != 0) AverageValue /= (double)NumberOfFieldProcessed; else AverageValue = 0; cListSignature LDesc = new cListSignature(); cSignature NewDesc = new cSignature(AverageValue, TmpDescType, cGlobalInfo.CurrentScreening); LDesc.Add(NewDesc); TmpWell.AddSignatures(LDesc); IdxWell++; } IdxPlateProg++; } WindowProgress.Dispose(); cGlobalInfo.CurrentScreening.ListDescriptors.UpDateDisplay(); cGlobalInfo.CurrentScreening.UpDatePlateListWithFullAvailablePlate(); for (int idxP = 0; idxP < cGlobalInfo.CurrentScreening.ListPlatesActive.Count; idxP++) cGlobalInfo.CurrentScreening.ListPlatesActive[idxP].UpDataMinMax(); }
private void generateDRCsToolStripMenuItem_Click(object sender, EventArgs e) { int nbrofdrugs = 6; int nbrofconcentrations = 10; int nbrofdesc = 3; double[, ,] DRC = new double[nbrofconcentrations, nbrofdrugs, nbrofdesc]; float[] X1 = new float[nbrofconcentrations]; X1[0] = 1000; for (int i = 1; i < X1.Length; i++) { X1[i] = X1[i - 1] / 3; } Random Bot = new Random(); Random To = new Random(); Random Ec5 = new Random(); Random Slop = new Random(); CompleteScreening = new cScreening("Current Screen", this.GlobalInfo); CompleteScreening.Columns = nbrofconcentrations; CompleteScreening.Rows = nbrofdrugs; for (int j = 0; j < nbrofdrugs; j++) { for (int k = 0; k < nbrofdesc; k++) { float Bottom = Bot.Next(10); float Top = To.Next(80, 100); float Ec50 = Ec5.Next(40, 60); float Slope = Slop.Next(1, 5); for (int i = 0; i < X1.Length; i++) { //DRC[i, j, k] = Bottom + (Top - Bottom) / (1 + Math.Pow(((Math.Pow(10, Ec50) / Math.Pow(10, X1[0]))), Slope)); DRC[i, j, k] = Bottom + (Top - Bottom) / (1 + Math.Pow((X1[i] / Ec50), -Slope)); } } } cPlate NewPlate = new cPlate("Cpds", "Plate0", CompleteScreening); CompleteScreening.AddPlate(NewPlate); CompleteScreening.ListDescriptors.Clean(); for (int k = 0; k < nbrofdesc; k++) { cDescriptorsType DescType = new cDescriptorsType("Desc" + k, true, 1, GlobalInfo); CompleteScreening.ListDescriptors.AddNew(DescType); } for (int j = 0; j < nbrofdrugs; j++) { for (int i = 0; i < nbrofconcentrations; i++) { List<cDescriptor> LDesc = new List<cDescriptor>(); for (int k = 0; k < nbrofdesc; k++) { //DRC[i, j, k] = Bottom + (Top - Bottom) / (1 + Math.Pow(((Math.Pow(10, Ec50) / Math.Pow(10, X1[0]))), Slope)); cDescriptor CurrentDesc = new cDescriptor(DRC[i, j, k], CompleteScreening.ListDescriptors[k], CompleteScreening); LDesc.Add(CurrentDesc); } cWell NewWell = new cWell(LDesc, i+1, j+1, CompleteScreening, NewPlate); NewWell.Concentration = X1[i]; NewPlate.AddWell(NewWell); } } CompleteScreening.ListDescriptors.UpDateDisplay(); CompleteScreening.UpDatePlateListWithFullAvailablePlate(); for (int idxP = 0; idxP < CompleteScreening.ListPlatesActive.Count; idxP++) CompleteScreening.ListPlatesActive[idxP].UpDataMinMax(); StartingUpDateUI(); this.toolStripcomboBoxPlateList.Items.Clear(); for (int IdxPlate = 0; IdxPlate < CompleteScreening.ListPlatesActive.Count; IdxPlate++) { string Name = CompleteScreening.ListPlatesActive.GetPlate(IdxPlate).Name; this.toolStripcomboBoxPlateList.Items.Add(Name); PlateListWindow.listBoxPlateNameToProcess.Items.Add(Name); PlateListWindow.listBoxAvaliableListPlates.Items.Add(Name); } CompleteScreening.CurrentDisplayPlateIdx = 0; CompleteScreening.SetSelectionType(comboBoxClass.SelectedIndex - 1); UpdateUIAfterLoading(); }
/// <summary> /// Perform an EM clustering on each plate independantely /// </summary> /// <param name="CurrentPlateToProcess">the plate to process</param> /// <param name="ClassNumber">Number of class</param> private void ClusteringEMSinglePlate(cPlate CurrentPlateToProcess, int ClassNumber, FormForEMInfo WindowEMinfo) { weka.core.Instances Ninsts = CurrentPlateToProcess.CreateInstancesWithoutClass();// CreateInstanceWithoutClass(CurrentTable); if (Ninsts.numInstances() == 0) { MessageBox.Show("No active wells !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } weka.clusterers.EM EMCluster = new EM(); EMCluster.setNumClusters(ClassNumber); EMCluster.setMaxIterations((int)WindowEMinfo.numericUpDownMaxIterations.Value); EMCluster.setMinStdDev((double)WindowEMinfo.numericUpDownMinStdev.Value); EMCluster.setSeed((int)WindowEMinfo.numericUpDownSeedNumber.Value); EMCluster.buildClusterer(Ninsts); EMCluster.getClusterModelsNumericAtts(); if (EMCluster.numberOfClusters() > GlobalInfo.GetNumberofDefinedClass()) { richTextBoxInfoClustering.AppendText("\n Plate " + CurrentPlateToProcess.Name + ", cluster Number: more than " + GlobalInfo.GetNumberofDefinedClass() + ", clustering not operated.\n"); return; } else richTextBoxInfoClustering.AppendText("\n" + CurrentPlateToProcess.Name + ": " + EMCluster.numberOfClusters() + " cluster(s)"); ClusterEvaluation eval = new ClusterEvaluation(); eval.setClusterer(EMCluster); eval.evaluateClusterer(Ninsts); CurrentPlateToProcess.AssignClass(eval.getClusterAssignments()); }
public void SetInputData(cPlate Input) { this.Input = Input; }
/// <summary> /// K-Mean for Systematic error Identification /// </summary> /// <param name="Classes"></param> /// <param name="PlateToProcess"></param> /// <param name="Desc"></param> /// <returns></returns> private bool KMeans(int Classes, cPlate PlateToProcess, int Desc) { int NumWell = PlateToProcess.GetNumberOfActiveWells(); int Numdesc = cGlobalInfo.CurrentScreening.GetNumberOfActiveDescriptor(); double[,] DataForKMeans = new double[NumWell, Numdesc]; List<double> CurrentDesc = new List<double>(); double[] NormDesc = null; for (int IdxValue = 0; IdxValue < cGlobalInfo.CurrentScreening.Columns; IdxValue++) for (int IdxValue0 = 0; IdxValue0 < cGlobalInfo.CurrentScreening.Rows; IdxValue0++) { cWell TmpWell = PlateToProcess.GetWell(IdxValue, IdxValue0, true); if (TmpWell != null) CurrentDesc.Add(TmpWell.ListSignatures[Desc].GetValue()); } if (CurrentDesc.Count == 0) return false; NormDesc = MeanCenteringStdStandarization(CurrentDesc.ToArray()); for (int row = 0; row < NumWell; row++) DataForKMeans[row, 0] = NormDesc[row]; int Info; double[,] CenterPos; int[] ClusterIndx; try { alglib.kmeansgenerate(DataForKMeans, NumWell, Numdesc, Classes, 10, out Info, out CenterPos, out ClusterIndx); int Idx = 0; for (int IdxValue = 0; IdxValue < cGlobalInfo.CurrentScreening.Columns; IdxValue++) for (int IdxValue0 = 0; IdxValue0 < cGlobalInfo.CurrentScreening.Rows; IdxValue0++) { cWell TmpWell = PlateToProcess.GetWell(IdxValue, IdxValue0, true); if (TmpWell != null) { if (ClusterIndx[Idx] == -1) TmpWell.SetAsNoneSelected(); else TmpWell.SetClass(ClusterIndx[Idx]); Idx++; } } } catch { MessageBox.Show("Check the data validity", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } return true; }
public FormToDisplayDistanceMap(cPlate CurrentPlate, cScreening CompleteScreening) { this.CurrentScreening = CompleteScreening; this.LUT = this.CurrentScreening.GlobalInfo.LUTs.LUT_FIRE; this.AssociatedPlate = CurrentPlate; bool ResMiss = false; //this.MouseDoubleClick += new MouseEventHandler(this.FormToDisplayPlate_MouseDoubleClick); this.MouseClick += new MouseEventHandler(this.FormToDisplayDistanceMap_MouseClick); ValuesMatrix = new double[CurrentPlate.ListActiveWells.Count][]; for (int i = 0; i < ValuesMatrix.Length; i++) ValuesMatrix[i] = new double[CurrentPlate.ListActiveWells.Count]; RecomputeDistances(eDistances.EUCLIDEAN); this.SetNewCellSize(2); }
public FormToDisplayPlate(cPlate PlateToDisplay, cScreening CompleteScreening) { //this.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; // this.WindowToDisplayEntireScreening = WindowToDisplayEntireScreening; this.PlateToDisplay = PlateToDisplay; this.CompleteScreening = CompleteScreening; this.CurrentScreening = CompleteScreening; this.LUT = this.CurrentScreening.GlobalInfo.LUT; this.AssociatedPlate = PlateToDisplay; bool ResMiss = false; this.MouseDoubleClick += new MouseEventHandler(this.FormToDisplayPlate_MouseDoubleClick); this.MouseClick += new MouseEventHandler(this.FormToDisplayPlate_MouseClick); ValuesMatrix = PlateToDisplay.GetAverageValueDescTable1(CompleteScreening.ListDescriptors.CurrentSelectedDescriptor, out ResMiss); System.Windows.Forms.ToolTip ToolTip = new System.Windows.Forms.ToolTip(); ToolTip.SetToolTip(this, PlateToDisplay.Name); for (int j = 0; j < ValuesMatrix.Length; j++) for (int i = 0; i < ValuesMatrix[0].Length; i++) { if(double.IsNaN(ValuesMatrix[j][i])) continue; if (ValuesMatrix[j][i] > Max) Max = ValuesMatrix[j][i]; if (ValuesMatrix[j][i] < Min) Min = ValuesMatrix[j][i]; } this.SetNewCellSize(5); //DisplayMatrix(); // this.Update(); }
public void RemovePlate(cPlate PlateToRemove) { for (int i = 0; i < PanelList.Count; i++) { if (PanelList[i].AssociatedPlate == PlateToRemove) { PanelList.RemoveAt(i); RefreshDisplay(false); break; } } }
private Microsoft.Msagl.Drawing.Graph DisplayTheGraph(cPlate PlateForTree) { FormForClassificationTree WindowForTree = new FormForClassificationTree(); WindowForTree.Text = PlateForTree.GetName(); string StringForTree = PlateForTree.GetInfoClassif().StringForTree; if ((StringForTree == null) || (StringForTree.Length == 0)) return null; WindowForTree.richTextBoxConsoleForClassification.Clear(); WindowForTree.richTextBoxConsoleForClassification.AppendText(cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate().GetInfoClassif().StringForQuality); WindowForTree.richTextBoxConsoleForClassification.AppendText(cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate().GetInfoClassif().ConfusionMatrix); return ComputeAndDisplayGraph(StringForTree.Remove(StringForTree.Length - 3, 3), false); }
private cExtendedTable GenerateArtifactMessage(cExtendedTable TmpTable, cPlate PlateToProcess) { cLinearize Lin = new cLinearize(); Lin.SetInputData(TmpTable); Lin.Run(); cExtendedTable LINTable = Lin.GetOutPut(); cClustering Cluster = new cClustering(); Cluster.SetInputData(LINTable); Cluster.ParamAlgoForClustering = this.ParamAlgoForClustering; if (Cluster.Run().IsSucceed == false) return null; this.ClusteredTable = Cluster.GetOutPut(); // now clustering //if (!KMeans((int)cGlobalInfo.OptionsWindow.numericUpDownSystErrorIdentKMeansClasses.Value, PlateToProcess, CurrentDescSel)) //{ // List<string> ListMessageError = new List<string>(); // ListMessageError.Add("K-Means Error"); // return ListMessageError; //} //// and finally classification // return this.ComputePlateBasedClassification(MinObjectsNumber); //} cExtendedTable ET = PlateToProcess.ListWells.GetPositionRelatedSignatures(); ET.Add(this.ClusteredTable[this.ClusteredTable.Count - 1]); weka.core.Instances insts = ET.CreateWekaInstancesWithClasses(); //CurrentPlateToProcess.CreateInstancesWithClassesWithPlateBasedDescriptor(Classes); weka.classifiers.trees.J48 ClassificationModel = new weka.classifiers.trees.J48(); ClassificationModel.setMinNumObj(MinObjectsNumber); weka.core.Instances train = new weka.core.Instances(insts, 0, insts.numInstances()); ClassificationModel.buildClassifier(train); string DotString = ClassificationModel.graph().Remove(0, ClassificationModel.graph().IndexOf("{") + 2); int DotLenght = DotString.Length; string NewDotString = DotString.Remove(DotLenght - 3, 3); // display the tree is requested //cDisplayTree DT = new cDisplayTree(); //DT.SetInputData(NewDotString); //DT.Run(); cExtendedTable ToReturn = new cExtendedTable(4, 1, 0); ToReturn.ListRowNames = new List<string>(); ToReturn.ListTags = new List<object>(); int CurrentPos = 0; int NextReturnPos = CurrentPos; List<int> ListNodeId = new List<int>(); string TmpDotString = NewDotString; int TmpClass = 0; string ErrorString = ""; int ErrorMessage = 0; ToReturn[0].Name = "Edge artifact"; // edge ToReturn[1].Name = "Column artifact"; // col ToReturn[2].Name = "Row artifact"; // row ToReturn[3].Name = "Bowl artifact"; // bowl #region build message while (NextReturnPos != -1) { int NextBracket = NewDotString.IndexOf("["); string StringToProcess = NewDotString.Remove(NextBracket - 1); string StringToProcess1 = StringToProcess.Remove(0, 1); if (StringToProcess1.Contains("N") == false) { int Id = Convert.ToInt32(StringToProcess1); int LabelPos = NewDotString.IndexOf("label=\""); string LabelString = NewDotString.Remove(0, LabelPos + 7); LabelPos = LabelString.IndexOf("\""); string FinalLabel = LabelString.Remove(LabelPos); // if (TmpClass < Classes) { if ((FinalLabel == "Dist_To_Border") || (FinalLabel == "Col_Pos") || (FinalLabel == "Row_Pos") || (FinalLabel == "Dist_To_Center")) { if ((FinalLabel == "Dist_To_Border") && (!ErrorString.Contains(" an edge effect")) && (!ErrorString.Contains(" a bowl effect")) && (ErrorMessage < 2)) { if (TmpClass > 0) ErrorString += " combined with"; ErrorString += " an " + cGlobalInfo.ListArtifacts[0]; ErrorMessage++; ToReturn[0][0] = 1; } else if ((FinalLabel == "Col_Pos") && (!ErrorString.Contains(" a column artifact")) && (ErrorMessage < 2)) { if (TmpClass > 0) ErrorString += " combined with"; ErrorString += " a " + cGlobalInfo.ListArtifacts[1]; ErrorMessage++; ToReturn[1][0] = 1; } else if ((FinalLabel == "Row_Pos") && (!ErrorString.Contains(" a row artifact")) && (ErrorMessage < 2)) { if (TmpClass > 0) ErrorString += " combined with"; ErrorString += " a " + cGlobalInfo.ListArtifacts[2]; ErrorMessage++; ToReturn[2][0] = 1; } else if ((FinalLabel == "Dist_To_Center") && (!ErrorString.Contains(" a bowl effect")) && (!ErrorString.Contains(" an edge effect")) && (ErrorMessage < 2)) { if (TmpClass > 0) ErrorString += " combined with"; ErrorString += " a " + cGlobalInfo.ListArtifacts[3]; ErrorMessage++; ToReturn[3][0] = 1; } TmpClass++; } } } NextReturnPos = NewDotString.IndexOf("\n"); if (NextReturnPos != -1) { string TmpString = NewDotString.Remove(0, NextReturnPos + 1); NewDotString = TmpString; } } if (TmpClass == 0) { string NoError = "No systematic error detected !"; ToReturn.ListTags.Add(NoError); //ToReturn.Add(NoError); return ToReturn; } string FinalString = "You have a systematic error !\nThis is " + ErrorString; NewDotString = TmpDotString; NextReturnPos = 0; while (NextReturnPos != -1) { int NextBracket = NewDotString.IndexOf("["); string StringToProcess = NewDotString.Remove(NextBracket - 1); string StringToProcess1 = StringToProcess.Remove(0, 1); if (StringToProcess1.Contains("N")) { //// this is an edge string stringNodeIdxStart = StringToProcess1.Remove(StringToProcess1.IndexOf("-")); int NodeIdxStart = Convert.ToInt32(stringNodeIdxStart); string stringNodeIdxEnd = StringToProcess1.Remove(0, StringToProcess1.IndexOf("N") + 1); int NodeIdxSEnd = Convert.ToInt32(stringNodeIdxEnd); int LabelPos = NewDotString.IndexOf("label="); LabelPos += 7; string CurrLabelString = NewDotString.Remove(0, LabelPos); } NextReturnPos = NewDotString.IndexOf("\n"); if (NextReturnPos != -1) { string TmpString = NewDotString.Remove(0, NextReturnPos + 1); NewDotString = TmpString; } } ToReturn.ListTags.Add(FinalString + "."); #endregion return ToReturn; }
private void createAveragePlateToolStripMenuItem_Click(object sender, EventArgs e) { FormForPlateAveraging FFPA = new FormForPlateAveraging(); PanelForPlatesSelection PlatesSelectionPanel = new PanelForPlatesSelection(true, null, true); PlatesSelectionPanel.Height = FFPA.panelForPlateList.Height; FFPA.panelForPlateList.Controls.Add(PlatesSelectionPanel); if (FFPA.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; cListPlates LP = PlatesSelectionPanel.GetListSelectedPlates(); cPlate NewPlate = new cPlate("Average Plate", cGlobalInfo.CurrentScreening); cWell TmpWell; #region QC report cExtendedList TmpReportForQuality = new cExtendedList("Weight"); TmpReportForQuality.ListTags = new List<object>(); cExtendedTable TableForQCReport = new cExtendedTable(TmpReportForQuality); TableForQCReport.ListRowNames = new List<string>(); TableForQCReport.ListTags = new List<object>(); foreach (cPlate TmpPlate in LP) { object QualityValue = TmpPlate.ListProperties.FindValueByName("Quality"); if ((QualityValue != null) && (FFPA.checkBoxWeightedSum.Checked)) TableForQCReport[0].Add((double)QualityValue); else { this.richTextBoxConsole.AppendText(TmpPlate.GetName() + " - Quality is NULL. Weight set to 1.\n"); TableForQCReport[0].Add(1); } TableForQCReport.ListRowNames.Add(TmpPlate.GetName()); TableForQCReport.ListTags.Add(TmpPlate); TableForQCReport[0].ListTags.Add(TmpPlate); } cDisplayExtendedTable DET = new cDisplayExtendedTable(); DET.SetInputData(TableForQCReport); DET.Title = "QC report"; TableForQCReport.Name = "QC report"; DET.Run(); #endregion for (int X = 0; X < cGlobalInfo.CurrentScreening.Columns; X++) for (int Y = 0; Y < cGlobalInfo.CurrentScreening.Rows; Y++) { cListSignature LDesc = new cListSignature(); for (int i = 0; i < cGlobalInfo.CurrentScreening.ListDescriptors.Count; i++) { double Value = 0; double NormFactor = 0; foreach (cPlate TmpPlate in LP) { double Weight = 1; object QualityValue = TmpPlate.ListProperties.FindValueByName("Quality"); if ((QualityValue != null) && (FFPA.checkBoxWeightedSum.Checked)) Weight = (double)QualityValue; NormFactor += Weight; TmpWell = TmpPlate.GetWell(X, Y, false); if (TmpWell != null) { Value += Weight * TmpWell.ListSignatures[i].GetValue(); } } if (NormFactor > 0) { cSignature Desc = new cSignature(Value / NormFactor, cGlobalInfo.CurrentScreening.ListDescriptors[i], cGlobalInfo.CurrentScreening); LDesc.Add(Desc); } } cWell NewWell = new cWell(LDesc, X + 1, Y + 1, cGlobalInfo.CurrentScreening, NewPlate); NewWell.SetCpdName("Average Well [" + (X + 1) + ":" + (Y + 1) + "]"); NewPlate.AddWell(NewWell); } cGlobalInfo.CurrentScreening.AddPlate(NewPlate); cGlobalInfo.CurrentScreening.ListPlatesActive.Add(NewPlate); toolStripcomboBoxPlateList.Items.Add(NewPlate.GetName()); cGlobalInfo.CurrentScreening.ListPlatesActive[cGlobalInfo.CurrentScreening.ListPlatesActive.Count - 1].UpDataMinMax(); cGlobalInfo.CurrentScreening.CurrentDisplayPlateIdx = 0; cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate().DisplayDistribution(cGlobalInfo.CurrentScreening.ListDescriptors.GetActiveDescriptor(), true); }
public cWell(string FileName, cScreening screenParent, cPlate CurrentPlate) { this.Parent = screenParent; this.AssociatedPlate = CurrentPlate; StreamReader sr = new StreamReader(FileName); int Idx; string NewLine; string TmpLine; string line; // we have to build the descriptor list if (screenParent.ListDescriptors.Count == 0) { Idx = FileName.LastIndexOf("\\"); NewLine = FileName.Remove(0, Idx + 1); TmpLine = NewLine; Idx = TmpLine.IndexOf("x"); NewLine = TmpLine.Remove(Idx); if (!int.TryParse(NewLine, out this.PosX)) { MessageBox.Show("Error in load the current file.\n", "Loading error !", MessageBoxButtons.OK, MessageBoxIcon.Error); sr.Close(); return; } NewLine = TmpLine.Remove(0, Idx + 1); Idx = NewLine.IndexOf("."); TmpLine = NewLine.Remove(Idx); this.PosY = Convert.ToInt16(TmpLine); line = sr.ReadLine(); while (line != null) { if (line != null) { Idx = line.IndexOf("\t"); string DescName = line.Remove(Idx); List<double> readData = new List<double>(); NewLine = line.Remove(0, Idx + 1); line = NewLine; Idx = line.IndexOf("\t"); int NumValue = 0; while (Idx > 0) { string DescValue = line.Remove(Idx); double CurrentValue = Convert.ToDouble(DescValue); readData.Add(CurrentValue); NewLine = line.Remove(0, Idx + 1); line = NewLine; Idx = line.IndexOf("\t"); NumValue++; } if (line.Length > 0) { double Value = Convert.ToDouble(line); readData.Add(Value); } // first check if the descriptor exist screenParent.ListDescriptors.AddNew(new cDescriptorsType(DescName, true, NumValue)); } line = sr.ReadLine(); } sr.Close(); } this.ListDescriptors = new List<cDescriptor>(); sr = new StreamReader(FileName); Idx = FileName.LastIndexOf("\\"); NewLine = FileName.Remove(0, Idx + 1); TmpLine = NewLine; Idx = TmpLine.IndexOf("x"); NewLine = TmpLine.Remove(Idx); this.PosX = Convert.ToInt16(NewLine); NewLine = TmpLine.Remove(0, Idx + 1); Idx = NewLine.IndexOf("."); TmpLine = NewLine.Remove(Idx); this.PosY = Convert.ToInt16(TmpLine); line = sr.ReadLine(); int IDxLine = 0; while (line != null) { if (line != null) { Idx = line.IndexOf("\t"); string DescName = line.Remove(Idx); List<double> readData = new List<double>(); NewLine = line.Remove(0, Idx + 1); line = NewLine; Idx = line.IndexOf("\t"); while (Idx > 0) { string DescValue = line.Remove(Idx); double CurrentValue = Convert.ToDouble(DescValue); readData.Add(CurrentValue); NewLine = line.Remove(0, Idx + 1); line = NewLine; Idx = line.IndexOf("\t"); } if (line.Length > 0) { double Value = Convert.ToDouble(line); readData.Add(Value); } cDescriptor CurrentDesc = new cDescriptor(readData.ToArray(), 0, screenParent.ListDescriptors[IDxLine].GetBinNumber() - 1, screenParent.ListDescriptors[IDxLine], this.Parent/* DescName*/); this.ListDescriptors.Add(CurrentDesc); } line = sr.ReadLine(); IDxLine++; } sr.Close(); this.CurrentColor = this.Parent.GlobalInfo.GetColor(ClassForClassif); return; }
/// <summary> /// Perform an Hierarchical clustering on each plate independantely /// </summary> /// <param name="CurrentPlateToProcess">the plate to process</param> /// <param name="ClassNumber">Number of class</param> private void ClusteringHierarchicalSinglePlate(cPlate CurrentPlateToProcess, int ClassNumber) { weka.core.Instances Ninsts = CurrentPlateToProcess.CreateInstancesWithoutClass(); weka.clusterers.HierarchicalClusterer HClusterer = new HierarchicalClusterer(); //string OptionDistance = " -A \"weka.core."; string OptionDistance = " -A \""; switch (cGlobalInfo.OptionsWindow.comboBoxHierarchicalDistance.SelectedIndex) { case 0: OptionDistance += "EuclideanDistance"; break; case 1: OptionDistance += "ManhattanDistance"; break; case 2: OptionDistance += "ChebyshevDistance"; break; default: break; } OptionDistance += " -R first-last\""; string[] TAGS_LINK_TYPE = { "SINGLE", "COMPLETE", "AVERAGE", "MEAN", "CENTROID", "WARD", "ADJCOMPLETE" }; string WekaOption = "-L " + TAGS_LINK_TYPE[cGlobalInfo.OptionsWindow.comboBoxHierarchicalLinkType.SelectedIndex];// + OptionDistance; HClusterer.setOptions(weka.core.Utils.splitOptions(WekaOption)); //EuclideanDistance2 Dist2 = new EuclideanDistance2(); //HClusterer.setDistanceFunction(Dist2); HClusterer.setNumClusters(ClassNumber); HClusterer.buildClusterer(Ninsts); richTextBoxInfoClustering.AppendText("\n" + CurrentPlateToProcess.GetName() + ": " + HClusterer.numberOfClusters() + " cluster(s)"); ClusterEvaluation eval = new ClusterEvaluation(); eval.setClusterer(HClusterer); eval.evaluateClusterer(Ninsts); CurrentPlateToProcess.AssignClass(eval.getClusterAssignments()); }
/// <summary> /// Perform an EM clustering on each plate independantely /// </summary> /// <param name="CurrentPlateToProcess">the plate to process</param> /// <param name="ClassNumber">Number of class</param> private void ClusteringEMSinglePlate(cPlate CurrentPlateToProcess, int ClassNumber) { weka.core.Instances Ninsts = CurrentPlateToProcess.CreateInstancesWithoutClass();// CreateInstanceWithoutClass(CurrentTable); weka.clusterers.EM EMCluster = new EM(); EMCluster.setNumClusters(ClassNumber); EMCluster.buildClusterer(Ninsts); EMCluster.getClusterModelsNumericAtts(); if (EMCluster.numberOfClusters() > GlobalInfo.GetNumberofDefinedClass()) { richTextBoxInfoClustering.AppendText("\n Plate " + CurrentPlateToProcess.Name + ", cluster Number: more than " + GlobalInfo.GetNumberofDefinedClass() + ", clustering not operated.\n"); return; } else richTextBoxInfoClustering.AppendText("\n" + CurrentPlateToProcess.Name + ": " + EMCluster.numberOfClusters() + " cluster(s)"); ClusterEvaluation eval = new ClusterEvaluation(); eval.setClusterer(EMCluster); eval.evaluateClusterer(Ninsts); CurrentPlateToProcess.AssignClass(eval.getClusterAssignments()); }
/// <summary> /// Perform an EM clustering on each plate independantely /// </summary> /// <param name="CurrentPlateToProcess">the plate to process</param> /// <param name="ClassNumber">Number of class</param> private void ClusteringEMSinglePlate(cPlate CurrentPlateToProcess, int ClassNumber, FormForEMInfo WindowEMinfo) { weka.core.Instances Ninsts = CurrentPlateToProcess.CreateInstancesWithoutClass();// CreateInstanceWithoutClass(CurrentTable); weka.clusterers.EM EMCluster = new EM(); EMCluster.setNumClusters(ClassNumber); EMCluster.setMaxIterations((int)WindowEMinfo.numericUpDownMaxIterations.Value); EMCluster.setMinStdDev((double)WindowEMinfo.numericUpDownMinStdev.Value); EMCluster.setSeed((int)WindowEMinfo.numericUpDownSeedNumber.Value); EMCluster.buildClusterer(Ninsts); EMCluster.getClusterModelsNumericAtts(); if (EMCluster.numberOfClusters() > cGlobalInfo.ListWellClasses.Count) { richTextBoxInfoClustering.AppendText("\n Plate " + CurrentPlateToProcess.GetName() + ", cluster Number: more than " + cGlobalInfo.ListWellClasses.Count + ", clustering not operated.\n"); return; } else richTextBoxInfoClustering.AppendText("\n" + CurrentPlateToProcess.GetName() + ": " + EMCluster.numberOfClusters() + " cluster(s)"); ClusterEvaluation eval = new ClusterEvaluation(); eval.setClusterer(EMCluster); eval.evaluateClusterer(Ninsts); CurrentPlateToProcess.AssignClass(eval.getClusterAssignments()); }
private List<string> GenerateArtifactMessage(cPlate PlateToProcess, int CurrentDescSel) { int NumWell = PlateToProcess.GetNumberOfActiveWells(); List<string> Messages = new List<string>(); // Normality Test List<double> CurrentDesc = new List<double>(); for (int IdxValue = 0; IdxValue < CompleteScreening.Columns; IdxValue++) for (int IdxValue0 = 0; IdxValue0 < CompleteScreening.Rows; IdxValue0++) { cWell TmpWell = PlateToProcess.GetWell(IdxValue, IdxValue0, true); if (TmpWell != null) CurrentDesc.Add(TmpWell.ListDescriptors[CurrentDescSel].GetValue()); } CurrentDesc.Sort(); if ((std(CurrentDesc.ToArray()) == 0)) { //Messages.Add(/*PlateToProcess.Name + "\n \n*/"No systematic error detected !"); return null; } double Anderson_DarlingValue = Anderson_Darling(CurrentDesc.ToArray()); Messages.Add(string.Format("{0:0.###}", Anderson_DarlingValue)); // now clustering if (!KMeans((int)GlobalInfo.OptionsWindow.numericUpDownSystErrorIdentKMeansClasses.Value, PlateToProcess, CurrentDescSel)) { List<string> ListMessageError = new List<string>(); ListMessageError.Add("K-Means Error"); return ListMessageError; } // and finally classification int MinObjectsNumber = (NumWell * (int)GlobalInfo.OptionsWindow.numericUpDownSystemMinWellRatio.Value) / 100; List<string> ListMessage = ComputePlateBasedClassification((int)GlobalInfo.OptionsWindow.numericUpDownSystErrorIdentKMeansClasses.Value, MinObjectsNumber, PlateToProcess); for (int i = 0; i < ListMessage.Count; i++) Messages.Add(ListMessage[i]); return Messages; }
private List<string> ComputePlateBasedClassification(int Classes, int MinObjectsNumber, cPlate CurrentPlateToProcess) { CurrentPlateToProcess.ComputePlateBasedDescriptors(); weka.core.Instances insts = CurrentPlateToProcess.CreateInstancesWithClassesWithPlateBasedDescriptor(Classes); weka.classifiers.trees.J48 ClassificationModel = new weka.classifiers.trees.J48(); ClassificationModel.setMinNumObj(MinObjectsNumber); weka.core.Instances train = new weka.core.Instances(insts, 0, insts.numInstances()); ClassificationModel.buildClassifier(train); // display the tree string DotString = ClassificationModel.graph().Remove(0, ClassificationModel.graph().IndexOf("{") + 2); int DotLenght = DotString.Length; string NewDotString = DotString.Remove(DotLenght - 3, 3); ComputeAndDisplayGraph(NewDotString); return ComputeGraph(NewDotString, Classes); }
public cWell(string FileName, cScreening screenParent, cPlate CurrentPlate) { // Parent = screenParent; this.AssociatedPlate = CurrentPlate; StreamReader sr = new StreamReader(FileName); int Idx; string NewLine; string TmpLine; string line; // we have to build the descriptor list if (cGlobalInfo.CurrentScreening.ListDescriptors.Count == 0) { Idx = FileName.LastIndexOf("\\"); NewLine = FileName.Remove(0, Idx + 1); TmpLine = NewLine; Idx = TmpLine.IndexOf("x"); NewLine = TmpLine.Remove(Idx); if (!int.TryParse(NewLine, out this.PosX)) { MessageBox.Show("Error in load the current file.\n", "Loading error !", MessageBoxButtons.OK, MessageBoxIcon.Error); sr.Close(); return; } NewLine = TmpLine.Remove(0, Idx + 1); Idx = NewLine.IndexOf("."); TmpLine = NewLine.Remove(Idx); this.PosY = Convert.ToInt16(TmpLine); line = sr.ReadLine(); while (line != null) { if (line != null) { Idx = line.IndexOf("\t"); string DescName = line.Remove(Idx); List<double> readData = new List<double>(); NewLine = line.Remove(0, Idx + 1); line = NewLine; Idx = line.IndexOf("\t"); int NumValue = 0; while (Idx > 0) { string DescValue = line.Remove(Idx); double CurrentValue = Convert.ToDouble(DescValue); readData.Add(CurrentValue); NewLine = line.Remove(0, Idx + 1); line = NewLine; Idx = line.IndexOf("\t"); NumValue++; } if (line.Length > 0) { double Value = Convert.ToDouble(line); readData.Add(Value); } // first check if the descriptor exist cGlobalInfo.CurrentScreening.ListDescriptors.AddNew(new cDescriptorType(DescName, true, NumValue)); } line = sr.ReadLine(); } sr.Close(); } this.ListSignatures = new cListSignature(); sr = new StreamReader(FileName); Idx = FileName.LastIndexOf("\\"); NewLine = FileName.Remove(0, Idx + 1); TmpLine = NewLine; Idx = TmpLine.IndexOf("x"); NewLine = TmpLine.Remove(Idx); this.PosX = Convert.ToInt16(NewLine); NewLine = TmpLine.Remove(0, Idx + 1); Idx = NewLine.IndexOf("."); TmpLine = NewLine.Remove(Idx); this.PosY = Convert.ToInt16(TmpLine); line = sr.ReadLine(); int IDxLine = 0; while (line != null) { if (line != null) { Idx = line.IndexOf("\t"); string DescName = line.Remove(Idx); cExtendedList readData = new cExtendedList(); NewLine = line.Remove(0, Idx + 1); line = NewLine; Idx = line.IndexOf("\t"); while (Idx > 0) { string DescValue = line.Remove(Idx); double CurrentValue = Convert.ToDouble(DescValue); readData.Add(CurrentValue); NewLine = line.Remove(0, Idx + 1); line = NewLine; Idx = line.IndexOf("\t"); } if (line.Length > 0) { double Value = Convert.ToDouble(line); readData.Add(Value); } cSignature CurrentDesc = new cSignature(readData, cGlobalInfo.CurrentScreening.ListDescriptors[IDxLine].GetBinNumber() - 1, cGlobalInfo.CurrentScreening.ListDescriptors[IDxLine], cGlobalInfo.CurrentScreening); this.ListSignatures.Add(CurrentDesc); } line = sr.ReadLine(); IDxLine++; } sr.Close(); // this.ListClass.Add(this.InitialClass); this.ListProperties = new cListWellProperty(this); this.ListProperties.UpdateValueByName("Well Class", 2); // this.CurrentColor = this.cGlobalInfo.ListClasses[ClassForClassif].ColourForDisplay; return; }
public cPlateLUTManager(cPlate Sender) { this.AssociatedPlate = Sender; }
private void convertDRCToWellToolStripMenuItem1_Click(object sender, EventArgs e) { System.Windows.Forms.DialogResult ResWin = MessageBox.Show("By applying this process, the current screening will be entirely updated ! Proceed ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (ResWin == System.Windows.Forms.DialogResult.No) return; //foreach (cDescriptorsType DescType in CompleteScreening.ListDescriptors) //{ // CompleteScreening.ListDescriptors.RemoveDescUnSafe(DescType, CompleteScreening); //} if (CompleteScreening != null) CompleteScreening.Close3DView(); // CompleteScreening.ListDescriptors.RemoveDesc(CompleteScreening.ListDescriptors[IntToTransfer], CompleteScreening); cScreening MergedScreening = new cScreening("Merged Screen", GlobalInfo); MergedScreening.PanelForPlate = this.panelForPlate; MergedScreening.Rows = CompleteScreening.Rows; MergedScreening.Columns = CompleteScreening.Columns; MergedScreening.ListPlatesAvailable = new cExtendPlateList(); // create the descriptor MergedScreening.ListDescriptors.Clean(); int Idesc = 0; List<cDescriptorsType> ListDescType = new List<cDescriptorsType>(); for (int i = 0; i < CompleteScreening.ListDescriptors.Count; i++) { if (!CompleteScreening.ListDescriptors[i].IsActive()) continue; cDescriptorsType DescEC50 = new cDescriptorsType("EC50_" + CompleteScreening.ListDescriptors[i].GetName(), true, 1, GlobalInfo); ListDescType.Add(DescEC50); MergedScreening.ListDescriptors.AddNew(DescEC50); cDescriptorsType DescTop = new cDescriptorsType("Top_" + CompleteScreening.ListDescriptors[i].GetName(), true, 1, GlobalInfo); ListDescType.Add(DescTop); MergedScreening.ListDescriptors.AddNew(DescTop); cDescriptorsType DescBottom = new cDescriptorsType("Bottom_" + CompleteScreening.ListDescriptors[i].GetName(), true, 1, GlobalInfo); ListDescType.Add(DescBottom); MergedScreening.ListDescriptors.AddNew(DescBottom); cDescriptorsType DescSlope = new cDescriptorsType("Slope_" + CompleteScreening.ListDescriptors[i].GetName(), true, 1, GlobalInfo); ListDescType.Add(DescSlope); MergedScreening.ListDescriptors.AddNew(DescSlope); Idesc++; } MergedScreening.ListDescriptors.CurrentSelectedDescriptor = 0; foreach (cPlate CurrentPlate in CompleteScreening.ListPlatesAvailable) { cPlate NewPlate = new cPlate("Cpds", CurrentPlate.Name + " Merged", MergedScreening); // check if the plate exist already MergedScreening.AddPlate(NewPlate); foreach (cDRC_Region CurrentRegion in CurrentPlate.ListDRCRegions) { List<cDescriptor> LDesc = new List<cDescriptor>(); Idesc = 0; int IDESCBase = 0; for (int i = 0; i < CompleteScreening.ListDescriptors.Count; i++) { if (!CompleteScreening.ListDescriptors[i].IsActive()) continue; cDRC CurrentDRC = CurrentRegion.GetDRC(CompleteScreening.ListDescriptors[IDESCBase++]); cDescriptor Desc_EC50 = new cDescriptor(CurrentDRC.EC50, ListDescType[Idesc++], CompleteScreening); LDesc.Add(Desc_EC50); cDescriptor Desc_Top = new cDescriptor(CurrentDRC.Top, ListDescType[Idesc++], CompleteScreening); LDesc.Add(Desc_Top); cDescriptor Desc_Bottom = new cDescriptor(CurrentDRC.Bottom, ListDescType[Idesc++], CompleteScreening); LDesc.Add(Desc_Bottom); cDescriptor Desc_Slope = new cDescriptor(CurrentDRC.Slope, ListDescType[Idesc++], CompleteScreening); LDesc.Add(Desc_Slope); } cWell NewWell = new cWell(LDesc, CurrentRegion.PosXMin + 1, CurrentRegion.PosYMin + 1, MergedScreening, NewPlate); NewWell.Name = "DRC [" + CurrentRegion.PosXMin + ":" + CurrentRegion.PosYMin + "]"; NewPlate.AddWell(NewWell); } } // PanelList[0].CurrentScreening.ListPlatesActive.Clear(); // PanelList[0].CurrentScreening.GlobalInfo.WindowHCSAnalyzer.RefreshInfoScreeningRichBox(); MergedScreening.ListPlatesActive = new cExtendPlateList(); for (int i = 0; i < MergedScreening.ListPlatesAvailable.Count; i++) { MergedScreening.ListPlatesActive.Add(MergedScreening.ListPlatesAvailable[i]); // MergedScreening.GlobalInfo.WindowHCSAnalyzer.toolStripcomboBoxPlateList.Items.Add(PanelList[0].CurrentScreening.ListPlatesActive[i].Name); } //PanelList[0].CurrentScreening.CurrentDisplayPlateIdx = 0; //PanelList[0].CurrentScreening.GlobalInfo.WindowHCSAnalyzer.toolStripcomboBoxPlateList.SelectedIndex = 0; //PanelList[0].CurrentScreening.GetCurrentDisplayPlate().DisplayDistribution(PanelList[0].CurrentScreening.ListDescriptors.CurrentSelectedDescriptor, false); CompleteScreening.ListDescriptors = MergedScreening.ListDescriptors; CompleteScreening.ListPlatesAvailable = MergedScreening.ListPlatesAvailable; CompleteScreening.ListPlatesActive = MergedScreening.ListPlatesActive; CompleteScreening.UpDatePlateListWithFullAvailablePlate(); for (int idxP = 0; idxP < CompleteScreening.ListPlatesActive.Count; idxP++) CompleteScreening.ListPlatesActive[idxP].UpDataMinMax(); CompleteScreening.GetCurrentDisplayPlate().DisplayDistribution(CompleteScreening.ListDescriptors.CurrentSelectedDescriptor, true); }