Ejemplo n.º 1
0
        private void updateResultsDataToolStripMenuItem_Click(object sender, EventArgs e)
        {
            EUpdateResults options = EnumHelper.SumEnum(DataSet.ForFlagsEnum <EUpdateResults>(this._core, "Batch Options").ShowCheckBox(this, null));

            if (options == EUpdateResults.None)
            {
                return;
            }

            IEnumerable <ClusterEvaluationPointer> tests = DataSet.ForTests(this._core).ShowCheckBox(this, null);

            if (tests == null)
            {
                return;
            }

            EClustererStatistics stats;

            if (options.Has(EUpdateResults.Statistics))
            {
                stats = EnumHelper.SumEnum(DataSet.ForFlagsEnum <EClustererStatistics>(this._core, "Statistics").ShowCheckBox(this, null));
            }
            else
            {
                stats = EClustererStatistics.None;
            }

            string log = FrmWait.Show <string>(this, "Batch Process", null, proggy => this.BatchProcess(options, tests, stats, proggy));

            FrmInputMultiLine.ShowFixed(this, this.Text, "Batch Process", "Results of the batch process", log);
        }
Ejemplo n.º 2
0
        private void _btnOk_Click(object sender, EventArgs e)
        {
            List <string>     results = new List <string>();
            SpreadsheetReader ssr     = new SpreadsheetReader();

            foreach (QueuedExport q in this.listBox1.Items)
            {
                ISpreadsheet ss = q.Target.ExportData();

                if (ss == null)
                {
                    results.Add("NO-DATA: " + q.ToString());
                }
                else
                {
                    try
                    {
                        ssr.Write(ss, q.FileName);
                        results.Add("SUCCESS: " + q.ToString());
                    }
                    catch
                    {
                        results.Add("ERROR: " + q.ToString());
                    }
                }
            }

            FrmInputMultiLine.ShowFixed(this, this.Text, "Export", null, string.Join("\r\n\r\n", results));
        }
Ejemplo n.º 3
0
        void break_query()
        {
            Debugger.Break();

            FrmMsgBox.ShowInfo(this, "Message", "This is a message");

            FrmInputMultiLine.ShowFixed(this, "Break query", "Allow debugger to take control", "Showing text stored in temporary string", "");
        }
        private void _btnComment_Click(object sender, EventArgs e)
        {
            string newComment = FrmInputMultiLine.Show(this, this.Text, "Edit Comments", "Enter comments for your algorithm", this._comment);

            if (newComment != null)
            {
                this._comment = newComment;
            }
        }
Ejemplo n.º 5
0
        internal static void ShowError(Form owner, string subTitle, Exception ex)
        {
            MsgBoxButton[] buttons = { new MsgBoxButton("Abort",   Resources.MnuAccept, DialogResult.No),
                                       new MsgBoxButton("Details", Resources.MnuAccept, DialogResult.Yes) };

            if (Show(owner, "Error", subTitle, ex.Message, Resources.MsgError, buttons) == DialogResult.Yes)
            {
                FrmInputMultiLine.ShowFixed(owner, "Error", "Error Details", ex.Message, ex.ToString());
            }
        }
