예제 #1
0
        public AddIrtStandardsDlg(int peptideCount, bool peptidesExcluded)
        {
            _peptideCount = peptideCount;
            _graphData    = null;

            InitializeComponent();

            labelMessage.Text = string.Format(!peptidesExcluded ? labelMessage.Text : Resources.AddIrtStandardsDlg_AddIrtStandardsDlg_MessagePeptidesExcluded, peptideCount);
        }
예제 #2
0
        private static RegressionLine GetRegression(TargetMap <double> knownIrts, DbIrtPeptide[] matchingPeptides, int?minPoints, out RegressionGraphData graphData)
        {
            graphData = null;

            var matchingPeptideIrts = new TargetMap <List <double> >(matchingPeptides.Select(pep =>
                                                                                             new KeyValuePair <Target, List <double> >(pep.ModifiedTarget, new List <double>())));

            foreach (var pep in matchingPeptides)
            {
                var list = matchingPeptideIrts[pep.ModifiedTarget];
                list.Add(pep.Irt);
            }
            var listX   = new List <double>();
            var listY   = new List <double>();
            var targets = new Dictionary <int, Target>();

            foreach (var(i, kvp) in matchingPeptideIrts.Where(kvp => kvp.Value.Count > 0).Select((kvp, i) => Tuple.Create(i, kvp)))
            {
                targets[i] = kvp.Key;
                listX.Add(new Statistics(kvp.Value).Median());
                listY.Add(knownIrts[kvp.Key]);
            }

            var regressionMinPoints = minPoints ?? RCalcIrt.MinStandardCount(knownIrts.Count);
            var removed             = new List <Tuple <double, double> >();

            if (!IrtRegression.TryGet <RegressionLine>(listX, listY, regressionMinPoints, out var regression, removed))
            {
                return(null);
            }

            var outliers = new HashSet <int>();

            for (var i = 0; i < listX.Count; i++)
            {
                if (removed.Contains(Tuple.Create(listX[i], listY[i])))
                {
                    outliers.Add(i);
                }
            }

            graphData = new RegressionGraphData
            {
                Title          = Resources.ChooseIrtStandardPeptidesDlg_OkDialog_Linear_regression,
                LabelX         = Resources.ChooseIrtStandardPeptidesDlg_OkDialog_Library_iRTs,
                LabelY         = Resources.ChooseIrtStandardPeptidesDlg_OkDialog_Known_iRTs,
                XValues        = listX.ToArray(),
                YValues        = listY.ToArray(),
                Tooltips       = targets.ToDictionary(target => target.Key, target => target.Value.ToString()),
                OutlierIndices = outliers,
                RegressionLine = regression,
                MinCorrelation = RCalcIrt.MIN_IRT_TO_TIME_CORRELATION,
                MinPoints      = regressionMinPoints,
            };
            return(regression as RegressionLine);
        }
예제 #3
0
        public AddIrtStandardsDlg(int peptideCount, string message, RegressionGraphData graphData = null)
        {
            _peptideCount = peptideCount;
            _graphData    = graphData;

            InitializeComponent();

            labelMessage.Text = message;
            btnGraph.Visible  = graphData != null;
        }
예제 #4
0
        private void ShowGraph(string title, double[] xValues, double[] yValues, Dictionary <int, string> tooltips, RegressionLine line, bool xIrt)
        {
            var data = new RegressionGraphData
            {
                Title          = title,
                LabelX         = !xIrt ? Resources.CalibrateIrtDlg_ShowGraph_Measured : Resources.CalibrateIrtDlg_ShowGraph_Old_iRT,
                LabelY         = !xIrt ? Resources.CalibrateIrtDlg_ShowGraph_iRT : Resources.CalibrateIrtDlg_ShowGraph_New_iRT,
                XValues        = xValues,
                YValues        = yValues,
                Tooltips       = tooltips,
                RegressionLine = line,
            };

            using (var graph = new GraphRegression(new[] { data })
            {
                Width = 800, Height = 600
            })
            {
                graph.ShowDialog(this);
            }
        }
예제 #5
0
        public void ShowGraph()
        {
            DPRegressionData regressionData = GetRegressionData();

            if (regressionData == null)
            {
                return;
            }
            var graphData = new RegressionGraphData
            {
                Title                 = Resources.EditDPDlg_ShowGraph_Declustering_Potential_Regression,
                LabelX                = Resources.EditDPDlg_ShowGraph_Precursor_m_z,
                LabelY                = Resources.EditDPDlg_ShowGraph_Declustering_Potential,
                XValues               = regressionData.PrecursorMzValues,
                YValues               = regressionData.BestValues,
                RegressionLine        = regressionData.RegressionLine,
                RegressionLineCurrent = regressionData.RegressionLineSetting
            };

            using (var dlg = new GraphRegression(new[] { graphData }))
            {
                dlg.ShowDialog(this);
            }
        }
