Пример #1
0
        protected override void DoTest()
        {
            var document   = new SrmDocument(SrmSettingsList.GetDefault());
            var staticMods = document.Settings.PeptideSettings.Modifications.StaticModifications.ToList();

            staticMods.Add(UniMod.GetModification("Phospho (ST)", true).ChangeVariable(true));
            var heavyMods = new List <StaticMod> {
                UniMod.GetModification("Label:13C(6)15N(4) (C-term R)", false)
            };

            document = document.ChangeSettings(document.Settings
                                               .ChangePeptideModifications(mods => mods.ChangeStaticModifications(staticMods).ChangeHeavyModifications(heavyMods))
                                               .ChangeTransitionFilter(filt => filt.ChangePrecursorCharges(new [] { 2, 3, 4, 5 })));
            Assert.IsTrue(SkylineWindow.SetDocument(document, SkylineWindow.Document));

            RunUI(() => SkylineWindow.Paste(TextUtil.LineSeparate(PEPTIDE_MODIFIED, PEPTIDE_UNMODIFIED)));
            document = WaitForDocumentChangeLoaded(document);
            RunUI(() => SkylineWindow.Paste(PEPTIDE_EXTRA));
            var docPaste1 = WaitForDocumentChangeLoaded(document);

            AssertEx.IsDocumentState(docPaste1, null, 2, 6, 44, 129);

            TestErrorMessages();
            TestUse();
        }
        private AAModMatch?GetModByName(AAModInfo info)
        {
            bool      structural = false;
            StaticMod modMatch   = null;

            // First, look in the document/global settings.
            foreach (var mod in UserDefinedTypedMods.Keys)
            {
                bool matchStuctural = UserDefinedTypedMods[mod].IsLight;
                if (Equals(info.Name, mod.Name) &&
                    (!info.UserIndicatedHeavy || !matchStuctural))
                {
                    modMatch   = mod;
                    structural = matchStuctural;
                }
            }
            // If not found, then look in Unimod.
            modMatch = modMatch ?? UniMod.GetModification(info.Name, out structural);
            if (!info.IsModMatch(modMatch) || (info.UserIndicatedHeavy && structural))
            {
                return(null);
            }
            return(new AAModMatch
            {
                StructuralMod = structural ? modMatch : null,
                HeavyMod = !structural ? modMatch : null
            });
        }
Пример #3
0
        protected override void DoTest()
        {
            Settings.Default.MruList.Add(@"C:\test1");
            Settings.Default.MruList.Add(@"C:\path\to\filename.txt");
            Settings.Default.MruList.Add(@"D:\path\to\another\file.sky");
            Assert.AreEqual(3, Settings.Default.MruList.Count);
            Settings.Default.AnnotationColor = 5;
            Settings.Default.StaticModList.Add(UniMod.GetModification("Oxidation (M)", true));
            Assert.AreEqual(2, Settings.Default.StaticModList.Count);
            Settings.Default.HeavyModList.Add(UniMod.GetModification("Label:13C(6) (C-term K)", false));
            Assert.AreEqual(1, Settings.Default.HeavyModList.Count);

            var toolsOptions = ShowDialog <ToolOptionsUI>(SkylineWindow.ShowToolOptionsUI);

            RunUI(() => toolsOptions.SelectedTab = ToolOptionsUI.TABS.Miscellaneous);

            RunDlg <MultiButtonMsgDlg>(toolsOptions.ResetAllSettings, messageDlg => messageDlg.BtnCancelClick());

            Assert.AreEqual(5, Settings.Default.AnnotationColor);
            Assert.AreEqual(3, Settings.Default.MruList.Count);
            Assert.AreEqual(2, Settings.Default.StaticModList.Count);
            Assert.AreEqual(1, Settings.Default.HeavyModList.Count);

            RunDlg <MultiButtonMsgDlg>(toolsOptions.ResetAllSettings, messageDlg => messageDlg.Btn1Click());

            Assert.AreEqual(0, Settings.Default.AnnotationColor);
            Assert.AreEqual(0, Settings.Default.MruList.Count);
            Assert.AreEqual(1, Settings.Default.StaticModList.Count);
            Assert.AreEqual(0, Settings.Default.HeavyModList.Count);

            OkDialog(toolsOptions, toolsOptions.OkDialog);
        }
Пример #4
0
        /// <summary>
        /// Sequences are passed to Prosit as an array of indices mapping into an array
        /// of amino acids (with modifications). Actually throwing exceptions in this method
        /// slows down constructing inputs (for larger data sets with unknown mods (and aa's)significantly,
        /// which is why PrositExceptions (only) are set as an output parameter and null is returned.
        /// </summary>
        public static int[] EncodeSequence(SrmSettings settings, ISequenceContainer peptide, IsotopeLabelType label, out PrositException exception)
        {
            if (!peptide.Target.IsProteomic)
            {
                throw new PrositSmallMoleculeException(peptide.ModifiedTarget);
            }

            var sequence = peptide.Target.Sequence;

            if (sequence.Length > PrositConstants.PEPTIDE_SEQ_LEN)
            {
                exception = new PrositPeptideTooLongException(peptide.ModifiedTarget);
                return(null);
            }

            var modifiedSequence = ModifiedSequence.GetModifiedSequence(settings, peptide, label);
            var result           = new int[PrositConstants.PEPTIDE_SEQ_LEN];

            for (var i = 0; i < sequence.Length; ++i)
            {
                if (!PrositConstants.AMINO_ACIDS.TryGetValue(sequence[i], out var prositAA))
                {
                    exception = new PrositUnsupportedAminoAcidException(peptide.ModifiedTarget, i);
                    return(null);
                }

                var mods = modifiedSequence.ExplicitMods.Where(m => m.IndexAA == i).ToArray();
                foreach (var mod in mods)
                {
                    if (mod.MonoisotopicMass == 0.0)
                    {
                        continue;
                    }

                    var staticMod = UniMod.FindMatchingStaticMod(mod.StaticMod, true) ?? mod.StaticMod;
                    if (!PrositConstants.MODIFICATIONS.TryGetValue(staticMod.Name, out var prositAAMod))
                    {
                        exception = new PrositUnsupportedModificationException(peptide.ModifiedTarget,
                                                                               mod.StaticMod,
                                                                               mod.IndexAA);
                        return(null);
                    }

                    result[i] = prositAAMod.PrositIndex;
                    break;
                }

                if (result[i] == 0)
                {
                    // Not modified
                    result[i] = prositAA.PrositIndex;
                }
            }

            exception = null;
            return(result);
        }
Пример #5
0
 private SrmDocument AddOxidationM(SrmDocument doc)
 {
     return(doc.ChangeSettings(
                doc.Settings.ChangePeptideModifications(mod =>
     {
         var staticMods = mod.StaticModifications.ToList();
         staticMods.Add(UniMod.GetModification("Oxidation (M)", true).ChangeVariable(false));
         return mod.ChangeStaticModifications(staticMods);
     })));
 }
Пример #6
0
        protected override void DoTest()
        {
            RunDlg <TransitionSettingsUI>(SkylineWindow.ShowTransitionSettingsUI, transitionSettingsUi =>
            {
                transitionSettingsUi.SelectedTab              = TransitionSettingsUI.TABS.Filter;
                transitionSettingsUi.FragmentTypes            = @"p";
                transitionSettingsUi.SelectedTab              = TransitionSettingsUI.TABS.FullScan;
                transitionSettingsUi.PrecursorIsotopesCurrent = FullScanPrecursorIsotopes.Count;
                transitionSettingsUi.PrecursorMassAnalyzer    = FullScanMassAnalyzerType.qit;
                transitionSettingsUi.Peaks        = 1;
                transitionSettingsUi.PrecursorRes = 0.7;
                transitionSettingsUi.OkDialog();
            });
            var peptideSettingsUi = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);

            RunUI(() =>
            {
                peptideSettingsUi.SelectedTab = PeptideSettingsUI.TABS.Modifications;
            });
            var editModListDlg = ShowEditStaticModsDlg(peptideSettingsUi);

            // Define a crosslinker which is a water loss. In this way, two peptides can be joined end to end
            // and will have the same chemical formula as a single concatenated peptide
            RunDlg <EditStaticModDlg>(editModListDlg.AddItem, editStaticModDlg => {
                {
                    editStaticModDlg.Modification  = new StaticMod(crosslinkerName, null, null, "-H2O");
                    editStaticModDlg.IsCrosslinker = true;
                    editStaticModDlg.OkDialog();
                }
            });
            RunDlg <EditStaticModDlg>(editModListDlg.AddItem, editStaticModDlg =>
            {
                editStaticModDlg.Modification = UniMod.GetModification("Oxidation (M)", true);
                editStaticModDlg.OkDialog();
            });
            OkDialog(editModListDlg, editModListDlg.OkDialog);
            OkDialog(peptideSettingsUi, peptideSettingsUi.OkDialog);
            var peptidesToPaste = TextUtil.LineSeparate(PEPTIDE_SEQUENCES.Select(MakeCrosslinkedSequence));

            RunDlg <PasteDlg>(SkylineWindow.ShowPastePeptidesDlg, pasteDlg =>
            {
                SetClipboardText(peptidesToPaste);
                pasteDlg.PastePeptides();
                pasteDlg.OkDialog();
            });
            RunUI(() => SkylineWindow.SaveDocument(TestFilesDir.GetTestPath("CrosslinkChromatogramTest.sky")));
            ImportResultsFile(TestFilesDir.GetTestPath("CAexample.mzXML"));
            RunUI(() => SkylineWindow.ShowRTRegressionGraphScoreToRun());
            RunUI(() => SkylineWindow.SaveDocument());
        }
