Ejemplo n.º 1
0
            /// <summary>
            /// Get, create, or update the current dictionary that gives uniqueness information for peptides of interest.
            /// </summary>
            /// <param name="peptideSettings">enzyme info in case we need to perform digestion</param>
            /// <param name="peptidesOfInterest">this is a dictionary instead of a list only because we need an efficient lookup, and caller will already have created this which can be large and expensive to construct.</param>
            /// <param name="progressMonitor">cancellation checker</param>
            /// <returns>updated peptide settings with uniqueness information for peptides of interest</returns>
            public Dictionary <Target, DigestionPeptideStats> GetUniquenessDict(PeptideSettings peptideSettings, Dictionary <Target, bool> peptidesOfInterest, SrmSettingsChangeMonitor progressMonitor)
            {
                // Do we have a cached dictionary suitable to the task?
                var enzyme = peptideSettings.Enzyme;

                if (!(enzyme.Name != _enzymeNameForPeptideUniquenessDictDigest || peptidesOfInterest.Keys.Any(pep => !_peptideUniquenessDict.ContainsKey(pep))))
                {
                    return(_peptideUniquenessDict);  // No change needed
                }

                if (!_parent.UpdateProgressAndCheckForCancellation(progressMonitor, 0))
                {
                    return(null);  // Cancelled
                }
                // Any peptides we were interested in before (ie in the current dict if any) are likely still
                // interesting in future calls, even if not of immediate interest
                foreach (var seq in _peptideUniquenessDict.Where(i => !peptidesOfInterest.ContainsKey(i.Key)))
                {
                    peptidesOfInterest.Add(seq.Key, true);
                }

                var newDict = _parent.GetPeptidesAppearanceCounts(peptidesOfInterest, enzyme, peptideSettings, progressMonitor);

                if (newDict == null)
                {
                    return(null); // Cancelled
                }
                if (!Equals(enzyme.Name, _enzymeNameForPeptideUniquenessDictDigest))
                {
                    _peptideUniquenessDict = new Dictionary <Target, DigestionPeptideStats>();
                }
                else
                {
                    _peptideUniquenessDict = _peptideUniquenessDict.ToDictionary(s => s.Key, s => s.Value);
                }
                foreach (var pair in newDict)
                {
                    if (!_peptideUniquenessDict.ContainsKey(pair.Key))
                    {
                        _peptideUniquenessDict.Add(pair.Key, pair.Value);
                    }
                    else
                    {
                        _peptideUniquenessDict[pair.Key] = pair.Value;
                    }
                }
                _enzymeNameForPeptideUniquenessDictDigest = enzyme.Name;
                if (!_parent.UpdateProgressAndCheckForCancellation(progressMonitor, 100))
                {
                    return(null);  // Cancelled
                }
                return(_peptideUniquenessDict);
            }