Пример #1
0
        private TransitionGroupDocNode CreateChoice(Identity childId, ExplicitMods mods)
        {
            TransitionGroup tranGroup = (TransitionGroup)childId;

            TransitionDocNode[] transitions = DocNode.GetMatchingTransitions(
                tranGroup, DocSettings, mods);

            var nodeGroup = new TransitionGroupDocNode(tranGroup, transitions);

            return(nodeGroup.ChangeSettings(DocSettings, DocNode, mods, SrmSettingsDiff.ALL));
        }
        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);
        }
Пример #3
0
        public void AddRemoveExplicitModTest()
        {
            SrmDocument docStudy7      = CreateStudy7Doc();
            string      transitionList = ExportCsv(docStudy7);

            Assert.AreEqual(69, transitionList.Split('\n').Length); // Special test mode may add an extra doc node

            var modifications  = docStudy7.Settings.PeptideSettings.Modifications;
            var listStaticMods = modifications.StaticModifications;
            var listHeavyMods  = modifications.AllHeavyModifications.ToList();

            docStudy7 = docStudy7.ChangeSettings(docStudy7.Settings.ChangeTransitionFilter(filter => filter.ChangeAutoSelect(false)));

            // Remove all modifications
            int i = 0;
            // But save them for later
            var removedMods = new Dictionary <int, ExplicitMods>();

            foreach (var peptide in docStudy7.Peptides)
            {
                if (peptide.HasExplicitMods)
                {
                    removedMods.Add(i, peptide.ExplicitMods);

                    IdentityPath path = docStudy7.GetPathTo((int)SrmDocument.Level.Molecules, i);
                    docStudy7 = docStudy7.ChangePeptideMods(path, null, listStaticMods, listHeavyMods);
                }
                i++;
            }

            // Removes heavy from peptide with c-terminal P
            AssertEx.IsDocumentState(docStudy7, 6, 7, 11, 21, 63);
            modifications = docStudy7.Settings.PeptideSettings.Modifications;
            Assert.AreEqual(2, modifications.AllHeavyModifications.Count());
            Assert.AreEqual(0, modifications.AllHeavyModifications.Count(mod => mod.IsExplicit));
            Assert.AreEqual(0, docStudy7.Peptides.Count(peptide => peptide.HasExplicitMods));

            listHeavyMods = ATOMIC_HEAVY_MODS;

            foreach (var pair in removedMods)
            {
                IdentityPath path = docStudy7.GetPathTo((int)SrmDocument.Level.Molecules, pair.Key);
                docStudy7 = docStudy7.ChangePeptideMods(path, pair.Value, listStaticMods, listHeavyMods);
            }

            AssertEx.IsDocumentState(docStudy7, 11, 7, 11, 21, 63);

            // Replace the heavy precursor that was removed
            // TODO: Yuck.  Would be nice to have a way to do this without duplicating
            //       so much of the logic in PeptideDocNode and PeptideTreeNode
            var pepPath        = docStudy7.GetPathTo((int)SrmDocument.Level.Molecules, 10);
            var nodePep        = (PeptideDocNode)docStudy7.FindNode(pepPath);
            var mods           = nodePep.ExplicitMods;
            var nodeGroupLight = (TransitionGroupDocNode)nodePep.Children[0];
            var settings       = docStudy7.Settings;

            foreach (var tranGroup in nodePep.GetTransitionGroups(settings, mods, false))
            {
                if (tranGroup.PrecursorAdduct.Equals(nodeGroupLight.TransitionGroup.PrecursorAdduct) &&
                    !tranGroup.LabelType.IsLight)
                {
                    TransitionDocNode[] transitions = nodePep.GetMatchingTransitions(tranGroup, settings, mods);
                    var nodeGroup = new TransitionGroupDocNode(tranGroup, transitions);
                    nodeGroup = nodeGroup.ChangeSettings(settings, nodePep, mods, SrmSettingsDiff.ALL);
                    docStudy7 = (SrmDocument)docStudy7.Add(pepPath, nodeGroup);
                    break;
                }
            }

            AssertEx.IsDocumentState(docStudy7, 12, 7, 11, 22, 66);

            modifications = docStudy7.Settings.PeptideSettings.Modifications;
            Assert.AreEqual(2, modifications.AllHeavyModifications.Count(mod => mod.IsExplicit && mod.Label13C));
            Assert.AreEqual(2, modifications.AllHeavyModifications.Count(mod => mod.Formula != null));
            Assert.AreEqual(3, docStudy7.Peptides.Count(peptide => peptide.HasExplicitMods));
            Assert.AreEqual(2, docStudy7.Peptides.Count(peptide => peptide.HasExplicitMods &&
                                                        peptide.ExplicitMods.StaticModifications.Count > 0 &&
                                                        peptide.ExplicitMods.StaticModifications[0].Modification.AAs[0] == 'C'));
            Assert.AreEqual(2, docStudy7.Peptides.Count(peptide => peptide.HasExplicitMods &&
                                                        peptide.ExplicitMods.HeavyModifications[0].Modification.AAs[0] == 'V' &&
                                                        peptide.ExplicitMods.HeavyModifications[0].Modification.Label13C));
            Assert.AreEqual(1, docStudy7.Peptides.Count(peptide => peptide.HasExplicitMods &&
                                                        peptide.ExplicitMods.HeavyModifications[0].Modification.AAs[0] == 'L' &&
                                                        peptide.ExplicitMods.HeavyModifications[0].Modification.Label13C));

            AssertEx.NoDiff(transitionList, ExportCsv(docStudy7));
        }