Ejemplo n.º 6
0
        void find_distance_range()
        {
            ProgressReporter prog = new ProgressReporter(this);

            double             smallest  = double.MaxValue;
            double             largest   = double.MinValue;
            Tuple <Peak, Peak> smallestT = null;
            Tuple <Peak, Peak> largestT  = null;
            IMatrixProvider    vmatrix   = DataSet.ForMatrixProviders(this._core).ShowList(this, null);

            if (vmatrix == null)
            {
                return;
            }

            ConfigurationMetric metric = new ConfigurationMetric();

            metric.Args = new ArgsMetric(Algo.ID_METRIC_EUCLIDEAN, vmatrix, null);

            DistanceMatrix dmatrix = DistanceMatrix.Create(this._core, vmatrix.Provide, metric, prog);

            for (int peakIndex1 = 0; peakIndex1 < this._core.Peaks.Count; peakIndex1++)
            {
                for (int peakIndex2 = 0; peakIndex2 < this._core.Peaks.Count; peakIndex2++)
                {
                    if (peakIndex1 != peakIndex2)
                    {
                        double result = dmatrix.Values[peakIndex1, peakIndex2];

                        Peak peak1 = this._core.Peaks[peakIndex1];
                        Peak peak2 = this._core.Peaks[peakIndex2];

                        if (result > largest)
                        {
                            largest  = result;
                            largestT = new Tuple <Peak, Peak>(peak1, peak2);
                        }

                        if (result < smallest)
                        {
                            smallest  = result;
                            smallestT = new Tuple <Peak, Peak>(peak1, peak2);
                        }
                    }
                }
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("| " + smallestT.Item1.DisplayName + " - " + smallestT.Item2.DisplayName + " | = " + smallest);
            sb.AppendLine("| " + largestT.Item1.DisplayName + " - " + largestT.Item2.DisplayName + " | = " + largest);

            FrmInputMultiLine.ShowFixed(this, "Find distance range", "Maximum and minimum differences", "Showing the closest and furthest peaks", sb.ToString());
        }
Ejemplo n.º 7
0
        void display_type_info()
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < this._core.Groups.Count; i++)
            {
                sb.AppendLine("========== " + i + " ==========");
                sb.AppendLine(this._core.Groups[i].ToString());
            }

            FrmInputMultiLine.ShowFixed(this, "Debugging", "Type Info", null, sb.ToString());
        }
Ejemplo n.º 8
0
        void evaluate_cluster_performance()
        {
            bool   warning;
            double d;
            int    di;
            double dz;
            int    dzi;
            double best;
            double worst;
            int    bwcount;
            List <Tuple <Peak, double> > all = new List <Tuple <Peak, double> >();

            QuantifyAssignments(this._core, out warning, out d, out di, out dz, out dzi, out worst, out best, out bwcount, all);
            var all2 = all.Where(λ => λ.Item1.FindAssignments(this._core).All(z => z.Cluster.States == Cluster.EStates.None));

            StringBuilder sb = new StringBuilder();

            sb.AppendLine();
            sb.AppendLine("Value = Σ(i) ( Distance( x(i) - c(i) ) )");
            sb.AppendLine("  Where x = values(i), Distance = Euclidean and c(x) = Closest centre in assigned cluster for i.");
            sb.AppendLine();
            sb.AppendLine("All clusters");
            sb.AppendLine("  Observations = " + di);
            sb.AppendLine("  Value        = " + d);
            sb.AppendLine("  Average      = " + (double)d / di);
            sb.AppendLine();
            sb.AppendLine("All significant clusters");
            sb.AppendLine("  Observations = " + dzi);
            sb.AppendLine("  Value        = " + dz);
            sb.AppendLine("  Average      = " + (double)dz / dzi);
            sb.AppendLine();
            sb.AppendLine("Best/worst 10% in significant clusters");
            sb.AppendLine("  Observations = " + bwcount);
            sb.AppendLine("  Best         = " + best);
            sb.AppendLine("  Worst        = " + worst);
            sb.AppendLine("  Avg. Best    = " + best / bwcount);
            sb.AppendLine("  Avg. Worst   = " + worst / bwcount);
            sb.AppendLine();
            sb.AppendLine("Distribution");
            sb.AppendLine("  all.names = c(" + StringHelper.ArrayToString(all, λ => "\"" + λ.Item1.DisplayName + "\"") + " )");
            sb.AppendLine("  all.values = c(" + StringHelper.ArrayToString(all, λ => λ.Item2.ToString()) + " )");
            sb.AppendLine("  signif.names = c(" + StringHelper.ArrayToString(all2, λ => λ.Item1.DisplayName) + " )");
            sb.AppendLine("  signif.values = c(" + StringHelper.ArrayToString(all2, λ => λ.Item2.ToString()) + " )");

            if (warning)
            {
                FrmMsgBox.ShowWarning(this, "Performance", "One or more clusters had no centres, their centres were set to the average of the assignments.");
            }

            FrmInputMultiLine.ShowFixed(this, "Performance", "Performance", null, sb.ToString());
        }
