예제 #1
0
 public SrmSettingsDiff(SrmSettingsDiff diff, SrmSettingsDiff diffUnion)
 {
     DiffPeptides = diff.DiffPeptides || diffUnion.DiffPeptides;
     DiffPeptideProps = diff.DiffPeptideProps || diffUnion.DiffPeptideProps;
     DiffTransitionGroups = diff.DiffTransitionGroups || diffUnion.DiffTransitionGroups;
     DiffTransitionGroupProps = diff.DiffTransitionGroupProps || diffUnion.DiffTransitionGroupProps;
     DiffTransitions = diff.DiffTransitions || diffUnion.DiffTransitions;
     DiffTransitionProps = diff.DiffTransitionProps || diffUnion.DiffTransitionProps;
     DiffResults = diff.DiffResults || diffUnion.DiffResults;
     DiffResultsAll = diff.DiffResultsAll || diffUnion.DiffResultsAll;
     SettingsOld = diff.SettingsOld;
 }
        public PeptideDocNode GetModifiedNode(LibKey key, string seqUnmod, SrmSettings settings, SrmSettingsDiff diff)
        {
            if (string.IsNullOrEmpty(seqUnmod))
                return null;

            var peptide = new Peptide(null, seqUnmod, null, null,
                                  settings.PeptideSettings.Enzyme.CountCleavagePoints(seqUnmod));
            // First try and create the match from the settings created to match the library explorer.
            Settings = HasMatches
                ? settings.ChangePeptideModifications(mods => MatcherPepMods)
                : settings;
            TransitionGroupDocNode nodeGroup;
            var nodePep = CreateDocNodeFromSettings(key.Sequence, peptide, diff, out nodeGroup);
            if (nodePep != null)
            {
                if (diff == null)
                {
                    nodePep = (PeptideDocNode)nodePep.ChangeAutoManageChildren(false);
                }
                else
                {
                    // Keep only the matching transition group, so that modifications
                    // will be highlighted differently for light and heavy forms.
                    // Only performed when getting peptides for display in the explorer.
                    nodePep = (PeptideDocNode)nodePep.ChangeChildrenChecked(
                        new DocNode[] { nodeGroup });
                }
                return nodePep;
            }
            else if (Matches == null)
                return null;
            bool hasHeavy;
            // Create explicit mods from the found matches.
            nodePep = CreateDocNodeFromMatches(new PeptideDocNode(peptide),
                                            EnumerateSequenceInfos(key.Key, true), false, out hasHeavy);

            if (nodePep == null)
                return null;

            // Call change settings with the matched modification settings to enumerate the children.
            nodePep = nodePep.ChangeSettings(settings.ChangePeptideModifications(mods =>
                !HasMatches ? settings.PeptideSettings.Modifications : MatcherPepMods), diff ?? SrmSettingsDiff.ALL);
            if (nodePep.Children.Count == 0)
                return null;
            // Select the correct child, only for use with the library explorer.
            if (diff != null && nodePep.Children.Count > 1)
            {
                nodePep =
                    (PeptideDocNode)
                    nodePep.ChangeChildrenChecked(new List<DocNode> { nodePep.Children[hasHeavy ? 1 : 0] });
            }
            if (diff == null)
            {
                nodePep = (PeptideDocNode)nodePep.ChangeAutoManageChildren(false);
            }
            return nodePep;
        }
        public PeptideDocNode CreateDocNodeFromSettings(string seq, Peptide peptide, SrmSettingsDiff diff,
            out TransitionGroupDocNode nodeGroupMatched)
        {
            seq = Transition.StripChargeIndicators(seq, TransitionGroup.MIN_PRECURSOR_CHARGE, TransitionGroup.MAX_PRECURSOR_CHARGE);
            if (peptide == null)
            {
                string seqUnmod = FastaSequence.StripModifications(seq);
                try
                {
                    peptide = new Peptide(null, seqUnmod, null, null,
                        Settings.PeptideSettings.Enzyme.CountCleavagePoints(seqUnmod));
                }
                catch (InvalidDataException)
                {
                    nodeGroupMatched = null;
                    return null;
                }
            }

            // Use the number of modifications as the maximum, if it is less than the current
            // settings to keep from over enumerating, which can be slow.
            var filter = new MaxModFilter(Math.Min(seq.Count(c => c == '[' || c == '('),
                                                   Settings.PeptideSettings.Modifications.MaxVariableMods));
            foreach (var nodePep in peptide.CreateDocNodes(Settings, filter))
            {
                var nodePepMod = CreateDocNodeFromSettings(seq, nodePep, diff, out nodeGroupMatched);
                if (nodePepMod != null)
                    return nodePepMod;
            }
            nodeGroupMatched = null;
            return null;
        }
 private PeptideDocNode CreateDocNodeFromSettings(string seq, PeptideDocNode nodePep, SrmSettingsDiff diff,
     out TransitionGroupDocNode nodeGroupMatched)
 {
     PeptideDocNode nodePepMod = nodePep.ChangeSettings(Settings, diff ?? SrmSettingsDiff.ALL, false);
     TransitionGroupDocNode nodeGroupMatchedFound;
     if (IsMatch(seq, nodePepMod, out nodeGroupMatchedFound))
     {
         nodeGroupMatched = nodeGroupMatchedFound;
         return nodePepMod;
     }
     nodeGroupMatched = null;
     return null;
 }
