예제 #1
0
        public bool CalcRegressionWith(IRetentionTimeProvider retentionTimes, IEnumerable <DbIrtPeptide> standardPeptideList, DbIrtPeptide[] items)
        {
            if (items.Any())
            {
                // Attempt to get a regression based on shared peptides
                var calculator    = new CurrentCalculator(standardPeptideList, items);
                var peptidesTimes = retentionTimes.PeptideRetentionTimes.ToArray();
                var regression    = RetentionTimeRegression.FindThreshold(RCalcIrt.MIN_IRT_TO_TIME_CORRELATION,
                                                                          RetentionTimeRegression.ThresholdPrecision,
                                                                          peptidesTimes,
                                                                          new MeasuredRetentionTime[0],
                                                                          peptidesTimes, null,
                                                                          calculator,
                                                                          RegressionMethodRT.linear,
                                                                          () => false);

                var startingCount   = peptidesTimes.Length;
                var regressionCount = regression != null ? regression.PeptideTimes.Count : 0;
                if (regression != null && RCalcIrt.IsAcceptableStandardCount(startingCount, regressionCount))
                {
                    // Finally must recalculate the regression, because it is transposed from what
                    // we want.
                    var statTimes = new Statistics(regression.PeptideTimes.Select(pt => pt.RetentionTime));
                    var statIrts  = new Statistics(regression.PeptideTimes.Select(pt =>
                                                                                  calculator.ScoreSequence(pt.PeptideSequence) ?? calculator.UnknownScore));

                    RegressionRefined = new RegressionLine(statIrts.Slope(statTimes), statIrts.Intercept(statTimes));
                    RegressionSuccess = true;
                    return(true);
                }
            }
            return(false);
        }
예제 #2
0
        private static RegressionLine CalcConversion(IList <TimeScorePair> listPepCorr, int minCount)
        {
            var listTime  = listPepCorr.Select(p => p.Time).ToList();
            var listScore = listPepCorr.Select(p => p.Score).ToList();

            RegressionLine line;

            return(RCalcIrt.TryGetRegressionLine(listScore, listTime, minCount, out line) ? line : null);
        }
예제 #3
0
 public bool Equals(RCalcIrt other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(base.Equals(other) && Equals(other._database, _database) && Equals(other.DatabasePath, DatabasePath));
 }
예제 #4
0
        public override IEnumerable <Target> ChooseRegressionPeptides(IEnumerable <Target> peptides, out int minCount)
        {
            var returnStandard = peptides.Where(_dictStandards.ContainsKey).ToArray();
            var returnCount    = returnStandard.Length;
            var standardsCount = _dictStandards.Count;

            if (!RCalcIrt.IsAcceptableStandardCount(standardsCount, returnCount))
            {
                throw new IncompleteStandardException(this);
            }

            minCount = RCalcIrt.MinStandardCount(standardsCount);
            return(returnStandard);
        }
예제 #5
0
 public static List<DbIrtPeptide> GetUnscoredIrtPeptides(List<DbIrtPeptide> dbIrtPeptides, RCalcIrt calcIrt)
 {
     var dbIrtPeptidesFilter = new List<DbIrtPeptide>();
     // Filter out peptides that have the same sequence and iRT as those in the database
     foreach (var dbIrtPeptide in dbIrtPeptides)
     {
         double? oldScore = calcIrt != null ? calcIrt.ScoreSequence(dbIrtPeptide.PeptideModSeq) : null;
         if (oldScore == null || Math.Abs(oldScore.Value - dbIrtPeptide.Irt) > DbIrtPeptide.IRT_MIN_DIFF)
         {
             dbIrtPeptidesFilter.Add(dbIrtPeptide);
         }
     }
     return dbIrtPeptidesFilter;
 }
예제 #6
0
 private RCalcIrt LoadCalculator(IDocumentContainer container, RCalcIrt calc)
 {
     // TODO: Something better than locking for the entire load
     lock (_loadedCalculators)
     {
         RCalcIrt calcResult;
         if (!_loadedCalculators.TryGetValue(calc.Name, out calcResult))
         {
             calcResult = (RCalcIrt)calc.Initialize(new LoadMonitor(this, container, calc));
             if (calcResult != null)
             {
                 _loadedCalculators.Add(calcResult.Name, calcResult);
             }
         }
         return(calcResult);
     }
 }
예제 #7
0
        private static RegressionLine CalcConversion(IList <TimeScorePair> listPepCorr, int minCount)
        {
            var listTime  = listPepCorr.Select(p => p.Time).ToList();
            var listScore = listPepCorr.Select(p => p.Score).ToList();

            RegressionLine line;

            if (RCalcIrt.TryGetRegressionLine(listScore, listTime, minCount, out line))
            {
                return(line);
            }

            // TODO: Figure out something better here
            var statTime  = new Statistics(listTime);
            var statScore = new Statistics(listScore);

            return(new RegressionLine(statTime.Slope(statScore), statTime.Intercept(statScore)));
        }
