Пример #1
0
            private void backgroundWorkerForCSVtoDB_DoWork(object sender, DoWorkEventArgs e)
            {
                BackgroundWorker worker = sender as BackgroundWorker;

                CSVsr = new CsvFileReader(PathName);
                CSVsr.Separator = this.Delimiter.ToCharArray()[0];
                CsvRow OriginalNames = new CsvRow();
                
                if (!CSVsr.ReadRow(OriginalNames))
                {
                    CSVsr.Close();
                    return;
                }

                int ColPlateName = GetColIdxFor("Plate name", CSVWindow);
                int ColCol = GetColIdxFor("Column", CSVWindow);
                int ColRow = GetColIdxFor("Row", CSVWindow);
                int ColWellPos = GetColIdxFor("Well position", CSVWindow);
                int ColPhenotypeClass = GetColIdxFor("Phenotype Class", CSVWindow);
                int[] ColsForDescriptors = GetColsIdxFor("Descriptor", CSVWindow);

                FormForProgress ProgressWindow = new FormForProgress();
                ProgressWindow.Text = "CSV -> DB : processing";
                ProgressWindow.Show();
                CsvRow CurrentDesc = new CsvRow();
                int TotalPlateNumber = 0;
                int TotalObjectNumber = 0;
                int TotalWellNumber = 0;
                string OriginalPlatePlateName;
                string CurrentPlateName;
                string ConvertedName;


                this.CompleteReportString += "Source file: " + PathName + "\n";
                this.CompleteReportString += OriginalNames.Count + " features selected.\n";
                this.CompleteReportString += "Time stamp: " + DateTime.Now.ToString() + " \n";

                if (CSVsr.ReadRow(CurrentDesc) == false) return;
                do
                {
                    if (ColPlateName == -1)
                    {
                        ConvertedName = OriginalPlatePlateName = CurrentPlateName = "Generated Plate Name";
                    }
                    else
                    {
                        OriginalPlatePlateName = CurrentDesc[ColPlateName];
                        CurrentPlateName = CurrentDesc[ColPlateName];
                        ConvertedName = "";

                        foreach (var c in System.IO.Path.GetInvalidFileNameChars())
                            ConvertedName = OriginalPlatePlateName.Replace(c, '-');
                    }

                    List<string> ListNameSignature = new List<string>();

                    for (int idxDesc = 0/*Mode + 1*/; idxDesc < ColsForDescriptors.Length/* + Mode + 1*/; idxDesc++)
                    {
                        string TmpSignature = OriginalNames[ColsForDescriptors[idxDesc]];
                        TmpSignature = TmpSignature.Replace('[', '_');
                        TmpSignature = TmpSignature.Replace(']', '_');

                        ListNameSignature.Add(TmpSignature);
                    }
                    ListNameSignature.Add("Phenotype_Class");
                    ListNameSignature.Add("Phenotype_Confidence");
                    cSQLiteDatabase SQDB = new cSQLiteDatabase(SelectedPath + "\\" + ConvertedName, ListNameSignature, true);

                    this.CompleteReportString += "\n" + CurrentPlateName + ":\n";
                    TotalPlateNumber++;

                    do
                    {
                        string OriginalWellPos;
                        int[] Pos = new int[2];

                        if (Mode == 1)
                        {
                            Pos = ConvertPosition(CurrentDesc[ColWellPos]);
                            if (Pos == null)
                            {
                                if (MessageBox.Show("Error in converting the current well position.\nGo to Edit->Options->Import-Export->Well Position Mode to fix this.\nDo you want continue ?", "Loading error !", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.No)
                                {
                                    CSVsr.Close();
                                    return;
                                }
                                //else
                                //    goto NEXTLOOP;
                            }
                            OriginalWellPos = CurrentDesc[ColWellPos];
                        }
                        else
                        {
                            if (int.TryParse(CurrentDesc[ColCol], out Pos[0]) == false)
                                goto NEXTLOOP;
                            if (int.TryParse(CurrentDesc[ColRow], out Pos[1]) == false)
                                goto NEXTLOOP;

                            OriginalWellPos = ConvertPosition(int.Parse(CurrentDesc[ColCol]), int.Parse(CurrentDesc[ColRow]));// "("+CurrentDesc[ColCol]+","+CurrentDesc[ColRow]+")";
                        }

                        string CurrentWellPos = OriginalWellPos;

                        cWellForDatabase WellForDB = new cWellForDatabase(OriginalPlatePlateName, Pos[0], Pos[1]);
                        cExtendedTable ListData = new cExtendedTable();
                        //   for (int idxDesc = 0; idxDesc < ColsForDescriptors.Length; idxDesc++)
                        //   ListData[idxDesc] = new List<double>();

                        ProgressWindow.richTextBoxForComment.AppendText(CurrentPlateName + " : " + CurrentWellPos + "\n");
                        //ProgressWindow.label.Refresh();
                        ProgressWindow.Refresh();

                        do
                        {
                            //  CurrentWellPos = CurrentDesc[ColWellPos];
                            cExtendedList Signature = new cExtendedList();

                            for (int idxDesc = 0; idxDesc < ColsForDescriptors.Length; idxDesc++)
                            {
                                double Value;

                                if (double.TryParse(CurrentDesc[ColsForDescriptors[idxDesc]], NumberStyles.Any, CultureInfo.InvariantCulture/*.CreateSpecificCulture("en-US")*/, out Value))
                                {
                                    if (double.IsNaN(Value))
                                        Signature.Add(0);
                                    else
                                        Signature.Add(Value);
                                }
                                else
                                {
                                    Signature.Add(0);
                                }

                            }
                            // if the class of the phenotype is defined in the file then use it
                            // if not, put it at 0
                            double ValueClass;
                            if ((ColPhenotypeClass != -1) && (double.TryParse(CurrentDesc[ColPhenotypeClass], out ValueClass) == true))
                            {
                                double IntValue = (int)(ValueClass) % cGlobalInfo.ListCellularPhenotypes.Count;
                                Signature.Add(IntValue);
                            }
                            else
                            {
                                Signature.Add(0);
                            }

                            // finally add the classification confidence column (1 by default)
                            Signature.Add(1);

                            ListData.Add(Signature);
                            // WellForDB.AddSignature(Signature);
                            // manage the end of the file
                            if (CSVsr.ReadRow(CurrentDesc) == false)
                            {
                                WellForDB.AddListSignatures(ListData);
                                cFeedBackMessage FeedBackMessage = SQDB.AddNewWell(WellForDB);
                                SQDB.CloseConnection();
                                // this.CompleteReportString += FeedBackMessage.Message + "\n";
                                goto NEXTLOOP;
                            }
                            if (ColPlateName == -1)
                                CurrentPlateName = "Generated Plate Name";
                            else
                                CurrentPlateName = CurrentDesc[ColPlateName];

                            if (Mode == 1)
                                CurrentWellPos = CurrentDesc[ColWellPos];
                            else
                            {
                                int ResCol;
                                int ResRow;
                                if ((!int.TryParse(CurrentDesc[ColCol], out ResCol)) || (!int.TryParse(CurrentDesc[ColRow], out ResRow))) goto NEXTLOOP;

                                CurrentWellPos = ConvertPosition(ResCol, ResRow);
                            }

                            TotalObjectNumber++;

                            // NEXTSIGNATURE: ;

                        } while (CurrentWellPos == OriginalWellPos);

                        TotalWellNumber++;

                        WellForDB.AddListSignatures(ListData);
                        SQDB.AddNewWell(WellForDB);

                        ReportTable.ListRowNames.Add(CurrentPlateName + " : " + CurrentWellPos);
                        ReportTable[0].Add(ListData.Count);
                        ReportTable[0].ListTags.Add(CurrentPlateName + " : " + CurrentWellPos + "\n" + ListData.Count + " objects");
                        this.CompleteReportString += "\t" + CurrentWellPos + " : " + ListData.Count + " objects\n";

                    NEXTSIGNATURE: ;

                    } while (OriginalPlatePlateName == CurrentPlateName);

                    SQDB.CloseConnection();
                } while (true);

            NEXTLOOP: ;
                ProgressWindow.Close();

                this.CompleteReportString += "\n-----------------------------\n";
                this.CompleteReportString += TotalPlateNumber + " plates\n";
                this.CompleteReportString += TotalWellNumber + " wells\n";
                this.CompleteReportString += TotalObjectNumber + " objects\n";
                this.CompleteReportString += "\nDataBase location:\n" + SelectedPath;
                //    worker.ReportProgress(10);
            }
Пример #2
0
        private void HarmonyToDB(string DefaultPath)
        {
            #region Get the directory
            if (!Directory.Exists(DefaultPath)) DefaultPath = "";

            var dlg1 = new Ionic.Utils.FolderBrowserDialogEx();
            dlg1.Description = "Select the folder of your experiment.";
            dlg1.ShowNewFolderButton = true;
            dlg1.ShowEditBox = true;
            if (DefaultPath != "")
                dlg1.SelectedPath = DefaultPath;
            //dlg1.NewStyle = false;
            //dlg1.SelectedPath = txtExtractDirectory.Text;
            dlg1.ShowFullPathInEditBox = true;
            dlg1.RootFolder = System.Environment.SpecialFolder.Desktop;

            // Show the FolderBrowserDialog.
            DialogResult result = dlg1.ShowDialog();
            if (result != DialogResult.OK) return;

            string Path = dlg1.SelectedPath;

            if (Directory.Exists(Path) == false) return;
            #endregion

            #region Get the different files

            string[] ListFilesForPlates = null;
            try
            {
                ListFilesForPlates = Directory.GetFiles(Path, "Objects_Population - *.txt", SearchOption.AllDirectories);
            }
            catch (System.Exception excep)
            {
                MessageBox.Show(excep.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            if (ListFilesForPlates.Length == 0)
            {
                MessageBox.Show("The selected directory do not contain any Objects_Population files !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            string[] Sep = new string[1];
            Sep[0] = "\\";

            Dictionary<string, string> CurrentPlateDico = new Dictionary<string, string>();
          //  string[] FirstListImages = Directory.GetFiles(PlateDirectories[i], TmpPlateName + "_*.C01", SearchOption.AllDirectories);

            foreach (var item in ListFilesForPlates)
            {
                string[] Res = item.Split(Sep, StringSplitOptions.RemoveEmptyEntries);
                string CurrentName = Res[Res.Length-1];

                if (CurrentPlateDico.ContainsKey(CurrentName.Remove(CurrentName.Length - 4))) continue;

                CurrentPlateDico.Add(CurrentName.Remove(CurrentName.Length-4), item);

            }

            string[] ListTypes = CurrentPlateDico.Keys.ToArray();

            // plates selection GUI
            FormForPlateSelection FFP = new FormForPlateSelection(ListTypes,false);
            FFP.Text = "Object Types Selection";

            if (FFP.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
            ListFilesForPlates = FFP.GetListPlatesSelected();

            #endregion

            if (ListFilesForPlates.Length == 0) return;

            ListFilesForPlates = Directory.GetFiles(Path, ListFilesForPlates[0] + ".txt", SearchOption.AllDirectories);

            #region And now let's analyse the files adn create the CSV

            CsvRow CurrentRow = new CsvRow();

            bool IsHeaderWritten = false;
            string OriginalHeader = "";

            Sep[0] = "\\";
            string[] TmpSplit = ListFilesForPlates[0].Split(Sep, StringSplitOptions.RemoveEmptyEntries);

           //TmpSplit[TmpSplit.Length-1].Replace(".txt",".csv");
            string TPath = Path + "\\" + TmpSplit[TmpSplit.Length - 1].Replace(".txt", ".csv");
                
            Sep[0] = ",";  // specifically for the bounding box processing

            FormForProgress MyProgressBar = new FormForProgress();

            MyProgressBar.progressBar.Maximum = ListFilesForPlates.Length;
            MyProgressBar.Show();


            for (int i = 0; i < ListFilesForPlates.Length ; i++)
            {
                MyProgressBar.richTextBoxForComment.AppendText(ListFilesForPlates[i]);
                MyProgressBar.richTextBoxForComment.Update();

                StreamWriter stream = new StreamWriter(TPath, true, Encoding.ASCII);
                
                #region process the header
                string CurrentFile = ListFilesForPlates[i];
                CsvFileReader CSVReader = new CsvFileReader(CurrentFile);
                CSVReader.Separator = '\t';
                
                CSVReader.ReadRow(CurrentRow);
                // let's take care of the header first
                while (CurrentRow[0]!="Plate Name")
                {
                    CSVReader.ReadRow(CurrentRow);
                }

                string PlateName = CurrentRow[1];

                // skip the rest of the header
                while (CurrentRow[0] != "[Data]")
                {
                    CSVReader.ReadRow(CurrentRow);
                }

                // read the columns names
                CSVReader.ReadRow(CurrentRow);
                List<string> Descs = CurrentRow;

                string TobeWritten = "Plate Name,";
                int IdxBoundingBox = -1;
                int IndexCol = -1;
                int IndexRow = -1;
                int IndexCompound = -1;
                int IndexConcentration = -1;
                int IndexCellcount = -1;
                
                int NumDesc = Descs.Count;

                for (int j = 0; j < Descs.Count; j++)
			    {
                    if (Descs[j] == "Bounding Box")
                    {
                        TobeWritten += "X_Min,Y_Min,X_Max,Y_Max,";
                        IdxBoundingBox = j;
                       // NumDesc += 3; 
                    }
                    else if (Descs[j] == "Row")
                    {
                        IndexRow = j;
                        TobeWritten += "Well Position,";
                    }
                    else if (Descs[j] == "Column")
                    {
                        IndexCol = j;
                    }
                    else if (Descs[j] == "Compound")
                    {
                        // skipped
                        IndexCompound = j;
                    }
                    else if (Descs[j] == "Concentration")
                    {
                        // skipped
                        IndexConcentration = j;
                    }
                    else if (Descs[j] == "Cell Count")
                    {
                        // skipped
                        IndexCellcount = j;
                    }
                    else
                        TobeWritten += Descs[j] + ",";
			 
			    }

                TobeWritten = TobeWritten.Remove(TobeWritten.Length - 1);

                if (IsHeaderWritten == false)
                {
                    OriginalHeader = TobeWritten;
                    stream.WriteLine(TobeWritten);
                    IsHeaderWritten = true;
                }
                else
                {
                    // inconsistency between the headers... skip the plate
                    if (TobeWritten != OriginalHeader)
                    {
                        continue;
                    }
                }

                #endregion

                // now let's process the data
                int IdxRow = 0;
                while (!CSVReader.EndOfStream)
                {
                    CSVReader.ReadRow(CurrentRow);
                    TobeWritten = PlateName+",";
                    for (int j = 0; j < Descs.Count; j++)
                    {
                        if ((IdxBoundingBox > -1) && (j == IdxBoundingBox))
                        {
                            // let's process the bounding box
                            string BB = CurrentRow[j];
                            BB = BB.Remove(BB.Length - 1);
                            BB = BB.Remove(0, 1);

                            string[] Splitted = BB.Split(Sep, StringSplitOptions.None);
                            TobeWritten += Splitted[0] + "," + Splitted[1] + "," + Splitted[2] + "," + Splitted[3] + ",";
                            // j += 3;
                        }
                        else if (j == IndexRow)
                        {
                            TobeWritten += ConvertPosition(int.Parse(CurrentRow[IndexCol]), int.Parse(CurrentRow[IndexRow]))+",";
                        }
                        else if ((j == IndexCol)||(j==IndexCellcount)||(j==IndexCompound)||(j==IndexConcentration))
                        {
                            // do nothing
                        }
                        else
                        {
                            if (CurrentRow[j] != "")
                                TobeWritten += CurrentRow[j] + ",";
                            else
                                TobeWritten += "NaN,";
                        }

                    }
                    TobeWritten = TobeWritten.Remove(TobeWritten.Length - 1);
                    stream.WriteLine(TobeWritten );
                    IdxRow++;
                }

                CSVReader.Close();
                stream.Dispose();
                MyProgressBar.progressBar.Value++;
                MyProgressBar.progressBar.Update();
            }
            MyProgressBar.Close();
            #endregion

            #region let's build the database now

            // if (CSVFeedBackWindow == null) return;
            // if (CSVFeedBackWindow.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
            string DBPath = Path + "\\DB";
            Directory.CreateDirectory(DBPath);
            cConvertCSVtoDB CCTODB = CSVtoDB(TPath, ",", DBPath);
            if (CCTODB == null)
            {
                return;
            }
            else
            {
                // update image accessor
                cGlobalInfo.OptionsWindow.radioButtonImageAccessDefined.Checked = false;
                cGlobalInfo.OptionsWindow.radioButtonImageAccessHarmony35.Checked = true;
                cGlobalInfo.OptionsWindow.textBoxImageAccesImagePath.Text = Path;

                cGlobalInfoToBeExported GlobalInfoToBeExported = new cGlobalInfoToBeExported();
                cGlobalInfo.OptionsWindow.TmpOptionPath = GlobalInfoToBeExported.Save(DBPath+"\\Options.opt");

                //cGlobalInfo.OptionsWindow.sav
            }

            #endregion
        }
Пример #3
0
        private void TSItemSubPopSelectionDataTableImages(object sender, EventArgs e)
        {
            ToolStripMenuItem ParentTag = (ToolStripMenuItem)(sender);
            List<int> MyList = ((List<int>)(ParentTag.Tag));

            cExtendedTable ET = new cExtendedTable(this.InputSimpleData.Count, MyList.Count, 0);

            for (int i = 0; i < this.InputSimpleData.Count; i++)
            {
                ET[i].Name = this.InputSimpleData[i].Name;
            }

            ET.ListRowNames = new List<string>();
            for (int i = 0; i < MyList.Count; i++)
            {
                ET.ListRowNames.Add(i.ToString());
            }

            if (this.InputSimpleData.ListTags != null) ET.ListTags = new List<object>();

            int IdxPt = 0;

            FormForProgress FP = new FormForProgress();
            FP.Show();

            int MaxProgress = MyList.Count;
            FP.progressBar.Maximum = MaxProgress;

            foreach (var item in MyList)
            {
                for (int i = 0; i < this.InputSimpleData.Count; i++)
                {
                    ET[i][IdxPt] = this.InputSimpleData[i][MyList[IdxPt]];
                }

                if ((this.InputSimpleData.ListTags != null) && (this.InputSimpleData.ListTags[IdxPt] != null))
                {
                    if (this.InputSimpleData.ListTags[MyList[IdxPt]].GetType() == typeof(cSingleBiologicalObject))
                    {
                        cSingleBiologicalObject TmpBioObj = ((cSingleBiologicalObject)this.InputSimpleData.ListTags[MyList[IdxPt]]);
                        List<cImageMetaInfo> ListMeta = cGlobalInfo.ImageAccessor.GetImageInfo(TmpBioObj);
                        if (ListMeta==null) continue;
                        cImage Image = new cImage(ListMeta);
                        TmpBioObj.BD_BoxMax.Z = TmpBioObj.BD_BoxMin.Z = 0;
                        cImage CroppedImaged = Image.Crop(TmpBioObj.BD_BoxMin, TmpBioObj.BD_BoxMax);

                        if((cGlobalInfo.TmpImageDisplayProperties==null)||(cGlobalInfo.TmpImageDisplayProperties.ListMin.Count != CroppedImaged.GetNumChannels()))
                        {
                            ET.ListTags.Add(CroppedImaged.GetBitmap(1f, null, null));
                        }
                        else
                        {
                            cImageDisplayProperties IP = cGlobalInfo.TmpImageDisplayProperties;
                            ET.ListTags.Add(CroppedImaged.GetBitmap(1f, IP, null));
                        }

                        FP.richTextBoxForComment.AppendText("Object "+ IdxPt +" / "+MyList.Count +"\n");
                    }

                }
                FP.progressBar.Value = IdxPt;

                FP.Refresh();
                IdxPt++;
            }

            FP.Close();

            ET.Name = "Data Table - " + MyList.Count + " Objects";
            cDisplayExtendedTable DET = new cDisplayExtendedTable();
            DET.SetInputData(ET);
            DET.Run();

            //DataPoint DP = new DataPoint();

            //if (this.InputSimpleData[0].ListTags != null)
            //{
            //    if (j >= this.InputSimpleData[0].ListTags.Count) continue;
            //    DP.Tag = this.InputSimpleData[0].ListTags[j];

            //    //    if (DP.Tag.GetType() == typeof(cWell))
            //    //    {
            //    //        DP.Color = ((cWell)(DP.Tag)).GetClassColor();
            //    //        DP.ToolTip = ((cWell)(DP.Tag)).GetShortInfo() + Value[0];
            //    //    }
            //    if (DP.Tag.GetType() == typeof(cSingleBiologicalObject))
            //    {
            //        //        DP.Color = ((cSingleBiologicalObject)(DP.Tag)).GetColor();
            //        //        DP.ToolTip = ((cSingleBiologicalObject)(DP.Tag)).GetAssociatedPhenotype().Name + "\nValue: (" + DP.XValue.ToString("N2") + ":" + DP.YValues[0].ToString("N2") + ")";

            //    }
            //}
        }
Пример #4
0
        private void generateDBFromCSVToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog CurrOpenFileDialog = new OpenFileDialog();
            CurrOpenFileDialog.Filter = "csv files (*.csv)|*.csv";//|db files (*.db)|*.db|nc files (*.nc)|*.nc
            CurrOpenFileDialog.Multiselect = false;

            DialogResult Res = CurrOpenFileDialog.ShowDialog();
            if (Res != DialogResult.OK) return;

            FormForImportExcel CSVWindow = CellByCellFromCSV(CurrOpenFileDialog.FileNames[0]);

            if (CSVWindow == null) return;
            if (CSVWindow.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;

            if (CompleteScreening != null) CompleteScreening.Close3DView();

            FolderBrowserDialog WorkingFolderDialog = new FolderBrowserDialog();
            WorkingFolderDialog.ShowNewFolderButton = true;
            WorkingFolderDialog.Description = "Select the working directory";
            if (WorkingFolderDialog.ShowDialog() != DialogResult.OK) return;

            //if (IsFileUsed(CurrOpenFileDialog.FileNames[0]))
            //{
            //    MessageBox.Show("File currently used by another application.\n", "Loading error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    return;
            //}

            //Microsoft.Research.Science.Data.DataSet Datacsv = Microsoft.Research.Science.Data.CSV.CsvDataSet.Open(CurrOpenFileDialog.FileNames[0]);

            //int NumDesc = Datacsv.Variables.Count;

            //for (int IdxDesc = 0; IdxDesc < NumDesc; IdxDesc++)
            //{
            //    var DescInfo = Datacsv.Variables[IdxDesc];
            //    string NameDesc = DescInfo.Name;

            //    var TypeData = DescInfo.TypeOfData;
            //    string DataName = TypeData.Name;
            //}

            int NumPlateName = 0;
            int NumRow = 0;
            int NumCol = 0;
            int NumWellPos = 0;
            // int NumLocusID = 0;
            // int NumConcentration = 0;
            //  int NumName = 0;
            //   int NumInfo = 0;
            //   int NumClass = 0;

            int numDescritpor = 0;

            for (int i = 0; i < CSVWindow.dataGridViewForImport.Rows.Count; i++)
            {
                string CurrentVal = CSVWindow.dataGridViewForImport.Rows[i].Cells[2].Value.ToString();
                if ((CurrentVal == "Plate name") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value))
                    NumPlateName++;
                if ((CurrentVal == "Row") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value))
                    NumRow++;
                if ((CurrentVal == "Column") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value))
                    NumCol++;
                if ((CurrentVal == "Well position") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value))
                    NumWellPos++;
                if ((CurrentVal == "Descriptor") && ((bool)CSVWindow.dataGridViewForImport.Rows[i].Cells[1].Value))
                    numDescritpor++;
            }

            if (NumPlateName != 1)
            {
                MessageBox.Show("One and only one \"Plate Name\" has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if ((NumRow != 1) && (GlobalInfo.OptionsWindow.radioButtonWellPosModeDouble.Checked == true))
            {
                MessageBox.Show("One and only one \"Row\" has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if ((NumCol != 1) && (GlobalInfo.OptionsWindow.radioButtonWellPosModeDouble.Checked == true))
            {
                MessageBox.Show("One and only one \"Column\" has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if ((NumWellPos != 1) && (GlobalInfo.OptionsWindow.radioButtonWellPosModeSingle.Checked == true))
            {
                MessageBox.Show("One and only one \"Well position\" has to be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if ((numDescritpor < 1) && (CSVWindow.IsImportCSV))
            {
                MessageBox.Show("You need to select at least one \"Descriptor\" !", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int Mode = 2;
            if (GlobalInfo.OptionsWindow.radioButtonWellPosModeSingle.Checked) Mode = 1;
            CsvFileReader CSVsr = new CsvFileReader(CurrOpenFileDialog.FileNames[0]);

            CsvRow OriginalNames = new CsvRow();
            if (!CSVsr.ReadRow(OriginalNames))
            {
                CSVsr.Close();
                return;
            }

            int ColPlateName = GetColIdxFor("Plate name", CSVWindow);
            int ColCol = GetColIdxFor("Column", CSVWindow);
            int ColRow = GetColIdxFor("Row", CSVWindow);
            int ColWellPos = GetColIdxFor("Well position", CSVWindow);
            int[] ColsForDescriptors = GetColsIdxFor("Descriptor", CSVWindow);

            int WellLoaded = 0;
            int FailToLoad = 0;

            //  CompleteScreening.Columns = (int)CSVWindow.numericUpDownColumns.Value;
            //  CompleteScreening.Rows = (int)CSVWindow.numericUpDownRows.Value;
            //  CompleteScreening.ListDescriptors.Clean();

            FormForProgress ProgressWindow = new FormForProgress();
            ProgressWindow.Show();
            CsvRow CurrentDesc = new CsvRow();
            if (CSVsr.ReadRow(CurrentDesc) == false) return;
            do
            {

                string OriginalPlatePlateName = CurrentDesc[ColPlateName];
                string CurrentPlateName = CurrentDesc[ColPlateName];
                string ConvertedName = "";

                foreach (var c in System.IO.Path.GetInvalidFileNameChars())
                {
                    ConvertedName = OriginalPlatePlateName.Replace(c, '-');
                }

                List<string> ListNameSignature = new List<string>();

                for (int idxDesc = Mode + 1; idxDesc < ColsForDescriptors.Length + Mode + 1; idxDesc++)
                    ListNameSignature.Add(OriginalNames[idxDesc]);

                cSQLiteDatabase SQDB = new cSQLiteDatabase(WorkingFolderDialog.SelectedPath + "\\" + ConvertedName, ListNameSignature, true);

                do
                {
                    string OriginalWellPos = CurrentDesc[ColWellPos];
                    string CurrentWellPos = OriginalWellPos;
                    int[] Pos = new int[2];
                    if (Mode == 1)
                    {
                        Pos = ConvertPosition(CurrentDesc[ColWellPos]);
                        if (Pos == null)
                        {
                            if (MessageBox.Show("Error in converting the current well position.\nGo to Edit->Options->Import-Export->Well Position Mode to fix this.\nDo you want continue ?", "Loading error !", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == System.Windows.Forms.DialogResult.No)
                            {
                                CSVsr.Close();
                                return;
                            }
                            //else
                            //    goto NEXTLOOP;
                        }

                    }
                    else
                    {
                        //if (int.TryParse(CurrentDesc[ColCol], out Pos[0]) == false)
                        //  //  goto NEXTLOOP;
                        //if (int.TryParse(CurrentDesc[ColRow], out Pos[1]) == false)
                        //  goto NEXTLOOP;
                    }
                    cWellForDatabase WellForDB = new cWellForDatabase(OriginalPlatePlateName, Pos[0], Pos[1]);
                    List<List<double>> ListData = new List<List<double>>();
                    //   for (int idxDesc = 0; idxDesc < ColsForDescriptors.Length; idxDesc++)
                    //   ListData[idxDesc] = new List<double>();

                    ProgressWindow.label.Text = OriginalWellPos;
                    ProgressWindow.label.Refresh();

                    do
                    {
                        //  CurrentWellPos = CurrentDesc[ColWellPos];
                        List<double> Signature = new List<double>();

                        for (int idxDesc = 0; idxDesc < ColsForDescriptors.Length; idxDesc++)
                        {
                            double Value;
                            if ((double.TryParse(CurrentDesc[ColsForDescriptors[idxDesc]], out Value)) && (!double.IsNaN(Value)))
                            {
                                //cDescriptor CurrentDescriptor = new cDescriptor(Value, CompleteScreening.ListDescriptors[idxDesc/* + ShiftIdx*/], CompleteScreening);
                                Signature.Add(Value);
                            }
                            /*else
                            {
                                FailToLoad++;
                                goto NEXTLOOP;
                            }*/
                        }

                        ListData.Add(Signature);

                        // WellForDB.AddSignature(Signature);

                        if (CSVsr.ReadRow(CurrentDesc) == false)
                        {
                            WellForDB.AddListSignatures(ListData);
                            SQDB.AddNewWell(WellForDB);
                            SQDB.CloseConnection();
                            goto NEXTLOOP;
                        }
                        CurrentPlateName = CurrentDesc[ColPlateName];
                        CurrentWellPos = CurrentDesc[ColWellPos];
                    } while (CurrentWellPos == OriginalWellPos);

                    WellForDB.AddListSignatures(ListData);
                    SQDB.AddNewWell(WellForDB);

                } while (OriginalPlatePlateName == CurrentPlateName);

                SQDB.CloseConnection();
            } while (true);

            NEXTLOOP: ;
            ProgressWindow.Close();

            FormForPlateDimensions PlateDim = new FormForPlateDimensions();
            PlateDim.Text = "Load generated screening";
            PlateDim.checkBoxAddCellNumber.Visible = true;
            PlateDim.checkBoxIsOmitFirstColumn.Visible = true;
            PlateDim.labelHisto.Visible = true;
            PlateDim.numericUpDownHistoSize.Visible = true;

            if (PlateDim.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return;
            LoadCellByCellDB(PlateDim, WorkingFolderDialog.SelectedPath);
        }
Пример #5
0
        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);
        }
Пример #6
0
        public cFeedBackMessage Run()
        {
            if (this.Input == null)
            {
                FeedBackMessage.IsSucceed = false;
                FeedBackMessage.Message = "No input data defined.";
                return FeedBackMessage;
            }

            if (FilePath == "")
            {
                // user interface for file selection
                SaveFileDialog CurrSaveFileDialog = new SaveFileDialog();
                CurrSaveFileDialog.Filter = "CSV file (*.csv)|*.csv";
                System.Windows.Forms.DialogResult Res = CurrSaveFileDialog.ShowDialog();
                if (Res != System.Windows.Forms.DialogResult.OK)
                    return new cFeedBackMessage(false,this);
                FilePath = CurrSaveFileDialog.FileName;
            }

            try
            {
                using (FileStream fs = new FileStream(FilePath, FileMode.OpenOrCreate))
                {
                }
            }
            catch (IOException ex)
            {
                MessageBox.Show("File currently used by another application.\n", "Saving error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return new cFeedBackMessage(false,this);
            }

            // create the file
            string separator = ",";
            List<cDescriptorType> ListSelectedDesc = cGlobalInfo.CurrentScreening.ListDescriptors.GetActiveSingleCellDescriptors();

            if (ListSelectedDesc.Count == 0)
            {
                MessageBox.Show("No single cell based descriptor selected.\n", "Saving error !", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return new cFeedBackMessage(false, this);
            }

            FormForProgress MyProgressBar = new FormForProgress();
            MyProgressBar.progressBar.Maximum = this.Input.Count;

            MyProgressBar.Show();

            using (StreamWriter myFile = new StreamWriter(FilePath, false, Encoding.Default))
            {
                string HeaderToBeWritten = "Plate,Well,";
                for (int i = 0; i < ListSelectedDesc.Count; i++)
                {
                    HeaderToBeWritten += ListSelectedDesc[i].GetName() + separator;
                }
                HeaderToBeWritten += "Phenotype_Class";
                myFile.WriteLine(HeaderToBeWritten);

                int IdxWell = 0;
                foreach(cWell TmpWell in this.Input)
                {
                    cListWells TmpList = new cListWells(TmpWell);

                    // this table should contain all the selected descriptor values and the phenotypic classes
                    cExtendedTable CompleteTable = TmpList.GetSingleObjectDescriptorValuesFull(ListSelectedDesc);

                    HeaderToBeWritten = TmpWell.AssociatedPlate.GetName() + separator;
                    HeaderToBeWritten += TmpWell.GetPos() + separator;

                    for (int Row = 0; Row < CompleteTable[0].Count; Row++)
                    {
                        string ToBeWritten = HeaderToBeWritten;

                        for (int i = 0; i < CompleteTable.Count - 1; i++)
                            ToBeWritten += CompleteTable[i][Row] + separator;

                        ToBeWritten += CompleteTable[CompleteTable.Count - 1][Row];
                        myFile.WriteLine(ToBeWritten);
                    }

                    MyProgressBar.progressBar.Value = IdxWell++;
                    MyProgressBar.richTextBoxForComment.Text = TmpWell.GetShortInfo();
                    MyProgressBar.Update();
                }
                myFile.Close();
            }

            MyProgressBar.Close();

            return FeedBackMessage;
        }
Пример #7
0
        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);
        }
Пример #8
0
        private void SubPopulationStatDescItem(object sender, EventArgs e)
        {
            PanelForClassSelection ClassSelectionPanel = new PanelForClassSelection(true, eClassType.PHENOTYPE);
            //ClassSelectionPanel.Height = WindowToDisplay.Height;
            ClassSelectionPanel.UnSelectAll();
            ClassSelectionPanel.Select(0);
            ClassSelectionPanel.Select(1);
            ClassSelectionPanel.Location = new System.Drawing.Point(10, 10);
            ClassSelectionPanel.Width = 150;
            ClassSelectionPanel.Height = ClassSelectionPanel.ListCheckBoxes.Count * 25;
            ClassSelectionPanel.BorderStyle = BorderStyle.Fixed3D;

            FormForStatDesc NewWindow = new FormForStatDesc(this.GlobalInfo);
            NewWindow.panelForSubPopulation.Controls.Add(ClassSelectionPanel);
            NewWindow.textBoxDescName.Text = cGlobalInfo.CurrentScreening.ListDescriptors[IntToTransfer].GetName() + "_Average";
            if (NewWindow.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;

            if ((NewWindow.comboBoxStatistics.Text != "Average") && (NewWindow.comboBoxStatistics.Text != "Stdev") &&
                (NewWindow.comboBoxStatistics.Text != "Sum") && (NewWindow.comboBoxStatistics.Text != "Median") && (NewWindow.comboBoxStatistics.Text != "MAD") && (NewWindow.comboBoxStatistics.Text != "CV%"))
                return;

            List<cCellularPhenotype> LCP = new List<cCellularPhenotype>();
            for (int IdxPheno = 0; IdxPheno < ClassSelectionPanel.GetListSelectedClass().Count; IdxPheno++)
            {
                if (ClassSelectionPanel.GetListSelectedClass()[IdxPheno])
                    LCP.Add(cGlobalInfo.ListCellularPhenotypes[IdxPheno]);
            }

            if (LCP.Count == 0) return;

            double RatioPopulation = 1;

            string description = "This descriptor has been generated by computing the " + NewWindow.textBoxDescName.Text + " of " + RatioPopulation * 100 + "% the following phenotypic sub-populations:\n";
            foreach (var item in LCP)
            {
                description += item.Name + "\n";
            }

            cDescriptorType NewAverageType = new cDescriptorType(NewWindow.textBoxDescName.Text, true, 1, description);
            cGlobalInfo.CurrentScreening.ListDescriptors.AddNew(NewAverageType);

            FormForProgress ProgressWindow = new FormForProgress();
            ProgressWindow.Show();

            int IdxProgress = 0;
            int MaxProgress = 0;

            foreach (cPlate CurrentPlateToProcess in cGlobalInfo.CurrentScreening.ListPlatesAvailable)
                MaxProgress += (int)CurrentPlateToProcess.ListActiveWells.Count;

            ProgressWindow.progressBar.Maximum = MaxProgress;

            foreach (cPlate TmpPlate in cGlobalInfo.CurrentScreening.ListPlatesAvailable)
            {
                foreach (cWell Tmpwell in TmpPlate.ListActiveWells)
                {
                    TmpPlate.DBConnection = new cDBConnection(TmpPlate, Tmpwell.SQLTableName);
                    List<cDescriptorType> LDT = new List<cDescriptorType>();
                    LDT.Add(cGlobalInfo.CurrentScreening.ListDescriptors[IntToTransfer]);

                    cExtendedTable CT = TmpPlate.DBConnection.GetWellValues(Tmpwell, LDT, LCP, RatioPopulation);
                    cListSignature LDesc = new cListSignature();

                    double Value = 0;
                    if (CT.Count == 1)
                    {

                        if (CT[0].Count == 0)
                        {
                            Value = 0;
                            richTextBoxConsole.AppendText(TmpPlate.GetName() + " : " + Tmpwell.GetShortInfo().Remove(Tmpwell.GetShortInfo().Length - 2) + ": no objects fullfill your request. Statistics set to null.\n");
                        }
                        else
                        {
                            if (NewWindow.comboBoxStatistics.Text == "Average")
                                Value = CT[0].Average();
                            else if (NewWindow.comboBoxStatistics.Text == "Stdev")
                                Value = CT[0].Std();
                            else if (NewWindow.comboBoxStatistics.Text == "Sum")
                                Value = CT[0].Sum();
                            else if (NewWindow.comboBoxStatistics.Text == "Median")
                                Value = CT[0].Median();
                            else if (NewWindow.comboBoxStatistics.Text == "MAD")
                                Value = CT[0].MAD(true);
                            else if (NewWindow.comboBoxStatistics.Text == "CV%")
                                Value = CT[0].CV();
                        }
                    }

                    ProgressWindow.richTextBoxForComment.AppendText(Tmpwell.GetShortInfo() + ": " + CT[0].Count.ToString() + " / " + Tmpwell.GetNumBiologicalObjects() + "\n");

                    cSignature NewDesc = new cSignature(Value, NewAverageType, cGlobalInfo.CurrentScreening);
                    LDesc.Add(NewDesc);
                    Tmpwell.AddSignatures(LDesc);
                    TmpPlate.DBConnection.CloseConnection();

                    ProgressWindow.progressBar.Value = IdxProgress++;

                    ProgressWindow.richTextBoxForComment.AppendText(TmpPlate.GetName() + " : " + Tmpwell.GetShortInfo().Remove(Tmpwell.GetShortInfo().Length - 2) + "\n");
                    ProgressWindow.Refresh();
                }
            }
            ProgressWindow.Close();

            cGlobalInfo.CurrentScreening.ListDescriptors.UpDateDisplay();
            cGlobalInfo.CurrentScreening.UpDatePlateListWithFullAvailablePlate();

            for (int idxP = 0; idxP < cGlobalInfo.CurrentScreening.ListPlatesActive.Count; idxP++)
                cGlobalInfo.CurrentScreening.ListPlatesActive[idxP].UpDataMinMax();
        }
Пример #9
0
        private void SingleCellOperationPhenotypToDesc(object sender, EventArgs e)
        {
            string description = "This descriptor has been generated by converting single cell phenotypic class into feature\n";

            FormForNameRequest FFNR = new FormForNameRequest();
            FFNR.Text = "Descriptor Name";
            FFNR.textBoxForName.Text = "Phenotype Class";
            if (FFNR.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;
            if (FFNR.textBoxForName.Text == "") return;

            cDescriptorType NewDescType = new cDescriptorType(FFNR.textBoxForName.Text, true, cGlobalInfo.ListCellularPhenotypes.Count, true);
            cGlobalInfo.CurrentScreening.ListDescriptors.AddNew(NewDescType);

            FormForProgress ProgressWindow = new FormForProgress();
            ProgressWindow.Show();

            int IdxProgress = 0;
            int MaxProgress = 0;

            foreach (cPlate CurrentPlateToProcess in cGlobalInfo.CurrentScreening.ListPlatesAvailable)
                MaxProgress += (int)CurrentPlateToProcess.ListActiveWells.Count;

            ProgressWindow.progressBar.Maximum = MaxProgress;

            foreach (cPlate CurrentPlate in cGlobalInfo.CurrentScreening.ListPlatesAvailable)
            {
                CurrentPlate.DBConnection.OpenConnection();

                CurrentPlate.DBConnection.CreateNewColumnFromExisting(NewDescType, "Phenotype_Class", GlobalInfo, ref CurrentPlate.ListActiveWells);

                CurrentPlate.DBConnection.CloseConnection();
                ProgressWindow.progressBar.Value = IdxProgress++;
                ProgressWindow.progressBar.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);
        }
Пример #10
0
        private void RatioPopDescItem(object sender, EventArgs e)
        {
            cGUI_2ClassesSelection GUI_ListClasses = new cGUI_2ClassesSelection();
            GUI_ListClasses.ClassType = eClassType.PHENOTYPE;
            GUI_ListClasses.PanelRight_IsCheckBoxes = true;
            GUI_ListClasses.PanelLeft_IsCheckBoxes = true;

            if (GUI_ListClasses.Run(this.GlobalInfo).IsSucceed == false) return;

            List<cCellularPhenotype> LCP0 = new List<cCellularPhenotype>();
            List<cCellularPhenotype> LCP1 = new List<cCellularPhenotype>();

            for (int IdxPheno = 0; IdxPheno < GUI_ListClasses.GetOutPut()[0].Count; IdxPheno++)
            {
                if (GUI_ListClasses.GetOutPut()[0][IdxPheno] == 1)
                    LCP0.Add(cGlobalInfo.ListCellularPhenotypes[IdxPheno]);

                if (GUI_ListClasses.GetOutPut()[1][IdxPheno] == 1)
                    LCP1.Add(cGlobalInfo.ListCellularPhenotypes[IdxPheno]);
            }

            //if (LCP.Count == 0) return;

            string description = "Ratio of:\n";

            foreach (var item in LCP0)
                description += item.Name + "\n";

            description += "over\n";

            foreach (var item in LCP1)
                description += item.Name + "\n";

            cDescriptorType NewAverageType = new cDescriptorType("Ratio_Pop", true, 1, description);
            cGlobalInfo.CurrentScreening.ListDescriptors.AddNew(NewAverageType);

            FormForProgress ProgressWindow = new FormForProgress();
            ProgressWindow.Show();

            int IdxProgress = 0;
            int MaxProgress = 0;

            foreach (cPlate CurrentPlateToProcess in cGlobalInfo.CurrentScreening.ListPlatesAvailable)
                MaxProgress += (int)CurrentPlateToProcess.ListWells.Count;

            ProgressWindow.progressBar.Maximum = MaxProgress;

            foreach (cPlate TmpPlate in cGlobalInfo.CurrentScreening.ListPlatesAvailable)
            {
                foreach (cWell Tmpwell in TmpPlate.ListWells)
                {
                    TmpPlate.DBConnection = new cDBConnection(TmpPlate, Tmpwell.SQLTableName);
                    List<cDescriptorType> LDT = new List<cDescriptorType>();
                    LDT.Add(cGlobalInfo.CurrentScreening.ListDescriptors[0]);

                    cExtendedTable CT = TmpPlate.DBConnection.GetWellValues(Tmpwell, LDT, LCP0, 1);
                    double NumObject0 = CT[0].Count;

                    cExtendedTable CT1 = TmpPlate.DBConnection.GetWellValues(Tmpwell, LDT, LCP1, 1);
                    double NumObject1 = CT1[0].Count;

                    cListSignature LDesc = new cListSignature();

                    double Value = 0;
                    if (NumObject1 == 0)
                        Value = 0;
                    else
                        Value = NumObject0 / NumObject1;

                    cSignature NewDesc = new cSignature(Value, NewAverageType, cGlobalInfo.CurrentScreening);
                    LDesc.Add(NewDesc);
                    Tmpwell.AddSignatures(LDesc);
                    TmpPlate.DBConnection.CloseConnection();

                    ProgressWindow.richTextBoxForComment.AppendText(TmpPlate.GetName() + " : " + Tmpwell.GetShortInfo().Remove(Tmpwell.GetShortInfo().Length - 2) + "\n");
                    ProgressWindow.progressBar.Value = IdxProgress++;
                    ProgressWindow.Refresh();
                }
            }
            ProgressWindow.Close();

            cGlobalInfo.CurrentScreening.ListDescriptors.UpDateDisplay();
            cGlobalInfo.CurrentScreening.UpDatePlateListWithFullAvailablePlate();

            for (int idxP = 0; idxP < cGlobalInfo.CurrentScreening.ListPlatesActive.Count; idxP++)
                cGlobalInfo.CurrentScreening.ListPlatesActive[idxP].UpDataMinMax();
        }
Пример #11
0
        public void PerformClassification()
        {
            FormForSingleCellClassifOptions FFSC = new FormForSingleCellClassifOptions();
            //cGUI_ListClasses GLC = new cGUI_ListClasses();
            //GLC.ClassType = eClassType.PHENOTYPE;
            //GLC.IsCheckBoxes = true;
            //GLC.IsSelectAll = true;
            //GLC.Run(GlobalInfo);

            PanelForClassSelection PhenotypeSelectionPanel = new PanelForClassSelection( true, eClassType.PHENOTYPE);
            PhenotypeSelectionPanel.Height = FFSC.panelPhenoToBeClassified.Height;
            FFSC.panelPhenoToBeClassified.Controls.Add(PhenotypeSelectionPanel);

            PanelForClassSelection WellClassSelectionPanel = new PanelForClassSelection( true, eClassType.WELL);
            WellClassSelectionPanel.Height = FFSC.panelWellToBeClassified.Height;
            FFSC.panelWellToBeClassified.Controls.Add(WellClassSelectionPanel);

            PanelForPlatesSelection PlatesSelectionPanel = new PanelForPlatesSelection( true, null, true);
            PlatesSelectionPanel.Height = FFSC.panelWellToBeClassified.Height;
            FFSC.tabPagePlates.Controls.Add(PlatesSelectionPanel);

            if (FFSC.ShowDialog() != DialogResult.OK) return;

            // ----------------------- Classification ------------------------------
            int DescrCount = cGlobalInfo.CurrentScreening.ListDescriptors.Count;

            this.UpDateNumberOfCluster();
            if (NumberOfClusters == 0)
            {
                System.Windows.Forms.MessageBox.Show("Number of cluster is null", "Error !", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }

            //if (FFSC.checkBoxGenerationRatio.Checked)
            //{
            //    // first we update the descriptor
            //    for (int i = 0; i < this.NumberOfClusters; i++)
            //        GlobalInfo.CurrentScreening.ListDescriptors.AddNew(new cDescriptorType("Ratio_" + GlobalInfo.ListCellularPhenotypes[i].Name, true, 1, GlobalInfo));
            //}

            FormForProgress ProgressWindow = new FormForProgress();
            ProgressWindow.Show();

            int IdxProgress = 0;
            int MaxProgress = 0;

            #region Confusion Matrix init
            cListExtendedTable LT = new cListExtendedTable();
            cExtendedTable ConfusionMatrix = new cExtendedTable(cGlobalInfo.ListCellularPhenotypes.Count, cGlobalInfo.ListCellularPhenotypes.Count, 0);
            ConfusionMatrix.Name = "Confusion Matrix (global)";
            ConfusionMatrix.ListRowNames = new List<string>();
            for (int i = 0; i < cGlobalInfo.ListCellularPhenotypes.Count; i++)
            {
                ConfusionMatrix.ListRowNames.Add(cGlobalInfo.ListCellularPhenotypes[i].Name + "*");
                ConfusionMatrix[i].Name = cGlobalInfo.ListCellularPhenotypes[i].Name;
            }
            LT.Add(ConfusionMatrix);
            for (int i = 0; i < cGlobalInfo.ListWellClasses.Count; i++)
            {
                cExtendedTable ConfusionMatrixTmp = new cExtendedTable(cGlobalInfo.ListCellularPhenotypes.Count, cGlobalInfo.ListCellularPhenotypes.Count, 0);
                ConfusionMatrixTmp.Name = "Confusion Matrix - " + cGlobalInfo.ListWellClasses[i].Name;
                ConfusionMatrixTmp.ListRowNames = new List<string>();
                for (int j = 0; j < cGlobalInfo.ListCellularPhenotypes.Count; j++)
                {
                    ConfusionMatrixTmp.ListRowNames.Add(cGlobalInfo.ListCellularPhenotypes[j].Name + "*");
                    ConfusionMatrixTmp[j].Name =cGlobalInfo.ListCellularPhenotypes[j].Name;
                }
                LT.Add(ConfusionMatrixTmp);
            }
            #endregion

            cListPlates LP = PlatesSelectionPanel.GetListSelectedPlates();

            foreach (cPlate CurrentPlateToProcess in LP /*GlobalInfo.CurrentScreening.ListPlatesAvailable*/)
                MaxProgress += (int)CurrentPlateToProcess.ListActiveWells.Count;
            ProgressWindow.progressBar.Maximum = MaxProgress;

            FastVector attVals = new FastVector();
            for (int i = 0; i < this.NumberOfClusters; i++)
                attVals.addElement(i.ToString());

            cPlate CurrentDispPlate = cGlobalInfo.CurrentScreening.GetCurrentDisplayPlate();

            foreach (cPlate CurrentPlateToProcess in LP/* GlobalInfo.CurrentScreening.ListPlatesAvailable*/)
            {
                foreach (cWell TmpWell in CurrentPlateToProcess.ListActiveWells)
                {
                    ProgressWindow.progressBar.Value = IdxProgress++;

                    if (TmpWell.GetCurrentClassIdx() == -1) continue;
                    if (WellClassSelectionPanel.ListCheckBoxes[TmpWell.GetCurrentClassIdx()].Checked == false) continue;

                    DataTable FinalDataTable = new DataTable();
                    TmpWell.AssociatedPlate.DBConnection = new cDBConnection(TmpWell.AssociatedPlate, TmpWell.SQLTableName);
                    TmpWell.AssociatedPlate.DBConnection.AddWellToDataTable(TmpWell, FinalDataTable, this.GlobalInfo);
                    cListSingleBiologicalObjects LSBO = TmpWell.AssociatedPlate.DBConnection.GetBiologicalPhenotypes(TmpWell);
                    //TmpWell.AssociatedPlate.DBConnection.AddWellToDataTable(TmpWell, FinalDataTable, checkBoxIncludeWellClassAsDesc.Checked, GlobalInfo);
                    Instances ListInstancesTOClassify = this.CreateInstancesWithoutClass(FinalDataTable);

                    ListInstancesTOClassify.insertAttributeAt(new weka.core.Attribute("Class", attVals), ListInstancesTOClassify.numAttributes());
                    ListInstancesTOClassify.setClassIndex(ListInstancesTOClassify.numAttributes() - 1);

                    cExtendedList ListNewClasses = new cExtendedList();

                    int NumInstances = ListInstancesTOClassify.numInstances();
                    for (int i = 0; i < NumInstances; i++)
                    {
                        // ClassId contains the new class
                        Instance CurrentInst = ListInstancesTOClassify.instance(i);

                        double classId = this.CurrentClassifier.classifyInstance(CurrentInst);
                        double[] ClassConfidence = this.CurrentClassifier.distributionForInstance(CurrentInst);
                        LSBO[i].ClassificationConfidence = ClassConfidence[(int)classId];
                        ListNewClasses.Add(classId);

                        if (CurrentPlateToProcess == CurrentDispPlate)
                        {
                            LT[0][LSBO[i].GetAssociatedPhenotype().Idx][(int)classId]++;

                            if (TmpWell.GetCurrentClassIdx() >= 0)
                                LT[TmpWell.GetCurrentClassIdx() + 1][LSBO[i].GetAssociatedPhenotype().Idx][(int)classId]++;
                        }
                    }

                    ProgressWindow.richTextBoxForComment.AppendText(TmpWell.GetShortInfo().Remove(TmpWell.GetShortInfo().Length - 2) + " : " + NumInstances + " objects\n");
                    ProgressWindow.Refresh();
                    // ------------- update class within the database -----------------------------
                    TmpWell.AssociatedPlate.DBConnection.ChangePhenotypeClass(TmpWell, ListNewClasses);

                    //if (FFSC.checkBoxGenerationRatio.Checked)
                    //{
                    //    List<double[]> Histo = ListNewClasses.CreateHistogram(0, ListInstancesTOClassify.numClasses(), ListInstancesTOClassify.numClasses());
                    //    cListSignature LDesc = new cListSignature();

                    //    for (int IdxHisto = 0; IdxHisto < Histo[1].Length - 1; IdxHisto++)
                    //    {
                    //        Histo[1][IdxHisto] = (100.0 * Histo[1][IdxHisto]) / (double)ListInstancesTOClassify.numInstances();

                    //        cSignature NewDesc = new cSignature(Histo[1][IdxHisto], GlobalInfo.CurrentScreening.ListDescriptors[IdxHisto + DescrCount], GlobalInfo.CurrentScreening);
                    //        LDesc.Add(NewDesc);
                    //    }
                    //    TmpWell.AddSignatures(LDesc);
                    //}

                    TmpWell.AssociatedPlate.DBConnection.CloseConnection();
                }
            }

            #region Display Report
            cDesignerSplitter DS = new cDesignerSplitter();
            DS.Orientation = Orientation.Vertical;

            cViewertext VTEXT = new cViewertext();
            VTEXT.SetInputData(ProgressWindow.richTextBoxForComment.Text);
            VTEXT.Run();

            cDesignerTab DT = new cDesignerTab();
            DT.IsMultiline = false;

            foreach (var item in LT)
            {
                cViewerTable VT = new cViewerTable();
                VT.SetInputData(item);
                VT.DigitNumber = 0;
                VT.Run();
                DT.SetInputData(VT.GetOutPut());
            }

            DT.Run();

            cExtendedControl TextEC = DT.GetOutPut();
            TextEC.Width = 0;
            TextEC.Height = 0;
            TextEC.Anchor = (System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom
                                                                | System.Windows.Forms.AnchorStyles.Left
                                                                | System.Windows.Forms.AnchorStyles.Right);

            DS.SetInputData(VTEXT.GetOutPut());
            DS.SetInputData(TextEC);

            DS.Run();

            ProgressWindow.Close();

            cDisplayToWindow CDT = new cDisplayToWindow();
            CDT.SetInputData(DS.GetOutPut());
            CDT.IsModal = true;
            CDT.Title = "Phenotypic Classificaton Report";
            CDT.Run();
            CDT.Display();

            #endregion

            //if (IsKeepOriginalDesc == System.Windows.Forms.DialogResult.No)
            //{
            //    // int DescNumToRemove = GlobalInfo.CurrentScreen.ListDescriptors.Count -
            //    for (int IdxDesc = 0; IdxDesc < DescrCount; IdxDesc++)
            //        GlobalInfo.CurrentScreening.ListDescriptors.RemoveDesc(GlobalInfo.CurrentScreening.ListDescriptors[0], GlobalInfo.CurrentScreening);
            //}

            cGlobalInfo.CurrentScreening.ListDescriptors.UpDateDisplay();
            cGlobalInfo.CurrentScreening.UpDatePlateListWithFullAvailablePlate();

            for (int idxP = 0; idxP < cGlobalInfo.CurrentScreening.ListPlatesActive.Count; idxP++)
                cGlobalInfo.CurrentScreening.ListPlatesActive[idxP].UpDataMinMax();

            //WindowFormForCellbyCellClassif.Close();
            //WindowClusteringInfo.Close();
        }
Пример #12
0
        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();
        }
        private void buttonStartCluster_Click(object sender, EventArgs e)
        {
            FormSingleCellClusteringInfo WindowClusteringInfo = new FormSingleCellClusteringInfo(GlobalInfo);
            if (WindowClusteringInfo.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;

            Instances ListInstances = GlobalInfo.CurrentScreen.CellBasedClassification.CreateInstancesWithoutClass(dt);
            if ((WindowClusteringInfo.radioButtonAutomated.Checked) && (WindowClusteringInfo.radioButtonEM.Checked))
            {
                ClusterEvaluation eval;
                Classes = new cExtendedList();
                weka.clusterers.EM EMCluster = new EM();
                if(WindowClusteringInfo.checkBoxEMAutomated.Checked)
                    EMCluster.setNumClusters(-1);
                else
                    EMCluster.setNumClusters((int)WindowClusteringInfo.numericUpDownClassNumber.Value);
                EMCluster.buildClusterer(ListInstances);
                EMCluster.getClusterModelsNumericAtts();

                eval = new ClusterEvaluation();
                eval.setClusterer(EMCluster);

                eval.evaluateClusterer(ListInstances);

                Classes.AddRange(eval.getClusterAssignments());
                NumClusters= eval.getNumClusters();
                ReDraw();
                FormForCellByCellClusteringResults WindowFormForCellByCellClusteringResults = new FormForCellByCellClusteringResults();
                WindowFormForCellByCellClusteringResults.richTextBoxResults.Clear();
                WindowFormForCellByCellClusteringResults.richTextBoxResults.AppendText(eval.clusterResultsToString());
                if (WindowFormForCellByCellClusteringResults.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;

            }
            else if (WindowClusteringInfo.radioButtonDescriptorBased.Checked)
            {
                Classes = new cExtendedList();
                DataTable FinalDataTable = new DataTable();
                int IdxDescForClassSelect = WindowClusteringInfo.comboBoxDescriptorForClass.SelectedIndex;
                for (int IdxWell = 0; IdxWell < GlobalInfo.ListSelectedWell.Count; IdxWell++)
                {
                    cWell TmpWell = GlobalInfo.ListSelectedWell[IdxWell];

                 //   if (IdxWell == 0)
                    if (TmpWell.ListDescriptors[IdxDescForClassSelect].GetAssociatedType().DataType == eDataType.HISTOGRAM)
                    {
                        Classes.AddRange(TmpWell.ListDescriptors[IdxDescForClassSelect].GetOriginalValues());
                    }
                    else
                    {
                        double ClasseValue = TmpWell.ListDescriptors[IdxDescForClassSelect].GetValue();

                        for (int IdxCell = 0; IdxCell < TmpWell.CellNumber; IdxCell++)
                            Classes.Add(ClasseValue);
                        //TmpWell.AddDescriptors
                    }
                }

                List<double> ListClassValues = new List<double>();
                foreach (var item in Classes.Distinct())
                {
                    ListClassValues.Add(item);
                }

                    //(List<double>)Classes.Distinct();
                NumClusters = ListClassValues.Count();
                //Classes = new cExtendedList();
                for (int IdxClust = 0; IdxClust < Classes.Count; IdxClust++)
                {
                    for (int IdxCl = 0; IdxCl < ListClassValues.Count; IdxCl++)
                    {
                        if (ListClassValues[IdxCl] == Classes[IdxClust])
                        {
                            Classes[IdxClust] = IdxCl;
                            break;
                        }
                    }
                    //Classes[IdxClust] = ListClassValues.Find(Classes[IdxClust]);
                }
                //int NumClusters =
                ReDraw();

            }

            //    ReDraw();

            //if (MessageBox.Show("Do you want perform a j48 training process ?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes) return;

            weka.core.FastVector attVals = new FastVector();
            for (int i = 0; i < NumClusters; i++)
                attVals.addElement("Class__" + (i).ToString());

            ListInstances.insertAttributeAt(new weka.core.Attribute("Class__", attVals), ListInstances.numAttributes());

            for (int i = 0; i < Classes.Count; i++)
            {
                ListInstances.get(i).setValue(ListInstances.numAttributes() - 1, Classes[i]);
            }
            ListInstances.setClassIndex(ListInstances.numAttributes() - 1);

               GlobalInfo.CurrentScreen.CellBasedClassification.ClassificationModel_CellBased = new weka.classifiers.trees.J48();
               GlobalInfo.CurrentScreen.CellBasedClassification.SetJ48Tree((weka.classifiers.trees.J48)GlobalInfo.CurrentScreen.CellBasedClassification.ClassificationModel_CellBased,Classes.Count);
               GlobalInfo.CurrentScreen.CellBasedClassification.J48Model.setMinNumObj((int)GlobalInfo.OptionsWindow.numericUpDownJ48MinNumObjects.Value);

            weka.core.Instances train = new weka.core.Instances(ListInstances, 0, ListInstances.numInstances());

            GlobalInfo.CurrentScreen.CellBasedClassification.ClassificationModel_CellBased.buildClassifier(train);
            GlobalInfo.ConsoleWriteLine(GlobalInfo.CurrentScreen.CellBasedClassification.ClassificationModel_CellBased.ToString());

               GlobalInfo.CurrentScreen.CellBasedClassification.evaluation = new weka.classifiers.Evaluation(ListInstances);
               GlobalInfo.CurrentScreen.CellBasedClassification.evaluation.crossValidateModel(GlobalInfo.CurrentScreen.CellBasedClassification.ClassificationModel_CellBased, ListInstances, 2, new java.util.Random(1));

            GlobalInfo.CurrentScreen.CellBasedClassification.DisplayTree(GlobalInfo).Show();

            FormForCellbyCellClassif WindowFormForCellbyCellClassif = new FormForCellbyCellClassif();
            if (WindowFormForCellbyCellClassif.ShowDialog() != System.Windows.Forms.DialogResult.OK) return;

            int DescrCount = GlobalInfo.CurrentScreen.ListDescriptors.Count;

            // first we update the descriptor
            for (int i = 0; i < ListInstances.numClasses(); i++)
                GlobalInfo.CurrentScreen.ListDescriptors.AddNew(new cDescriptorsType("Ratio_Class " + i, true, 1, GlobalInfo));

            FormForProgress ProgressWindow = new FormForProgress();
            ProgressWindow.Show();

            int IdxProgress = 0;
            int MaxProgress = 0;

            foreach (cPlate CurrentPlateToProcess in GlobalInfo.CurrentScreen.ListPlatesAvailable)
                MaxProgress += CurrentPlateToProcess.ParentScreening.Columns * CurrentPlateToProcess.ParentScreening.Rows;
            ProgressWindow.progressBar.Maximum = MaxProgress;

            attVals = new FastVector();
            for (int i = 0; i < NumClusters; i++)
                attVals.addElement(i.ToString());

            //ParallelOptions options = new ParallelOptions();
            //options.MaxDegreeOfParallelism = -1; // -1 is for unlimited. 1 is for sequential.
            //Stopwatch stopwatch = new Stopwatch();
            //stopwatch.Start();
            //////for (int PlateIdx = 0; PlateIdx < NumberOfPlates; PlateIdx++)
            //int NumberOfPlates = CompleteScreening.ListPlatesAvailable.Count;
            //Parallel.For(0, NumberOfPlates, options, (PlateIdx) =>
            //{
            //    cPlate CurrentPlateToProcess = CompleteScreening.ListPlatesActive.GetPlate((string)Parent.GlobalInfo.PlateListWindow.listBoxPlateNameToProcess.Items[PlateIdx]);

            //    for (int row = 0; row < Parent.Rows; row++)
            //        for (int col = 0; col < Parent.Columns; col++)
            //        {
            //            TempWell = CurrentPlateToProcess.GetWell(col, row, false);
            //            if (TempWell == null) continue;
            //            else
            //            {
            //                if (TempWell.GetClass() == this.ClassForClassif)
            //                    Pos.Add(TempWell.ListDescriptors[Parent.ListDescriptors.CurrentSelectedDescriptor].GetValue());
            //            }
            //        }
            //}
            //);

            foreach (cPlate CurrentPlateToProcess in GlobalInfo.CurrentScreen.ListPlatesAvailable)
            //Parallel.ForEach(GlobalInfo.CurrentScreen.ListPlatesActive, options, CurrentPlateToProcess =>
            {
                //Parallel.ForEach(CurrentPlateToProcess.ListActiveWells, options, TmpWell =>
                for(int j=0;j<CurrentPlateToProcess.ParentScreening.Rows;j++)
                    for (int k = 0; k < CurrentPlateToProcess.ParentScreening.Columns; k++)
                {
                    cWell TmpWell = CurrentPlateToProcess.GetWell(k, j, false);
                    if (TmpWell == null) continue;
                    ProgressWindow.progressBar.Value = IdxProgress++;

                    //DataTable FinalDataTable = new DataTable();
                    //TmpWell.AssociatedPlate.DBConnection = new cDBConnection(TmpWell.AssociatedPlate, TmpWell.SQLTableName);
                    //TmpWell.AssociatedPlate.DBConnection.AddWellToDataTable(TmpWell, FinalDataTable, false);
                    DataTable FinalDataTable = TmpWell.GetDescDataTable(true);
                    Instances ListInstancesTOClassify = GlobalInfo.CurrentScreen.CellBasedClassification.CreateInstancesWithoutClass(FinalDataTable);

                    ListInstancesTOClassify.insertAttributeAt(new weka.core.Attribute("Class", attVals), ListInstancesTOClassify.numAttributes());
                    ListInstancesTOClassify.setClassIndex(ListInstancesTOClassify.numAttributes() - 1);

                    cExtendedList ListClasses = new cExtendedList();

                    for (int i = 0; i < ListInstancesTOClassify.numInstances(); i++)
                    {
                        double classId = GlobalInfo.CurrentScreen.CellBasedClassification.ClassificationModel_CellBased.classifyInstance(ListInstancesTOClassify.instance(i));
                        ListClasses.Add(classId);
                    }
                    List<double[]> Histo = ListClasses.CreateHistogram(0, ListInstances.numClasses() - 1, ListInstances.numClasses() - 1);
                    List<cDescriptor> LDesc = new List<cDescriptor>();

                    for (int IdxHisto = 0; IdxHisto < Histo[1].Length; IdxHisto++)
                    {
                        double Value = (100.0 * Histo[1][IdxHisto]) / (double)ListInstancesTOClassify.numInstances();

                        cDescriptor NewDesc = new cDescriptor(Value, GlobalInfo.CurrentScreen.ListDescriptors[IdxHisto + DescrCount], GlobalInfo.CurrentScreen);
                        LDesc.Add(NewDesc);
                    }

                    TmpWell.AddDescriptors(LDesc);
                    //TmpWell.AssociatedPlate.DBConnection.DB_CloseConnection();

                }//);
            }
            ProgressWindow.Close();

            if (WindowFormForCellbyCellClassif.checkBoxKeepOriginalDesc.Checked == false)
            {

               // int DescNumToRemove = GlobalInfo.CurrentScreen.ListDescriptors.Count -
                for (int IdxDesc = 0; IdxDesc < DescrCount; IdxDesc++)
                GlobalInfo.CurrentScreen.ListDescriptors.RemoveDesc(GlobalInfo.CurrentScreen.ListDescriptors[0], GlobalInfo.CurrentScreen);

            }

            GlobalInfo.CurrentScreen.ListDescriptors.UpDateDisplay();
            GlobalInfo.CurrentScreen.UpDatePlateListWithFullAvailablePlate();

            for (int idxP = 0; idxP < GlobalInfo.CurrentScreen.ListPlatesActive.Count; idxP++)
                GlobalInfo.CurrentScreen.ListPlatesActive[idxP].UpDataMinMax();

            if (WindowFormForCellbyCellClassif.checkBoxKeepOriginalDesc.Checked == false)
                GlobalInfo.CurrentScreen.GetCurrentDisplayPlate().DisplayDistribution(0, false);

            //WindowFormForCellbyCellClassif.Close();
            //WindowClusteringInfo.Close();
        }