Пример #7
0
        public void SetModification(string modName, bool isVariable)
        {
            var modification = UniMod.GetModification(modName, IsStructural);

            // Avoid setting loss-only modifications to variable, since losses themselves act as variable
            if (modification.HasLoss && !modification.HasMod)
            {
                isVariable = false;
            }
            if (IsStructural && isVariable)
            {
                modification = modification.ChangeVariable(true);
            }
            Modification = modification;
        }
Пример #8
0
        private static Exception ThrowUnimodException(string seq, int uniModId, int indexAA, int indexBracket, int indexClose)
        {
            int    indexFirst        = Math.Max(0, indexBracket - 1);
            int    indexLast         = Math.Min(seq.Length, indexClose + 1);
            string unrecognizedAaMod = seq.Substring(indexFirst, indexLast - indexFirst);

            if (UniMod.IsValidUnimodId(uniModId))
            {
                throw new FormatException(
                          string.Format(Resources.ModificationMatcher_ThrowUnimodException_Unrecognized_modification_placement_for_Unimod_id__0__in_modified_peptide_sequence__1___amino_acid__2____3___,
                                        uniModId, seq, indexAA + 1, unrecognizedAaMod));
            }

            throw new FormatException(
                      string.Format(Resources.ModificationMatcher_ThrowUnimodException_Unrecognized_Unimod_id__0__in_modified_peptide_sequence__1___amino_acid__2____3___,
                                    uniModId, seq, indexAA + 1, unrecognizedAaMod));
        }
Пример #9
0
        public void SetModification(string modName, bool isVariable)
        {
            var modification = UniMod.GetModification(modName, IsStructural);

            if (modification == null)
            {
                throw new ArgumentException(string.Format(Resources.EditStaticModDlg_SetModification___0___is_not_a_recognized_Unimod_name_, modName));
            }

            // Avoid setting loss-only modifications to variable, since losses themselves act as variable
            if (modification.HasLoss && !modification.HasMod)
            {
                isVariable = false;
            }
            if (IsStructural && isVariable)
            {
                modification = modification.ChangeVariable(true);
            }
            Modification = modification;
        }
Пример #10
0
        private IEnumerable <AAModInfo> EnumerateSequenceInfos(string seq, bool includeUnmod)
        {
            string aas             = FastaSequence.StripModifications(seq);
            bool   isSpecificHeavy = FastaSequence.OPEN_MOD.All(paren => aas.Length > seq.Count(c => c == paren));
            int    indexAA         = 0;
            int    indexAAInSeq    = 0;
            int    i = 0;

            while (i < seq.Length)
            {
                var aa           = aas[indexAA];
                int indexBracket = i + 1;
                if (indexBracket < seq.Length && (FastaSequence.OPEN_MOD.Contains(seq[indexBracket])))
                {
                    char   openBracket  = seq[indexBracket];
                    bool   isHeavy      = openBracket == '{';
                    char   closeBracket = FastaSequence.CLOSE_MOD[FastaSequence.OPEN_MOD.IndexOf(c => c == openBracket)];
                    int    indexStart   = indexBracket + 1;
                    int    indexClose   = seq.IndexOf(closeBracket, indexBracket);
                    string mod          = seq.Substring(indexStart, indexClose - indexStart);
                    i = indexClose;
                    ModTerminus?modTerminus = null;
                    if (indexAA == 0)
                    {
                        modTerminus = ModTerminus.N;
                    }
                    if (indexAA == aas.Length - 1)
                    {
                        modTerminus = ModTerminus.C;
                    }
                    string name      = null;
                    double?mass      = null;
                    int    roundedTo = 0;
                    // If passed in modification in UniMod notation, look up the id and find the name and mass
                    int uniModId;
                    if (TryGetIdFromUnimod(mod, out uniModId))
                    {
                        var staticMod = GetStaticMod(uniModId, aa, modTerminus);
                        if (staticMod == null)
                        {
                            throw ThrowUnimodException(seq, uniModId, indexAA, indexBracket, indexClose);
                        }
                        name    = staticMod.Name;
                        isHeavy = !UniMod.IsStructuralModification(name);
                        // CONSIDER: Mass depends on TransitionPrediction settings for precursors
                        mass      = staticMod.MonoisotopicMass;
                        roundedTo = DEFAULT_ROUNDING_DIGITS;
                    }
                    else
                    {
                        MassModification massModification = MassModification.Parse(mod);
                        if (massModification != null)
                        {
                            mass      = massModification.Mass;
                            roundedTo = Math.Min(massModification.Precision, DEFAULT_ROUNDING_DIGITS);
                        }
                        else
                        {
                            name = mod;
                        }
                    }

                    if (mass.HasValue)
                    {
                        mass = Math.Round(mass.Value, roundedTo);
                    }

                    var key = new AAModKey
                    {
                        Name                   = name,
                        Mass                   = mass,
                        AA                     = aa,
                        Terminus               = modTerminus,
                        UserIndicatedHeavy     = isHeavy,
                        RoundedTo              = roundedTo,
                        AppearsToBeSpecificMod = isSpecificHeavy
                    };

                    yield return(new AAModInfo
                    {
                        ModKey = key,
                        IndexAA = indexAA,
                        IndexAAInSeq = indexAAInSeq,
                    });
                }
                else if (includeUnmod)
                {
                    // If need unmodified amino acids (as when
                    // checking for equality), yield SequenceKeys for these AA's.
                    var key = new AAModKey
                    {
                        AA   = aa,
                        Mass = 0
                    };
                    yield return(new AAModInfo
                    {
                        ModKey = key,
                        IndexAA = indexAA,
                    });
                }
                // If the next character is a bracket, continue using the same amino
                // acid and leave i where it is.
                int iNext = i + 1;
                if (iNext >= seq.Length || !FastaSequence.OPEN_MOD.Contains(seq[iNext]))
                {
                    i = indexAAInSeq = iNext;
                    indexAA++;
                }
            }
        }
