コード例 #1
0
        private void StandardsChanged(object sender, EventArgs eventArgs)
        {
            if (!FireStandardsChanged)
            {
                return;
            }

            var oldPeps = comboMinPeptide.Items.Cast <string>().ToArray();
            var newPeps = StandardPeptideList.Select(pep => pep.Sequence).ToArray();

            if (oldPeps.SequenceEqual(newPeps))
            {
                return;
            }

            UpdatePeptideCount();

            var curMin = (string)comboMinPeptide.SelectedItem;
            var curMax = (string)comboMaxPeptide.SelectedItem;

            comboMinPeptide.Items.Clear();
            comboMaxPeptide.Items.Clear();

            if (newPeps.Length == 0 || !comboMinPeptide.Enabled)
            {
                return;
            }

            comboMinPeptide.Items.AddRange(newPeps);
            comboMaxPeptide.Items.AddRange(newPeps);

            var newMinIdx = newPeps.IndexOf(pep => pep.Equals(curMin));

            if (newMinIdx < 0)
            {
                newMinIdx = 0;
            }
            var newMaxIdx = newPeps.IndexOf(pep => pep.Equals(curMax));

            if (newMaxIdx < 0)
            {
                newMaxIdx = comboMaxPeptide.Items.Count - 1;
            }

            if (newMinIdx > newMaxIdx)
            {
                var tmp = newMinIdx;
                newMinIdx = newMaxIdx;
                newMaxIdx = tmp;
            }

            comboMinPeptide.SelectedIndex = newMinIdx;
            comboMaxPeptide.SelectedIndex = newMaxIdx;
        }
コード例 #2
0
        private void UpdateEquation(object sender, EventArgs e)
        {
            if (!TryGetLine(false, out var line))
            {
                lblEquation.Text = string.Empty;
                if (!IsRecalibration)
                {
                    FireStandardsChanged = false;
                    StandardPeptideList.ForEach(pep => pep.Irt = double.NaN);
                    StandardPeptideList.ResetBindings();
                    FireStandardsChanged = true;
                }
                return;
            }
            var equationSb = new StringBuilder();

            equationSb.Append(Resources.CalibrateIrtDlg_UpdateControls_iRT);
            equationSb.Append(@" =");
            var roundedSlope     = Math.Round(line.Slope, 4);
            var roundedIntercept = Math.Round(line.Intercept, 4);

            if (roundedSlope != 0 || roundedIntercept != 0)
            {
                if (roundedSlope != 0)
                {
                    if (roundedSlope != 1)
                    {
                        equationSb.Append(string.Format(@" {0:F04} *", roundedSlope));
                    }
                    equationSb.Append(' ');
                    equationSb.Append(Resources.CalibrateIrtDlg_UpdateControls_RT);
                }
                if (roundedIntercept != 0)
                {
                    equationSb.Append(roundedSlope != 0
                        ? string.Format(@" {0} {1:F04}", roundedIntercept >= 0 ? '+' : '-', Math.Abs(roundedIntercept))
                        : string.Format(@" {0:F04}", roundedIntercept));
                }
            }
            else
            {
                equationSb.Append(string.Format(@" {0:F04}", 0));
            }
            lblEquation.Text = equationSb.ToString();
            if (!IsRecalibration && !SelectedRegressionOption.ForcedIrts)
            {
                FireStandardsChanged = false;
                StandardPeptideList.ForEach(pep => pep.Irt = line.GetY(pep.RetentionTime));
                StandardPeptideList.ResetBindings();
                FireStandardsChanged = true;
            }
        }