Пример #4
0
        public void AddRemoveExplicitModTest()
        {
            SrmDocument docStudy7 = CreateStudy7Doc();
            string transitionList = ExportCsv(docStudy7);
            Assert.AreEqual(69 + (TestSmallMolecules ? 2 : 0), transitionList.Split('\n').Length); // Special test mode may add an extra doc node

            var modifications = docStudy7.Settings.PeptideSettings.Modifications;
            var listStaticMods = modifications.StaticModifications;
            var listHeavyMods = modifications.HeavyModifications;

            docStudy7 = docStudy7.ChangeSettings(docStudy7.Settings.ChangeTransitionFilter(filter => filter.ChangeAutoSelect(false)));

            // Remove all modifications
            int i = 0;
            // But save them for later
            var removedMods = new Dictionary<int, ExplicitMods>();
            foreach (var peptide in docStudy7.Peptides)
            {
                if (peptide.HasExplicitMods)
                {
                    removedMods.Add(i, peptide.ExplicitMods);

                    IdentityPath path = docStudy7.GetPathTo((int) SrmDocument.Level.Molecules, i);
                    docStudy7 = docStudy7.ChangePeptideMods(path, null, listStaticMods, listHeavyMods);
                }
                i++;
            }

            // Removes heavy from peptide with c-terminal P
            AssertEx.IsDocumentState(docStudy7, 6, 7, 11, 21, 63);
            modifications = docStudy7.Settings.PeptideSettings.Modifications;
            Assert.AreEqual(2, modifications.HeavyModifications.Count);
            Assert.AreEqual(0, modifications.HeavyModifications.Count(mod => mod.IsExplicit));
            Assert.AreEqual(0, docStudy7.Peptides.Count(peptide => peptide.HasExplicitMods));

            listHeavyMods = ATOMIC_HEAVY_MODS;

            foreach (var pair in removedMods)
            {
                IdentityPath path = docStudy7.GetPathTo((int)SrmDocument.Level.Molecules, pair.Key);
                docStudy7 = docStudy7.ChangePeptideMods(path, pair.Value, listStaticMods, listHeavyMods);
            }

            AssertEx.IsDocumentState(docStudy7, 11, 7, 11, 21, 63);

            // Replace the heavy precursor that was removed
            // TODO: Yuck.  Would be nice to have a way to do this without duplicating
            //       so much of the logic in PeptideDocNode and PeptideTreeNode
            var pepPath = docStudy7.GetPathTo((int) SrmDocument.Level.Molecules, 10);
            var nodePep = (PeptideDocNode) docStudy7.FindNode(pepPath);
            var mods = nodePep.ExplicitMods;
            var nodeGroupLight = (TransitionGroupDocNode) nodePep.Children[0];
            var settings = docStudy7.Settings;
            foreach (var tranGroup in nodePep.GetTransitionGroups(settings, mods, false))
            {
                if (tranGroup.PrecursorCharge == nodeGroupLight.TransitionGroup.PrecursorCharge &&
                        !tranGroup.LabelType.IsLight)
                {
                    TransitionDocNode[] transitions = nodePep.GetMatchingTransitions(tranGroup, settings, mods);
                    var nodeGroup = new TransitionGroupDocNode(tranGroup, transitions);
                    nodeGroup = nodeGroup.ChangeSettings(settings, nodePep, mods, SrmSettingsDiff.ALL);
                    docStudy7 = (SrmDocument) docStudy7.Add(pepPath, nodeGroup);
                    break;
                }
            }

            AssertEx.IsDocumentState(docStudy7, 12, 7, 11, 22, 66);

            modifications = docStudy7.Settings.PeptideSettings.Modifications;
            Assert.AreEqual(2, modifications.HeavyModifications.Count(mod => mod.IsExplicit && mod.Label13C));
            Assert.AreEqual(2, modifications.HeavyModifications.Count(mod => mod.Formula != null));
            Assert.AreEqual(3, docStudy7.Peptides.Count(peptide => peptide.HasExplicitMods));
            Assert.AreEqual(2, docStudy7.Peptides.Count(peptide => peptide.HasExplicitMods &&
                peptide.ExplicitMods.StaticModifications.Count > 0 &&
                peptide.ExplicitMods.StaticModifications[0].Modification.AAs[0] == 'C'));
            Assert.AreEqual(2, docStudy7.Peptides.Count(peptide => peptide.HasExplicitMods &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.AAs[0] == 'V' &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.Label13C));
            Assert.AreEqual(1, docStudy7.Peptides.Count(peptide => peptide.HasExplicitMods &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.AAs[0] == 'L' &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.Label13C));

            AssertEx.NoDiff(transitionList, ExportCsv(docStudy7));
        }
