Exemplo n.º 1
0
        private void listView1_SelectedIndexChanged(object sender, EventArgs ev)
        {
            object p = this.GetSelected();

            bool itemSelected = p != null;

            this._btnRemove.Enabled        = itemSelected;
            this._btnView.Enabled          = itemSelected;
            this._btnEdit.Enabled          = itemSelected;
            this._btnRename.Enabled        = itemSelected && IVisualisableExtensions.SupportsRename(p as Visualisable);
            this._btnUp.Enabled            = itemSelected;
            this._btnDown.Enabled          = itemSelected;
            this._btnDuplicate.Enabled     = itemSelected;
            this._btnEnableDisable.Enabled = itemSelected && IVisualisableExtensions.SupportsDisable(p as Visualisable);

            if ((p as Visualisable)?.Hidden ?? false)
            {
                this._btnEnableDisable.Text  = "Unhide";
                this._btnEnableDisable.Image = Resources.MnuEnable;
            }
            else
            {
                this._btnEnableDisable.Text  = "Hide";
                this._btnEnableDisable.Image = Resources.MnuDisable;
            }
        }
Exemplo n.º 2
0
        public static bool Show(Form owner, string windowText, string mainTitle, string subTitle, string defaultName, ref string name, ref string comments, bool readOnly, Visualisable supports)
        {
            bool canRename  = supports == null || IVisualisableExtensions.SupportsRename(supports);
            bool canComment = supports == null || IVisualisableExtensions.SupportsComment(supports);

            if (!canRename && !canComment)
            {
                FrmMsgBox.ShowInfo(owner, defaultName, "This item cannot be renamed.");
                return(false);
            }

            using (FrmEditINameable frm = new FrmEditINameable())
            {
                frm.Text = windowText;

                frm.textBox1.Watermark   = defaultName;
                frm.textBox1.Text        = name;
                frm._txtInput.Text       = comments;
                frm.ctlTitleBar1.Text    = mainTitle;
                frm.ctlTitleBar1.SubText = subTitle;

                frm.AcceptButton = null;
                frm.CancelButton = frm._btnCancel;

                frm.textBox1.Visible  = canRename;
                frm.label6.Visible    = !canRename;
                frm.label6.Text       = defaultName;
                frm._txtInput.Visible = canComment;
                frm.label2.Visible    = canComment;

                if (readOnly)
                {
                    frm._btnOk.Visible     = false;
                    frm._btnCancel.Text    = "  Close";
                    frm.AcceptButton       = frm._btnCancel;
                    frm.textBox1.ReadOnly  = true;
                    frm._txtInput.ReadOnly = true;
                }

                if (UiControls.ShowWithDim(owner, frm) == DialogResult.OK)
                {
                    name     = frm.textBox1.Text;
                    comments = frm._txtInput.Text;
                    return(true);
                }

                return(false);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// CONSTRUCTOR
        /// </summary>
        private FrmEditPeakFilterCondition(Form owner, Core core, PeakFilter.Condition defaults, bool readOnly)
            : this()
        {
            this._core     = core;
            this._readOnly = readOnly;

            this.ctlTitleBar1.Text = readOnly ? "View Condition" : "Edit Condition";

            // Setup boxes
            this._cbPeaks    = DataSet.ForPeaks(core).CreateConditionBox(this._txtIsInSet, this._btnIsInSet);
            this._cbFlags    = DataSet.ForUserFlags(core).CreateConditionBox(this._txtIsFlaggedWith, this._btnIsFlaggedWith);
            this._cbClusters = DataSet.ForClusters(core).CreateConditionBox(this._txtIsInCluster, this._btnIsInCluster);

            this._lsoFlags  = EnumComboBox.Create(this._lstFlagComparator, Filter.ESetOperator.Any);
            this._lsoPats   = EnumComboBox.Create(this._lstClusterComparator, Filter.ELimitedSetOperator.Any);
            this._lsoPeaks  = EnumComboBox.Create(this._lstPeakComparator, Filter.EElementOperator.Is);
            this._lsoFilter = EnumComboBox.Create(this._lstFilterOp, Filter.EElementOperator.Is);
            this._lsoStats  = EnumComboBox.Create(this._lstStatisticComparator, Filter.EStatOperator.LessThan);
            this._lstIsStatistic.Items.AddRange(IVisualisableExtensions.WhereEnabled(core.Statistics).ToArray());

            this._ecbFilter = DataSet.ForPeakFilter(core).CreateComboBox(this._lstFilter, null, EditableComboBox.EFlags.IncludeAll);

            this._isInitialised = true;

            if (defaults == null)
            {
                this.checkBox1.Checked = false;
                this._radAnd.Checked   = true;
                this._txtComp_TextChanged(null, null);
            }
            else
            {
                // Not
                this.checkBox1.Checked = defaults.Negate;
                this._radAnd.Checked   = defaults.CombiningOperator == Filter.ELogicOperator.And;
                this._radOr.Checked    = defaults.CombiningOperator == Filter.ELogicOperator.Or;

                if (defaults is PeakFilter.ConditionCluster)
                {
                    PeakFilter.ConditionCluster def = (PeakFilter.ConditionCluster)defaults;

                    List <Cluster> strong;

                    if (!def.Clusters.TryGetStrong(out strong))
                    {
                        this.ShowWeakFailureMessage("clusters");
                    }

                    this._chkIsInCluster.Checked   = true;
                    this._lsoPats.SelectedItem     = def.ClustersOp;
                    this._cbClusters.SelectedItems = strong;
                }
                else if (defaults is PeakFilter.ConditionPeak)
                {
                    PeakFilter.ConditionPeak def = (PeakFilter.ConditionPeak)defaults;

                    List <Peak> strong;

                    if (!def.Peaks.TryGetStrong(out strong))
                    {
                        this.ShowWeakFailureMessage("peaks");
                    }

                    this._chkIsInSet.Checked    = true;
                    this._lsoPeaks.SelectedItem = def.PeaksOp;
                    this._cbPeaks.SelectedItems = strong;
                }
                else if (defaults is PeakFilter.ConditionFlags)
                {
                    PeakFilter.ConditionFlags def = (PeakFilter.ConditionFlags)defaults;

                    List <UserFlag> strong;

                    if (!def.Flags.TryGetStrong(out strong))
                    {
                        this.ShowWeakFailureMessage("peaks");
                    }

                    this._chkIsFlaggedWith.Checked = true;
                    this._lsoFlags.SelectedItem    = def.FlagsOp;
                    this._cbFlags.SelectedItems    = strong;
                }
                else if (defaults is PeakFilter.ConditionStatistic)
                {
                    PeakFilter.ConditionStatistic def = (PeakFilter.ConditionStatistic)defaults;

                    ConfigurationStatistic strong;

                    if (!def.Statistic.TryGetTarget(out strong))
                    {
                        this.ShowWeakFailureMessage("statistics");
                    }

                    ConfigurationStatistic stat = def.Statistic.GetTarget();

                    if (stat == null)
                    {
                        FrmMsgBox.ShowError(this, "The statistic specified when this condition was created has since been removed. Please select a different statistic.");
                    }

                    this._chkIsStatistic.Checked      = true;
                    this._lsoStats.SelectedItem       = def.StatisticOp;
                    this._lstIsStatistic.SelectedItem = stat;
                    this._txtStatisticValue.Text      = def.StatisticValue.ToString();
                }
                else if (defaults is PeakFilter.ConditionFilter)
                {
                    PeakFilter.ConditionFilter def = (PeakFilter.ConditionFilter)defaults;

                    this._radFilter.Checked      = true;
                    this._lsoFilter.SelectedItem = def.FilterOp ? Filter.EElementOperator.Is : Filter.EElementOperator.IsNot;
                    this._ecbFilter.SelectedItem = def.Filter;
                }
                else
                {
                    throw new SwitchException(defaults.GetType());
                }
            }

            if (readOnly)
            {
                UiControls.MakeReadOnly(this);
            }
        }
Exemplo n.º 4
0
        private void UpdateScores()
        {
            StringBuilder title = new StringBuilder();

            IntensityMatrix sourceMatrix = this._selectedCorrection.Provide;
            IntensityMatrix source       = sourceMatrix.Subset(this._peakFilter, this._obsFilter, ESubsetFlags.None);

            double[] plsrResponseMatrix = null;

            this._lblPcaSource.Text = this._transposeToShowPeaks ? "Peaks" : "Observations";
            this.transposeToShowObservationsToolStripMenuItem.Checked = !this._transposeToShowPeaks;
            this.transposeToShowPeaksToolStripMenuItem.Checked        = this._transposeToShowPeaks;

            this._lblObs.Text         = this._obsFilter.ToString();
            this._lblPeaks.Text       = this._peakFilter.ToString();
            this._lblCorrections.Text = this._selectedCorrection.ToString();

            this._lblMethod.Text   = this._method.ToString().ToUpper();
            this.ctlTitleBar1.Text = this._method.ToUiString();

            this._lblPlsrSource.Visible = this._mnuPlsrSource.Visible = this._method == EMethod.Plsr;

            int corIndex = IVisualisableExtensions.WhereEnabled(this._core.Corrections).IndexOf(this._selectedCorrection);

            Column plsrColumn;

            this.GetSource(this._regressAgainst, out plsrColumn);

            this._lblPlsrSource.Text = plsrColumn.DisplayName;

            double[,] valueMatrix = this._transposeToShowPeaks ? new double[source.NumRows, source.NumCols] : new double[source.NumCols, source.NumRows];

            for (int row = 0; row < source.NumRows; row++)
            {
                Vector vector = source.Vectors[row];

                int obsIndex = 0;

                for (int col = 0; col < source.NumCols; col++)
                {
                    if (this._transposeToShowPeaks)
                    {
                        valueMatrix[row, col] = source.Values[row, col];
                    }
                    else
                    {
                        valueMatrix[col, row] = source.Values[row, col];
                    }

                    ++obsIndex;
                }
            }

            this._pcaPeaks        = source.Rows.Select(z => z.Peak).ToArray();
            this._pcaObservations = source.Columns.Select(z => z.Observation).ToArray();

            if (this._method == EMethod.Plsr)
            {
                plsrResponseMatrix = new double[valueMatrix.GetLength(0)];

                IEnumerable rows;

                if (this._transposeToShowPeaks)
                {
                    rows = this._pcaPeaks;
                }
                else
                {
                    rows = this._pcaObservations;
                }

                IEnumerator en  = rows.GetEnumerator();
                Factoriser  fac = new Factoriser();

                for (int n = 0; n < plsrResponseMatrix.Length; n++)
                {
                    en.MoveNext();
                    object row = plsrColumn.GetRow((Visualisable)en.Current);
                    plsrResponseMatrix[n] = fac.Factor(row);
                }
            }

            try
            {
                switch (this._method)
                {
                case EMethod.Pca:
                    FrmWait.Show(this, "PCA", "Updating scores", () =>
                                 Arr.Instance.Pca(valueMatrix, out this._scores, out this._loadings));
                    break;

                case EMethod.Plsr:
                    FrmWait.Show(this, "PLSR", "Updating scores", () =>
                                 Arr.Instance.Plsr(valueMatrix, plsrResponseMatrix, out this._scores, out this._loadings));
                    break;

                default:
                    throw new SwitchException(this._method);
                }

                this._errorMessage = null;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("there is no package called 'pls'"))
                {
                    this._errorMessage = "The 'pls' library for R is not installed on your system. Please install that library to use the PLS feature.";
                    FrmMsgBox.ShowError(this, this._errorMessage);
                }
                else
                {
                    this._errorMessage = ex.Message;
                }

                this._scores   = null;
                this._loadings = null;
            }

            this.UpdatePlot();
        }