コード例 #3
0
ファイル: CalibrateIrtDlg.cs プロジェクト: rfellers/pwiz
        public void StandardsChanged(object sender, EventArgs eventArgs)
        {
            var oldPeps = comboMinPeptide.Items.Cast <string>().ToArray();
            var newPeps = StandardPeptideList.Select(pep => pep.Sequence).ToArray();

            if (oldPeps.SequenceEqual(newPeps))
            {
                return;
            }
            labelStandardCount.Text = StandardPeptideList.Count != 1
                ? ModeUIAwareStringFormat(Resources.CalibrateIrtDlg_StandardsChanged__0__peptides, StandardPeptideCount)
                : ModeUIAwareStringFormat(Resources.CalibrateIrtDlg_StandardsChanged__1_peptide);

            var curMin = (string)comboMinPeptide.SelectedItem;
            var curMax = (string)comboMaxPeptide.SelectedItem;

            comboMinPeptide.Items.Clear();
            comboMaxPeptide.Items.Clear();

            if (newPeps.Length == 0 || !comboMinPeptide.Enabled)
            {
                return;
            }

            comboMinPeptide.Items.AddRange(newPeps);
            comboMaxPeptide.Items.AddRange(newPeps);

            var newMinIdx = newPeps.IndexOf(pep => pep.Equals(curMin));

            if (newMinIdx < 0)
            {
                newMinIdx = 0;
            }
            var newMaxIdx = newPeps.IndexOf(pep => pep.Equals(curMax));

            if (newMaxIdx < 0)
            {
                newMaxIdx = comboMaxPeptide.Items.Count - 1;
            }

            if (newMinIdx > newMaxIdx)
            {
                var tmp = newMinIdx;
                newMinIdx = newMaxIdx;
                newMaxIdx = tmp;
            }

            comboMinPeptide.SelectedIndex = newMinIdx;
            comboMaxPeptide.SelectedIndex = newMaxIdx;
        }
コード例 #4
0
        private void comboRegression_SelectedIndexChanged(object sender, EventArgs e)
        {
            labelMinIrt.Enabled         = textMinIrt.Enabled = labelMaxIrt.Enabled = textMaxIrt.Enabled =
                labelMinPeptide.Enabled = comboMinPeptide.Enabled = labelMaxPeptide.Enabled = comboMaxPeptide.Enabled = SelectedRegressionOption.AllowEditEquation;
            if (!SelectedRegressionOption.AllowEditEquation)
            {
                textMinIrt.Clear();
                textMaxIrt.Clear();
                comboMinPeptide.Items.Clear();
                comboMaxPeptide.Items.Clear();
            }
            lblEquation.Visible = calibrateMeasuredRt.Visible = !SelectedRegressionOption.ForcedIrts;
            if (IsRecalibration)
            {
                UpdateEquation(sender, e);
                return;
            }
            calibratePeptides.ReadOnly           = calibrateMeasuredRt.ReadOnly = !SelectedRegressionOption.AllowEditGrid;
            gridViewCalibrate.AllowUserToAddRows = gridViewCalibrate.AllowUserToDeleteRows = SelectedRegressionOption.AllowEditGrid;
            if (SelectedRegressionOption.ForcedStandards)
            {
                _gridViewDriver.SetPeptides(SelectedRegressionOption.StandardPeptides.Select(pep => new StandardPeptide(pep)).ToArray());
                return;
            }
            if (SelectedRegressionOption.MatchedPeptideCount == 0) // fixed point
            {
                StandardsChanged(sender, e);
                UpdateEquation(sender, e);
                return;
            }

            // If standard peptide list is empty, or contains over 50% of the selected regression's peptides, use results
            var regressionPeptides = new TargetMap <bool>(SelectedRegressionOption.MatchedRegressionPeptides.Select(match =>
                                                                                                                    new KeyValuePair <Target, bool>(match.Item1.ModifiedTarget, true)));

            if (StandardPeptideCount == 0 || StandardPeptideList.Count(pep => regressionPeptides.ContainsKey(pep.Target)) >= regressionPeptides.Count / 2)
            {
                if (!SetCalibrationPeptides())
                {
                    comboRegression.SelectedIndex = 0;
                    return;
                }
            }
            UpdateEquation(sender, e);
        }
コード例 #5
0
ファイル: CalibrateIrtDlg.cs プロジェクト: joey10086/pwiz
        public void SetFixedPoints(int one, int two)
        {
            int count = StandardPeptideList.Count;

            if (one >= two || two >= count)
            {
                return;
            }
            for (int i = 0; i < count; i++)
            {
                bool fixedPoint = (i == one || i == two);
                var  peptide    = StandardPeptideList[i];
                if (peptide.FixedPoint != fixedPoint)
                {
                    peptide.FixedPoint = fixedPoint;
                    StandardPeptideList.ResetItem(i);
                }
            }
        }
