Esempio n. 1
0
        private RetentionScoreCalculatorSpec RecalcRegression(IList <MeasuredRetentionTime> peptides)
        {
            var tryCalcs = Settings.Default.RTScoreCalculatorList.ToList();
            RetentionScoreCalculatorSpec calculator = null;

            while (calculator == null && tryCalcs.Count > 0)
            {
                try
                {
                    calculator = RecalcRegression(tryCalcs, peptides);
                    break;
                }
                catch (IncompleteStandardException e)
                {
                    tryCalcs.Remove(e.Calculator);
                }
            }
            return(calculator);
        }
            public GraphData(SrmDocument document, GraphData dataPrevious,
                             int resultIndex, double threshold, int?thresholdPrecision, bool refine, bool bestResult, PointsTypeRT pointsType)
            {
                _document           = document;
                _resultIndex        = resultIndex;
                _bestResult         = bestResult;
                _threshold          = threshold;
                _thresholdPrecision = thresholdPrecision;
                _pointsType         = pointsType;
                _peptidesIndexes    = new List <PeptideDocumentIndex>();
                _peptidesTimes      = new List <MeasuredRetentionTime>();
                int index = -1;

                var standards = new HashSet <string>();

                if (RTGraphController.PointsType == PointsTypeRT.standards)
                {
                    standards = document.GetRetentionTimeStandards();
                }

                // CONSIDER: Retention time prediction for small molecules?
                foreach (var nodePeptide in document.Peptides)
                {
                    index++;

                    switch (RTGraphController.PointsType)
                    {
                    default:
                        if (nodePeptide.IsDecoy)
                        {
                            continue;
                        }
                        break;

                    case PointsTypeRT.standards:
                        if (!standards.Contains(document.Settings.GetModifiedSequence(nodePeptide)))
                        {
                            continue;
                        }
                        break;

                    case PointsTypeRT.decoys:
                        if (!nodePeptide.IsDecoy)
                        {
                            continue;
                        }
                        break;
                    }

                    float?rt = null;
                    if (!bestResult)
                    {
                        rt = nodePeptide.GetSchedulingTime(resultIndex);
                    }
                    else
                    {
                        int iBest = nodePeptide.BestResult;
                        if (iBest != -1)
                        {
                            rt = nodePeptide.GetSchedulingTime(iBest);
                        }
                    }
                    if (!rt.HasValue)
                    {
                        rt = 0;
                    }

                    _peptidesIndexes.Add(new PeptideDocumentIndex(nodePeptide, index));
                    string modSeq = _document.Settings.GetSourceTextId(nodePeptide);
                    _peptidesTimes.Add(new MeasuredRetentionTime(modSeq, rt.Value));
                }

                _calculatorName = Settings.Default.RTCalculatorName;
                RetentionScoreCalculatorSpec calc = !string.IsNullOrEmpty(_calculatorName)
                                                        ? Settings.Default.GetCalculatorByName(Settings.Default.RTCalculatorName)
                                                        : null;

                if (calc == null)
                {
                    // Initialize all calculators
                    Settings.Default.RTScoreCalculatorList.Initialize(null);

                    //This call will pick the best calculator, disqualifying any iRT Calcs that do not have
                    //connected databases
                    _regressionAll = RetentionTimeRegression.CalcRegression(XmlNamedElement.NAME_INTERNAL,
                                                                            Settings.Default.RTScoreCalculatorList,
                                                                            _peptidesTimes,
                                                                            _scoreCache,
                                                                            true,
                                                                            out _statisticsAll,
                                                                            out _calculator);
                }
                else
                {
                    // Initialize the one calculator
                    calc = Settings.Default.RTScoreCalculatorList.Initialize(null, calc);

                    _regressionAll = RetentionTimeRegression.CalcRegression(XmlNamedElement.NAME_INTERNAL,
                                                                            new[] { calc },
                                                                            _peptidesTimes,
                                                                            _scoreCache,
                                                                            true,
                                                                            out _statisticsAll,
                                                                            out _calculator);

                    //If _regressionAll is null, it is safe to assume that the calculator is an iRT Calc with
                    //its database disconnected.
                    if (_regressionAll == null)
                    {
                        var tryIrtCalc = calc as RCalcIrt;
                        //Only show an error message if the user specifically chooses this calculator.
                        if (dataPrevious != null && !ReferenceEquals(calc, dataPrevious.Calculator) && tryIrtCalc != null)
                        {
                            throw new DatabaseNotConnectedException(tryIrtCalc);
                        }
                    }
                }

                if (_regressionAll != null)
                {
                    _scoreCache = new RetentionTimeScoreCache(new[] { _calculator }, _peptidesTimes,
                                                              dataPrevious != null ? dataPrevious._scoreCache : null);

                    if (dataPrevious != null && !ReferenceEquals(_calculator, dataPrevious._calculator))
                    {
                        _scoreCache.RecalculateCalcCache(_calculator);
                    }

                    _scoresRefined = _statisticsAll.ListHydroScores.ToArray();
                    _timesRefined  = _statisticsAll.ListRetentionTimes.ToArray();
                }

                _regressionPredict = document.Settings.PeptideSettings.Prediction.RetentionTime;
                if (_regressionPredict != null)
                {
                    if (!Equals(_calculator, _regressionPredict.Calculator))
                    {
                        _regressionPredict = null;
                    }
                    else
                    {
                        IDictionary <string, double> scoreCache = null;
                        if (_regressionAll != null && ReferenceEquals(_regressionAll.Calculator, _regressionPredict.Calculator))
                        {
                            scoreCache = _statisticsAll.ScoreCache;
                        }
                        _statisticsPredict = _regressionPredict.CalcStatistics(_peptidesTimes, scoreCache);
                    }
                }

                // Only refine, if not already exceeding the threshold
                _refine = refine && !IsRefined();
            }
