public FormForDescriptorInfo(cDescriptorType CurrentDesc) { this.CurrentDesc = CurrentDesc; InitializeComponent(); this.textBoxNameDescriptor.Text = CurrentDesc.GetName(); this.richTextBoxDescription.Text = CurrentDesc.description; this.labelDataType.Text = CurrentDesc.GetDataType(); if (CurrentDesc.GetDataType() == "Single") this.numericUpDownBinValue.Visible = false; this.numericUpDownBinValue.Value = CurrentDesc.GetBinNumber(); this.OriginalBinNumber = CurrentDesc.GetBinNumber(); if (CurrentDesc.IsConnectedToDatabase) { this.labelDataBaseConnection.Text = "DataBase Connection."; panelForColor.BackColor = Color.LightGreen; } else { this.labelDataBaseConnection.Text = "No DataBase connection."; panelForColor.BackColor = Color.Red; } }
public string GeneratePCADescriptor(cListPlates PlatesToProcess, int NumberOfAxis, int NeutralClass) { int NumWell = 0; int NumWellForLearning = 0; foreach (cPlate CurrentPlate in PlatesToProcess) { NumWellForLearning += CurrentPlate.GetNumberOfWellOfClass(NeutralClass); NumWell += cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate().GetNumberOfActiveWells(); } if (NumWellForLearning == 0) { MessageBox.Show("No well identified !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return null; } int NumDesc = cGlobalInfo.CurrentScreening.GetNumberOfActiveDescriptor(); if (NumDesc <= 1) { MessageBox.Show("More than one descriptor are required for this operation", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return null; } double[,] DataForLDA = new double[NumWellForLearning, cGlobalInfo.CurrentScreening.GetNumberOfActiveDescriptor() + 1]; // return; Matrix EigenVectors = PCAComputation(DataForLDA, NumWellForLearning, NumDesc, NeutralClass, PlatesToProcess); string AxeName = ""; int IDxDesc = 0; //for (int Desc = 0; Desc < CompleteScreening.ListDescriptors.Count; Desc++) //{ // if (CompleteScreening.ListDescriptors[Desc].IsActive() == false) continue; // AxeName += String.Format("{0:0.##}", EigenVectors.getElement(CompleteScreening.ListDescriptors.Count - 1, 0)) + "x" + CompleteScreening.ListDescriptorName[CompleteScreening.ListDescriptors.Count - 1]; //} int OriginalDescNumber = cGlobalInfo.WindowHCSAnalyzer.checkedListBoxActiveDescriptors.Items.Count; for (int AxesIdx = 0; AxesIdx < NumberOfAxis; AxesIdx++) { //for (int Idx = 0; Idx < CompleteScreening.GlobalInfo.WindowHCSAnalyzer.checkedListBoxActiveDescriptors.Items.Count; Idx++) //{ // if (CompleteScreening.ListDescriptors[Idx].IsActive()) // if (CompleteScreening.ListDescriptors[Idx].GetBinNumber() == 1) // { // AxeName += String.Format("{0:0.###}", EigenVectors.getElement(IDxDesc++, AxesIdx)) + "x" + CompleteScreening.ListDescriptors[Idx].GetName() + " + "; // } // else // { // MessageBox.Show("Descriptor length not consistent (" + CompleteScreening.ListDescriptors[Idx].GetName() + " : " + CompleteScreening.ListDescriptors[Idx].GetBinNumber() + " bins", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); // return ""; // } //} //cDescriptorsType ColumnType = new cDescriptorsType(AxeName.Remove(AxeName.Length - 3), true, 1); cDescriptorType ColumnType = new cDescriptorType("PCA_" + (AxesIdx + 1), true, 1); while (cGlobalInfo.CurrentScreening.ListDescriptors.AddNew(ColumnType) == false) { FormForNewDescName NewNameWindow = new FormForNewDescName(); NewNameWindow.textBoxName.Text = ColumnType.GetName(); if (NewNameWindow.ShowDialog() != System.Windows.Forms.DialogResult.OK) return ColumnType.GetName(); ColumnType.ChangeName(NewNameWindow.textBoxName.Text); } //CompleteScreening.ListDescriptors.AddNew(ColumnType); foreach (cPlate TmpPlate in cGlobalInfo.CurrentScreening.ListPlatesAvailable) { foreach (cWell Tmpwell in TmpPlate.ListActiveWells) { cListSignature LDesc = new cListSignature(); double NewValue = 0; IDxDesc = 0; // AxeName += "\nPCA_" + (AxesIdx + 1); for (int Idx = 0; Idx < OriginalDescNumber - 1; Idx++) { if (cGlobalInfo.CurrentScreening.ListDescriptors[Idx].IsActive()) // AxeName += String.Format("{0:0.###}", EigenVectors.getElement(IDxDesc, AxesIdx)) + "x" + CompleteScreening.ListDescriptors[Idx].GetName() + " + "; NewValue += EigenVectors.getElement(IDxDesc++, AxesIdx) * Tmpwell.ListSignatures[Idx].GetValue(); } cSignature NewDesc = new cSignature(NewValue, ColumnType, cGlobalInfo.CurrentScreening); LDesc.Add(NewDesc); Tmpwell.AddSignatures(LDesc); } } } cGlobalInfo.CurrentScreening.ListDescriptors.UpDateDisplay(); cGlobalInfo.CurrentScreening.UpDatePlateListWithFullAvailablePlate(); for (int idxP = 0; idxP < cGlobalInfo.CurrentScreening.ListPlatesActive.Count; idxP++) cGlobalInfo.CurrentScreening.ListPlatesActive[idxP].UpDataMinMax(); StartingUpDateUI(); return AxeName; }
public void ExportToHTML(cDescriptorType Desc) { if (Desc.IsConnectedToDatabase == false) return; List<cDescriptorType> LCDT = new List<cDescriptorType>(); LCDT.Add(Desc); List<cCellularPhenotype> ListCellularPhenotypesToBeSelected = new List<cCellularPhenotype>(); cGUI_ListClasses GUIClasses = new cGUI_ListClasses(); GUIClasses.IsCheckBoxes = true; GUIClasses.IsSelectAll = true; GUIClasses.ClassType = eClassType.PHENOTYPE; if (!GUIClasses.Run().IsSucceed) return; int IDx = 0; foreach (var item in cGlobalInfo.ListCellularPhenotypes) { if ((GUIClasses.GetOutPut()[0][IDx++] != 0)) ListCellularPhenotypesToBeSelected.Add(item); } cExtendedTable ET = new cExtendedTable(cGlobalInfo.CurrentScreening.Columns, cGlobalInfo.CurrentScreening.Rows, 0); ET.Name = this.Name + " [" + Desc.GetName() + "]"; ET.ListRowNames = new List<string>(); for (int i = 0; i < ET[0].Count; i++) { ET.ListRowNames.Add(((char)(i + 65)).ToString()); } FormForProgress MyProgressBar = new FormForProgress(); MyProgressBar.progressBar.Maximum = this.ListActiveWells.Count; MyProgressBar.Show(); //ET.ListTags = new List<object>(); for (int i = 0; i < cGlobalInfo.CurrentScreening.Columns; i++) { ET[i].ListTags = new List<object>(); ET[i].Name = (i + 1).ToString(); for (int j = 0; j < cGlobalInfo.CurrentScreening.Rows; j++) { MyProgressBar.progressBar.Update(); cWell TmpWell = this.GetWell(i, j, true); if (TmpWell == null) { ET[i].ListTags.Add("n.a."); continue; } MyProgressBar.progressBar.Value++; cExtendedTable TmpET = null; if (cGlobalInfo.OptionsWindow.FFAllOptions.checkBoxHTMLExportStackedHisto.Checked) TmpET = TmpWell.GetValuesList(LCDT, ListCellularPhenotypesToBeSelected, true); else TmpET = TmpWell.GetValuesList(LCDT, ListCellularPhenotypesToBeSelected, false); TmpET.Name = "[" + TmpWell.GetPos() + "] - " + TmpET[0].Count + " Objects"; // get the values associated to this well and descriptor if (cGlobalInfo.OptionsWindow.FFAllOptions.checkBoxHTMLExportStackedHisto.Checked) { cExtendedTable FinalTable = new cExtendedTable(); FinalTable.Name = "Stacked Histogram - " + this.GetName(); int Idx = 0; foreach (var item in cGlobalInfo.ListCellularPhenotypes) { FinalTable.Add(new cExtendedList()); FinalTable[Idx].Name = item.Name; FinalTable[Idx].Tag = item; for (int k = 0; k < TmpET[1].Count; k++) { if (TmpET[1][k] == Idx) FinalTable[Idx].Add(TmpET[0][k]); } Idx++; } cViewerStackedHistogram VSH = new cViewerStackedHistogram(); VSH.SetInputData(FinalTable);//TmpET); VSH.Chart.LabelAxisX = Desc.GetName(); VSH.Chart.IsLine = false; VSH.Chart.CurrentTitle.Text = TmpET.Name; if ((cGlobalInfo.OptionsWindow.radioButtonHistoDisplayManualMinMax.Checked) || (cGlobalInfo.OptionsWindow.radioButtonHistoDisplayAutomatedMinMax.Checked)) { VSH.Chart.DefaultAxisXMin = new cExtendedList(); VSH.Chart.DefaultAxisXMin.Add((double)cGlobalInfo.OptionsWindow.numericUpDownManualMin.Value); VSH.Chart.DefaultAxisXMax = new cExtendedList(); VSH.Chart.DefaultAxisXMax.Add((double)cGlobalInfo.OptionsWindow.numericUpDownManualMax.Value); if (cGlobalInfo.OptionsWindow.FFAllOptions.checkBoxHTMLExportBackColorClass.Checked) VSH.Chart.BackgroundColor = TmpWell.GetClassColor(); } VSH.Chart.BinNumber = Desc.GetBinNumber(); VSH.Chart.IsShadow = false; VSH.Chart.IsBorder = false; VSH.Run(); ET[i].ListTags.Add((Chart)VSH.Chart); } else { cViewerHistogram VH = new cViewerHistogram(); VH.SetInputData(TmpET); VH.Chart.LabelAxisX = Desc.GetName(); VH.Chart.CurrentTitle.Text = TmpET.Name; if ((cGlobalInfo.OptionsWindow.radioButtonHistoDisplayManualMinMax.Checked) || (cGlobalInfo.OptionsWindow.radioButtonHistoDisplayAutomatedMinMax.Checked)) { VH.Chart.DefaultAxisXMin = new cExtendedList(); VH.Chart.DefaultAxisXMin.Add((double)cGlobalInfo.OptionsWindow.numericUpDownManualMin.Value); VH.Chart.DefaultAxisXMax = new cExtendedList(); VH.Chart.DefaultAxisXMax.Add((double)cGlobalInfo.OptionsWindow.numericUpDownManualMax.Value); if (cGlobalInfo.OptionsWindow.FFAllOptions.checkBoxHTMLExportBackColorClass.Checked) VH.Chart.BackgroundColor = TmpWell.GetClassColor(); } VH.Run(); ET[i].ListTags.Add((Chart)VH.Chart); } } } MyProgressBar.Close(); cTableToHTML TToHTML = new cTableToHTML(); TToHTML.IsDisplayUIForFilePath = true; TToHTML.SetInputData(ET); TToHTML.Run(); }
public cExtendedTable GetAverageValueTable(cDescriptorType DescriptorType, bool OnlySelectedWells) { cExtendedTable DV = new cExtendedTable(ParentScreening.Columns, ParentScreening.Rows, double.NaN); DV.ListRowNames = new List<string>(); for (int i = 0; i < ParentScreening.Columns; i++) { DV[i].Name = (i + 1).ToString(); DV[i].ListTags = new List<object>(); for (int j = 0; j < ParentScreening.Rows; j++) { if (i == 0) { byte[] strArray = new byte[1]; strArray[0] = (byte)(j + 65); string Chara = Encoding.UTF7.GetString(strArray); DV.ListRowNames.Add(String.Format("{0}\t", Chara)); } cWell TmpWell = this.GetWell(i, j, OnlySelectedWells); if (TmpWell != null) { DV[i].ListTags.Add(TmpWell); DV[i][j] = TmpWell.GetAverageValue(DescriptorType); } } } DV.Name = this.GetName() + " - " + DescriptorType.GetName(); return DV; }
public void CreateNewColumnFromExisting(cDescriptorType NewDescType, string DescToBeDuplicated, cGlobalInfo GlobalInfo, ref cListWells ListWell) { this.CreateNewColumn(NewDescType.GetName(), 0); // cExtendedList ListResults = null; foreach (var item in GetListTableNames()) { SQLiteCommand mycommand = new SQLiteCommand(_SQLiteConnection); //update tableName set onefield = secondfield; string SQL = "UPDATE \"" + item + "\" SET \"" + NewDescType.GetName() + "\" = \"" + DescToBeDuplicated + "\""; using (SQLiteCommand Command = new SQLiteCommand(SQL, _SQLiteConnection)) { Command.ExecuteNonQuery(); } #region Update the screening data List<cDescriptorType> LDes = new List<cDescriptorType>(); LDes.Add(NewDescType); cExtendedTable LValues = this.GetWellValues(item, LDes); cListSignature LDesc = new cListSignature(); cSignature NewSignature = new cSignature(LValues[0], NewDescType.GetBinNumber(), NewDescType, cGlobalInfo.CurrentScreening); LDesc.Add(NewSignature); string[] Positions = item.Split('x'); ListWell.GetFirstWell(int.Parse(Positions[1]), int.Parse(Positions[2])).AddSignatures(LDesc); #endregion } return; }
public void CreateNewColumn(cDescriptorType NewDescType, cDescriptorType Desc0, eUnaryOperationType OperationType, cGlobalInfo GlobalInfo, ref cListWells ListWell) { string ColumnName = NewDescType.GetName(); int NumTableProcessed = 0; foreach (var item in GetListTableNames()) // loop over the wells { // compute the new values List<cDescriptorType> LDes = new List<cDescriptorType>(); LDes.Add(Desc0); // LDes.Add(Desc1); cExtendedTable LValues = this.GetWellValues(item, LDes); cExtendedList ListResults = new cExtendedList();// LValues[0].Operation(LValues[1], OperationType); if (OperationType == eUnaryOperationType.LOG) { for (int i = 0; i < LValues[0].Count; i++) { double tmpVal = LValues[0][i]; if (tmpVal <= 0) tmpVal = double.Epsilon; ListResults.Add(Math.Log10(tmpVal)); } } else if (OperationType == eUnaryOperationType.SQRT) { for (int i = 0; i < LValues[0].Count; i++) { double tmpVal = LValues[0][i]; if (tmpVal < 0) tmpVal = 0; ListResults.Add(Math.Sqrt(tmpVal)); } } else if (OperationType == eUnaryOperationType.ABS) { for (int i = 0; i < LValues[0].Count; i++) { double tmpVal = LValues[0][i]; ListResults.Add(Math.Abs(tmpVal)); } } else if (OperationType == eUnaryOperationType.EXP) { for (int i = 0; i < LValues[0].Count; i++) { double tmpVal = LValues[0][i]; ListResults.Add(Math.Exp(tmpVal)); } } #region Update the database // create new column SQLiteCommand mycommand = new SQLiteCommand(_SQLiteConnection); String SQL = "ALTER TABLE \"" + item + "\" ADD COLUMN \"" + ColumnName + "\" REAL DEFAULT 0"; using (SQLiteCommand Command = new SQLiteCommand(SQL, _SQLiteConnection)) { Command.ExecuteNonQuery(); } // write data using (SQLiteTransaction transaction = _SQLiteConnection.BeginTransaction()) using (SQLiteDataAdapter sqliteAdapter = new SQLiteDataAdapter("SELECT * FROM \"" + item + "\"", _SQLiteConnection)) { DataSet DS = new DataSet(); sqliteAdapter.Fill(DS); using (sqliteAdapter.InsertCommand = new SQLiteCommandBuilder(sqliteAdapter).GetUpdateCommand()) { for (int i = 0; i < DS.Tables[0].Rows.Count; i++) DS.Tables[0].Rows[i][ColumnName] = ListResults[i]; sqliteAdapter.Update(DS); } transaction.Commit(); } #endregion #region Update the screening data cListSignature LDesc = new cListSignature(); cSignature NewSignature = new cSignature(ListResults, 256, NewDescType, cGlobalInfo.CurrentScreening); LDesc.Add(NewSignature); string[] Positions = item.Split('x'); ListWell.GetFirstWell(int.Parse(Positions[1]), int.Parse(Positions[2])).AddSignatures(LDesc); #endregion NumTableProcessed++; } }
/// <summary> /// Create a new column in the database of the current plate /// </summary> /// <param name="ColumnName">Column name</param> /// <param name="DefaultValue">Array of values</param> /// <returns>Return the number of table (i.e. wells) processed</returns> public void CreateNewColumn(cDescriptorType NewDescType, cDescriptorType Desc0, cDescriptorType Desc1, cSingleCellOperations SingleCellOperations, cGlobalInfo GlobalInfo, ref cListWells ListWell) { string ColumnName = NewDescType.GetName(); int NumTableProcessed = 0; foreach (var item in GetListTableNames()) // loop over the wells { // compute the new values List<cDescriptorType> LDes = new List<cDescriptorType>(); LDes.Add(Desc0); LDes.Add(Desc1); cExtendedTable LValues = this.GetWellValues(item, LDes); cExtendedList ListResults = LValues[0].Operation(LValues[1], SingleCellOperations.ListDualOperations[0]); if ((SingleCellOperations.PostProcessingOperation != null) && (SingleCellOperations.PostProcessingOperation.Count > 0)) { switch (SingleCellOperations.PostProcessingOperation[0]) { case eBinaryOperationType.ADD: ListResults += SingleCellOperations.PostProcessingValue; break; case eBinaryOperationType.SUBSTRACT: ListResults -= SingleCellOperations.PostProcessingValue; break; case eBinaryOperationType.MULTIPLY: ListResults *= SingleCellOperations.PostProcessingValue; break; case eBinaryOperationType.DIVIDE: ListResults /= SingleCellOperations.PostProcessingValue; break; default: break; } } #region Update the database // create new column SQLiteCommand mycommand = new SQLiteCommand(_SQLiteConnection); String SQL = "ALTER TABLE \"" + item + "\" ADD COLUMN \"" + ColumnName + "\" REAL DEFAULT 0"; using (SQLiteCommand Command = new SQLiteCommand(SQL, _SQLiteConnection)) { Command.ExecuteNonQuery(); } // write data using (SQLiteTransaction transaction = _SQLiteConnection.BeginTransaction()) using (SQLiteDataAdapter sqliteAdapter = new SQLiteDataAdapter("SELECT * FROM \"" + item + "\"", _SQLiteConnection)) { DataSet DS = new DataSet(); sqliteAdapter.Fill(DS); using (sqliteAdapter.InsertCommand = new SQLiteCommandBuilder(sqliteAdapter).GetUpdateCommand()) { for (int i = 0; i < DS.Tables[0].Rows.Count; i++) DS.Tables[0].Rows[i][ColumnName] = ListResults[i]; sqliteAdapter.Update(DS); } transaction.Commit(); } #endregion #region Update the screening data cListSignature LDesc = new cListSignature(); cSignature NewSignature = new cSignature(ListResults, 256, NewDescType, cGlobalInfo.CurrentScreening); LDesc.Add(NewSignature); string[] Positions = item.Split('x'); cWell TmpWell = ListWell.GetFirstWell(int.Parse(Positions[1]), int.Parse(Positions[2])); if(TmpWell!=null) TmpWell.AddSignatures(LDesc); #endregion NumTableProcessed++; } }