Пример #5
0
        private DocNode CreateChoice(Identity childId, ExplicitMods mods)
        {
            TransitionGroup tranGroup = (TransitionGroup)childId;
            TransitionDocNode[] transitions = DocNode.GetMatchingTransitions(
                tranGroup, DocSettings, mods);

            var nodeGroup = new TransitionGroupDocNode(tranGroup, transitions);
            return nodeGroup.ChangeSettings(DocSettings, DocNode, mods, SrmSettingsDiff.ALL);
        }
Пример #6
0
        private PeptideDocNode Refine(PeptideDocNode nodePep,
            SrmDocument document,
            int bestResultIndex,
            List<int> acceptedCharges)
        {
            int minTrans = MinTransitionsPepPrecursor ?? 0;

            bool addedGroups = false;
            var listGroups = new List<TransitionGroupDocNode>();
            foreach (TransitionGroupDocNode nodeGroup in nodePep.Children)
            {
                if (acceptedCharges != null && !acceptedCharges.Contains(nodeGroup.TransitionGroup.PrecursorCharge))
                    continue;

                if (!AddLabelType && RefineLabelType != null && Equals(RefineLabelType, nodeGroup.TransitionGroup.LabelType))
                    continue;

                double? peakFoundRatio = nodeGroup.GetPeakCountRatio(bestResultIndex);
                if (!peakFoundRatio.HasValue)
                {
                    if (RemoveMissingResults)
                        continue;
                }
                else
                {
                    if (MinPeakFoundRatio.HasValue)
                    {
                        if (peakFoundRatio < MinPeakFoundRatio.Value)
                            continue;
                    }
                    if (MaxPeakFoundRatio.HasValue)
                    {
                        if (peakFoundRatio > MaxPeakFoundRatio.Value)
                            continue;
                    }
                }

                TransitionGroupDocNode nodeGroupRefined = nodeGroup;
                if (AutoPickTransitionsAll && nodeGroup.AutoManageChildren == AutoPickChildrenOff)
                {
                    nodeGroupRefined = (TransitionGroupDocNode) nodeGroupRefined.ChangeAutoManageChildren(!AutoPickChildrenOff);
                    var settings = document.Settings;
                    if (!settings.TransitionSettings.Filter.AutoSelect && !AutoPickChildrenOff)
                        settings = settings.ChangeTransitionFilter(filter => filter.ChangeAutoSelect(!AutoPickChildrenOff));
                    nodeGroupRefined = nodeGroupRefined.ChangeSettings(settings, nodePep, nodePep.ExplicitMods,
                        new SrmSettingsDiff(false, false, false, false, true, false));
                }
                nodeGroupRefined = Refine(nodeGroupRefined, bestResultIndex);
                if (nodeGroupRefined.Children.Count < minTrans)
                    continue;

                if (peakFoundRatio.HasValue)
                {
                    if (DotProductThreshold.HasValue)
                    {
                        float? dotProduct = nodeGroupRefined.GetLibraryDotProduct(bestResultIndex);
                        if (dotProduct.HasValue && dotProduct.Value < DotProductThreshold.Value)
                            continue;
                    }
                    if (IdotProductThreshold.HasValue)
                    {
                        float? idotProduct = nodeGroupRefined.GetIsotopeDotProduct(bestResultIndex);
                        if (idotProduct.HasValue && idotProduct.Value < IdotProductThreshold.Value)
                            continue;
                    }
                }

                // If this precursor node is going to be added, check to see if it
                // should be added with another matching isotope label type.
                var explicitMods = nodePep.ExplicitMods;
                if (IsLabelTypeRequired(nodePep, nodeGroup, listGroups) &&
                        document.Settings.TryGetPrecursorCalc(RefineLabelType, explicitMods) != null)
                {
                    // CONSIDER: This is a lot like some code in PeptideDocNode.ChangeSettings
                    Debug.Assert(RefineLabelType != null);  // Keep ReSharper from warning
                    var tranGroup = new TransitionGroup(nodePep.Peptide,
                                                        nodeGroup.TransitionGroup.PrecursorCharge,
                                                        RefineLabelType,
                                                        false,
                                                        nodeGroup.TransitionGroup.DecoyMassShift);
                    var settings = document.Settings;
            //                    string sequence = nodePep.Peptide.Sequence;
                    TransitionDocNode[] transitions = nodePep.GetMatchingTransitions(
                        tranGroup, settings, explicitMods);

                    var nodeGroupMatch = new TransitionGroupDocNode(tranGroup,
                                                                    Annotations.EMPTY,
                                                                    settings,
                                                                    explicitMods,
                                                                    nodeGroup.LibInfo,
                                                                    nodeGroup.ExplicitValues,
                                                                    null,   // results
                                                                    transitions,
                                                                    transitions == null);

                    nodeGroupMatch = nodeGroupMatch.ChangeSettings(settings, nodePep, explicitMods, SrmSettingsDiff.ALL);

                    // Make sure it is measurable before adding it
                    if (settings.TransitionSettings.IsMeasurablePrecursor(nodeGroupMatch.PrecursorMz))
                    {
                        listGroups.Add(nodeGroupMatch);
                        addedGroups = true;
                    }
                }

                listGroups.Add(nodeGroupRefined);
            }

            // If groups were added, make sure everything is in the right order.
            if (addedGroups)
                listGroups.Sort(Peptide.CompareGroups);

            // Change the children, but only change auto-management, if the child
            // identities have changed, not if their contents changed.
            var childrenNew = listGroups.ToArray();
            bool updateAutoManage = !PeptideDocNode.AreEquivalentChildren(nodePep.Children, childrenNew);
            return (PeptideDocNode) nodePep.ChangeChildrenChecked(childrenNew, updateAutoManage);
        }