コード例 #6
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            if (!helper.ValidateNameTextBox(textName, out var name))
            {
                return;
            }
            else if (_existing.Contains(r => !ReferenceEquals(_standard, r) && Equals(name, r.Name)))
            {
                helper.ShowTextBoxError(textName, Resources.CalibrateIrtDlg_OkDialog_The_iRT_standard__0__already_exists_, name);
                return;
            }

            if (!TryGetLine(true, out var linearEquation))
            {
                return;
            }

            if (!IsRecalibration)
            {
                IrtStandard = new IrtStandard(name, null,
                                              StandardPeptideList.Select(pep => new DbIrtPeptide(pep.Target, pep.Irt, true, TimeSource.peak)));
            }
            else
            {
                foreach (var pep in _updatePeptides)
                {
                    pep.Irt = linearEquation.GetY(pep.Irt);
                }
                IrtStandard = new IrtStandard(name, null,
                                              _standard.Peptides.Select(pep =>
                                                                        new DbIrtPeptide(pep.Target, linearEquation.GetY(pep.Irt), true, TimeSource.peak)));
            }
            DialogResult = DialogResult.OK;
        }
コード例 #7
0
ファイル: CalibrateIrtDlg.cs プロジェクト: rfellers/pwiz
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            if (!helper.ValidateNameTextBox(textName, out var name))
            {
                return;
            }
            else if (_existing.Contains(r => !ReferenceEquals(_standard, r) && Equals(name, r.Name)))
            {
                helper.ShowTextBoxError(textName, Resources.CalibrateIrtDlg_OkDialog_The_iRT_standard__0__already_exists_, name);
                return;
            }

            if (!IsRecalibration)
            {
                var irts = IrtStandard.CIRT.Peptides.ToDictionary(p => p.GetNormalizedModifiedSequence(), p => p.Irt);
                var calibrationPeptides = new List <Tuple <DbIrtPeptide, double> >();
                foreach (var pep in StandardPeptideList)
                {
                    double irt;
                    if (!irts.TryGetValue(SequenceMassCalc.NormalizeModifiedSequence(pep.Target), out irt))
                    {
                        break;
                    }
                    calibrationPeptides.Add(new Tuple <DbIrtPeptide, double>(
                                                new DbIrtPeptide(pep.Target, irt, true, TimeSource.peak), pep.RetentionTime));
                }

                if (calibrationPeptides.Count == StandardPeptideList.Count)
                {
                    var statStandard = new Statistics(calibrationPeptides.Select(p => p.Item1.Irt));
                    var statMeasured = new Statistics(calibrationPeptides.Select(p => p.Item2));
                    if (statStandard.R(statMeasured) >= RCalcIrt.MIN_IRT_TO_TIME_CORRELATION)
                    {
                        var result = MultiButtonMsgDlg.Show(this,
                                                            Resources.CalibrateIrtDlg_OkDialog_All_of_these_peptides_are_known_CiRT_peptides__Would_you_like_to_use_the_predefined_iRT_values_,
                                                            MultiButtonMsgDlg.BUTTON_YES, MultiButtonMsgDlg.BUTTON_NO, true);
                        if (result == DialogResult.Cancel)
                        {
                            return;
                        }

                        if (result == DialogResult.Yes)
                        {
                            IrtStandard  = new IrtStandard(name, null, calibrationPeptides.Select(x => x.Item1));
                            DialogResult = DialogResult.OK;
                            return;
                        }
                    }
                }
            }

            if (!TryGetLine(true, out var linearEquation))
            {
                return;
            }

            if (!IsRecalibration)
            {
                IrtStandard = new IrtStandard(name, null,
                                              StandardPeptideList.Select(pep =>
                                                                         new DbIrtPeptide(pep.Target, linearEquation.GetY(pep.RetentionTime), true, TimeSource.peak)));
            }
            else
            {
                foreach (var pep in _updatePeptides)
                {
                    pep.Irt = linearEquation.GetY(pep.Irt);
                }
                IrtStandard = new IrtStandard(name, null,
                                              _standard.Peptides.Select(pep =>
                                                                        new DbIrtPeptide(pep.Target, linearEquation.GetY(pep.Irt), true, TimeSource.peak)));
            }
            DialogResult = DialogResult.OK;
        }