コード例 #1
0
        /// <summary>
        /// Align retention times with a target.
        /// For the MS2 Id's that are found in both the target and the timesToAlign, the MS2 id's
        /// are plotted against each other, and a linear regression is performed.
        /// In cases where there is more than one MS2 id in either file, only the earliest MS2 id from
        /// each file is used.
        /// </summary>
        public static AlignedRetentionTimes AlignLibraryRetentionTimes(IDictionary <Target, double> target, IDictionary <Target, double> originalTimes, double refinementThreshhold, RegressionMethodRT regressionMethod,
                                                                       Func <bool> isCanceled)
        {
            var calculator      = new DictionaryRetentionScoreCalculator("alignment", originalTimes); // Not L10N
            var targetTimesList = new List <MeasuredRetentionTime>();

            foreach (var entry in calculator.RetentionTimes)
            {
                double targetTime;
                if (!target.TryGetValue(entry.Key, out targetTime))
                {
                    continue;
                }
                MeasuredRetentionTime measuredRetentionTime;
                try
                {
                    measuredRetentionTime = new MeasuredRetentionTime(entry.Key, targetTime);
                }
                catch
                {
                    continue;
                }
                targetTimesList.Add(measuredRetentionTime);
            }
            RetentionTimeStatistics regressionStatistics;
            var regression = RetentionTimeRegression.CalcRegression(XmlNamedElement.NAME_INTERNAL, new[] { calculator }, regressionMethod, targetTimesList, out regressionStatistics);

            if (regression == null)
            {
                return(null);
            }
            RetentionTimeRegression regressionRefined;
            RetentionTimeStatistics regressionRefinedStatistics = regressionStatistics;
            HashSet <int>           outIndexes = new HashSet <int>();

            if (regressionStatistics.R >= refinementThreshhold)
            {
                regressionRefined = regression;
            }
            else
            {
                var cache = new RetentionTimeScoreCache(new[] { calculator }, new MeasuredRetentionTime[0], null);
                regressionRefined = regression.FindThreshold(refinementThreshhold, null, 0,
                                                             targetTimesList.Count, new MeasuredRetentionTime[0], targetTimesList, null, regressionStatistics,
                                                             calculator, regressionMethod, cache, isCanceled, ref regressionRefinedStatistics,
                                                             ref outIndexes);
            }

            return(new AlignedRetentionTimes
            {
                TargetTimes = target,
                OriginalTimes = originalTimes,
                Regression = regression,
                RegressionStatistics = regressionStatistics,
                RegressionRefined = regressionRefined,
                RegressionRefinedStatistics = regressionRefinedStatistics,
                OutlierIndexes = outIndexes,
                Calculator = calculator
            });
        }
コード例 #2
0
        /// <summary>
        /// Align retention times with a target.
        /// For the MS2 Id's that are found in both the target and the timesToAlign, the MS2 id's 
        /// are plotted against each other, and a linear regression is performed.
        /// In cases where there is more than one MS2 id in either file, only the earliest MS2 id from
        /// each file is used.
        /// </summary>
        public static AlignedRetentionTimes AlignLibraryRetentionTimes(IDictionary<string, double> target, IDictionary<string, double> originalTimes, double refinementThreshhold, Func<bool> isCanceled)
        {
            var calculator = new DictionaryRetentionScoreCalculator("alignment", originalTimes); // Not L10N
            var targetTimesList = new List<MeasuredRetentionTime>();
            foreach (var entry in calculator.RetentionTimes)
            {
                double targetTime;
                if (!target.TryGetValue(entry.Key, out targetTime))
                {
                    continue;
                }
                MeasuredRetentionTime measuredRetentionTime;
                try
                {
                    measuredRetentionTime = new MeasuredRetentionTime(entry.Key, targetTime);
                }
                catch
                {
                    continue;
                }
                targetTimesList.Add(measuredRetentionTime);
            }
            RetentionTimeStatistics regressionStatistics;
            var regression = RetentionTimeRegression.CalcRegression(XmlNamedElement.NAME_INTERNAL, new[] {calculator}, targetTimesList, out regressionStatistics);
            if (regression == null)
            {
                return null;
            }
            RetentionTimeRegression regressionRefined;
            RetentionTimeStatistics regressionRefinedStatistics = regressionStatistics;
            HashSet<int> outIndexes = new HashSet<int>();
            if (regressionStatistics.R >= refinementThreshhold)
            {
                regressionRefined = regression;
            }
            else
            {
                var cache = new RetentionTimeScoreCache(new[] {calculator}, new MeasuredRetentionTime[0], null);
                regressionRefined = regression.FindThreshold(refinementThreshhold, null, 0,
                                                                targetTimesList.Count, new MeasuredRetentionTime[0], targetTimesList, regressionStatistics,
                                                                calculator, cache, isCanceled, ref regressionRefinedStatistics,
                                                                ref outIndexes);
            }

            return new AlignedRetentionTimes
                       {
                           TargetTimes = target,
                           OriginalTimes = originalTimes,
                           Regression = regression,
                           RegressionStatistics = regressionStatistics,
                           RegressionRefined = regressionRefined,
                           RegressionRefinedStatistics = regressionRefinedStatistics,
                           OutlierIndexes = outIndexes,
                       };
        }