예제 #5
0
        public ViewLibraryPepInfo AssociateMatchingPeptide(ViewLibraryPepInfo pepInfo, int charge, SrmSettingsDiff settingsDiff)
        {
            var key = pepInfo.Key;

            var settings = _chargeSettingsMap[charge];
            // Change current document settings to match the current library and change the charge filter to
            // match the current peptide.
            if (settings == null)
            {
                settings = _document.Settings;
                var rankId = settings.PeptideSettings.Libraries.RankId;
                if (rankId != null && !_selectedSpec.PeptideRankIds.Contains(rankId))
                    settings = settings.ChangePeptideLibraries(lib => lib.ChangeRankId(null));

                settings = settings.ChangePeptideLibraries(
                        lib => lib.ChangeLibraries(new[] { _selectedSpec }, new[] { _selectedLibrary })
                                  .ChangePick(PeptidePick.library))
                    .ChangeTransitionFilter(
                        filter => filter.ChangePrecursorCharges(new[] { charge }).ChangeAutoSelect(true))
                    .ChangeMeasuredResults(null);

                _chargeSettingsMap[charge] = settings;
            }

            var nodePep = _matcher.GetModifiedNode(key, pepInfo.GetAASequence(_lookupPool), settings, settingsDiff);
            if (nodePep != null)
            {
                pepInfo.PeptideNode = nodePep;
            }
            return pepInfo;
        }