Пример #11
0
        public void OkDialog()
        {
            var helper = new MessageBoxHelper(this);

            string name;

            if (!helper.ValidateNameTextBox(_editing ? (Control)textName : comboMod, out name))
            {
                return;
            }

            // Allow updating the original modification
            if (!_editing || !Equals(name, Modification.Name))
            {
                if (!ModNameAvailable(name))
                {
                    helper.ShowTextBoxError(_editing ? (Control)textName : comboMod,
                                            Resources.EditStaticModDlg_OkDialog_The_modification__0__already_exists, name);
                    return;
                }
            }

            string aas = comboAA.Text;

            if (string.IsNullOrEmpty(aas))
            {
                aas = null;
            }
            else
            {
                // Use the cleanest possible format.
                var sb = new StringBuilder();
                foreach (string aaPart in aas.Split(SEPARATOR_AA))
                {
                    string aa = aaPart.Trim();
                    if (aa.Length == 0)
                    {
                        continue;
                    }
                    if (sb.Length > 0)
                    {
                        sb.Append(", "); // Not L10N
                    }
                    sb.Append(aa);
                }
            }

            string      termString = comboTerm.SelectedItem.ToString();
            ModTerminus?term       = null;

            if (!string.IsNullOrEmpty(termString))
            {
                term = (ModTerminus)Enum.Parse(typeof(ModTerminus), termString);
            }

            if (cbVariableMod.Checked && aas == null && term == null)
            {
                MessageDlg.Show(this, Resources.EditStaticModDlg_OkDialog_Variable_modifications_must_specify_amino_acid_or_terminus);
                comboAA.Focus();
                return;
            }

            string     formula    = null;
            double?    monoMass   = null;
            double?    avgMass    = null;
            LabelAtoms labelAtoms = LabelAtoms.None;

            if (cbChemicalFormula.Checked)
            {
                formula = Formula;
            }
            else
            {
                labelAtoms = LabelAtoms;
            }

            // Get the losses to know whether any exist below
            IList <FragmentLoss> losses = null;

            if (listNeutralLosses.Items.Count > 0)
            {
                losses = Losses.ToArray();
            }

            if (!string.IsNullOrEmpty(formula))
            {
                try
                {
                    SequenceMassCalc.FormulaMass(BioMassCalc.MONOISOTOPIC, formula, SequenceMassCalc.MassPrecision);
                }
                catch (ArgumentException x)
                {
                    _formulaBox.ShowTextBoxErrorFormula(helper, x.Message);
                    return;
                }
            }
            else if (labelAtoms == LabelAtoms.None)
            {
                formula = null;

                // Allow formula and both masses to be empty, if losses are present
                if (NotZero(_formulaBox.MonoMass) || NotZero(_formulaBox.AverageMass) || losses == null)
                {
                    // TODO: Maximum and minimum masses should be formalized and applied everywhere
                    double mass;
                    if (!_formulaBox.ValidateMonoText(helper, -1500, 5000, out mass))
                    {
                        return;
                    }
                    monoMass = mass;
                    if (!_formulaBox.ValidateAverageText(helper, -1500, 5000, out mass))
                    {
                        return;
                    }
                    avgMass = mass;
                }
                // Loss-only modifications may not be variable
                else if (cbVariableMod.Checked)
                {
                    MessageDlg.Show(this, Resources.EditStaticModDlg_OkDialog_The_variable_checkbox_only_applies_to_precursor_modification_Product_ion_losses_are_inherently_variable);
                    cbVariableMod.Focus();
                    return;
                }
            }
            else if (aas == null && term.HasValue)
            {
                MessageDlg.Show(this, Resources.EditStaticModDlg_OkDialog_Labeled_atoms_on_terminal_modification_are_not_valid);
                return;
            }

            RelativeRT relativeRT = RelativeRT.Matching;

            if (comboRelativeRT.Visible && comboRelativeRT.SelectedItem != null)
            {
                relativeRT = RelativeRTExtension.GetEnum(comboRelativeRT.SelectedItem.ToString());
            }

            // Store state of the chemical formula checkbox for next use.
            if (cbChemicalFormula.Visible)
            {
                Settings.Default.ShowHeavyFormula = _formulaBox.FormulaVisible;
            }

            var newMod = new StaticMod(name,
                                       aas,
                                       term,
                                       cbVariableMod.Checked,
                                       formula,
                                       labelAtoms,
                                       relativeRT,
                                       monoMass,
                                       avgMass,
                                       losses);

            foreach (StaticMod mod in _existing)
            {
                if (newMod.Equivalent(mod) && !(_editing && mod.Equals(_originalModification)))
                {
                    if (DialogResult.OK == MultiButtonMsgDlg.Show(
                            this,
                            TextUtil.LineSeparate(Resources.EditStaticModDlg_OkDialog_There_is_an_existing_modification_with_the_same_settings,
                                                  string.Format("'{0}'.", mod.Name), // Not L10N
                                                  string.Empty,
                                                  Resources.EditStaticModDlg_OkDialog_Continue),
                            MultiButtonMsgDlg.BUTTON_OK))
                    {
                        Modification = newMod;
                        DialogResult = DialogResult.OK;
                    }
                    return;
                }
            }

            var uniMod = UniMod.GetModification(name, IsStructural);

            // If the modification name is not found in Unimod, check if there exists a modification in Unimod that matches
            // the dialog modification, and prompt the user to to use the Unimod modification instead.
            if (uniMod == null)
            {
                var matchingMod = UniMod.FindMatchingStaticMod(newMod, IsStructural);
                if (matchingMod != null &&
                    (ModNameAvailable(matchingMod.Name) ||
                     (_editing && Equals(matchingMod.Name, Modification.Name))))
                {
                    var result = MultiButtonMsgDlg.Show(
                        this,
                        TextUtil.LineSeparate(Resources.EditStaticModDlg_OkDialog_There_is_a_Unimod_modification_with_the_same_settings,
                                              string.Empty,
                                              string.Format(Resources.EditStaticModDlg_OkDialog_Click__Unimod__to_use_the_name___0___, matchingMod.Name),
                                              string.Format(Resources.EditStaticModDlg_OkDialog_Click__Custom__to_use_the_name___0___, name)),
                        Resources.EditStaticModDlg_OkDialog_Unimod,
                        Resources.EditStaticModDlg_OkDialog_Custom,
                        true);
                    if (result == DialogResult.Yes)
                    {
                        newMod = matchingMod.MatchVariableAndLossInclusion(newMod);   // Unimod
                    }
                    if (result == DialogResult.Cancel)
                    {
                        return;
                    }
                }
            }
            else
            {
                // If the dialog modification matches the modification of the same name in Unimod,
                // use the UnimodId.
                if (newMod.Equivalent(uniMod))
                {
                    newMod = uniMod.MatchVariableAndLossInclusion(newMod);
                }
                else
                {
                    // Finally, if the modification name is found in Unimod, but the modification in Unimod does not
                    // match the dialog modification, prompt the user to use the Unimod modification definition instead.
                    if (DialogResult.OK != MultiButtonMsgDlg.Show(
                            this,
                            TextUtil.LineSeparate(string.Format(Resources.EditStaticModDlg_OkDialog_This_modification_does_not_match_the_Unimod_specifications_for___0___, name),
                                                  string.Empty,
                                                  Resources.EditStaticModDlg_OkDialog_Use_non_standard_settings_for_this_name),
                            MultiButtonMsgDlg.BUTTON_OK))
                    {
                        return;
                    }
                }
            }

            _modification = newMod;

            DialogResult = DialogResult.OK;
        }
