Beispiel #1
0
        public void SettingsChangeNotDoc()
        {
            SrmDocument docFasta = CreateMixedDoc();
            SrmSettings settings = docFasta.Settings;

            // Change declustering potential, collision energy, and retention time
            var regressions = new DeclusterPotentialList();

            regressions.AddDefaults();
            var dpRegress  = regressions["SCIEX"];
            var collisions = new CollisionEnergyList();

            collisions.AddDefaults();
            var ceRegress = collisions["SCIEX"];
            var calc      = Settings.Default.RTScoreCalculatorList.GetDefaults().First();
            var rtRegress = new RetentionTimeRegression("Test", calc, 3.5, 10.4, 12.8,
                                                        new MeasuredRetentionTime[0]);

            SrmSettings settings2 = settings.ChangePeptidePrediction(p => p.ChangeRetentionTime(rtRegress)).
                                    ChangeTransitionPrediction(p => p.ChangeCollisionEnergy(ceRegress).ChangeDeclusteringPotential(dpRegress));

            SrmDocument docFasta2 = docFasta.ChangeSettings(settings2);

            AssertEx.IsDocumentState(docFasta2, docFasta.RevisionIndex + 1, 3, 111, 352);
            Assert.AreSame(docFasta.Children, docFasta2.Children);
            Assert.AreNotEqual(docFasta.Settings, docFasta2.Settings);

            // Change auto-select toggles
            SrmSettings settings3 = settings.ChangePeptideFilter(f => f.ChangeAutoSelect(false)).
                                    ChangeTransitionFilter(f => f.ChangeAutoSelect(false));

            SrmDocument docFasta3 = docFasta.ChangeSettings(settings3);

            AssertEx.IsDocumentState(docFasta3, docFasta.RevisionIndex + 1, 3, 111, 352);
            Assert.AreSame(docFasta.Children, docFasta3.Children);
            Assert.AreNotEqual(docFasta.Settings, docFasta3.Settings);
        }
