Example #1
0
        /// <summary>
        /// Adds a list of PeptideDocNodes found in the library to the current document.
        /// </summary>
        public SrmDocument AddPeptides(SrmDocument document, ILongWaitBroker broker, IdentityPath toPath, out IdentityPath selectedPath)
        {
            if (toPath != null &&
                toPath.Depth == (int)SrmDocument.Level.MoleculeGroups &&
                ReferenceEquals(toPath.GetIdentity((int)SrmDocument.Level.MoleculeGroups), SequenceTree.NODE_INSERT_ID))
            {
                toPath = null;
            }

            SkippedPeptideCount = 0;
            var dictCopy = new Dictionary <PeptideSequenceModKey, PeptideMatch>();

            // Make heavy mods explicit
            if (PeptideMatches.Values.Contains(match => match.NodePep.HasExplicitMods &&
                                               match.NodePep.ExplicitMods.HeavyModifications != null))
            {
                _matcher.ConvertAllHeavyModsExplicit();
            }

            // Call ensure mods on all peptides to be added to the document.
            var listDefStatMods = new MappedList <string, StaticMod>();

            listDefStatMods.AddRange(Properties.Settings.Default.StaticModList);
            listDefStatMods.AddRange(document.Settings.PeptideSettings.Modifications.StaticModifications);

            var listDefHeavyMods = new MappedList <string, StaticMod>();

            listDefHeavyMods.AddRange(Properties.Settings.Default.HeavyModList);
            listDefHeavyMods.AddRange(document.Settings.PeptideSettings.Modifications.AllHeavyModifications);

            foreach (var key in PeptideMatches.Keys)
            {
                var match         = PeptideMatches[key];
                var nodePepDocSet = match.NodePep;
                if (_matcher.MatcherPepMods != null)
                {
                    nodePepDocSet = match.NodePep.EnsureMods(_matcher.MatcherPepMods,
                                                             document.Settings.PeptideSettings.Modifications,
                                                             listDefStatMods, listDefHeavyMods);
                }
                if (!dictCopy.ContainsKey(nodePepDocSet.SequenceKey))
                {
                    dictCopy.Add(nodePepDocSet.SequenceKey,
                                 new PeptideMatch(nodePepDocSet, match.Proteins,
                                                  match.MatchesFilterSettings));
                }
            }

            if (!Properties.Settings.Default.LibraryPeptidesKeepFiltered)
            {
                // TODO: This removes entire peptides where only a single
                //       precursor does not match.  e.g. the library contains
                //       a singly charged precursor match, but also doubly charged
                dictCopy = dictCopy.Where(match => match.Value.MatchesFilterSettings)
                           .ToDictionary(match => match.Key, match => match.Value);
            }
            SrmDocument newDocument = UpdateExistingPeptides(document, dictCopy, toPath, out selectedPath);

            toPath = selectedPath;

            // If there is an associated background proteome, add peptides that can be
            // matched to the proteins from the background proteom.
            if (_backgroundProteome != null)
            {
                newDocument = AddProteomePeptides(newDocument, dictCopy, broker,
                                                  toPath, out selectedPath);
            }
            toPath = selectedPath;

            // Add all remaining peptides as a peptide list.
            if (_backgroundProteome == null || Properties.Settings.Default.LibraryPeptidesAddUnmatched)
            {
                var listPeptidesToAdd = dictCopy.Values.ToList();
                listPeptidesToAdd.RemoveAll(match => match.Proteins != null && match.Proteins.Count > 0);
                if (listPeptidesToAdd.Count > 0)
                {
                    newDocument = AddPeptidesToLibraryGroup(newDocument, listPeptidesToAdd, broker,
                                                            toPath, out selectedPath);
                    if (listPeptidesToAdd.Count > 1000)
                    {
                        selectedPath = selectedPath.Parent; // Don't force Skyline to open a massive peptide list, if it wouldn't otherwise
                    }
                }
            }

            return(newDocument);
        }