예제 #6
0
        public PeptideGroupDocNode ChangeSettings(SrmSettings settingsNew, SrmSettingsDiff diff)
        {
            if (diff.Monitor != null)
                diff.Monitor.ProcessGroup(this);

            if (diff.DiffPeptides && settingsNew.PeptideSettings.Filter.AutoSelect && AutoManageChildren)
            {
                IList<DocNode> childrenNew = new List<DocNode>();

                int countPeptides = 0;
                int countIons = 0;

                Dictionary<int, DocNode> mapIndexToChild = CreateGlobalIndexToChildMap();
                Dictionary<PeptideModKey, DocNode> mapIdToChild = CreatePeptideModToChildMap();

                foreach(PeptideDocNode nodePep in GetPeptideNodes(settingsNew, true))
                {
                    PeptideDocNode nodePepResult = nodePep;
                    SrmSettingsDiff diffNode = SrmSettingsDiff.ALL;

                    DocNode existing;
                    // Add values that existed before the change. First check for exact match by
                    // global index, which will happen when explicit modifications are added,
                    // and then by content identity.
                    if (mapIndexToChild.TryGetValue(nodePep.Id.GlobalIndex, out existing) ||
                        mapIdToChild.TryGetValue(nodePep.Key, out existing))
                    {
                        nodePepResult = (PeptideDocNode) existing;
                        diffNode = diff;
                    }

                    if (nodePepResult != null)
                    {
                        // Materialize children of the peptide.
                        nodePepResult = nodePepResult.ChangeSettings(settingsNew, diffNode);

                        childrenNew.Add(nodePepResult);

                        // Make sure a single peptide group does not exceed document limits.
                        countPeptides++;
                        countIons += nodePepResult.TransitionCount;
                        if (countIons > SrmDocument.MAX_TRANSITION_COUNT)
                            throw new InvalidDataException(String.Format(
                                Resources.PeptideGroupDocNode_ChangeSettings_The_current_document_settings_would_cause_the_number_of_targeted_transitions_to_exceed__0_n0___The_document_settings_must_be_more_restrictive_or_add_fewer_proteins_,
                                SrmDocument.MAX_TRANSITION_COUNT));
                        if (countPeptides > SrmDocument.MAX_PEPTIDE_COUNT)
                            throw new InvalidDataException(String.Format(
                                Resources.PeptideGroupDocNode_ChangeSettings_The_current_document_settings_would_cause_the_number_of_peptides_to_exceed__0_n0___The_document_settings_must_be_more_restrictive_or_add_fewer_proteins_,
                                SrmDocument.MAX_PEPTIDE_COUNT));
                    }
                }

                if (PeptideGroup.Sequence != null)
                    childrenNew = PeptideGroup.RankPeptides(childrenNew, settingsNew, true);

                return (PeptideGroupDocNode) ChangeChildrenChecked(childrenNew);
            }
            else
            {
                var nodeResult = this;

                if (diff.DiffPeptides && diff.SettingsOld != null)
                {
                    // If variable modifications changed, remove all peptides with variable
                    // modifications which are no longer possible.
                    var modsNew = settingsNew.PeptideSettings.Modifications;
                    var modsVarNew = modsNew.VariableModifications.ToArray();
                    var modsOld = diff.SettingsOld.PeptideSettings.Modifications;
                    var modsVarOld = modsOld.VariableModifications.ToArray();
                    if (modsNew.MaxVariableMods < modsOld.MaxVariableMods ||
                        !ArrayUtil.EqualsDeep(modsVarNew, modsVarOld))
                    {
                        IList<DocNode> childrenNew = new List<DocNode>();
                        foreach (PeptideDocNode nodePeptide in nodeResult.Children)
                        {
                            if (nodePeptide.AreVariableModsPossible(modsNew.MaxVariableMods, modsVarNew))
                                childrenNew.Add(nodePeptide);
                        }

                        nodeResult = (PeptideGroupDocNode)nodeResult.ChangeChildrenChecked(childrenNew);
                    }
                }

                // Check for changes affecting children
                if (diff.DiffPeptideProps || diff.DiffExplicit ||
                    diff.DiffTransitionGroups || diff.DiffTransitionGroupProps ||
                    diff.DiffTransitions || diff.DiffTransitionProps ||
                    diff.DiffResults)
                {
                    IList<DocNode> childrenNew = new List<DocNode>();

                    // Enumerate the nodes making necessary changes.
                    foreach (PeptideDocNode nodePeptide in nodeResult.Children)
                        childrenNew.Add(nodePeptide.ChangeSettings(settingsNew, diff));

                    childrenNew = RankChildren(settingsNew, childrenNew);

                    nodeResult = (PeptideGroupDocNode)nodeResult.ChangeChildrenChecked(childrenNew);
                }
                return nodeResult;
            }
        }