예제 #8
0
        private bool TryGetCirtRegression(int count, out RegressionLine regression, out List <ScoredPeptide> peptides)
        {
            peptides = new List <ScoredPeptide>(_cirtPeptides);
            var rts           = _cirtPeptides.Select(pep => pep.Peptide.RetentionTime).ToList();
            var irts          = _cirtPeptides.Select(pep => _cirtAll[pep.Peptide.Target]).ToList();
            var removedValues = new List <Tuple <double, double> >();

            if (!RCalcIrt.TryGetRegressionLine(rts, irts, count, out regression, removedValues))
            {
                return(false);
            }

            for (var i = peptides.Count - 1; i >= 0; i--)
            {
                if (removedValues.Contains(Tuple.Create(rts[i], irts[i])))
                {
                    peptides.RemoveAt(i);
                }
            }
            return(peptides.Count >= count);
        }
예제 #9
0
        public RetentionTimeProviderData(IRetentionTimeProvider retentionTimes, IEnumerable <DbIrtPeptide> standardPeptides)
        {
            RetentionTimeProvider = retentionTimes;

            Peptides = standardPeptides.Select(standardPeptide => new Peptide(standardPeptide.ModifiedTarget,
                                                                              retentionTimes.GetRetentionTime(standardPeptide.ModifiedTarget), standardPeptide.Irt)).ToList();
            Peptides.Sort((x, y) => x.Irt.CompareTo(y.Irt));

            if (!FilteredPeptides.Any())
            {
                Regression        = null;
                RegressionRefined = null;
                RegressionSuccess = false;
            }

            var filteredRt  = FilteredPeptides.Select(pep => pep.RetentionTime.Value).ToList();
            var filteredIrt = FilteredPeptides.Select(pep => pep.Irt).ToList();
            var statTimes   = new Statistics(filteredRt);
            var statIrts    = new Statistics(filteredIrt);

            Regression = new RegressionLine(statIrts.Slope(statTimes), statIrts.Intercept(statTimes));

            var removed = new List <Tuple <double, double> >();

            RegressionSuccess = RCalcIrt.TryGetRegressionLine(filteredRt, filteredIrt, MinPoints, out _regressionRefined, removed);
            foreach (var remove in removed)
            {
                for (var i = 0; i < Peptides.Count; i++)
                {
                    var peptide = Peptides[i];
                    if (peptide.RetentionTime.Equals(remove.Item1) && peptide.Irt.Equals(remove.Item2))
                    {
                        Peptides[i] = new Peptide(peptide, true);
                    }
                }
            }
        }
예제 #10
0
 public DatabaseNotConnectedException(RCalcIrt calc)
     : base(string.Format(DBERROR, calc.Name, calc.DatabasePath))
 {
     _calculator = calc;
 }
예제 #11
0
        public RetentionTimeProviderData(IRetentionTimeProvider retentionTimes, IEnumerable <DbIrtPeptide> standardPeptides)
        {
            RetentionTimeProvider = retentionTimes;

            // Attempt to get regression based on standards
            var listPeptides = new List <Target>();
            var listTimes    = new List <double>();
            var listIrts     = new List <double>();

            foreach (var standardPeptide in standardPeptides)
            {
                listPeptides.Add(standardPeptide.ModifiedTarget);
                listTimes.Add(retentionTimes.GetRetentionTime(standardPeptide.ModifiedTarget) ?? double.MaxValue);
                listIrts.Add(standardPeptide.Irt);
            }

            var arrayTimes = listTimes.ToArray();

            // var libraryTimes = retentionTimes as LibraryRetentionTimes;
            // if (libraryTimes != null)
            //     Trace.WriteLine(libraryTimes.Name);
            // Trace.WriteLine(string.Format("times = {0}", string.Join(", ", arrayTimes.Select(t => string.Format("{0:F02}", t)))));

            Peptides       = listPeptides.ToArray();
            Times          = arrayTimes;
            Irts           = listIrts.ToArray();
            MissingIndices = new HashSet <int>();
            for (var i = 0; i < Times.Length; i++)
            {
                if (Times[i] == double.MaxValue)
                {
                    MissingIndices.Add(i);
                }
            }
            TimesFiltered = Times.Where((v, i) => !MissingIndices.Contains(i)).ToArray();
            IrtsFiltered  = Irts.Where((v, i) => !MissingIndices.Contains(i)).ToArray();

            OutlierIndices = new HashSet <int>();
            if (TimesFiltered.Any())
            {
                var statTimes = new Statistics(TimesFiltered);
                var statIrts  = new Statistics(IrtsFiltered);
                Regression = new RegressionLine(statIrts.Slope(statTimes), statIrts.Intercept(statTimes));

                var removed = new List <Tuple <double, double> >();
                RegressionSuccess = RCalcIrt.TryGetRegressionLine(TimesFiltered.ToList(), IrtsFiltered.ToList(), MinPoints, out _regressionRefined, removed);
                foreach (var remove in removed)
                {
                    for (var i = 0; i < Times.Length && i < Irts.Length; i++)
                    {
                        if (Times[i] == remove.Item1 && Irts[i] == remove.Item2)
                        {
                            OutlierIndices.Add(i);
                        }
                    }
                }
            }
            else
            {
                Regression        = null;
                RegressionRefined = null;
                RegressionSuccess = false;
            }
        }