Ejemplo n.º 9
0
        private void _btnOk_Click(object sender, EventArgs e)
        {
            this._uniqueTable.Reset();

            FrmWait.Show(this, "Exporting data", "Your data is being exported", this.ExportSelected);

            if (this._uniqueTable.Renamed.Count != 0)
            {
                string allRenames = string.Join("\r\n", this._uniqueTable.Renamed.Select(z => z.DisplayName + " --> " + this._uniqueTable.Name(z)).ToArray());
                FrmInputMultiLine.ShowFixed(this, this.Text, "Name clashes", null, "There are some objects with the same DisplayName. To avoid conflicts the objects were temporarily renamed. The new names are guaranteed to match for all tables exported in this instance, but may not match exports made at a later time.\r\n\r\n" + allRenames);
            }

            this.DialogResult = DialogResult.OK;
        }
Ejemplo n.º 10
0
        private void _btnComment_Click(object sender, EventArgs e)
        {
            if (this._readOnly)
            {
                FrmInputMultiLine.ShowFixed(this, this.Text, "View Comments", this._txtName.Text, this._comments);
            }
            else
            {
                string newComments = FrmInputMultiLine.Show(this, this.Text, "Edit Comments", this._txtName.Text, this._comments);

                if (newComments != null)
                {
                    this._comments = newComments;
                }
            }
        }
Ejemplo n.º 11
0
        void do_something_in_r()
        {
            string text = FrmInputMultiLine.Show(this, "R", "Enter command", null, "a = 42\r\na");

            if (text != null)
            {
                try
                {
                    string newText = Arr.Instance.Evaluate(text).ToString();

                    FrmInputMultiLine.ShowFixed(this, "R", "Result of user command", null, newText);
                }
                catch (Exception ex)
                {
                    FrmMsgBox.ShowError(this, ex.Message);
                }
            }
        }
Ejemplo n.º 12
0
        private void _btnHelp_Click(object sender, EventArgs e)
        {
            if (this.HelpClicked != null)
            {
                CancelEventArgs e2 = new CancelEventArgs();

                this.HelpClicked(this, e2);

                if (e2.Cancel)
                {
                    return;
                }
            }

            if (!string.IsNullOrEmpty(this._helpText))
            {
                FrmInputMultiLine.ShowFixed(this.FindForm(), "Help", "Help", this.Text, this._helpText);
            }
        }
Ejemplo n.º 13
0
        public static bool Show(Form owner, TextBox name, ref string comments, bool readOnly)
        {
            if (readOnly)
            {
                FrmInputMultiLine.ShowFixed(owner, owner.Text, "View Comments", name.Text, comments);
                return(false);
            }
            else
            {
                string names = name.Text;

                if (FrmEditINameable.Show(owner, owner.Text, "Edit name and comments", null, name.Text, ref names, ref comments, readOnly, null))
                {
                    name.Text = names;
                    return(true);
                }

                return(false);
            }
        }
Ejemplo n.º 14
0
        void view_variable_full()
        {
            IMatrixProvider im = DataSet.ForMatrixProviders(this._core).ShowList(this, null);

            if (im == null)
            {
                return;
            }

            Vector peak = this.PickVariable(im.Provide);

            if (peak != null)
            {
                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < peak.Observations.Length; i++)
                {
                    ObservationInfo obs = peak.Observations[i];
                    sb.AppendLine(obs.Time + obs.Group.DisplayShortName + obs.Rep + " = " + peak.Values[i]);
                }

                FrmInputMultiLine.ShowFixed(this, "View full variable", peak.ToString(), "Full variable information", sb.ToString());
            }
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Menu: Column help
 /// </summary>
 void _descm_Click(object sender, EventArgs e)
 {
     FrmInputMultiLine.ShowFixed(this.ListView.FindForm(), "Help", "Column Help", this._clickedColumn.Id, this._clickedColumn.Comment);
 }
Ejemplo n.º 16
0
 private void _btnDetails_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     FrmInputMultiLine.ShowFixed(this, this.Text, "Data file sources", "These were the files used to create the initial dataset. Note that these files may have been moved or renamed since the dataset's creation.", this._dfn.GetDetails());
 }
