Esempio n. 1
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);
        }