Beispiel #2
0
        public void SettingsChangePeptides()
        {
            SrmDocument docFasta = CreateMixedDoc();
            const int   posList  = 0; // Peptide list is first peptide group.
            SrmSettings settings = docFasta.Settings;

            // Change enzymes, and verify expected peptide changes
            var enzymes = new EnzymeList();

            enzymes.AddDefaults();
            SrmDocument docCnbr = docFasta.ChangeSettings(settings.ChangePeptideSettings(
                                                              p => p.ChangeEnzyme(enzymes["CNBr [M | P]"])));

            foreach (PeptideDocNode nodePeptide in docCnbr.Peptides)
            {
                if (nodePeptide.Peptide.FastaSequence == null)
                {
                    continue;
                }
                Peptide peptide = nodePeptide.Peptide;
                char    prev    = peptide.PrevAA;
                if (prev != 'M')
                {
                    Assert.Fail("Unexpected preceding cleavage at {0}", prev);
                }
                string seq  = peptide.Sequence;
                char   last = seq[seq.Length - 1];
                if (last != 'M' && peptide.NextAA != '-')
                {
                    Assert.Fail("Unexpected cleavage at {0}", last);
                }
            }
            Assert.IsTrue(docCnbr.PeptideCount < docFasta.PeptideCount);
            // Peptide list should not have changed.
            Assert.AreSame(docFasta.Children[posList], docCnbr.Children[posList]);

            // Change back to original enzyme, and make sure peptides are restored
            SrmDocument docFasta2 = docCnbr.ChangeSettings(settings);

            Assert.AreEqual(docFasta.RevisionIndex + 2, docFasta2.RevisionIndex);
            Assert.AreEqual(docFasta.PeptideCount, docFasta2.PeptideCount);
            Assert.AreEqual(docFasta.PeptideTransitionCount, docFasta2.PeptideTransitionCount);

            // Allow missed cleavages, and verify changes
            docFasta2 = docFasta.ChangeSettings(settings.ChangePeptideSettings(
                                                    p => p.ChangeDigestSettings(new DigestSettings(1, false))));
            Assert.IsTrue(docFasta.PeptideCount < docFasta2.PeptideCount);
// TODO: Make minimum transition count work immediately
//            Assert.IsTrue((docFasta2.PeptideCount - docFasta.PeptideCount) * 3 <
//                docFasta2.TransitionCount - docFasta.TransitionCount);
            int missedCleavageCount = 0;
            var dictOrig            = docFasta.Peptides.ToDictionary(node => node.Peptide);

            foreach (PeptideDocNode nodePeptide in docFasta2.Peptides)
            {
                // Make sure all zero-cleavage peptides are the same as the old document
                int missed = nodePeptide.Peptide.MissedCleavages;
                if (missed == 0)
                {
                    Assert.AreEqual(nodePeptide, dictOrig[nodePeptide.Peptide]);
                }

                // Count the number of new missed cleavages
                missedCleavageCount += nodePeptide.Peptide.MissedCleavages;
            }
            Assert.AreEqual(docFasta2.PeptideCount - docFasta.PeptideCount, missedCleavageCount);
            // Peptide list should not have changed.
            Assert.AreSame(docFasta.Children[posList], docFasta2.Children[posList]);

            // Increase minimum peptide length
            const int minNew = 12;

            docFasta2 = docFasta.ChangeSettings(settings.ChangePeptideFilter(f => f.ChangeMinPeptideLength(minNew)));
            CheckPeptides(docFasta, docFasta2, node => node.Peptide.Length >= minNew);
            Assert.AreSame(docFasta.Children[posList], docFasta2.Children[posList]);

            // Decrease maximum peptide length
            const int maxNew = 18;

            docFasta2 = docFasta.ChangeSettings(settings.ChangePeptideFilter(f => f.ChangeMaxPeptideLength(maxNew)));
            CheckPeptides(docFasta, docFasta2, node => node.Peptide.Length <= maxNew);
            Assert.AreSame(docFasta.Children[posList], docFasta2.Children[posList]);

            // Increase n-term AA exclustion
            const int ntermStart = 50;

            docFasta2 = docFasta.ChangeSettings(settings.ChangePeptideFilter(
                                                    f => f.ChangeExcludeNTermAAs(ntermStart)));
            CheckPeptides(docFasta, docFasta2, node =>
                          node.Peptide.Begin.HasValue && node.Peptide.Begin.Value >= ntermStart);
            Assert.AreSame(docFasta.Children[posList], docFasta2.Children[posList]);

            // Use ragged end exclusion
            docFasta2 = docFasta.ChangeSettings(settings.ChangePeptideSettings(
                                                    p => p.ChangeDigestSettings(new DigestSettings(0, true))));
            CheckPeptides(docFasta, docFasta2, IsNotRagged);
            Assert.AreSame(docFasta.Children[posList], docFasta2.Children[posList]);

            // Check custom exclusions
            var exclusions = new PeptideExcludeList();

            exclusions.AddDefaults();

            // Exclude Cys
            docFasta2 = docFasta.ChangeSettings(settings.ChangePeptideFilter(
                                                    f => f.ChangeExclusions(new[] { exclusions["Cys"] })));
            CheckPeptides(docFasta, docFasta2, node => node.Peptide.Sequence.IndexOf('C') == -1);
            Assert.AreSame(docFasta.Children[posList], docFasta2.Children[posList]);

            // Exclude Met
            docFasta2 = docFasta.ChangeSettings(settings.ChangePeptideFilter(
                                                    f => f.ChangeExclusions(new[] { exclusions["Met"] })));
            CheckPeptides(docFasta, docFasta2, node => node.Peptide.Sequence.IndexOf('M') == -1);

            // Exclude Hys
            docFasta2 = docFasta.ChangeSettings(settings.ChangePeptideFilter(
                                                    f => f.ChangeExclusions(new[] { exclusions["His"] })));
            CheckPeptides(docFasta, docFasta2, node => node.Peptide.Sequence.IndexOf('H') == -1);

            // Exclude NXS/NXT
            Regex regexNx = new Regex("N.[ST]");

            docFasta2 = docFasta.ChangeSettings(settings.ChangePeptideFilter(
                                                    f => f.ChangeExclusions(new[] { exclusions["NXT/NXS"] })));
            CheckPeptides(docFasta, docFasta2, node => !regexNx.Match(node.Peptide.Sequence).Success);

            // Exclude RP/KP
            docFasta2 = docFasta.ChangeSettings(settings.ChangePeptideFilter(
                                                    f => f.ChangeExclusions(new[] { exclusions["RP/KP"] })));
            CheckPeptides(docFasta, docFasta2, node => node.Peptide.Sequence.IndexOf("RP", StringComparison.Ordinal) == -1 &&
                          node.Peptide.Sequence.IndexOf("KP", StringComparison.Ordinal) == -1);

            // Custom exclude ^Q*K$
            var excludeCustom = new PeptideExcludeRegex("Custom", "^Q.*K$");

            docFasta2 = docFasta.ChangeSettings(settings.ChangePeptideFilter(
                                                    f => f.ChangeExclusions(new[] { excludeCustom })));
            CheckPeptides(docFasta, docFasta2, node =>
                          (!node.Peptide.Sequence.StartsWith("Q") || !node.Peptide.Sequence.EndsWith("K")));

            // Auto-picking off should keep any changes from occurring
            docFasta2 = docFasta.ChangeSettings(settings.ChangePeptideFilter(
                                                    f => f.ChangeAutoSelect(false).ChangeExclusions(new[] { exclusions["Cys"], exclusions["Met"], excludeCustom })));
            Assert.AreSame(docFasta.Children, docFasta2.Children);

            // Removing restriction with auto-picking off should change anything
            settings = docFasta2.Settings;
            SrmDocument docFasta3 = docFasta2.ChangeSettings(settings.ChangePeptideFilter(
                                                                 f => f.ChangeExclusions(new PeptideExcludeRegex[0])));

            Assert.AreSame(docFasta2.Children, docFasta3.Children);
        }
