private void AverageOperationsToDescriptorItem(object sender, EventArgs e) { FormForDescOperations MainWindow = new FormForDescOperations(cGlobalInfo.CurrentScreening.ListDescriptors.GetListNames()); MainWindow.Text = "Average Based Operations"; if (MainWindow.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; string NewDescName = MainWindow.textBoxNewDescName.Text; cDescriptorType DescType1 = cGlobalInfo.CurrentScreening.ListDescriptors.GetDescriptorByName(MainWindow.comboBoxDescriptor1.Text); cDescriptorType DescType2 = cGlobalInfo.CurrentScreening.ListDescriptors.GetDescriptorByName(MainWindow.comboBoxDescriptor2.Text); if ((DescType1 == null) || (DescType2 == null)) return; FormForProgress ProgressWindow = new FormForProgress(); ProgressWindow.Show(); int IdxProgress = 1; int MaxProgress = cGlobalInfo.CurrentScreening.ListPlatesAvailable.Count; ProgressWindow.progressBar.Maximum = MaxProgress; cDescriptorType NewDescType = new cDescriptorType(NewDescName, true, 1); cGlobalInfo.CurrentScreening.ListDescriptors.AddNew(NewDescType); eBinaryOperationType PostProcessBinaryOp = eBinaryOperationType.UNDEFINED; if (MainWindow.checkBoxActivePostProcess.Checked) { switch (MainWindow.domainUpDownPostProcessOperator.Text) { case "*": PostProcessBinaryOp = eBinaryOperationType.MULTIPLY; break; case "+": PostProcessBinaryOp = eBinaryOperationType.ADD; break; case "/": PostProcessBinaryOp = eBinaryOperationType.DIVIDE; break; case "-": PostProcessBinaryOp = eBinaryOperationType.SUBSTRACT; break; default: return; } } if (MainWindow.tabControlMain.SelectedTab.Name == "tabPageBinary") { // SingleCellOperation.ListDualOperations = new List<eBinaryOperationType>(); // eDualOperationType OperationType = eDualOperationType.ADD; eBinaryOperationType BinaryOp = eBinaryOperationType.ADD; switch (MainWindow.domainUpDown1.Text) { case "*": BinaryOp = eBinaryOperationType.MULTIPLY; break; case "+": BinaryOp = eBinaryOperationType.ADD; break; case "/": BinaryOp = eBinaryOperationType.DIVIDE; break; case "-": BinaryOp = eBinaryOperationType.SUBSTRACT; break; default: return; } foreach (cPlate CurrentPlate in cGlobalInfo.CurrentScreening.ListPlatesAvailable) { foreach (cWell Tmpwell in CurrentPlate.ListActiveWells) { cListSignature LDesc = new cListSignature(); cSignature NewDesc = null; double Val = 0; switch (BinaryOp) { case eBinaryOperationType.ADD: Val = Tmpwell.GetAverageValue(DescType1) + Tmpwell.GetAverageValue(DescType2); break; case eBinaryOperationType.MULTIPLY: Val = Tmpwell.GetAverageValue(DescType1) * Tmpwell.GetAverageValue(DescType2); break; case eBinaryOperationType.SUBSTRACT: Val = Tmpwell.GetAverageValue(DescType1) - Tmpwell.GetAverageValue(DescType2); break; case eBinaryOperationType.DIVIDE: double denominator = Tmpwell.GetAverageValue(DescType2); if (denominator == 0) Val = 0; else Val = Tmpwell.GetAverageValue(DescType1) / denominator; break; default: break; } if (PostProcessBinaryOp != eBinaryOperationType.UNDEFINED) { double ValuePostProcess = (double)MainWindow.numericUpDownPostProcessValue.Value; switch (PostProcessBinaryOp) { case eBinaryOperationType.ADD: Val += ValuePostProcess; break; case eBinaryOperationType.SUBSTRACT: Val -= ValuePostProcess; break; case eBinaryOperationType.MULTIPLY: Val *= ValuePostProcess; break; case eBinaryOperationType.DIVIDE: if (ValuePostProcess == 0) Val = 0; else Val /= ValuePostProcess; break; default: break; } } NewDesc = new cSignature(Val, NewDescType, cGlobalInfo.CurrentScreening); LDesc.Add(NewDesc); Tmpwell.AddSignatures(LDesc); } ProgressWindow.progressBar.Value = IdxProgress++; ProgressWindow.richTextBoxForComment.AppendText(CurrentPlate.GetShortInfo()); ProgressWindow.Refresh(); } } #region unary operator else { eUnaryOperationType OperationType = eUnaryOperationType.LOG; if (MainWindow.radioButtonSQRT.Checked) OperationType = eUnaryOperationType.SQRT; else if (MainWindow.radioButtonLog.Checked) OperationType = eUnaryOperationType.LOG; else if (MainWindow.radioButtonABS.Checked) OperationType = eUnaryOperationType.ABS; else if (MainWindow.radioButtonEXP.Checked) OperationType = eUnaryOperationType.EXP; foreach (cPlate CurrentPlate in cGlobalInfo.CurrentScreening.ListPlatesAvailable) { foreach (cWell Tmpwell in CurrentPlate.ListActiveWells) { cListSignature LDesc = new cListSignature(); cSignature NewDesc = null; double Val = 0; switch (OperationType) { case eUnaryOperationType.LOG: Val = Math.Log(Tmpwell.GetAverageValue(DescType1)); if (double.IsInfinity(Val) || double.IsNaN(Val)) Val = double.Epsilon; break; case eUnaryOperationType.SQRT: Val = Tmpwell.GetAverageValue(DescType1); if (Val < 0) Val = 0; Val = Math.Sqrt(Val); break; case eUnaryOperationType.ABS: Val = Math.Abs(Tmpwell.GetAverageValue(DescType1)); break; case eUnaryOperationType.EXP: Val = Math.Exp(Tmpwell.GetAverageValue(DescType1)); break; default: break; } if (PostProcessBinaryOp != eBinaryOperationType.UNDEFINED) { double ValuePostProcess = (double)MainWindow.numericUpDownPostProcessValue.Value; switch (PostProcessBinaryOp) { case eBinaryOperationType.ADD: Val += ValuePostProcess; break; case eBinaryOperationType.SUBSTRACT: Val -= ValuePostProcess; break; case eBinaryOperationType.MULTIPLY: Val *= ValuePostProcess; break; case eBinaryOperationType.DIVIDE: if (ValuePostProcess == 0) Val = 0; else Val /= ValuePostProcess; break; default: break; } } NewDesc = new cSignature(Val, NewDescType, cGlobalInfo.CurrentScreening); LDesc.Add(NewDesc); Tmpwell.AddSignatures(LDesc); } ProgressWindow.progressBar.Value = IdxProgress++; ProgressWindow.richTextBoxForComment.AppendText(CurrentPlate.GetShortInfo()); ProgressWindow.Refresh(); } } #endregion ProgressWindow.Close(); int IdxNull = 0; foreach (cPlate TmpPlate in cGlobalInfo.CurrentScreening.ListPlatesActive) { foreach (cWell TmpWell in TmpPlate.ListActiveWells) if (TmpWell.ListSignatures.Count != cGlobalInfo.CurrentScreening.ListDescriptors.Count) IdxNull++; } if (IdxNull > 0) System.Windows.Forms.MessageBox.Show("List signature count is different from list descriptor count", "Critical Error !", MessageBoxButtons.OK, MessageBoxIcon.Error); cGlobalInfo.CurrentScreening.ListDescriptors.UpDateDisplay(); // CompleteScreening.UpDatePlateListWithFullAvailablePlate(); for (int idxP = 0; idxP < cGlobalInfo.CurrentScreening.ListPlatesAvailable.Count; idxP++) cGlobalInfo.CurrentScreening.ListPlatesActive[idxP].UpDataMinMax(); StartingUpDateUI(); this.toolStripcomboBoxPlateList.Items.Clear(); for (int IdxPlate = 0; IdxPlate < cGlobalInfo.CurrentScreening.ListPlatesActive.Count; IdxPlate++) { string Name = cGlobalInfo.CurrentScreening.ListPlatesActive.GetPlate(IdxPlate).GetName(); this.toolStripcomboBoxPlateList.Items.Add(Name); PlateListWindow.listBoxPlateNameToProcess.Items.Add(Name); PlateListWindow.listBoxAvaliableListPlates.Items.Add(Name); } cGlobalInfo.CurrentScreening.CurrentDisplayPlateIdx = 0; cGlobalInfo.CurrentScreening.SetSelectionType(comboBoxClass.SelectedIndex - 1); UpdateUIAfterLoading(); cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate().DisplayDistribution(cGlobalInfo.CurrentScreening.ListDescriptors.GetActiveDescriptor(), false); }
private void SingleCellOperationsToDescriptorItem(object sender, EventArgs e) { List<string> ListNamesDesc = new List<string>(); foreach (var item in cGlobalInfo.CurrentScreening.ListDescriptors) { if (item.GetDataType() != "Single") { ListNamesDesc.Add(item.GetName()); } } FormForDescOperations MainWindow = new FormForDescOperations(ListNamesDesc); if (MainWindow.ShowDialog() != System.Windows.Forms.DialogResult.OK) return; string NewDescName = MainWindow.textBoxNewDescName.Text; cDescriptorType DescType1 = cGlobalInfo.CurrentScreening.ListDescriptors.GetDescriptorByName(MainWindow.comboBoxDescriptor1.Text); cDescriptorType DescType2 = cGlobalInfo.CurrentScreening.ListDescriptors.GetDescriptorByName(MainWindow.comboBoxDescriptor2.Text); if ((DescType1 == null) || (DescType2 == null)) return; FormForProgress ProgressWindow = new FormForProgress(); ProgressWindow.Show(); int IdxProgress = 1; int MaxProgress = cGlobalInfo.CurrentScreening.ListPlatesAvailable.Count; ProgressWindow.progressBar.Maximum = MaxProgress; cDescriptorType NewDescType = new cDescriptorType(NewDescName, true, 256, true); cGlobalInfo.CurrentScreening.ListDescriptors.AddNew(NewDescType); //HCSAnalyzer.Classes.General_Types.cDBConnection.cSingleCellOperations SCO = new HCSAnalyzer.Classes.General_Types.cDBConnection.cSingleCellOperations() cSingleCellOperations SingleCellOperation = new cSingleCellOperations(); if (MainWindow.tabControlMain.SelectedTab.Name == "tabPageBinary") { SingleCellOperation.ListDualOperations = new List<eBinaryOperationType>(); // eDualOperationType OperationType = eDualOperationType.ADD; switch (MainWindow.domainUpDown1.Text) { case "*": SingleCellOperation.ListDualOperations.Add(eBinaryOperationType.MULTIPLY); break; case "+": SingleCellOperation.ListDualOperations.Add(eBinaryOperationType.ADD); break; case "/": SingleCellOperation.ListDualOperations.Add(eBinaryOperationType.DIVIDE); break; case "-": SingleCellOperation.ListDualOperations.Add(eBinaryOperationType.SUBSTRACT); break; default: return; } if (MainWindow.checkBoxActivePostProcess.Checked) { SingleCellOperation.PostProcessingOperation = new List<eBinaryOperationType>(); switch (MainWindow.domainUpDownPostProcessOperator.Text) { case "*": SingleCellOperation.PostProcessingOperation.Add(eBinaryOperationType.MULTIPLY); break; case "+": SingleCellOperation.PostProcessingOperation.Add(eBinaryOperationType.ADD); break; case "/": SingleCellOperation.PostProcessingOperation.Add(eBinaryOperationType.DIVIDE); break; case "-": SingleCellOperation.PostProcessingOperation.Add(eBinaryOperationType.SUBSTRACT); break; default: return; } SingleCellOperation.PostProcessingValue = (double)MainWindow.numericUpDownPostProcessValue.Value; } foreach (cPlate CurrentPlate in cGlobalInfo.CurrentScreening.ListPlatesAvailable) { CurrentPlate.DBConnection.OpenConnection(); CurrentPlate.DBConnection.CreateNewColumn(NewDescType, DescType1, DescType2, SingleCellOperation, GlobalInfo, ref CurrentPlate.ListActiveWells); CurrentPlate.DBConnection.CloseConnection(); ProgressWindow.progressBar.Value = IdxProgress++; ProgressWindow.richTextBoxForComment.AppendText(CurrentPlate.GetShortInfo()); ProgressWindow.Refresh(); } } else { eUnaryOperationType OperationType = eUnaryOperationType.LOG; if (MainWindow.radioButtonSQRT.Checked) OperationType = eUnaryOperationType.SQRT; else if (MainWindow.radioButtonLog.Checked) OperationType = eUnaryOperationType.LOG; else if (MainWindow.radioButtonABS.Checked) OperationType = eUnaryOperationType.ABS; else if (MainWindow.radioButtonEXP.Checked) OperationType = eUnaryOperationType.EXP; foreach (cPlate CurrentPlate in cGlobalInfo.CurrentScreening.ListPlatesAvailable) { CurrentPlate.DBConnection.OpenConnection(); CurrentPlate.DBConnection.CreateNewColumn(NewDescType, DescType1, OperationType, GlobalInfo, ref CurrentPlate.ListActiveWells); CurrentPlate.DBConnection.CloseConnection(); ProgressWindow.progressBar.Value = IdxProgress++; ProgressWindow.richTextBoxForComment.AppendText(CurrentPlate.GetShortInfo()); ProgressWindow.Refresh(); } } ProgressWindow.Close(); int IdxNull = 0; foreach (cPlate TmpPlate in cGlobalInfo.CurrentScreening.ListPlatesActive) { foreach (cWell TmpWell in TmpPlate.ListActiveWells) if (TmpWell.ListSignatures.Count != cGlobalInfo.CurrentScreening.ListDescriptors.Count) IdxNull++; } if (IdxNull > 0) System.Windows.Forms.MessageBox.Show("List signature count is different from list descriptor count", "Critical Error !", MessageBoxButtons.OK, MessageBoxIcon.Error); cGlobalInfo.CurrentScreening.ListDescriptors.UpDateDisplay(); // CompleteScreening.UpDatePlateListWithFullAvailablePlate(); for (int idxP = 0; idxP < cGlobalInfo.CurrentScreening.ListPlatesAvailable.Count; idxP++) cGlobalInfo.CurrentScreening.ListPlatesActive[idxP].UpDataMinMax(); StartingUpDateUI(); this.toolStripcomboBoxPlateList.Items.Clear(); for (int IdxPlate = 0; IdxPlate < cGlobalInfo.CurrentScreening.ListPlatesActive.Count; IdxPlate++) { string Name = cGlobalInfo.CurrentScreening.ListPlatesActive.GetPlate(IdxPlate).GetName(); this.toolStripcomboBoxPlateList.Items.Add(Name); PlateListWindow.listBoxPlateNameToProcess.Items.Add(Name); PlateListWindow.listBoxAvaliableListPlates.Items.Add(Name); } cGlobalInfo.CurrentScreening.CurrentDisplayPlateIdx = 0; cGlobalInfo.CurrentScreening.SetSelectionType(comboBoxClass.SelectedIndex - 1); UpdateUIAfterLoading(); cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate().DisplayDistribution(cGlobalInfo.CurrentScreening.ListDescriptors.GetActiveDescriptor(), false); }