Пример #12
0
        protected override void DoTest()
        {
            // Exploring a Library,  p. 1
            PeptideSettingsUI peptideSettingsUI = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);
            var editListUI =
                ShowDialog <EditListDlg <SettingsListBase <LibrarySpec>, LibrarySpec> >(peptideSettingsUI.EditLibraryList);

            RunDlg <EditLibraryDlg>(editListUI.AddItem, editLibraryDlg =>
            {
                editLibraryDlg.LibrarySpec =
                    new BiblioSpecLibSpec("Experiment 15N", GetTestPath(@"labeled_15N.blib"));
                editLibraryDlg.OkDialog();
            });
            OkDialog(editListUI, editListUI.OkDialog);
            RunUI(() =>
            {
                peptideSettingsUI.SelectedTab     = PeptideSettingsUI.TABS.Library;
                peptideSettingsUI.PickedLibraries = new[] { "Experiment 15N" };
            });
            PauseForScreenShot <PeptideSettingsUI.LibraryTab>("Peptide Settings - Library tab", 3);

            // Modifications Tab in peptideSttingsUI to check "Carbamidomethyl Cysteine"
            const string carbamidoName = StaticModList.DEFAULT_NAME;

            RunUI(() =>
            {
                peptideSettingsUI.SelectedTab      = PeptideSettingsUI.TABS.Modifications;
                peptideSettingsUI.PickedStaticMods = new[] { carbamidoName };
            });
            PauseForScreenShot <PeptideSettingsUI.ModificationsTab>("Peptide Settings - Modifications tab", 4);

            OkDialog(peptideSettingsUI, peptideSettingsUI.OkDialog);

            Assert.IsTrue(WaitForCondition(() =>
                                           SkylineWindow.Document.Settings.PeptideSettings.Libraries.IsLoaded &&
                                           SkylineWindow.Document.Settings.PeptideSettings.Libraries.Libraries.Count > 0));

            // Go to view menu and click Spectral Libraries
            ViewLibraryDlg viewLibraryDlg = ShowDialog <ViewLibraryDlg>(SkylineWindow.ViewSpectralLibraries);
            var            matchedPepsDlg = WaitForOpenForm <AddModificationsDlg>();

            RunUI(matchedPepsDlg.CancelDialog);
            PauseForScreenShot <ViewLibraryDlg>("Library Explorer", 5);

            // Types text in Peptide textbox in the Spectral Library Explorer Window
            RunUI(() =>
            {
                viewLibraryDlg.FilterString = "Q"; // Not L10N
                Assert.AreEqual(7, viewLibraryDlg.PeptideDisplayCount);
            });
            PauseForScreenShot("Library Explorere filtered for peptides beginning with Q", 6);

            RunUI(() =>
            {
                viewLibraryDlg.FilterString = "I"; // Not L10N
                viewLibraryDlg.SetObservedMzValues(true);
                Assert.AreEqual(1, viewLibraryDlg.PeptideDisplayCount);
            });

            // Click B and 2 buttons on the right side of Spectral Library Explorer Window to show b-ions
            RunUI(() =>
            {
                Assert.AreEqual(11, viewLibraryDlg.GraphItem.IonLabels.Count());
                viewLibraryDlg.GraphSettings.ShowBIons   = true;
                viewLibraryDlg.GraphSettings.ShowCharge2 = true;
                Assert.AreEqual(35, viewLibraryDlg.GraphItem.IonLabels.Count());
            });
            PauseForScreenShot <ViewLibraryDlg>("Library Explorer showing ISERT peptide with b and charge 2 ions", 7);

            // Right click on spectrum chart and select Observed m/z Values
            RunUI(() =>
            {
                if (!Settings.Default.ShowObservedMz)
                {
                    if (!Settings.Default.ShowIonMz)
                    {
                        var labelsBefore = viewLibraryDlg.GraphItem.IonLabels.ToArray();
                        Assert.IsFalse(labelsBefore.Contains(label => label.Contains("\n"))); // Not L10N
                    }
                    viewLibraryDlg.SetObservedMzValues(true);
                }
                var labelsAfter = viewLibraryDlg.GraphItem.IonLabels;
                Assert.IsTrue(labelsAfter.Contains(label => label.Contains("\n"))); // Not L10N
            });

            // Clearing Peptide Textbox...
            RunUI(() =>
            {
                viewLibraryDlg.FilterString = string.Empty;
                Assert.AreEqual(43, viewLibraryDlg.PeptideDisplayCount);
            });

            // Matching Modifications p. 7

            // Settings > Peptides Settings
            var          peptideSettingsUI1 = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);
            const string glnPyroGluName     = "Gln->pyro-Glu (N-term Q)"; // Not L10N
            var          glnPyroGlu         = UniMod.GetModification(glnPyroGluName, out _);

            glnPyroGlu = glnPyroGlu.ChangeVariable(true);
            AddStaticMod(glnPyroGlu, peptideSettingsUI1, "Edit Structural Modification form", 8);

            RunUI(() => peptideSettingsUI1.PickedStaticMods = new[] { carbamidoName, glnPyroGluName });
            const string label15NName = "Label:15N"; // Not L10N
            var          mod15N       = UniMod.GetModification(label15NName, out _);

            AddHeavyMod(mod15N, peptideSettingsUI1, "Edit Structural Modification form", 9);
            RunUI(() => peptideSettingsUI1.PickedHeavyMods = new[] { label15NName });
            PauseForScreenShot <PeptideSettingsUI.ModificationsTab>("Peptide Settings - Modificatoins tab", 10);

            OkDialog(peptideSettingsUI1, peptideSettingsUI1.OkDialog);

            Assert.IsTrue(WaitForCondition(() =>
                                           SkylineWindow.Document.Settings.PeptideSettings.Modifications.StaticModifications.Count > 0 &&
                                           SkylineWindow.Document.Settings.PeptideSettings.Modifications.AllHeavyModifications.Any()));
            PauseForScreenShot("Peptide list clipped from Library Explorer", 11);

            if (IsCoverShotMode)
            {
                RestoreCoverViewOnScreen(false);
                RunUI(() =>
                {
                    viewLibraryDlg.SetBounds(SkylineWindow.Left, SkylineWindow.Top, SkylineWindow.Width, SkylineWindow.Height);
                });
                TakeCoverShot();

                OkDialog(viewLibraryDlg, viewLibraryDlg.CancelDialog);
                return;
            }
            // Adding Library Peptides to the Document p. 11

            // Adding AEVNGLAAQGKYEGSGEDGGAAAQSLYIANHAY
            var          docInitial       = WaitForProteinMetadataBackgroundLoaderCompletedUI();
            const string peptideSequence1 = "AEVNGLAAQGKYEGSGEDGGAAAQSLYIANHAY"; // Not L10N

            RunUI(() =>
            {
                viewLibraryDlg.FilterString = peptideSequence1;
                Assert.AreEqual(1, viewLibraryDlg.PeptideDisplayCount);
            });
            {
                var msgDlg = ShowDialog <FilterMatchedPeptidesDlg>(viewLibraryDlg.AddPeptide);
                PauseForScreenShot <FilterMatchedPeptidesDlg>("Filter peptides form", 11);

                OkDialog(msgDlg, msgDlg.OkDialog);
            }

            var docAdd1 = WaitForDocumentChange(docInitial);

            Assert.AreEqual(1, docAdd1.PeptideCount);
            Assert.AreEqual(peptideSequence1, docAdd1.Peptides.ToArray()[0].Peptide.Sequence);


            // Adding DNAGAATEEFIK++ (no ok dialog)
            const string peptideSequence2 = "DNAGAATEEFIK"; // Not L10N

            RunUI(() =>
            {
                viewLibraryDlg.FilterString = peptideSequence2 + "++"; // Not L10N
                Assert.AreEqual(2, viewLibraryDlg.PeptideDisplayCount);
            });
            RunUI(viewLibraryDlg.AddPeptide);

            var docAdd2 = WaitForDocumentChange(docAdd1);

            Assert.AreEqual(2, docAdd2.PeptideCount);
            Assert.AreEqual(peptideSequence2, docAdd2.Peptides.ToArray()[1].Peptide.Sequence);

            // Edit > ExpandAll > Peptides
            RunUI(() =>
            {
                SkylineWindow.ExpandPeptides();
                SkylineWindow.Size = new Size(918, 553);
            });
            RestoreViewOnScreen(12);
            PauseForScreenShot("Main window", 12);

            // Adding DNAGAATEEFIKR++ (has ok)
            const string peptideSequence3 = "DNAGAATEEFIKR"; // Not L10N

            RunUI(() =>
            {
                viewLibraryDlg.FilterString = peptideSequence3 + "++"; // Not L10N
                Assert.AreEqual(2, viewLibraryDlg.PeptideDisplayCount);
            });

            RunDlg <FilterMatchedPeptidesDlg>(viewLibraryDlg.AddPeptide, msgDlg => msgDlg.OkDialog());
            var docAdd3 = WaitForDocumentChange(docAdd2);

            Assert.AreEqual(3, docAdd3.PeptideCount);
            Assert.AreEqual(2, docAdd3.Peptides.ToArray()[2].Children.Count);
            Assert.AreEqual(peptideSequence3, docAdd3.Peptides.ToArray()[2].Peptide.Sequence);

            // Adding DNAGAATEEFIKR+++ (has ok)
            RunUI(() =>
            {
                viewLibraryDlg.FilterString = peptideSequence3 + "+++"; // Not L10N
                Assert.AreEqual(1, viewLibraryDlg.PeptideDisplayCount);
            });
            WaitForGraphs();

            RunDlg <FilterMatchedPeptidesDlg>(viewLibraryDlg.AddPeptide, msgDlg => msgDlg.OkDialog());
            var docAdd4 = WaitForDocumentChange(docAdd3);

            // peptideSequence4 is considered a sub of peptideSequence3
            Assert.AreEqual(3, docAdd4.PeptideCount);
            Assert.AreEqual(4, docAdd4.Peptides.ToArray()[2].Children.Count);

            // Close the Library Explorer dialog
            OkDialog(viewLibraryDlg, viewLibraryDlg.CancelDialog);

            // Save current document as 15N_library_peptides.sky
            RunUI(() => SkylineWindow.SaveDocument(GetTestPath(@"15N_library_peptides.sky")));
            RunUI(() => SkylineWindow.NewDocument());

            // Neutral Losses p. 13
            PeptideSettingsUI settingsUI = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);

            RunUI(() =>
            {
                settingsUI.SelectedTab      = PeptideSettingsUI.TABS.Modifications;
                settingsUI.PickedStaticMods = new[] { carbamidoName };           // Not L10N
                settingsUI.PickedHeavyMods  = new string[0];
                settingsUI.PickedLibraries  = new string[0];
            });
            PauseForScreenShot <PeptideSettingsUI.ModificationsTab>("Peptide Settings - Modifications tab", 14);

            var editListUI1 =
                ShowDialog <EditListDlg <SettingsListBase <LibrarySpec>, LibrarySpec> >(settingsUI.EditLibraryList);
            const string humanPhosphoLibName = "Human Phospho"; // Not L10N

            RunDlg <EditLibraryDlg>(editListUI1.AddItem, editLibraryDlg =>
            {
                editLibraryDlg.LibrarySpec =
                    new BiblioSpecLibSpec(humanPhosphoLibName, GetTestPath(@"phospho.blib"));
                editLibraryDlg.OkDialog();
            });
            OkDialog(editListUI1, editListUI1.OkDialog);
            RunUI(() =>
            {
                settingsUI.SelectedTab     = PeptideSettingsUI.TABS.Library;
                settingsUI.PickedLibraries = new[] { humanPhosphoLibName };
            });
            PauseForScreenShot <PeptideSettingsUI.LibraryTab>("Peptide Settings - Library tab", 15);

            {
                var msgDlg = ShowDialog <MultiButtonMsgDlg>(() => settingsUI.ShowViewLibraryDlg());
                PauseForScreenShot <MultiButtonMsgDlg>("Save changes", 15);

                OkDialog(msgDlg, msgDlg.Btn0Click);
            }

            Assert.IsTrue(WaitForCondition(() =>
                                           SkylineWindow.Document.Settings.PeptideSettings.Modifications.StaticModifications.Count == 1 &&
                                           !SkylineWindow.Document.Settings.PeptideSettings.Modifications.AllHeavyModifications.Any() &&
                                           SkylineWindow.Document.Settings.PeptideSettings.Libraries.IsLoaded &&
                                           SkylineWindow.Document.Settings.PeptideSettings.Libraries.Libraries.Count > 0));

            // Ignore modification matching form
            var matchedPepModsDlg = WaitForOpenForm <AddModificationsDlg>();

            RunUI(matchedPepModsDlg.CancelDialog);

            var       viewLibraryDlg1 = WaitForOpenForm <ViewLibraryDlg>();
            const int countLabels1    = 15;
            const int countLabels2    = 18;

            RunUI(() =>
            {
                viewLibraryDlg1.FilterString = "AISS"; // Not L10N
                Assert.AreEqual(2, viewLibraryDlg1.PeptideDisplayCount);
                Assert.AreEqual(countLabels1, viewLibraryDlg1.GraphItem.IonLabels.Count());
            });
            PauseForScreenShot <GraphSpectrum>("Spectrum graph metafile", 16);   // p. 16, figure 1a
            RunUI(() =>
            {
                viewLibraryDlg1.SelectedIndex = 1;
                Assert.AreEqual(countLabels2, viewLibraryDlg1.GraphItem.IonLabels.Count());
            });
            PauseForScreenShot <GraphSpectrum>("Spectrum graph metafile", 16);   // p. 16, figure 1b

            docInitial = SkylineWindow.Document;

            var          peptideSettingsUI2 = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);
            const string phosphoModName     = "Phospho (ST)";                                                                      // Not L10N
            var          phosphoSt          = new StaticMod(phosphoModName, "S, T", null, true, "HPO3", LabelAtoms.None,           // Not L10N
                                                            RelativeRT.Unknown, null, null, new[] { new FragmentLoss("H3PO4"), }); // Not L10N

            AddStaticMod(phosphoSt, peptideSettingsUI2, "Edit Structural Modifcation form", 17);

            // Check Phospho (ST) and Carbamidomethyl Cysteine
            RunUI(() => peptideSettingsUI2.PickedStaticMods = new[] { phosphoModName, carbamidoName }); // Not L10N
            OkDialog(peptideSettingsUI2, peptideSettingsUI2.OkDialog);

            var docPhospho = WaitForDocumentChange(docInitial);

            Assert.IsTrue(docPhospho.Settings.PeptideSettings.Modifications.StaticModifications.Count == 2);

            string    lossText         = Math.Round(-phosphoSt.Losses[0].MonoisotopicMass, 1).ToString(LocalizationHelper.CurrentCulture);
            const int countLossLabels1 = 12;
            const int countLossLabels2 = 15;
            const int countPrecursors1 = 1;
            const int countPrecursors2 = 2;

            RunUI(() =>
            {
                // New ions should be labeled, because of the added modification with loss
                viewLibraryDlg1.SelectedIndex = 0;
                Assert.AreEqual(countLabels1 + countLossLabels1, viewLibraryDlg1.GraphItem.IonLabels.Count());

                viewLibraryDlg1.GraphSettings.ShowPrecursorIon = true;

                // Make sure the precursor -98 ion was added
                var labelsPhospho = viewLibraryDlg1.GraphItem.IonLabels.ToList();
                Assert.AreEqual(countLossLabels1 + 1, labelsPhospho.Count(label => label.Contains(lossText)));
                Assert.IsTrue(labelsPhospho.Contains(label => label.Contains(string.Format("{0} {1}", IonType.precursor.GetLocalizedString(), lossText))));
                Assert.AreEqual(countLabels1 + countLossLabels1 + countPrecursors1, labelsPhospho.Count);
            });
            PauseForScreenShot <GraphSpectrum>("Spectrum graph metafile", 18);   // p. 18, figure 1a.

            RunUI(() =>
            {
                viewLibraryDlg1.SelectedIndex = 1;
                var labelsPhospho             = viewLibraryDlg1.GraphItem.IonLabels.ToList();
                Assert.AreEqual(countLossLabels2 + 1, labelsPhospho.Count(label => label.Contains(lossText)));
                Assert.IsTrue(labelsPhospho.Contains(label => label.Contains(string.Format("{0} {1}", IonType.precursor.GetLocalizedString(), lossText))));
                Assert.AreEqual(countLabels2 + countLossLabels2 + countPrecursors2, labelsPhospho.Count);
            });
            PauseForScreenShot <GraphSpectrum>("Spectrum graph metafile", 18);   // p. 18, figure 1b.

            // Matching Library Peptides to Proteins p. 18
            var peptideSettingsUI3         = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);
            var buildBackgroundProteomeDlg =
                ShowDialog <BuildBackgroundProteomeDlg>(peptideSettingsUI3.ShowBuildBackgroundProteomeDlg);

            RunUI(() =>
            {
                buildBackgroundProteomeDlg.BackgroundProteomePath = GetTestPath(@"human.protdb");
                buildBackgroundProteomeDlg.BackgroundProteomeName = "Human (mini)";
            });
            PauseForScreenShot <BuildBackgroundProteomeDlg>("Edit Background Proteome", 19);   // p. 19

            OkDialog(buildBackgroundProteomeDlg, buildBackgroundProteomeDlg.OkDialog);

            // Select Max Missed Cleavages to be 2
            RunUI(() =>
            {
                peptideSettingsUI3.MissedCleavages = 2;
            });
            OkDialog(peptideSettingsUI3, peptideSettingsUI3.OkDialog);

            WaitForBackgroundProteomeLoaderCompleted(); // wait for protDB to populate protein metadata

            RunUI(() =>
            {
                viewLibraryDlg1.FilterString = string.Empty;
                Assert.AreEqual(100, viewLibraryDlg1.PeptideDisplayCount);
            });

            // Check Associate Proteins check box on Spectral Library Explorer form
            RunUI(() =>
            {
                viewLibraryDlg1.AssociateMatchingProteins = true;
            });

            docInitial = WaitForProteinMetadataBackgroundLoaderCompletedUI();

            var confirmUpgrade = ShowDialog <AlertDlg>(viewLibraryDlg1.AddAllPeptides);
            // Add everything in the library to the document.
            var filterMatchedPeptidesDlg =
                ShowDialog <FilterMatchedPeptidesDlg>(confirmUpgrade.ClickYes);

            RunUI(() =>
            {
                filterMatchedPeptidesDlg.DuplicateProteinsFilter =
                    BackgroundProteome.DuplicateProteinsFilter.FirstOccurence;
                filterMatchedPeptidesDlg.AddUnmatched = true;
                filterMatchedPeptidesDlg.AddFiltered  = true;

                // Checks that Peptides were added with the correct buttons selected...
                Assert.AreEqual(163, filterMatchedPeptidesDlg.DuplicateMatchesCount);
                Assert.AreEqual(2, filterMatchedPeptidesDlg.UnmatchedCount);
            });
            PauseForScreenShot <FilterMatchedPeptidesDlg>("Filter Peptides", 20);   // p. 20, figure 1

            {
                var msgDlg = ShowDialog <MultiButtonMsgDlg>(filterMatchedPeptidesDlg.OkDialog);
                PauseForScreenShot("Message form", 20);   // p. 20, figure 2

                OkDialog(msgDlg, msgDlg.Btn1Click);
            }
            OkDialog(viewLibraryDlg1, viewLibraryDlg1.CancelDialog);

            var docProteins = WaitForDocumentChange(docInitial);

            AssertEx.IsDocumentState(docProteins, null, 250, 346, 347, 1041);

            RestoreViewOnScreen(21);
            PauseForScreenShot("Main window", 21);

            OkDialog(viewLibraryDlg, viewLibraryDlg.Close);
        }