Ejemplo n.º 17
0
        void find_classifier()
        {
            Core core = this._core;

            UserFlag type1;
            UserFlag type2;

            ConfigurationStatistic stat = DataSet.ForStatistics(this._core).ShowList(this, null);

            if (stat == null)
            {
                FrmMsgBox.ShowError(this, "No stat with this name");
                return;
            }

            string sign = FrmInputSingleLine.Show(this, "Classifier settings", "Find classifier", "Enter the cutoff, or 0 for for automatic", "0");
            double manCutoff;

            type1 = DataSet.ForUserFlags(this._core).IncludeMessage("Specify the comment flag signifying the first type").ShowList(this, null);

            if (type1 == null)
            {
                return;
            }

            type2 = DataSet.ForUserFlags(this._core).IncludeMessage("Specify the comment flag signifying the second type").ShowList(this, null);

            if (type2 == null)
            {
                return;
            }

            if (!double.TryParse(sign, out manCutoff))
            {
                return;
            }

            StringBuilder sb = new StringBuilder();

            // TID0 = Full
            // TID1..5 = Test/training
            // TID6..9 = Bootstrap
            for (int tid = 0; tid < 10; tid++)
            {
                // Get all significances
                List <double> sigs = new List <double>(core.Peaks.Select(λ => λ.GetStatistic(stat)));

                List <bool> inTrainingSet = new List <bool>(core.Peaks.Count);
                int         co;

                // For the training only include 75%
                if (tid >= 1 && tid <= 5)
                {
                    co = (int)(core.Peaks.Count * 0.75d);
                }
                else
                {
                    co = core.Peaks.Count;
                }

                for (int n = 0; n < core.Peaks.Count; n++)
                {
                    inTrainingSet.Add(n < co);
                }

                inTrainingSet.Shuffle();

                // For the boot-strap shuffle the sigs
                if (tid >= 6)
                {
                    sigs.Shuffle();
                }

                Tuple <double, int, int, int, int> best     = null;
                Tuple <double, int, int, int, int> bestTest = null;
                double cutoff = 0;

                // Find the best variable cutoff
                if (manCutoff == 0.0d)
                {
                    for (int n = 0; n < core.Peaks.Count; n++)
                    {
                        if (inTrainingSet[n])
                        {
                            var success = this.SimpleClassify(sigs[n], type1, type2, sigs, inTrainingSet, true);

                            if (best == null || success.Item1 > best.Item1)
                            {
                                best     = success;
                                bestTest = this.SimpleClassify(sigs[n], type1, type2, sigs, inTrainingSet, false);
                                cutoff   = sigs[n];
                            }
                        }
                    }
                }
                else
                {
                    best     = this.SimpleClassify(manCutoff, type1, type2, sigs, inTrainingSet, true);
                    bestTest = this.SimpleClassify(manCutoff, type1, type2, sigs, inTrainingSet, false);
                    cutoff   = manCutoff;
                }

                sb.AppendLine(tid == 0 ? "FULLDATA" : tid <= 5 ? "VALIDATION" : "BOOTSTRAP");
                sb.AppendLine();
                sb.AppendLine("    " + type1 + " <= " + cutoff + " < " + type2);
                sb.AppendLine();
                sb.AppendLine("    TRAINING SET (" + co + ")");
                sb.AppendLine("        " + type1 + " correct: " + StringHelper.AsFraction(best.Item2, best.Item2 + best.Item3));
                sb.AppendLine("        " + type2 + " correct: " + StringHelper.AsFraction(best.Item4, best.Item4 + best.Item5));
                sb.AppendLine("        Total correct: " + StringHelper.AsFraction(best.Item2 + best.Item4, best.Item2 + best.Item4 + best.Item3 + best.Item5));
                sb.AppendLine("        Variables used: " + StringHelper.AsFraction(best.Item2 + best.Item4 + best.Item3 + best.Item5, core.Peaks.Count));
                sb.AppendLine();
                if (co != core.Peaks.Count)
                {
                    sb.AppendLine("    TEST SET (" + (core.Peaks.Count - co) + ")");
                    sb.AppendLine("        " + type1 + " correct: " + StringHelper.AsFraction(bestTest.Item2, bestTest.Item2 + bestTest.Item3));
                    sb.AppendLine("        " + type2 + " correct: " + StringHelper.AsFraction(bestTest.Item4, bestTest.Item4 + bestTest.Item5));
                    sb.AppendLine("        Total correct: " + StringHelper.AsFraction(bestTest.Item2 + bestTest.Item4, bestTest.Item2 + bestTest.Item4 + bestTest.Item3 + bestTest.Item5));
                    sb.AppendLine("        Variables used: " + StringHelper.AsFraction(bestTest.Item2 + bestTest.Item4 + bestTest.Item3 + bestTest.Item5, core.Peaks.Count));
                    sb.AppendLine();
                    sb.AppendLine("    SCORE: " + (bestTest.Item1 * 100).ToString("F02"));
                }
                else
                {
                    sb.AppendLine("    SCORE: " + (best.Item1 * 100).ToString("F02"));
                }
                sb.AppendLine();
                sb.AppendLine("--------------------------------------------------------------------------------");
                sb.AppendLine();
            }

            FrmInputMultiLine.ShowFixed(this, "Find classifier", "Classifier results", "Best value to determine split between variables marked with \"" + type1 + "\" and \"" + type2 + "\" based on their significances", sb.ToString());
        }