예제 #7
0
        public PeptideDocNode ChangeSettings(SrmSettings settingsNew, SrmSettingsDiff diff, bool recurse = true)
        {
            if (diff.Monitor != null)
                diff.Monitor.ProcessMolecule(this);

            // If the peptide has explicit modifications, and the modifications have
            // changed, see if any of the explicit modifications have changed
            var explicitMods = ExplicitMods;
            if (HasExplicitMods &&
                !diff.IsUnexplainedExplicitModificationAllowed &&
                diff.SettingsOld != null &&
                !ReferenceEquals(settingsNew.PeptideSettings.Modifications,
                                 diff.SettingsOld.PeptideSettings.Modifications))
            {
                explicitMods = ExplicitMods.ChangeGlobalMods(settingsNew);
                if (explicitMods == null || !ArrayUtil.ReferencesEqual(explicitMods.GetHeavyModifications().ToArray(),
                                                                       ExplicitMods.GetHeavyModifications().ToArray()))
                {
                    diff = new SrmSettingsDiff(diff, SrmSettingsDiff.ALL);
                }
                else if (!ReferenceEquals(explicitMods.StaticModifications, ExplicitMods.StaticModifications))
                {
                    diff = new SrmSettingsDiff(diff, SrmSettingsDiff.PROPS);
                }
            }

            TransitionSettings transitionSettings = settingsNew.TransitionSettings;
            PeptideDocNode nodeResult = this;
            if (!ReferenceEquals(explicitMods, ExplicitMods))
                nodeResult = nodeResult.ChangeExplicitMods(explicitMods);
            nodeResult = nodeResult.UpdateModifiedSequence(settingsNew);

            if (diff.DiffPeptideProps)
            {
                var rt = settingsNew.PeptideSettings.Prediction.RetentionTime;
                bool isStandard = Equals(nodeResult.GlobalStandardType, STANDARD_TYPE_IRT);
                if (rt != null)
                {
                    bool isStandardNew = rt.IsStandardPeptide(nodeResult);
                    if (isStandard ^ isStandardNew)
                        nodeResult = nodeResult.ChangeStandardType(isStandardNew ? STANDARD_TYPE_IRT : null);
                }
                else if (isStandard)
                {
                    nodeResult = nodeResult.ChangeStandardType(null);
                }
            }

            if (diff.DiffTransitionGroups && settingsNew.TransitionSettings.Filter.AutoSelect && AutoManageChildren)
            {
                IList<DocNode> childrenNew = new List<DocNode>();

                PeptideRankId rankId = settingsNew.PeptideSettings.Libraries.RankId;
                bool useHighestRank = (rankId != null && settingsNew.PeptideSettings.Libraries.PeptideCount.HasValue);
                bool isPickedIntensityRank = useHighestRank &&
                                             ReferenceEquals(rankId, LibrarySpec.PEP_RANK_PICKED_INTENSITY);

                Dictionary<Identity, DocNode> mapIdToChild = CreateIdContentToChildMap();
                foreach (TransitionGroup tranGroup in GetTransitionGroups(settingsNew, explicitMods, true))
                {
                    TransitionGroupDocNode nodeGroup;
                    SrmSettingsDiff diffNode = diff;

                    DocNode existing;
                    // Add values that existed before the change, unless using picked intensity ranking,
                    // since this could bias the ranking, otherwise.
                    if (!isPickedIntensityRank && mapIdToChild.TryGetValue(tranGroup, out existing))
                        nodeGroup = (TransitionGroupDocNode)existing;
                    // Add new node
                    else
                    {
                        TransitionDocNode[] transitions = !isPickedIntensityRank
                            ? GetMatchingTransitions(tranGroup, settingsNew, explicitMods)
                            : null;

                        nodeGroup = new TransitionGroupDocNode(tranGroup, transitions);
                        // If not recursing, then ChangeSettings will not be called on nodeGroup.  So, make
                        // sure its precursor m/z is set correctly.
                        if (!recurse)
                            nodeGroup = nodeGroup.ChangePrecursorMz(settingsNew, explicitMods);
                        diffNode = SrmSettingsDiff.ALL;
                    }

                    if (nodeGroup != null)
                    {
                        TransitionGroupDocNode nodeChanged = recurse
                            ? nodeGroup.ChangeSettings(settingsNew, nodeResult, explicitMods, diffNode)
                            : nodeGroup;
                        if (transitionSettings.IsMeasurablePrecursor(nodeChanged.PrecursorMz))
                            childrenNew.Add(nodeChanged);
                    }
                }

                // If only using rank limited peptides, then choose only the single
                // highest ranked precursor charge.
                if (useHighestRank)
                {
                    childrenNew = FilterHighestRank(childrenNew, rankId);

                    // If using picked intensity, make sure original nodes are replaced
                    if (isPickedIntensityRank)
                    {
                        for (int i = 0; i < childrenNew.Count; i++)
                        {
                            var nodeNew = (TransitionGroupDocNode) childrenNew[i];
                            DocNode existing;
                            if (mapIdToChild.TryGetValue(nodeNew.TransitionGroup, out existing))
                                childrenNew[i] = existing;
                        }
                    }
                }

                nodeResult = (PeptideDocNode) nodeResult.ChangeChildrenChecked(childrenNew);
            }
            else
            {
                // Even with auto-select off, transition groups for which there is
                // no longer a precursor calculator must be removed.
                if (diff.DiffTransitionGroups && nodeResult.HasHeavyTransitionGroups)
                {
                    IList<DocNode> childrenNew = new List<DocNode>();
                    foreach (TransitionGroupDocNode nodeGroup in nodeResult.Children)
                    {
                        if (settingsNew.HasPrecursorCalc(nodeGroup.TransitionGroup.LabelType, explicitMods))
                            childrenNew.Add(nodeGroup);
                    }

                    nodeResult = (PeptideDocNode)nodeResult.ChangeChildrenChecked(childrenNew);
                }

                // Update properties and children, if necessary
                if (diff.DiffTransitionGroupProps ||
                    diff.DiffTransitions || diff.DiffTransitionProps ||
                    diff.DiffResults)
                {
                    IList<DocNode> childrenNew = new List<DocNode>();

                    // Enumerate the nodes making necessary changes.
                    foreach (TransitionGroupDocNode nodeGroup in nodeResult.Children)
                    {
                        TransitionGroupDocNode nodeChanged = nodeGroup.ChangeSettings(settingsNew, nodeResult, explicitMods, diff);
                        // Skip if the node can no longer be measured on the target instrument
                        if (!transitionSettings.IsMeasurablePrecursor(nodeChanged.PrecursorMz))
                            continue;
                        // Skip this node, if it is heavy and the update caused it to have the
                        // same m/z value as the light value.
                        if (!nodeChanged.TransitionGroup.LabelType.IsLight &&
                            !Peptide.IsCustomIon) // No mods on customs
                        {
                            double precursorMassLight = settingsNew.GetPrecursorMass(
                                IsotopeLabelType.light, Peptide.Sequence, explicitMods);
                            double precursorMzLight = SequenceMassCalc.GetMZ(precursorMassLight,
                                                                             nodeChanged.TransitionGroup.PrecursorCharge);
                            if (nodeChanged.PrecursorMz == precursorMzLight)
                                continue;
                        }

                        childrenNew.Add(nodeChanged);
                    }

                    nodeResult = (PeptideDocNode)nodeResult.ChangeChildrenChecked(childrenNew);
                }
            }

            if (diff.DiffResults || ChangedResults(nodeResult))
                nodeResult = nodeResult.UpdateResults(settingsNew /*, diff*/);

            return nodeResult;
        }
