コード例 #1
0
        /// <summary>
        /// Perform the analysis.  Many try-catch blocks provide error handling for each step of the process.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPerformAnalysis_Click(object sender, EventArgs e)
        {
            // reset GUI elements
            pgAnalysis.Value = 0;
            lstAnalysisResults.Items.Clear();
            // TODO - check to see if files are open so we don't get all the way through an analysis and then
            // find we can't open the file

            // TODO - all of this exception checking should be done in the SEAEnvironment class
            // set this flag to false at any step to halt processing
            bool bContinue = true;

            this.Cursor = Cursors.WaitCursor;
            FileInfoExtended fi = (FileInfoExtended)lstSubsLib.SelectedItem;
            // init SubstructureLibrary
            SubstructureLibrary library = _env.subsLib.FilteredLibrary;

            if (bContinue)
            {
                // set status of statistics based on checked/unchecked
                foreach (ListViewItem li in lvStatistics.Items)
                {
                    _env.stats.Item(li.Text).Perform = li.Checked;
                }
                try
                {
                    lblAnalysisProgress.Text = "Preparing analysis...";
                    Application.DoEvents();
                    _env.PrepAnalysisInteractive();
                    _cancelAnalysis          = false;
                    lblAnalysisProgress.Text = "Running analysis...";
                    // call the runinteractive method repeatedly to update the progress bar
                    int i = 0;
                    while (i != -1)
                    {
                        Application.DoEvents();
                        pgAnalysis.Value = i > pgAnalysis.Maximum ? pgAnalysis.Maximum : i;
                        Application.DoEvents();
                        if (!_cancelAnalysis)
                        {
                            i = _env.RunAnalysisInteractive();
                            // don't know if this is strictly necessary to let the form
                            // process a press of the Cancel button
                            System.Windows.Forms.Application.DoEvents();
                        }
                        else
                        {
                            // cancelled
                            i = -1;
                            lblAnalysisProgress.Text = "Analysis cancelled.";
                            pgAnalysis.Value         = 0;
                            bContinue = false;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("An error occurred while running the analysis: \r\n" + ex.Message + "\r\nMake sure that R and the R DCOM connector are installed.");
                    bContinue = false;
                }
                if (bContinue)
                {
                    // output library data
                    try
                    {
                        lblAnalysisProgress.Text = "Writing files...";
                        Application.DoEvents();
                        library.WriteAllAssayAnalysisFiles(_env.OutputPath);
                        library.WriteSummaryFile(_env.OutputPath + "\\Analysis Summary.txt");
                        // fill lstbox with analysis result files
                        lstAnalysisResults.Items.Add(new FileInfoExtended(_env.OutputPath + "\\Analysis Summary.txt"));
                        foreach (string assayName in _env.AssayResultsHash.Keys)
                        {
                            lstAnalysisResults.Items.Add(new FileInfoExtended(_env.OutputPath + "\\" + assayName + ".txt"));
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Sorry, an error occurred while writing the analysis files to disk.  This usually means you have some of these files open in Excel.  Close the analysis files, then try running the analysis again.");
                    }
                } // bcontinue
            }     // bcontinue
            lblAnalysisProgress.Text = bContinue ? "Analysis complete." : "Analysis cancelled.";
            this.Cursor = Cursors.Default;
        }