예제 #6
0
        public AddIrtPeptidesDlg(
            AddIrtPeptidesLocation location,
            ProcessedIrtAverages processed,
            IReadOnlyCollection <Target> existingPeptides,
            IReadOnlyCollection <Target> overwritePeptides,
            IReadOnlyCollection <Target> keepPeptides)
        {
            InitializeComponent();

            Icon = Resources.Skyline;

            _regressionGraphData = new Dictionary <DataGridViewRow, RegressionGraphData[]>();

            var successStyle = new DataGridViewCellStyle {
                BackColor = Color.LightGreen
            };
            var failStyle = new DataGridViewCellStyle {
                BackColor = Color.LightCoral
            };

            foreach (var kvp in processed.ProviderData)
            {
                var file = kvp.Key;
                var data = kvp.Value;

                var graphData = new RegressionGraphData
                {
                    Title                 = file,
                    LabelX                = Resources.AddIrtsResultsDlg_dataGridView_CellContentClick_Measured,
                    LabelY                = Resources.AddIrtPeptidesDlg_dataGridView_CellContentClick_iRT,
                    XValues               = data.Times,
                    YValues               = data.Irts,
                    Tooltips              = Enumerable.Range(0, data.Peptides.Length).ToDictionary(i => i, i => data.Peptides[i].ToString()),
                    MissingIndices        = data.MissingIndices,
                    OutlierIndices        = data.OutlierIndices,
                    RegressionLine        = data.RegressionRefined,
                    RegressionLineCurrent = data.Regression,
                    RegressionName        = data.RegressionSuccess
                        ? Resources.AddIrtPeptidesDlg_AddIrtPeptidesDlg_Regression_Refined
                        : Resources.AddIrtPeptidesDlg_AddIrtPeptidesDlg_Regression_Attempted,
                    ShowCurrentR = true,
                    MinR         = RCalcIrt.MIN_IRT_TO_TIME_CORRELATION,
                    MinPoints    = data.MinPoints
                };

                string filename;
                try
                {
                    filename = Path.GetFileName(file);
                }
                catch (Exception)
                {
                    filename = file;
                }
                dataGridView.Rows.Add(
                    filename,
                    graphData.RegularPoints.Count,
                    data.RegressionRefined != null ? data.RegressionRefined.Slope.ToString("F04") : string.Empty,     // Not L10N
                    data.RegressionRefined != null ? data.RegressionRefined.Intercept.ToString("F04") : string.Empty, // Not L10N
                    graphData.R.ToString("F03"),                                                                      // Not L10N
                    data.RegressionSuccess ? Resources.AddIrtPeptidesDlg_AddIrtPeptidesDlg_Success : Resources.AddIrtPeptidesDlg_AddIrtPeptidesDlg_Failed);
                var lastRow = dataGridView.Rows[dataGridView.RowCount - 1];
                lastRow.DefaultCellStyle = data.RegressionSuccess ? successStyle : failStyle;
                lastRow.Tag = data;

                _regressionGraphData[lastRow] = new[] { graphData };
            }

            PeptidesCount      = processed.DbIrtPeptides.Count() - existingPeptides.Count - overwritePeptides.Count - keepPeptides.Count;
            RunsConvertedCount = processed.ProviderData.Count(data => data.Value.RegressionSuccess);
            RunsFailedCount    = processed.ProviderData.Count - RunsConvertedCount;

            string locationStr;

            switch (location)
            {
            default:
                locationStr = Resources.AddIrtPeptidesDlg_AddIrtPeptidesDlg_iRT_database;
                break;

            case AddIrtPeptidesLocation.spectral_library:
                locationStr = Resources.AddIrtPeptidesDlg_AddIrtPeptidesDlg_spectral_library;
                break;
            }

            if (PeptidesCount == 0)
            {
                labelPeptidesAdded.Text = string.Format(Resources.AddIrtPeptidesDlg_AddIrtPeptidesDlg_No_new_peptides_will_be_added_to_the__0__, locationStr);
            }
            else if (PeptidesCount == 1)
            {
                labelPeptidesAdded.Text = string.Format(Resources.AddIrtPeptidesDlg_AddIrtPeptidesDlg_1_new_peptide_will_be_added_to_the__0__, locationStr);
            }
            else
            {
                labelPeptidesAdded.Text = string.Format(labelPeptidesAdded.Text, PeptidesCount, locationStr);
            }

            if (RunsConvertedCount == 0)
            {
                labelRunsConverted.Visible = false;
            }
            else
            {
                labelRunsConverted.Text = RunsConvertedCount > 1
                                              ? string.Format(labelRunsConverted.Text, RunsConvertedCount)
                                              : Resources.AddIrtPeptidesDlg_AddIrtPeptidesDlg_1_run_was_successfully_converted;
            }

            if (RunsFailedCount == 0)
            {
                labelRunsFailed.Visible = false;
            }
            else
            {
                labelRunsFailed.Text = RunsFailedCount > 1
                                           ? string.Format(labelRunsFailed.Text, RunsFailedCount)
                                           : Resources.AddIrtPeptidesDlg_AddIrtPeptidesDlg_1_run_was_not_converted_due_to_insufficient_correlation;
            }

            listExisting.Items.AddRange(existingPeptides.Cast <object>().ToArray());
            listOverwrite.Items.AddRange(overwritePeptides.Cast <object>().ToArray());
            listKeep.Items.AddRange(keepPeptides.Cast <object>().ToArray());

            labelExisting.Text  = string.Format(labelExisting.Text, listExisting.Items.Count);
            labelOverwrite.Text = string.Format(labelOverwrite.Text, listOverwrite.Items.Count);
            labelKeep.Text      = string.Format(labelKeep.Text, listKeep.Items.Count);

            panelExisting.Anchor &= ~AnchorStyles.Bottom;
            if (!processed.ProviderData.Any())
            {
                dataGridView.Visible = false;
                panelOverwrite.Top  -= dataGridView.Height;
                panelKeep.Top       -= dataGridView.Height;
                panelExisting.Top   -= dataGridView.Height;
                Height -= dataGridView.Height;
            }
            if (listOverwrite.Items.Count == 0)
            {
                panelOverwrite.Visible = false;
                panelKeep.Top         -= panelOverwrite.Height;
                panelExisting.Top     -= panelOverwrite.Height;
                Height -= panelOverwrite.Height;
            }
            if (listKeep.Items.Count == 0)
            {
                panelKeep.Visible  = false;
                panelExisting.Top -= panelKeep.Height;
                Height            -= panelKeep.Height;
            }
            panelExisting.Anchor |= AnchorStyles.Bottom;
            if (listExisting.Items.Count == 0)
            {
                panelExisting.Visible = false;
                Height -= panelExisting.Height;
            }

            if (!listOverwrite.Items.Any() && !listKeep.Items.Any() && !listExisting.Items.Any())
            {
                if (processed.ProviderData.Any())
                {
                    dataGridView.Anchor |= AnchorStyles.Bottom;
                }
                else
                {
                    FormBorderStyle = FormBorderStyle.FixedDialog;
                }
            }
        }
