示例#1
0
        public PeptideDocNode MatchSinglePeptide(ViewLibraryPepInfo pepInfo)
        {
            _chargeSettingsMap = new AdductMap <SrmSettings>();
            var nodePep = AssociateMatchingPeptide(pepInfo, pepInfo.Key.Adduct).PeptideNode;

            if (nodePep == null)
            {
                return(null);
            }

            IList <ProteinInfo> matchedProteins = null;

            var target = nodePep.Peptide.Target;

            if (pepInfo.Target.IsProteomic)
            {
                // This is only set if the user has checked the associate peptide box.
                if (_backgroundProteome != null)
                {
                    using (var proteomeDb = _backgroundProteome.OpenProteomeDb())
                    {
                        var digestion = _backgroundProteome.GetDigestion(proteomeDb, Settings.PeptideSettings);
                        if (digestion != null)
                        {
                            matchedProteins = digestion.GetProteinsWithSequence(target.Sequence)
                                              .Select(protein => new ProteinInfo(protein)).ToArray();
                        }
                    }
                }
            }
            PeptideMatches = new Dictionary <PeptideSequenceModKey, PeptideMatch>
            {
                { nodePep.SequenceKey, new PeptideMatch(nodePep, matchedProteins,
                                                        pepInfo.LibInfo,
                                                        MatchesFilter(target, pepInfo.Key.Adduct)) }
            };
            return(nodePep);
        }
        /// <summary>
        /// Tries to match each library peptide to document settings.
        /// </summary>
        public void MatchAllPeptides(ILongWaitBroker broker)
        {
            _chargeSettingsMap = new SrmSettings[128];

            // Build a dictionary mapping sequence to proteins because getting this information is slow.
            var dictSequenceProteins = new Dictionary <string, IList <ProteinInfo> >();
            var dictNewNodePeps      = new Dictionary <PeptideSequenceModKey, PeptideMatch>();

            PeptideMatches      = null;
            MatchedPeptideCount = 0;

            int peptides      = 0;
            int totalPeptides = _libraryPepInfos.Length;

            foreach (ViewLibraryPepInfo pepInfo in _libraryPepInfos)
            {
                if (broker.IsCanceled)
                {
                    return;
                }

                int charge = pepInfo.Key.Charge;
                // Find the matching peptide.
                var nodePepMatched = AssociateMatchingPeptide(pepInfo, charge).PeptideNode;
                if (nodePepMatched != null)
                {
                    MatchedPeptideCount++;

                    PeptideMatch peptideMatchInDict;
                    // If peptide is already in the dictionary of peptides to add, merge the children.
                    if (!dictNewNodePeps.TryGetValue(nodePepMatched.SequenceKey, out peptideMatchInDict))
                    {
                        IList <ProteinInfo> matchedProteins = null;

                        var sequence = nodePepMatched.Peptide.Sequence;
                        // This is only set if the user has checked the associate peptide box.
                        if (_backgroundProteome != null)
                        {
                            // We want to query the background proteome as little as possible,
                            // so sequences are mapped to protein lists in a dictionary.
                            if (!dictSequenceProteins.TryGetValue(sequence, out matchedProteins))
                            {
                                using (var proteomeDb = _backgroundProteome.OpenProteomeDb())
                                {
                                    var digestion = _backgroundProteome.GetDigestion(proteomeDb, Settings.PeptideSettings);
                                    if (digestion != null)
                                    {
                                        matchedProteins = digestion.GetProteinsWithSequence(sequence).Select(protein => new ProteinInfo(protein)).ToList();
                                        dictSequenceProteins.Add(sequence, matchedProteins);
                                    }
                                }
                            }
                        }
                        dictNewNodePeps.Add(nodePepMatched.SequenceKey,
                                            new PeptideMatch(nodePepMatched, matchedProteins,
                                                             MatchesFilter(sequence, charge)));
                    }
                    else
                    {
                        PeptideDocNode nodePepInDictionary = peptideMatchInDict.NodePep;
                        if (!nodePepInDictionary.HasChildCharge(charge))
                        {
                            List <DocNode> newChildren = nodePepInDictionary.Children.ToList();
                            newChildren.AddRange(nodePepMatched.Children);
                            newChildren.Sort(Peptide.CompareGroups);
                            var key = nodePepMatched.SequenceKey;
                            dictNewNodePeps.Remove(key);
                            dictNewNodePeps.Add(key,
                                                new PeptideMatch((PeptideDocNode)nodePepInDictionary.ChangeChildren(newChildren),
                                                                 peptideMatchInDict.Proteins, peptideMatchInDict.MatchesFilterSettings));
                        }
                    }
                }
                peptides++;
                int progressValue = (int)((peptides + 0.0) / totalPeptides * PERCENT_PEPTIDE_MATCH);
                broker.ProgressValue = progressValue;
            }
            PeptideMatches = dictNewNodePeps;
        }