Beispiel #3
0
        public PeptideGroupDocNode ChangeSettings(SrmSettings settingsNew, SrmSettingsDiff diff,
                                                  DocumentSettingsContext context = null)
        {
            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();

                IEnumerable <PeptideDocNode> peptideDocNodes;
                if (settingsNew.PeptideSettings.Filter.PeptideUniqueness == PeptideFilter.PeptideUniquenessConstraint.none ||
                    settingsNew.PeptideSettings.NeedsBackgroundProteomeUniquenessCheckProcessing)
                {
                    peptideDocNodes = GetPeptideNodes(settingsNew, true).ToList();
                }
                else
                {
                    // Checking peptide uniqueness against the background proteome can be expensive.
                    // Do all the regular processing, then filter those results at the end when we
                    // can do it in aggregate for best speed.
                    IEnumerable <PeptideDocNode> peptideDocNodesUnique;
                    var peptideDocNodesPrecalculatedForUniquenessCheck = context == null ? null : context.PeptideDocNodesPrecalculatedForUniquenessCheck;
                    var uniquenessDict = context == null ? null : context.UniquenessDict;
                    if (peptideDocNodesPrecalculatedForUniquenessCheck != null)
                    {
                        // Already processed, and a global list of peptides provided
                        Assume.IsNotNull(uniquenessDict);
                        peptideDocNodesUnique = peptideDocNodesPrecalculatedForUniquenessCheck;
                    }
                    else
                    {
                        // We'll have to do the processing for this node, and work with
                        // just the peptides on this node.  With luck the background proteome
                        // will already have those cached for uniqueness checks.
                        var settingsNoUniquenessFilter =
                            settingsNew.ChangePeptideFilter(f => f.ChangePeptideUniqueness(PeptideFilter.PeptideUniquenessConstraint.none));
                        var nodes     = GetPeptideNodes(settingsNoUniquenessFilter, true).ToList();
                        var sequences = new List <string>(from p in nodes select p.Peptide.Sequence);
                        peptideDocNodesUnique = nodes;  // Avoid ReSharper multiple enumeration warning
                        uniquenessDict        = settingsNew.PeptideSettings.Filter.CheckPeptideUniqueness(settingsNew, sequences, diff.Monitor);
                    }
                    // ReSharper disable once PossibleNullReferenceException
                    peptideDocNodes = peptideDocNodesUnique.Where(p =>
                    {
                        // It's possible during document load for uniqueness dict to get out of synch, so be
                        // cautious with lookup and just return false of not found. Final document change will clean that up.
                        bool isUnique;
                        return(uniquenessDict.TryGetValue(p.Peptide.Sequence, out isUnique) && isUnique);
                    });
                }

                foreach (var nodePep in peptideDocNodes)
                {
                    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);
            }
        }