예제 #7
0
        public void ShowGraph()
        {
            var calc = _driverCalculators.SelectedItem;

            if (calc == null)
            {
                return;
            }

            if (!calc.IsUsable)
            {
                using (var longWait = new LongWaitDlg
                {
                    Text = Resources.EditRTDlg_ShowGraph_Initializing,
                    Message = string.Format(Resources.EditRTDlg_ShowGraph_Initializing__0__calculator, calc.Name)
                })
                {
                    try
                    {
                        var status = longWait.PerformWork(this, 800, monitor =>
                        {
                            calc = Settings.Default.RTScoreCalculatorList.Initialize(monitor, calc);
                        });
                        if (status.IsError)
                        {
                            MessageBox.Show(this, status.ErrorException.Message, Program.Name);
                            return;
                        }
                    }
                    catch (Exception x)
                    {
                        var message = TextUtil.LineSeparate(string.Format(Resources.EditRTDlg_ShowGraph_An_error_occurred_attempting_to_initialize_the_calculator__0__,
                                                                          calc.Name),
                                                            x.Message);
                        MessageDlg.ShowWithException(this, message, x);
                        return;
                    }
                }
            }

            var helper = new MessageBoxHelper(this);

            double slope;

            if (!helper.ValidateDecimalTextBox(textSlope, out slope))
            {
                return;
            }

            double intercept;

            if (!helper.ValidateDecimalTextBox(textIntercept, out intercept))
            {
                return;
            }

            var scores = new List <double>();
            var times  = new List <double>();

            foreach (var measuredPeptide in Peptides)
            {
                times.Add(measuredPeptide.RetentionTime);
                double?score = calc.ScoreSequence(measuredPeptide.Target);
                scores.Add(score ?? calc.UnknownScore);
            }

            var    statScores       = new Statistics(scores);
            var    statTimes        = new Statistics(times);
            double slopeRegress     = statTimes.Slope(statScores);
            double interceptRegress = statTimes.Intercept(statScores);

            var regressionGraphData = new RegressionGraphData
            {
                Title                 = Resources.EditRTDlg_ShowGraph_Retention_Times_by_Score,
                LabelX                = calc.Name,
                LabelY                = Resources.EditRTDlg_ShowGraph_Measured_Time,
                XValues               = scores.ToArray(),
                YValues               = times.ToArray(),
                RegressionLine        = new RegressionLine(slopeRegress, interceptRegress),
                RegressionLineCurrent = new RegressionLine(slope, intercept)
            };

            using (var dlg = new GraphRegression(new[] { regressionGraphData }))
            {
                dlg.ShowDialog(this);
            }
        }