Esempio n. 3
0
 public DatabaseNotConnectedException(RCalcIrt calc)
     : base(string.Format(DBERROR, calc.Name, calc.DatabasePath))
 {
     _calculator = calc;
 }
Esempio n. 4
0
 public IncompleteStandardException(RetentionScoreCalculatorSpec calc)
     : base(String.Format(ERROR, calc.Name))
 {
     Calculator = calc;
 }
Esempio n. 5
0
 public IncompleteStandardException(RetentionScoreCalculatorSpec calc)
     : base(String.Format(ERROR, calc.Name))
 {
     Calculator = calc;
 }
Esempio n. 6
0
 public DatabaseNotConnectedException(RCalcIrt calc)
     : base(string.Format(DBERROR, calc.Name, calc.DatabasePath))
 {
     _calculator = calc;
 }
Esempio n. 7
0
 private void RecalcRegression(RetentionScoreCalculatorSpec calculator, IList <MeasuredRetentionTime> peptides)
 {
     RecalcRegression(new[] { calculator }, peptides);
 }
Esempio n. 8
0
        /// <summary>
        /// This function will update the calculator to the one given, or to the one with the best score for the document
        /// peptides. It will then return the peptides chosen by that calculator for regression.
        /// Todo: split this function into one that chooses and returns the calculator and one that returns the peptides
        /// todo: chosen by that calculator
        /// </summary>
        private IList <MeasuredRetentionTime> UpdateCalculator(RetentionScoreCalculatorSpec calculator, IList <MeasuredRetentionTime> activePeptides = null)
        {
            bool calcInitiallyNull = calculator == null;

            activePeptides = activePeptides ?? GetTablePeptides();
            if (activePeptides.Count == 0)
            {
                return(null);
            }

            //Try connecting all the calculators
            Settings.Default.RTScoreCalculatorList.Initialize(null);

            if (calculator == null)
            {
                //this will not update the calculator
                calculator = RecalcRegression(activePeptides);
                if (calculator == null)
                {
                    return(null);
                }
            }
            else
            {
                var calcSettings = Settings.Default.GetCalculatorByName(calculator.Name);
                if (calcSettings != null)
                {
                    calculator = calcSettings;
                }

                if (!calculator.IsUsable)
                {
                    MessageDlg.Show(this,
                                    Resources.
                                    EditRTDlg_UpdateCalculator_The_calculator_cannot_be_used_to_score_peptides_Please_check_its_settings);
                    return(activePeptides);
                }

                RecalcRegression(calculator, activePeptides);
            }

            int minCount;
            var usePeptides = new HashSet <Target>(calculator.ChooseRegressionPeptides(
                                                       activePeptides.Select(pep => pep.PeptideSequence), out minCount));
            //now go back and get the MeasuredPeptides corresponding to the strings chosen by the calculator
            var tablePeptides = activePeptides.Where(measuredRT =>
                                                     usePeptides.Contains(measuredRT.PeptideSequence)).ToList();

            if (tablePeptides.Count == 0 && activePeptides.Count != 0)
            {
                MessageDlg.Show(this,
                                String.Format(
                                    Resources.
                                    EditRTDlg_UpdateCalculator_The__0__calculator_cannot_score_any_of_the_peptides,
                                    calculator.Name));
                comboCalculator.SelectedIndex = 0;
                return(null);
            }

            //This "if" is to keep from getting into infinite loops
            if (calcInitiallyNull)
            {
                comboCalculator.SelectedItem = calculator.Name;
            }

            return(tablePeptides);
        }