public PeptideDocNode UpdateMolecule(IdentityPath parent, PeptideDocNode peptideDocNode)
        {
            CheckCancelled();
            AnnotationUpdater updater;

            _annotationUpdaters.TryGetValue(AnnotationDef.AnnotationTarget.peptide, out updater);
            var identityPath = new IdentityPath(parent, peptideDocNode.Peptide);

            if (updater != null)
            {
                var peptide     = new Databinding.Entities.Peptide(SkylineDataSchema, new IdentityPath(parent, peptideDocNode.Peptide));
                var annotations = updater.UpdateAnnotations(peptideDocNode.Annotations, peptide);
                if (!Equals(annotations, peptideDocNode.Annotations))
                {
                    peptideDocNode = (PeptideDocNode)peptideDocNode.ChangeAnnotations(annotations);
                }
            }

            if (!RecursePrecursors)
            {
                return(peptideDocNode);
            }

            var newChildren = peptideDocNode.TransitionGroups.Select(tg => UpdatePrecursor(identityPath, tg)).ToArray();

            if (!ArrayUtil.ReferencesEqual(peptideDocNode.Children, newChildren))
            {
                peptideDocNode = (PeptideDocNode)peptideDocNode.ChangeChildren(newChildren);
            }

            return(peptideDocNode);
        }
Example #2
0
        private PeptideDocNode RemoveTransition(PeptideDocNode nodePep)
        {
            var precursors = nodePep.TransitionGroups.ToList();

            precursors[0] = (TransitionGroupDocNode)precursors[0].ChangeChildren(precursors[0].Children.Skip(1).ToList());
            return((PeptideDocNode)nodePep.ChangeChildren(precursors.Cast <DocNode>().ToList()));
        }
        public PeptideDocNode PermuteModificationsOnPeptide(SrmDocument document, PeptideGroupDocNode peptideGroupDocNode,
                                                            PeptideDocNode peptideDocNode, List <IsotopeLabelType> partialLabelTypes)
        {
            if (SkipPeptide(peptideDocNode))
            {
                return(peptideDocNode);
            }

            var potentiallyModifiedResidues = PotentiallyModifiedResidues(peptideDocNode, IsotopeModification);

            if (potentiallyModifiedResidues.Count == 0)
            {
                return(peptideDocNode);
            }

            // Create a document containing only one peptide so that "ChangePeptideMods" does not have to walk
            // over a long list of peptides to see which modifications are in use.
            var smallDocument = (SrmDocument)document.ChangeChildren(new DocNode[]
                                                                     { peptideGroupDocNode.ChangeChildren(new DocNode[] { peptideDocNode }) });
            var newTypedExplicitModifications = PermuteTypedExplicitModifications(partialLabelTypes, peptideDocNode, potentiallyModifiedResidues);
            var newExplicitMods = new ExplicitMods(peptideDocNode.Peptide, peptideDocNode.ExplicitMods?.StaticModifications, newTypedExplicitModifications);
            var identityPath    = new IdentityPath(peptideGroupDocNode.PeptideGroup, peptideDocNode.Peptide);

            smallDocument = smallDocument.ChangePeptideMods(identityPath, newExplicitMods, false, GlobalStaticMods,
                                                            GlobalIsotopeMods);
            peptideDocNode = (PeptideDocNode)smallDocument.FindPeptideGroup(peptideGroupDocNode.PeptideGroup).FindNode(peptideDocNode.Peptide);
            var lightChargeStates   = peptideDocNode.TransitionGroups.Where(tg => tg.IsLight).Select(tg => tg.PrecursorCharge).Distinct().ToList();
            var chargeStatesByLabel =
                peptideDocNode.TransitionGroups.ToLookup(tg => tg.LabelType, tg => tg.PrecursorCharge);
            var transitionGroupsToAdd = new List <TransitionGroupDocNode>();

            foreach (var typedExplicitModifications in newExplicitMods.GetHeavyModifications())
            {
                var labelType = typedExplicitModifications.LabelType;
                foreach (var chargeState in lightChargeStates.Except(chargeStatesByLabel[labelType]))
                {
                    var tranGroup = new TransitionGroup(peptideDocNode.Peptide, Adduct.FromChargeProtonated(chargeState), labelType);
                    TransitionDocNode[] transitions = peptideDocNode.GetMatchingTransitions(tranGroup, smallDocument.Settings, newExplicitMods);

                    var nodeGroup = new TransitionGroupDocNode(tranGroup, transitions);
                    nodeGroup = nodeGroup.ChangeSettings(smallDocument.Settings, peptideDocNode, newExplicitMods, SrmSettingsDiff.ALL);
                    transitionGroupsToAdd.Add(nodeGroup);
                }
            }

            if (transitionGroupsToAdd.Any())
            {
                var newChildren = peptideDocNode.TransitionGroups.Concat(transitionGroupsToAdd).ToList();
                newChildren.Sort(Peptide.CompareGroups);
                peptideDocNode = (PeptideDocNode)peptideDocNode.ChangeChildren(newChildren.Cast <DocNode>().ToList());
            }
            return(peptideDocNode);
        }
Example #4
0
        /// <summary>
        /// Tries to match each library peptide to document settings.
        /// </summary>
        public void MatchAllPeptides(ILongWaitBroker broker)
        {
            _chargeSettingsMap = new  AdductMap <SrmSettings>();

            // 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.Count;

            ProteomeDb        proteomeDb = null;
            IStatelessSession session    = null;

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

                    var charge = pepInfo.Key.Adduct;
                    // 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 target = nodePepMatched.Peptide.Target;
                            // This is only set if the user has checked the associate peptide box.
                            if (target.IsProteomic && _backgroundProteome != null)
                            {
                                var sequence = target.Sequence;
                                // 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))
                                {
                                    if (proteomeDb == null)
                                    {
                                        proteomeDb = _backgroundProteome.OpenProteomeDb(broker.CancellationToken);
                                        session    = proteomeDb.OpenStatelessSession(false);
                                    }
                                    var digestion = proteomeDb.GetDigestion();
                                    if (sequence.Length >= MIN_PEPTIDE_LENGTH)
                                    {
                                        matchedProteins = digestion.GetProteinsWithSequence(session, sequence)
                                                          .Select(protein => new ProteinInfo(protein)).ToList();
                                    }
                                    if (matchedProteins == null || matchedProteins.Count > MAX_PROTEIN_MATCHES)
                                    {
                                        // If the peptide was too short, or matched too many proteins, then
                                        // treat it as if it was not found in any proteins.
                                        matchedProteins = new List <ProteinInfo>();
                                    }
                                    dictSequenceProteins.Add(sequence, matchedProteins);
                                }
                            }
                            dictNewNodePeps.Add(nodePepMatched.SequenceKey,
                                                new PeptideMatch(nodePepMatched, matchedProteins,
                                                                 MatchesFilter(target, 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;
            }
            finally
            {
                using (proteomeDb)
                    using (session)
                    {
                    }
            }
        }
        /// <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;
        }