Пример #13
0
        public void TestUniMod()
        {
            // UpdateTestXML is used to update the test files if the modifications in UniMod.cs
            // have changed. Before UpdateTestXML is called, TestUniMod should pass with the new changes
            // to make sure we haven't lost/broken any modifications from earlier versions of UniMod.cs.
            // Note: The test will always run against the last build XML. Run twice when updating.
            UpdateTestXML();

            foreach (StaticMod mod in UniMod.DictUniModIds.Values)
            {
                // UniModCompiler should not set the masses.
                if (mod.Formula == null)
                {
                    Assert.IsNull(mod.MonoisotopicMass);
                    Assert.IsNull(mod.AverageMass);
                }
                else
                {
                    Assert.AreEqual(mod.MonoisotopicMass,
                                    SequenceMassCalc.FormulaMass(BioMassCalc.MONOISOTOPIC, mod.Formula, SequenceMassCalc.MassPrecision));
                    Assert.AreEqual(mod.AverageMass,
                                    SequenceMassCalc.FormulaMass(BioMassCalc.AVERAGE, mod.Formula, SequenceMassCalc.MassPrecision));
                }
                // Everything amino acid/terminus that is part of the modification should be present in
                // the name of the modification.
                var aasAndTermInName = mod.Name.Split(new[] { ' ' }, 2)[1];
                if (mod.Terminus != null)
                {
                    Assert.IsTrue(aasAndTermInName.Contains(mod.Terminus.Value.ToString()));
                }
                if (mod.AAs != null)
                {
                    foreach (char aa in mod.AminoAcids)
                    {
                        Assert.IsTrue(aasAndTermInName.Contains(aa));
                    }
                }
                // Should not have label atoms if no amino acids are listed.
                if (!Equals(mod.LabelAtoms, LabelAtoms.None))
                {
                    Assert.IsTrue(mod.AAs != null);
                }
            }

            // Testing ValidateID.
            var phospho = UniMod.DictStructuralModNames["Phospho (ST)"];

            Assert.IsTrue(UniMod.ValidateID(phospho.ChangeExplicit(true)));
            Assert.IsTrue(UniMod.ValidateID(phospho.ChangeVariable(true)));
            Assert.IsFalse(UniMod.ValidateID((StaticMod)phospho.ChangeName("Phospho")));

            StreamReader staticReader = new StreamReader(GetTestStream(STATIC_LIST_FILE));
            string       staticMods   = staticReader.ReadToEnd();

            staticReader.Close();
            AssertEx.DeserializeNoError <StaticModList>(staticMods, false);

            StreamReader heavyReader = new StreamReader(GetTestStream(HEAVY_LIST_FILE));
            string       heavyMods   = heavyReader.ReadToEnd();

            heavyReader.Close();
            AssertEx.DeserializeNoError <HeavyModList>(heavyMods, false);
        }