예제 #8
0
 public PeptideDocNode MergeUserInfo(PeptideDocNode nodePepMerge, SrmSettings settings, SrmSettingsDiff diff)
 {
     var result = Merge(nodePepMerge, (n, nMerge) => n.MergeUserInfo(nodePepMerge, nMerge, settings, diff));
     var annotations = Annotations.Merge(nodePepMerge.Annotations);
     if (!ReferenceEquals(annotations, Annotations))
         result = (PeptideDocNode) result.ChangeAnnotations(annotations);
     return result.UpdateResults(settings);
 }
        public override IEnumerable<DocNode> GetChoices(bool useFilter)
        {
            var nodePep = PepNode;
            if (nodePep == null)
            {
                throw new InvalidOperationException(
                    Resources.TransitionGroupTreeNode_GetChoices_Invalid_attempt_to_get_choices_for_a_node_that_has_not_been_added_to_the_tree_yet);
            }

            var listChildrenNew = GetChoices(DocNode, DocSettings, nodePep.ExplicitMods, useFilter);
            // Existing transitions must be part of the first settings change to ensure proper
            // handling of user set peak boundaries.
            MergeChosen(listChildrenNew, useFilter, node => ((TransitionDocNode)node).Key(DocNode));
            var nodeGroup = (TransitionGroupDocNode)DocNode.ChangeChildrenChecked(listChildrenNew);
            var diff = new SrmSettingsDiff(DocSettings, true);
            // Update results on the group to correctly handle user set peak boundaries
            nodeGroup = nodeGroup.UpdateResults(DocSettings, diff, nodePep, DocNode);

            // Make sure any properties that depend on peptide relationships,
            // like ratios get updated.
            nodePep = (PeptideDocNode)nodePep.ReplaceChild(nodeGroup);
            diff = new SrmSettingsDiff(diff, SrmSettingsDiff.PROPS);
            nodePep = nodePep.ChangeSettings(DocSettings, diff);
            var id = nodeGroup.Id;
            int iGroup = nodePep.Children.IndexOf(n => ReferenceEquals(n.Id, id));
            if (iGroup != -1)
                nodeGroup = (TransitionGroupDocNode)nodePep.Children[iGroup];
            listChildrenNew = new List<DocNode>(nodeGroup.Children);
            // Merge with existing transitions again to avoid changes based on the settings
            // updates.
            MergeChosen(listChildrenNew, useFilter, node => ((TransitionDocNode)node).Key(nodeGroup));
            return listChildrenNew;
        }