Ejemplo n.º 18
0
        private void view_statistics()
        {
            Core          core = this._core;
            StringBuilder sb   = new StringBuilder();

            int    vwpid = core.Peaks.Count(λ => λ.Annotations.Count != 0);
            double td    = core.Peaks.Sum(λ => λ.FindAssignments(this._core).Any() ? λ.FindAssignments(this._core).Select(z => z.Score).Average() : double.NaN) / core.Peaks.Count;
            int    sigs  = core.Peaks.Count(λ => λ.FindAssignments(this._core).All(z => z.Cluster.States == Cluster.EStates.None));

            sb.AppendLine("Observations:");
            sb.AppendLine("    № observations = " + core.Observations.Count);
            sb.AppendLine("    № conditions = " + core.Conditions.Count);
            sb.AppendLine("    № types = " + core.Groups.Count);
            sb.AppendLine();

            sb.AppendLine("Variables:");
            sb.AppendLine("    № variables = " + core.Peaks.Count);
            sb.AppendLine("    № with potential IDs = " + StringHelper.AsFraction(vwpid, core.Peaks.Count));
            sb.AppendLine("    № significant (based on cluster) = " + StringHelper.AsFraction(sigs, core.Peaks.Count));
            sb.AppendLine("    Average distance = " + td.ToString("F02"));
            sb.AppendLine();

            sb.AppendLine("Clusters:");
            sb.AppendLine("    № clusters = " + core.Clusters.Count());
            sb.AppendLine("    Active count = " + core.Clusters.Count(p => p.States == Cluster.EStates.None));
            sb.AppendLine();

            foreach (Cluster p in core.Clusters)
            {
                sb.AppendLine("    " + p.DisplayName + " = " + StringHelper.AsFraction(p.Assignments.Count, core.Peaks.Count));
            }
            sb.AppendLine();

            int pc = core.Pathways.Count(p => !p.Compounds.TrueForAll(c => c.Annotations.Count == 0));

            sb.AppendLine("Pathways:");
            sb.AppendLine("    № pathways = " + core.Pathways.Count);
            sb.AppendLine("    № with 1+ potential IDs = " + StringHelper.AsFraction(pc, core.Pathways.Count));
            sb.AppendLine();

            int cc = core.Compounds.Count(c => c.Annotations.Count != 0);

            sb.AppendLine("Compounds:");
            sb.AppendLine("    № compounds = " + core.Compounds.Count);
            sb.AppendLine("    № with potential variables = " + StringHelper.AsFraction(cc, core.Compounds.Count));
            sb.AppendLine();

            sb.AppendLine("Adducts:");
            sb.AppendLine("    № adducts = " + core.Adducts.Count);
            sb.AppendLine();

            sb.AppendLine("Flags:");
            HashSet <UserFlag> flags = new HashSet <UserFlag>();

            foreach (Peak v in core.Peaks)
            {
                foreach (UserFlag flag in v.UserFlags)
                {
                    flags.Add(flag);
                }
            }

            foreach (UserFlag flag in flags)
            {
                int c = 0;

                foreach (Peak v in core.Peaks)
                {
                    if (v.UserFlags.Contains(flag))
                    {
                        c++;
                    }
                }

                sb.AppendLine("    " + flag + " = " + StringHelper.AsFraction(c, core.Peaks.Count));
            }

            FrmInputMultiLine.ShowFixed(this, "View statistics", "Statistics summary", null, sb.ToString());
        }