Пример #14
0
        public void TestModificationMatcher()
        {
            InitSeqs();

            var carbC = StaticModList.GetDefaultsOn()[0];

            // Test exception thrown if unable to match - mass.
            UpdateMatcherFail(STR_FAIL_MASS);
            UpdateMatcherFail(STR_FAIL_NOT_A_NUMBER);
            // Test exception thrown if unable to match - name.
            UpdateMatcherFail(STR_FAIL_NAME);
            // Can't match empty modifications.
            UpdateMatcherFail(STR_FAIL_EMPTY_MOD);
            UpdateMatcherFail(STR_FAIL_EMPTY_MOD2);
            // Can't match double modifications.
            UpdateMatcherFail(STR_FAIL_DOUBLE_MOD);
            // Test exception thrown if unimod not specified correctly
            UpdateMatcherFail(STR_FAIL_UNIMOD);
            UpdateMatcherFail(STR_UNKNOWN_UNIMOD);
            // Can't phosphorylate tryptophan
            UpdateMatcherFail(STR_FAIL_WRONG_AA_UNIMOD);
            // Can't put C-terminal modification in middle of peptide
            UpdateMatcherFail(STR_FAIL_UNIMOD_TERMINUS);

            // Test mods in UniMod match correctly.
            UpdateMatcher(StaticModList.GetDefaultsOn(), HeavyModList.GetDefaultsOn(), null, null);
            // A sequence with no modifications should not be explicitly modified.
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_NO_MODS).HasExplicitMods);
            var nodeCysOxi = MATCHER.GetModifiedNode(STR_CYS_AND_OXI);

            Assert.IsTrue(nodeCysOxi.HasExplicitMods);
            Assert.IsFalse(nodeCysOxi.ExplicitMods.HasHeavyModifications);
            // Modifications should match by name.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_MOD_BY_NAME).ExplicitMods.StaticModifications.Contains(mod =>
                                                                                                             Equals(mod.Modification.Name, "Phospho (ST)")));
            // Test can find terminal modification
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_TERM_ONLY).ExplicitMods.HeavyModifications.Contains(mod =>
                                                                                                          mod.Modification.EquivalentAll(UniMod.GetModification("Label:13C(6) (C-term R)", false))));
            // Test can find matches on terminus that are not terminal
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_MOD_BY_NAME).ExplicitMods.StaticModifications.Contains(mod =>
                                                                                                             mod.Modification.Terminus == null));
            // Test matching negative masses
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_AMMONIA_LOSS).ExplicitMods.StaticModifications.Contains(mod =>
                                                                                                              mod.Modification.EquivalentAll(UniMod.GetModification("Ammonia-loss (N-term C)", true))));

            // General and specific
            // If all AAs modified, try for most general modification.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15)
                          .ExplicitMods.HeavyModifications.Contains(mod => mod.Modification.Equivalent(LABEL15_N)));

            // Updating the settings.
            // Peptide settings should change to include new mods.
            var          docNew = new SrmDocument(SrmSettingsList.GetDefault());
            IdentityPath firstAdded;
            IdentityPath nextAdded;

            docNew = docNew.AddPeptideGroups(new[] { new PeptideGroupDocNode(new PeptideGroup(), "PepGroup1", "",
                                                                             new[] { MATCHER.GetModifiedNode(STR_MOD_BY_NAME) }) }, true, null, out firstAdded, out nextAdded);
            var pepSetNew = MATCHER.GetDocModifications(docNew);

            Assert.IsTrue(pepSetNew.StaticModifications.Contains(UniMod.GetModification("Phospho (ST)", true).ChangeExplicit(true)));
            // Update the document to the new settings.
            var pepSetNew1      = pepSetNew;
            var settingsNew2    = docNew.Settings.ChangePeptideModifications(mods => pepSetNew1);
            var lightGlobalMods = new MappedList <string, StaticMod>();

            lightGlobalMods.AddRange(settingsNew2.PeptideSettings.Modifications.StaticModifications);
            var heavyGlobalMods = new MappedList <string, StaticMod>();

            heavyGlobalMods.AddRange(settingsNew2.PeptideSettings.Modifications.AllHeavyModifications);
            // Match again. Test FoundMatches string should now be empty.
            MATCHER.CreateMatches(docNew.Settings.ChangePeptideModifications(mods => pepSetNew1),
                                  new List <string> {
                STR_MOD_BY_NAME
            }, lightGlobalMods, heavyGlobalMods);
            Assert.IsTrue(string.IsNullOrEmpty(MATCHER.FoundMatches));

            // Adding 15N to the settings.
            UpdateMatcher(new[] { carbC }, new[] { LABEL15_N }, null, null);
            // Test sequences with only explicit heavy mods should not have explicit light mods
            Assert.IsNull(MATCHER.GetModifiedNode(STR_HEAVY_ONLY).ExplicitMods.StaticModifications);

            // Test sequences with only explicit light mods should not have explicit heavy mods
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_LIGHT_ONLY).ExplicitMods.HasHeavyModifications);

            // Test global mods take precendence over UniMod
            UpdateMatcher(new[] { carbC }, null, new[] { OXIDATION_M_GLOBAL }, new[] { LABEL15_N });
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).ExplicitMods.StaticModifications
                          .Contains(mod => Equals(mod.Modification, OXIDATION_M_GLOBAL)));

            // Test document mods take precendence over UniMod
            UpdateMatcher(new[] { carbC, METHIONINE_OXIDATION }, null, new[] { OXIDATION_M_GLOBAL }, new[] { LABEL15_N });
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).HasExplicitMods);

            // Test exception thrown if match doesn't make sense - wrong AA.
            UpdateMatcherFail(STR_FAIL_OX_ON_D);
            // Test exception thrown if match doesn't make sense - wrong terminus.
            _seqs.Add(STR_FAIL_OX_TERM);
            AssertEx.ThrowsException <FormatException>(() => UpdateMatcher(new[] { OXIDATION_M_C_TERM }, null, null, null));
            _seqs.Remove(STR_FAIL_OX_TERM);

            // Heavy 15N - All AAs.
            UpdateMatcher(new[] { carbC, METHIONINE_OXIDATION }, new[] { LABEL15_N }, null, null);
            // Node should be created from document settings if possible.
            Assert.IsNull(MATCHER.GetModifiedNode(STR_HEAVY_15).ExplicitMods);
            // Heavy 15N - specific AA.
            // If only a specific AA is modified, there must be an explicit mod.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_F).HasExplicitMods);

            // Test variable mods match correctly.
            // Put variable mod in global mod and not on doc - make sure don't get variable mod,
            // should get explicit mod in that case.
            var variableMetOx = METHIONINE_OXIDATION.ChangeVariable(true);

            UpdateMatcher(new[] { carbC }, null, new[] { variableMetOx }, null);
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).HasExplicitMods);
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS).ExplicitMods.IsVariableStaticMods);
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS_CAP).ExplicitMods.IsVariableStaticMods);
            // Add variable mod to doc
            UpdateMatcher(new[] { carbC, variableMetOx }, null, null, null);
            // Mod can be created by the settings.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).HasExplicitMods);
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).ExplicitMods.IsVariableStaticMods);
            // Mod cannot be created by the settings.
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS).ExplicitMods.IsVariableStaticMods);
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_OXI_PHOS_CAP).ExplicitMods.IsVariableStaticMods);

            // Add Met Ox to global. Test: +16 finds it.
            UpdateMatcher(new[] { carbC }, null, new[] { MET_OX_ROUNDED }, null);
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).
                          ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, MET_OX_ROUNDED)));
            // Test: +15.99 finds UniMod.
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_HEAVY_15).
                           ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, MET_OX_ROUNDED)));
            // Add Methionine Oxidation before Met Ox. Test: +16 finds it.
            UpdateMatcher(new[] { carbC }, null, new[] { METHIONINE_OXIDATION, MET_OX_ROUNDED }, null);
            Assert.IsFalse(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).
                           ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, MET_OX_ROUNDED)));
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_CYS_AND_OXI).
                          ExplicitMods.StaticModifications.Contains(mod => Equals(mod.Modification, METHIONINE_OXIDATION)));
            // Test long masses rounded.
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_METOX_LONG_MASS).ExplicitMods.StaticModifications.Contains(mod =>
                                                                                                                 Equals(mod.Modification, METHIONINE_OXIDATION)));
            // Test UniMod label types
            var node = MATCHER.GetModifiedNode(STR_UNIMOD_LABEL);

            Assert.IsNotNull(node);
            Assert.IsNull(node.ExplicitMods.StaticModifications);
            Assert.IsTrue(node.ExplicitMods.HeavyModifications.Contains(mod =>
                                                                        Equals(mod.Modification, N_TERM_LABEL)));
            UpdateMatcherWithNoSequences(new[] { carbC }, new[] { N_TERM_LABEL }, new[] { METHIONINE_OXIDATION, MET_OX_ROUNDED }, null);
            var nodeNew = MATCHER.GetModifiedNode(STR_UNIMOD_LABEL);

            Assert.IsNotNull(nodeNew);
            Assert.IsTrue(nodeNew.TransitionGroups.Any(group => Equals(group.TransitionGroup.LabelType, IsotopeLabelType.heavy)));
            UpdateMatcher(new[] { carbC }, null, new[] { METHIONINE_OXIDATION, MET_OX_ROUNDED }, null);

            // Test case where there are lots of unimod labels
            var nodeUniAll = MATCHER.GetModifiedNode(STR_UNIMOD_ALL);

            Assert.AreEqual(nodeUniAll.ExplicitMods.HeavyModifications.Count, 10);
            Assert.IsNull(nodeUniAll.ExplicitMods.StaticModifications);
            foreach (var mod in nodeUniAll.ExplicitMods.HeavyModifications)
            {
                Assert.AreEqual(mod.Modification.ShortName, "+01");
                Assert.AreEqual(mod.Modification.UnimodId, 994);
            }

            // Test unimod terminal label
            var nodeUniTerm = MATCHER.GetModifiedNode(STR_UNIMOD_TERMINUS);

            Assert.AreEqual(nodeUniTerm.ExplicitMods.HeavyModifications.Count, 1);
            Assert.IsNull(nodeUniTerm.ExplicitMods.StaticModifications);
            Assert.AreEqual(nodeUniTerm.ExplicitMods.HeavyModifications[0].Modification.Terminus, ModTerminus.C);
            Assert.AreEqual(nodeUniTerm.ExplicitMods.HeavyModifications[0].Modification.UnimodId, 298);

            // Basic multi-label test
            var heavyLabelType2 = new IsotopeLabelType("Heavy2", 1);
            var typedMod        = new TypedModifications(heavyLabelType2, new List <StaticMod> {
                LABEL15_N
            });
            var peptideMods = new PeptideModifications(new List <StaticMod>(), new List <TypedModifications> {
                typedMod
            });
            var settingsMultiLabel = SrmSettingsList.GetDefault().ChangePeptideModifications(mods => peptideMods);
            var defSetSetLight     = new MappedList <string, StaticMod>();

            defSetSetLight.AddRange(StaticModList.GetDefaultsOn());
            var defSetHeavy = new MappedList <string, StaticMod>();

            defSetHeavy.AddRange(HeavyModList.GetDefaultsOn());
            defSetHeavy.Add(LABEL15_N);
            MATCHER.CreateMatches(settingsMultiLabel, new List <string> {
                STR_HEAVY_15_F
            }, defSetSetLight, defSetHeavy);
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_F).ExplicitMods.GetHeavyModifications().Contains(mod => Equals(mod.LabelType, heavyLabelType2)));
            // Peptide settings should not change.
            var docNew0 = new SrmDocument(settingsMultiLabel).AddPeptideGroups(new[] { new PeptideGroupDocNode(new PeptideGroup(),
                                                                                                               "PepGroup1", "", new[] { MATCHER.GetModifiedNode(STR_HEAVY_15_F) }) }, true, null, out firstAdded, out nextAdded);
            var settingsNew = MATCHER.GetDocModifications(docNew0);

            Assert.AreEqual(settingsMultiLabel.PeptideSettings.Modifications.ChangeHasHeavyModifications(false),
                            settingsNew.ChangeHasHeavyModifications(false));

            // Finding specific modifications.
            // If only specific AA modified, try for most specific modification.
            UpdateMatcher(null, null, null, null, new[] { STR_HEAVY_15_F });
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_F)
                          .ExplicitMods.HeavyModifications.Contains(mod =>
                                                                    mod.Modification.AminoAcids.Contains(c => c == 'F')));
            // If only some AAs modified, try for most specific modifications.
            UpdateMatcher(null, null, null, null, new[] { STR_HEAVY_15_NOT_ALL });
            Assert.IsTrue(MATCHER.GetModifiedNode(STR_HEAVY_15_NOT_ALL)
                          .ExplicitMods.HeavyModifications.Contains(mod =>
                                                                    mod.Modification.AminoAcids.Contains(c => c == 'I')));


            using (var testDir = new TestFilesDir(TestContext, ZIP_FILE))
                using (var modMatchDocContainer = InitMatchDocContainer(testDir))
                {
                    var libkeyModMatcher = new LibKeyModificationMatcher();
                    var anlLibSpec       = new BiblioSpecLiteSpec("ANL_Combo", testDir.GetTestPath("ANL_Combined.blib"));
                    var yeastLibSpec     = new BiblioSpecLiteSpec("Yeast", testDir.GetTestPath("Yeast_atlas_small.blib"));
                    modMatchDocContainer.ChangeLibSpecs(new[] { anlLibSpec, yeastLibSpec });
                    var docLibraries  = modMatchDocContainer.Document.Settings.PeptideSettings.Libraries.Libraries;
                    int anlLibIndex   = docLibraries.IndexOf(library => Equals(library.Name, anlLibSpec.Name));
                    int yeastLibIndex = docLibraries.IndexOf(library => Equals(library.Name, yeastLibSpec.Name));

                    libkeyModMatcher.CreateMatches(modMatchDocContainer.Document.Settings,
                                                   docLibraries[anlLibIndex].Keys, defSetSetLight, defSetHeavy);

                    // Test can match 15N
                    Assert.IsTrue(libkeyModMatcher.Matches.Values.Contains(match =>
                                                                           match.HeavyMod != null && match.HeavyMod.Equivalent(LABEL15_N)));

                    var uniModMetOx = UniMod.GetModification("Oxidation (M)", true);

                    // Test can match Met Ox
                    Assert.IsTrue(libkeyModMatcher.Matches.Values.Contains(match =>
                                                                           match.StructuralMod != null && match.StructuralMod.Equivalent(uniModMetOx)));

                    // Test can match 15N and Met ox!
                    Assert.IsTrue(libkeyModMatcher.Matches.Contains(match => match.Key.Mass == 17 &&
                                                                    match.Value.StructuralMod != null && match.Value.StructuralMod.Equivalent(uniModMetOx) &&
                                                                    match.Value.HeavyMod != null && match.Value.HeavyMod.Equivalent(LABEL15_N)));

                    // Test can match Cysteine (Implicit) and Met Ox (variable)
                    libkeyModMatcher.CreateMatches(modMatchDocContainer.Document.Settings,
                                                   docLibraries[yeastLibIndex].Keys, defSetSetLight, defSetHeavy);
                    Assert.IsTrue(libkeyModMatcher.MatcherPepMods.StaticModifications.Contains(mod =>
                                                                                               mod.Formula.Equals(UniMod.GetModification(StaticModList.DEFAULT_NAME, true).Formula) && !mod.IsVariable));
                    Assert.IsTrue(libkeyModMatcher.MatcherPepMods.StaticModifications.Contains(mod =>
                                                                                               mod.Formula.Equals("O") && mod.IsVariable));
                }
        }
Пример #15
0
        protected override void DoTest()
        {
            const string crosslinkerName = "Hydrolysis";

            RunUI(() => SkylineWindow.OpenFile(TestFilesDir.GetTestPath("CrosslinkNeutralLossTest.sky")));
            var peptideSettingsUi = ShowDialog <PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI);

            RunUI(() =>
            {
                peptideSettingsUi.SelectedTab = PeptideSettingsUI.TABS.Modifications;
            });
            var editModListDlg = ShowEditStaticModsDlg(peptideSettingsUi);

            // Define a crosslinker which is a water loss. In this way, two peptides can be joined end to end
            // and will have the same chemical formula as a single concatenated peptide
            RunDlg <EditStaticModDlg>(editModListDlg.AddItem, editStaticModDlg => {
                {
                    editStaticModDlg.Modification  = new StaticMod(crosslinkerName, null, null, "-H2O");
                    editStaticModDlg.IsCrosslinker = true;
                    editStaticModDlg.OkDialog();
                }
            });
            RunDlg <EditStaticModDlg>(editModListDlg.AddItem, editStaticModDlg =>
            {
                editStaticModDlg.Modification = ChangeLossesToIncludeAlways(UniMod.GetModification("Oxidation (M)", true));
                editStaticModDlg.OkDialog();
            });
            RunDlg <EditStaticModDlg>(editModListDlg.AddItem, editStaticModDlg =>
            {
                editStaticModDlg.Modification = ChangeLossesToIncludeAlways(UniMod.GetModification("Phospho (ST)", true));
                editStaticModDlg.OkDialog();
            });

            OkDialog(editModListDlg, editModListDlg.OkDialog);
            OkDialog(peptideSettingsUi, peptideSettingsUi.OkDialog);
            RunDlg <PasteDlg>(SkylineWindow.ShowPastePeptidesDlg, pasteDlg =>
            {
                // Insert two peptides which are equivalent to each other.
                // The first peptide is composed of two short peptides concatenated with the hydrolysis crosslinker.
                SetClipboardText(@"AMNFS[Phospho (ST)]GSPGAV-STSPT[Phospho (ST)]QSFM[Oxidation (M)]NTLPR-[Hydrolysis@11,1]
AMNFS[Phospho (ST)]GSPGAVSTSPT[Phospho (ST)]QSFM[Oxidation (M)]NTLPR");
                pasteDlg.PastePeptides();
                pasteDlg.OkDialog();
            });
            AssertEx.Serializable(SkylineWindow.Document);
            var crosslinkedPeptide = SkylineWindow.Document.Peptides.First();
            var flatPeptide        = SkylineWindow.Document.Peptides.Skip(1).First();

            Assert.IsNotNull(crosslinkedPeptide.ExplicitMods);
            Assert.IsNotNull(flatPeptide.ExplicitMods);
            Assert.IsTrue(crosslinkedPeptide.ExplicitMods.HasCrosslinks);
            Assert.IsFalse(flatPeptide.ExplicitMods.HasCrosslinks);
            Assert.AreEqual(1, crosslinkedPeptide.TransitionGroupCount);
            Assert.AreEqual(1, flatPeptide.TransitionGroupCount);

            var flatPrecursor        = flatPeptide.TransitionGroups.First();
            var crosslinkedPrecursor = crosslinkedPeptide.TransitionGroups.First();

            Assert.AreEqual(flatPrecursor.PrecursorMz, crosslinkedPrecursor.PrecursorMz, DELTA);
            ModificationSite crosslinkSite = new ModificationSite(10, crosslinkerName);
            var flatTransitionNames        = flatPrecursor.Transitions.Select(tran =>
                                                                              tran.ComplexFragmentIon.GetTargetsTreeLabel() +
                                                                              Transition.GetChargeIndicator(tran.Transition.Adduct))
                                             .ToList();

            Assert.AreEqual(flatPrecursor.TransitionCount, flatTransitionNames.Count);
            var crosslinkedTransitionNames = crosslinkedPrecursor.Transitions.Select(tran =>
                                                                                     tran.ComplexFragmentIon.GetTargetsTreeLabel() +
                                                                                     Transition.GetChargeIndicator(tran.Transition.Adduct))
                                             .ToList();

            Assert.AreEqual(crosslinkedPrecursor.TransitionCount, crosslinkedTransitionNames.Count);

            foreach (var transitionDocNode in flatPrecursor.Transitions)
            {
                // AMNFSGSPGAV(11)-STSPTQSFMNTLPR(14)
                ComplexFragmentIonName complexFragmentIonName = null;
                switch (transitionDocNode.Transition.IonType)
                {
                case IonType.precursor:
                    complexFragmentIonName = ComplexFragmentIonName.PRECURSOR.AddChild(crosslinkSite, ComplexFragmentIonName.PRECURSOR);
                    break;

                case IonType.b:
                    if (transitionDocNode.Transition.Ordinal == 11)
                    {
                        continue;
                    }
                    if (transitionDocNode.Transition.Ordinal <= 11)
                    {
                        complexFragmentIonName = new ComplexFragmentIonName(IonType.b, transitionDocNode.Transition.Ordinal);
                    }
                    else
                    {
                        complexFragmentIonName = ComplexFragmentIonName.PRECURSOR.AddChild(crosslinkSite,
                                                                                           new ComplexFragmentIonName(IonType.b, transitionDocNode.Transition.Ordinal - 11));
                    }

                    break;

                case IonType.y:
                    if (transitionDocNode.Transition.Ordinal == 14)
                    {
                        continue;
                    }

                    if (transitionDocNode.Transition.Ordinal < 14)
                    {
                        complexFragmentIonName = ComplexFragmentIonName.ORPHAN.AddChild(crosslinkSite,
                                                                                        new ComplexFragmentIonName(IonType.y, transitionDocNode.Transition.Ordinal));
                    }
                    else
                    {
                        complexFragmentIonName = new ComplexFragmentIonName(IonType.y, transitionDocNode.Transition.Ordinal - 14)
                                                 .AddChild(crosslinkSite, ComplexFragmentIonName.PRECURSOR);
                    }
                    break;
                }
                Assert.IsNotNull(complexFragmentIonName);

                if (transitionDocNode.Transition.IonType != IonType.precursor && transitionDocNode.Losses != null &&
                    transitionDocNode.Losses.Losses.Count > 1)
                {
                    continue;
                }

                var matchingTransitions = crosslinkedPrecursor.Transitions.Where(tran =>
                                                                                 complexFragmentIonName.Equals(tran.ComplexFragmentIon.GetName()) &&
                                                                                 Equals(transitionDocNode.Losses, tran.Losses) &&
                                                                                 Equals(transitionDocNode.Transition.Adduct, tran.Transition.Adduct)).ToList();
                AssertEx.AreEqual(1, matchingTransitions.Count);
                AssertEx.AreEqual(transitionDocNode.Mz, matchingTransitions[0].Mz, DELTA);
            }
        }