示例#1
0
 public TransitionLoss(StaticMod precursorMod, FragmentLoss loss, MassType massType)
     : this()
 {
     PrecursorMod = precursorMod;
     Loss = loss;
     Mass = Loss.GetMass(massType);
 }
示例#2
0
        private bool _showLoss = true; // Design mode with loss UI showing

        #endregion Fields

        #region Constructors

        public EditStaticModDlg(StaticMod modEditing, IEnumerable<StaticMod> existing, bool heavy)
        {
            _existing = existing;
            _editing = modEditing != null;
            _heavy = heavy;

            InitializeComponent();

            // Amino acid characters and termini should not be localized
            comboAA.Items.Add(string.Empty);
            foreach (char aa in AminoAcid.All)
                comboAA.Items.Add(aa.ToString(CultureInfo.InvariantCulture));
            comboTerm.Items.Add(string.Empty);
            comboTerm.Items.Add(ModTerminus.N.ToString());
            comboTerm.Items.Add(ModTerminus.C.ToString());

            //Formula Box
            var location = heavy
                ? new Point(panelAtoms.Location.X + cb13C.Location.X, panelAtoms.Location.Y + cb13C.Location.Y)
                : cbChemicalFormula.Location;
            _formulaBox = new FormulaBox(Resources.EditStaticModDlg_EditStaticModDlg_Chemical_formula_,
                Resources.EditMeasuredIonDlg_EditMeasuredIonDlg_A_verage_mass_,
                Resources.EditMeasuredIonDlg_EditMeasuredIonDlg__Monoisotopic_mass_)
            {
                Location = location
            };
            Controls.Add(_formulaBox);

            ComboNameVisible = !_editing;
            TextNameVisible = _editing;

            UpdateListAvailableMods();

            cbVariableMod.Visible = !heavy;
            _formulaBox.FormulaVisible = !heavy;
            cbChemicalFormula.Visible = heavy;
            cbChemicalFormula.Checked = !heavy || Settings.Default.ShowHeavyFormula;

            if (heavy)
            {
                labelRelativeRT.Left = labelAA.Left;
                comboRelativeRT.Left = comboAA.Left;
                comboRelativeRT.Items.Add(RelativeRT.Matching.GetLocalizedString());
                comboRelativeRT.Items.Add(RelativeRT.Overlapping.GetLocalizedString());
                comboRelativeRT.Items.Add(RelativeRT.Preceding.GetLocalizedString());
                comboRelativeRT.Items.Add(RelativeRT.Unknown.GetLocalizedString());
                comboRelativeRT.SelectedIndex = 0;
            }
            else
            {
                labelRelativeRT.Visible = false;
                comboRelativeRT.Visible = false;
            }

            ShowLoss = false;
            if (heavy)
                btnLoss.Visible = false;

            Modification = _originalModification = modEditing;
        }
示例#3
0
        public void MultiLabelExplicitSerialTest()
        {
            // Create a simple document and add two peptides
            SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault());
            const string pepSequence1 = "QFVLSCVILR";
            const string pepSequence2 = "DIEVYCDGAITTK";
            var reader = new StringReader(string.Join("\n", new[] {">peptides1", pepSequence1, pepSequence2}));
            IdentityPath path;
            document = document.ImportFasta(reader, true, IdentityPath.ROOT, out path);
            Assert.AreEqual(2, document.PeptideCount);

            // Add some modifications in two new label types
            var modCarb = new StaticMod("Carbamidomethyl Cysteine", "C", null, "C2H3ON");
            var modOther = new StaticMod("Another Cysteine", "C", null, "CO8N2");
            var staticMods = new[] {modCarb, modOther};
            var mod15N = new StaticMod("All 15N", null, null, null, LabelAtoms.N15, null, null);
            var modK13C = new StaticMod("13C K", "K", ModTerminus.C, null, LabelAtoms.C13, null, null);
            var modR13C = new StaticMod("13C R", "R", ModTerminus.C, null, LabelAtoms.C13, null, null);
            var modV13C = new StaticMod("Heavy V", "V", null, null, LabelAtoms.C13 | LabelAtoms.N15, null, null);
            var heavyMods = new[] { mod15N, modK13C, modR13C, modV13C };
            var labelTypeAA = new IsotopeLabelType("heavy AA", IsotopeLabelType.FirstHeavy);
            var labelTypeAll = new IsotopeLabelType("heavy All", IsotopeLabelType.FirstHeavy + 1);

            var settings = document.Settings;
            settings = settings.ChangePeptideModifications(mods =>
                new PeptideModifications(mods.StaticModifications,
                    new[]
                        {
                            new TypedModifications(labelTypeAA, new[] {modK13C, modR13C}),
                            new TypedModifications(labelTypeAll, new[] {mod15N})
                        }));
            document = document.ChangeSettings(settings);
            Assert.AreEqual(6, document.PeptideTransitionGroupCount);

            // Add modifications to light and heavy AA in the first peptide
            path = document.GetPathTo((int) SrmDocument.Level.Molecules, 0);
            var nodePepMod = (PeptideDocNode) document.FindNode(path);
            var explicitMod = new ExplicitMods(nodePepMod.Peptide,
                new[] {new ExplicitMod(pepSequence1.IndexOf('C'), modOther)},
                new[] {new TypedExplicitModifications(nodePepMod.Peptide, labelTypeAA, new ExplicitMod[0])});
            document = document.ChangePeptideMods(path, explicitMod, staticMods, heavyMods);
            Assert.AreEqual(5, document.PeptideTransitionGroupCount);

            // Add a modification to heavy All in the second peptide
            path = document.GetPathTo((int)SrmDocument.Level.Molecules, 1);
            nodePepMod = (PeptideDocNode)document.FindNode(path);
            explicitMod = new ExplicitMods(nodePepMod.Peptide, null,
                new[] { new TypedExplicitModifications(nodePepMod.Peptide, labelTypeAll,
                            new[] {new ExplicitMod(pepSequence2.IndexOf('V'), modV13C)}) });
            document = document.ChangePeptideMods(path, explicitMod, staticMods, heavyMods);
            Assert.AreEqual(5, document.PeptideTransitionGroupCount);

            AssertEx.Serializable(document, 3, AssertEx.DocumentCloned);
        }
示例#4
0
 public ExplicitMod(int indexAA, StaticMod modification)
 {
     IndexAA = indexAA;
     // In the document context, all static non-variable mods must have the explicit
     // flag off to behave correctly for equality checks.  Only in the
     // settings context is the explicit flag necessary to destinguish
     // between the global implicit modifications and the explicit modifications
     // which do not apply to everything.
     if (modification.IsUserSet)
         modification = modification.ChangeExplicit(false);
     Modification = modification;
 }
示例#5
0
        public void NeutralLossListTest()
        {
            TestSmallMolecules = false; // No concept of neutral loss for small molecules

            var phosphoLossMod = new StaticMod("Phospho Loss", "S, T, Y", null, false, "HPO3",
                LabelAtoms.None, RelativeRT.Matching, null, null, new[] { new FragmentLoss("H3PO4"), });

            SrmDocument document = new SrmDocument(SrmSettingsList.GetDefault().ChangePeptideModifications(mods =>
                mods.ChangeStaticModifications(new List<StaticMod>(mods.StaticModifications) { phosphoLossMod })));
            IdentityPath path = IdentityPath.ROOT;
            SrmDocument docFasta = document.ImportFasta(new StringReader(TEXT_FASTA_YEAST_7), false, path, out path);

            Assert.AreEqual(0, GetLossCount(docFasta, 1));

            // Insert losses into the first transition group
            var pathPeptide = docFasta.GetPathTo((int) SrmDocument.Level.Molecules, 0);
            var nodePep = (PeptideDocNode) docFasta.FindNode(pathPeptide);
            var nodeGroup = (TransitionGroupDocNode) nodePep.Children[0];
            var listChildren = new List<DocNode>(nodeGroup.Children);
            foreach (var nodeTran in nodeGroup.GetTransitions(docFasta.Settings,
                nodePep.ExplicitMods, nodeGroup.PrecursorMz, null, null, null, false))
            {
                if (!nodeTran.HasLoss)
                    continue;

                var tran = nodeTran.Transition;
                int matchIndex = listChildren.IndexOf(node =>
                    Equals(tran, ((TransitionDocNode)node).Transition));
                if (matchIndex == -1)
                    continue;

                while (matchIndex < listChildren.Count &&
                    Equals(tran, ((TransitionDocNode)listChildren[matchIndex]).Transition))
                {
                    matchIndex++;
                }
                listChildren.Insert(matchIndex, nodeTran);
            }

            var docLosses = (SrmDocument) docFasta.ReplaceChild(pathPeptide,
                nodeGroup.ChangeChildren(listChildren));

            int lossCount = GetLossCount(docLosses, 1);
            Assert.IsTrue(lossCount > 0);
            var docRoundTripped = AssertEx.RoundTripTransitionList(new ThermoMassListExporter(docLosses));
            Assert.AreEqual(lossCount, GetLossCount(docRoundTripped, 1));
            docRoundTripped = AssertEx.RoundTripTransitionList(new AgilentMassListExporter(docLosses));
            Assert.AreEqual(lossCount, GetLossCount(docRoundTripped, 1));
        }
 /// <summary>
 /// Checks if the given modification would impact the given peptides.
 /// </summary>
 /// <param name="mod">The modification to test</param>
 /// <param name="structural">True if this is a structural modification</param>
 /// <param name="includeUnmodVariable">True if variable modification should be counted</param>
 /// <param name="nodePeps">The list of peptides to test</param>
 /// <returns>True if the presence of this modification would change any of the peptides</returns>
 public static bool ModAppliesToDoc(StaticMod mod, bool structural, bool includeUnmodVariable,
     IEnumerable<PeptideDocNode> nodePeps)
 {
     // Enumerate all peptides where the modification matches the raw sequence.  Obviously,
     // it won't impact a peptide where the modification does not apply to the sequence.
     foreach (var nodePep in nodePeps.Where(nodePep => mod.IsMod(nodePep.Peptide.Sequence)))
     {
         // If the peptide has no explicit modifications
         if (!nodePep.HasExplicitMods)
         {
             // And the modification is not variable, or variable modifications
             // are being included, then the modification affects this peptide.
             if (!mod.IsVariable || includeUnmodVariable)
                 return true;
         }
         else
         {
             var expMods = nodePep.ExplicitMods;
             // Otherwise, if this is a structural modification
             if (structural)
             {
                 // And there are no explicit structural modifications, or
                 // the structural modifications are variable and the test modification is not
                 // variable or the variable modifications contain this modification.
                 if (expMods.StaticModifications == null
                         || (expMods.IsVariableStaticMods
                             && (!mod.IsVariable
                                 || expMods.StaticModifications.Contains(expMod => Equals(expMod.Modification, mod)))))
                 {
                     return true;
                 }
             }
             // Not structural and no explicit heavy modifications are present
             else if (!nodePep.ExplicitMods.HasHeavyModifications
                     || nodePep.ExplicitMods.GetHeavyModifications().First() != null)
             {
                 return true;
             }
         }
     }
     return false;
 }
示例#7
0
        /// <summary>
        /// Returns the number of StaticMod values in the dictionary that are equivalent to modToMatch.
        /// </summary>
        /// <param name="dict">Dictionary containing StaticMod values.</param>
        /// <param name="modToMatch">StaticMod we're comparing to values in dictionary.</param>
        /// <param name="equivMods">Dictionary we add count for StaticMods equivalent to modToMatch.</param>
        /// <param name="index">Index of modToMatch in dict.</param>
        /// <returns>Number of StaticMods equivalent to modToMatch. If there are no equivalent values, function will return 1.</returns>
        public int CountEquivalent(KeyValuePair<string, StaticMod>[] dict, StaticMod modToMatch, SortedDictionary<string, int> equivMods, int index)
        {
            int totalCount = 0;
            for (int i = 0; i < dict.Length; i++)
            {
                int count = 0;
                StaticMod mod = dict[i].Value;

                if (index != -1 && index == i)
                    Assert.IsTrue(mod.Equivalent(modToMatch));

                if (mod.Equivalent(modToMatch))
                    count++;
                if (!equivMods.ContainsKey(mod.Name))
                    equivMods.Add(mod.Name, count);
                else
                {
                    equivMods[mod.Name] += count;
                }
                totalCount += count;
            }

            return totalCount;
        }
 public bool IsModMatch(StaticMod mod)
 {
     return mod != null
         && (string.IsNullOrEmpty(mod.AAs) ||
             mod.AminoAcids.ContainsAA(AA.ToString(CultureInfo.InvariantCulture)))
         && ((mod.Terminus == null) || Equals(mod.Terminus, Terminus));
 }
 public bool IsMassMatch(StaticMod mod, double mass)
 {
     return Equals(Math.Round(GetDefaultModMass(AA, mod), RoundedTo), mass)
         && IsModMatch(mod);
 }
 private bool IsInSettings(StaticMod staticMod)
 {
     return Settings.PeptideSettings.Modifications.HasModification(staticMod);
 }
示例#11
0
        public StaticMod MatchVariableAndLossInclusion(StaticMod mod)
        {
            // Only allowed if the mods are equivalent
            Assume.IsTrue(Equivalent(mod));

            var result = this;
            if (!Equals(result.IsVariable, mod.IsVariable))
                result = result.ChangeVariable(mod.IsVariable);
            if (result.Losses != null && !ArrayUtil.EqualsDeep(result.Losses, mod.Losses))
            {
                int len = result.Losses.Count;
                var newLosses = new FragmentLoss[len];
                for (int i = 0; i < len; i++)
                {
                    newLosses[i] = result.Losses[i].ChangeInclusion(mod.Losses[i].Inclusion);
                }
                result = result.ChangeLosses(newLosses);
            }
            return result;
        }
 /// <summary>
 /// Look up the modification in the conflicting mod array.
 /// </summary>
 private bool IsVariableMod(StaticMod mod)
 {
     if (string.IsNullOrEmpty(mod.AAs))
     {
         bool? conflict = IsAAConflict(null, mod.Terminus);
         if (conflict.HasValue)
             return conflict.Value;
     }
     else
     {
         foreach (char aa in mod.AminoAcids)
         {
             bool? conflict = IsAAConflict((byte) aa, mod.Terminus);
             if (conflict.HasValue)
                 return conflict.Value;
         }
     }
     return true;
 }
 public void AddModification(StaticMod mod, IsotopeLabelType labelType)
 {
     if (MatcherPepMods.GetModificationTypes().Contains(labelType))
     {
         var newMods = MatcherPepMods.GetModifications(labelType)
             .Where(existingMod => !existingMod.Equivalent(mod)).ToList();
         newMods.Add(mod);
         MatcherPepMods = MatcherPepMods.ChangeModifications(labelType, newMods);
     }
     else if (labelType.IsLight)
     {
         MatcherPepMods =
             new PeptideModifications(new List<StaticMod> { mod }, MatcherPepMods.GetHeavyModifications().ToArray());
     }
     else
     {
         var typedHeavyMods =
             new List<TypedModifications>(MatcherPepMods.GetHeavyModifications())
                 { new TypedModifications(labelType, new List<StaticMod> { mod }) };
         MatcherPepMods = new PeptideModifications(MatcherPepMods.StaticModifications, typedHeavyMods);
     }
     MatchesUpdated = true;
 }
示例#14
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.ParseModMass(BioMassCalc.MONOISOTOPIC, formula);
                }
                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;
        }
示例#15
0
        private static void CheckPeptideImplicitMods(XmlNode peptideNode, StaticMod[] staticMods, StaticMod[] heavyMods,
            StaticMod[] heavy2Mods)
        {
            var modListStatic = peptideNode.SelectNodes(SrmDocument.EL.implicit_modifications + "/" +
                                                        SrmDocument.EL.implicit_static_modifications + "/" +
                                                        SrmDocument.EL.implicit_modification);
            CheckImplicitMods(staticMods, modListStatic);

            var modListHeavy = peptideNode.SelectNodes(SrmDocument.EL.implicit_modifications + "/" +
                                                       SrmDocument.EL.implicit_heavy_modifications +
                                                       "[not(@" + SrmDocument.ATTR.isotope_label + ")]/" +
                                                       SrmDocument.EL.implicit_modification);
            CheckImplicitMods(heavyMods, modListHeavy);

            var modListHeavy2 = peptideNode.SelectNodes(SrmDocument.EL.implicit_modifications + "/" +
                                                        SrmDocument.EL.implicit_heavy_modifications +
                                                        "[@" + SrmDocument.ATTR.isotope_label + " = 'heavy2']/" +
                                                        SrmDocument.EL.implicit_modification);
            CheckImplicitMods(heavy2Mods, modListHeavy2);
        }
示例#16
0
 private void AddMod(char aa, StaticMod mod, double[] modMasses, double[] modMassesExtra, string[] modFormulas)
 {
     modMasses[aa] = modMasses[char.ToLowerInvariant(aa)] += GetModMass(aa, mod);
     
     // Deal with formulas and unexplained masses
     double unexplainedMass;
     string formula = GetModFormula(aa, mod, out unexplainedMass);
     modFormulas[aa] = modFormulas[char.ToLowerInvariant(aa)] = CombineFormulas(modFormulas[aa], formula);
     modMassesExtra[aa] = modMassesExtra[char.ToLowerInvariant(aa)] += unexplainedMass;
 }
示例#17
0
 public string GetModFormula(char aa, StaticMod mod, out double unexplainedMass)
 {
     unexplainedMass = 0;
     if (!string.IsNullOrEmpty(mod.Formula))
         return mod.Formula;
     else if (mod.LabelAtoms != LabelAtoms.None)
         return GetHeavyFormula(aa, mod.LabelAtoms);
     if (_massCalc.MassType == MassType.Monoisotopic)
     {
         if (mod.MonoisotopicMass.HasValue)
             unexplainedMass = mod.MonoisotopicMass.Value;
     }
     else
     {
         if (mod.AverageMass.HasValue)
             unexplainedMass = mod.AverageMass.Value;
     }
     return null;
 }
示例#18
0
 public double GetModMass(char aa, StaticMod mod)
 {
     if (_massCalc.MassType == MassType.Monoisotopic)
     {
         if (mod.MonoisotopicMass.HasValue)
             return mod.MonoisotopicMass.Value;
     }
     else
     {
         if (mod.AverageMass.HasValue)
             return mod.AverageMass.Value;
     }
     if (!string.IsNullOrEmpty(mod.Formula))
         return ParseModMass(mod.Formula);
     else if (mod.LabelAtoms != LabelAtoms.None && AminoAcid.IsAA(aa))
         return ParseModMass(GetHeavyFormula(aa, mod.LabelAtoms));
     return 0;
 }
示例#19
0
 public static string GetModDiffDescription(double massDiff, StaticMod mod, SequenceModFormatType format)
 {
     switch (format)
     {
         case SequenceModFormatType.mass_diff:
             // Non-narrow format is used for library look-up and must be consistent with LibKey format
             return string.Format(CultureInfo.InvariantCulture, "[{0}{1:F01}]", (massDiff > 0 ? "+" : string.Empty), massDiff); // Not L10N
         case SequenceModFormatType.mass_diff_narrow:
             // Narrow format allows for removal of .0 when decimal is not present
             // One of the more important cases is 15N labeling which produces a lot of
             // [+1] and [+2] values.  Also assumed to be for UI, so use local format.
             return string.Format("[{0}{1}]", (massDiff > 0 ? "+" : string.Empty), Math.Round(massDiff, 1)); // Not L10N
         case SequenceModFormatType.three_letter_code:
             var shortName = mod.ShortName;
             if (string.IsNullOrEmpty(shortName))
             {
                 bool isStructural;
                 var foundMod = UniMod.GetModification(mod.Name, out isStructural);
                 if (foundMod != null)
                     shortName = foundMod.ShortName;
             }
             return shortName != null
                 ? string.Format("[{0}]", shortName) // Not L10N
                 : GetModDiffDescription(massDiff, null, SequenceModFormatType.mass_diff_narrow);
         default:
             throw new ArgumentOutOfRangeException("format"); // Not L10N
     }
 }
示例#20
0
        /// <summary>
        /// Equality minus <see cref="IsExplicit"/>, <see cref="UnimodId"/>, <see cref="IsVariable"/> and <see cref="XmlNamedElement.Equals(object)"/>.
        /// Used checking for matches between user defined modifications and UniMod modifications.
        /// </summary>
        public bool Equivalent(StaticMod obj)
        {
            if (!Equals(obj.AAs, AAs) ||
                !obj.Terminus.Equals(Terminus) ||
                !obj.AverageMass.Equals(AverageMass) ||
                !obj.MonoisotopicMass.Equals(MonoisotopicMass) ||
                !Equals(obj.RelativeRT, RelativeRT))
            {
                return false;
            }

            if (!ArrayUtil.EqualsDeep(obj._losses, _losses))
            {
                if (obj._losses != null && _losses != null)
                {
                    if (obj._losses.Count != _losses.Count)
                        return false;

                    var losses1 = _losses.OrderBy(l => l.MonoisotopicMass).ToArray();
                    var losses2 = obj._losses.OrderBy(l => l.MonoisotopicMass).ToArray();
                    if (losses1.Where((t, i) => !EquivalentFormulas(t, losses2[i])).Any())
                    {
                        return false;
                    }
                }
                else if (obj._losses == null || _losses == null)
                {
                    return false;
                }
            }

            if (AAs != null)
            {
                foreach (var aa in AminoAcids)
                {
                    if (!EquivalentFormulas(aa, obj))
                        return false;
                }
            }
            else if (Terminus != null)
            {
                return EquivalentFormulas('\0', obj); // Not L10N
            }
            else
            {
                // Label all amino acids with this label
                for (char aa = 'A'; aa <= 'Z'; aa++) // Not L10N
                {
                    if (AminoAcid.IsAA(aa) && !EquivalentFormulas(aa, obj))
                        return false;
                }
            }

            return true;
        }
示例#21
0
 public ExplicitMod ChangeModification(StaticMod prop)
 {
     if (prop.IsExplicit)
         prop = prop.ChangeExplicit(false);
     return ChangeProp(ImClone(this), (im, v) => im.Modification = v, prop);
 }
示例#22
0
        public void ChangeSettingsExplicitModTest()
        {
            SrmDocument docStudy7 = CreateStudy7Doc();
            string transitionList = ExportCsv(docStudy7);
            Assert.AreEqual(TestSmallMolecules ? 71: 69, transitionList.Split('\n').Length); // Did special test mode add a docnode to the end?

            var settings = docStudy7.Settings.ChangeTransitionFilter(filter => filter.ChangeAutoSelect(false));
            settings = settings.ChangePeptideModifications(mods => mods.ChangeHeavyModifications(ATOMIC_HEAVY_MODS));
            docStudy7 = docStudy7.ChangeSettings(settings);
            AssertEx.IsDocumentState(docStudy7, 1, 7, 11, 22, 66);

            Assert.AreEqual(3, docStudy7.Peptides.Count(peptide => peptide.HasExplicitMods));
            Assert.AreEqual(2, docStudy7.Peptides.Count(peptide => peptide.HasExplicitMods &&
                peptide.ExplicitMods.StaticModifications.Count > 0 &&
                peptide.ExplicitMods.StaticModifications[0].Modification.AAs[0] == 'C'));
            Assert.AreEqual(2, docStudy7.Peptides.Count(peptide => peptide.HasExplicitMods &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.AAs[0] == 'V' &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.Label13C));
            Assert.AreEqual(1, docStudy7.Peptides.Count(peptide => peptide.HasExplicitMods &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.AAs[0] == 'L' &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.Label13C));

            AssertEx.NoDiff(transitionList, ExportCsv(docStudy7));

            // Correct Heavy K
            var listHeavyMods = new List<StaticMod>(ATOMIC_HEAVY_MODS);
            listHeavyMods[0] = new StaticMod("Heavy K", "K", ModTerminus.C, null, LabelAtoms.C13|LabelAtoms.N15, null, null);
            settings = settings.ChangePeptideModifications(mods => mods.ChangeHeavyModifications(listHeavyMods));
            var docHeavyK = docStudy7.ChangeSettings(settings);
            var peptidesOld = docStudy7.Peptides.ToArray();
            var peptidesNew = docHeavyK.Peptides.ToArray();

            Assert.AreEqual(peptidesOld.Length, peptidesNew.Length);

            for (int i = 0; i < peptidesOld.Length; i++)
            {
                var peptideOld = peptidesOld[i];
                var peptideNew = peptidesNew[i];
                // Non-explicit cysteines should have changed, but no other peptides
                string seq = peptideOld.Peptide.Sequence;
                if (seq[seq.Length - 1] == 'K' && !peptideOld.HasExplicitMods)
                    Assert.AreNotSame(peptideOld, peptideNew);
                else
                    Assert.AreSame(peptideOld, peptideNew);
            }

            // Change valine explicit only modification
            listHeavyMods[2] = new StaticMod("13C V", "V", null, null, LabelAtoms.C13 | LabelAtoms.N15, null, null);
            listHeavyMods[2] = listHeavyMods[2].ChangeExplicit(true);
            settings = settings.ChangePeptideModifications(mods => mods.ChangeHeavyModifications(listHeavyMods));
            var docHeavyV = docHeavyK.ChangeSettings(settings);
            peptidesOld = docHeavyK.Peptides.ToArray();
            peptidesNew = docHeavyV.Peptides.ToArray();

            Assert.AreEqual(peptidesOld.Length, peptidesNew.Length);

            for (int i = 0; i < peptidesOld.Length; i++)
            {
                var peptideOld = peptidesOld[i];
                var peptideNew = peptidesNew[i];
                // Explicit valines should have changed, but no other peptides
                if (peptideOld.HasExplicitMods && peptideOld.ExplicitMods.HeavyModifications[0].Modification.AAs[0] == 'V')
                    Assert.AreNotSame(peptideOld, peptideNew);
                else
                    Assert.AreSame(peptideOld, peptideNew);
            }

            // Remove implicit cysteine modification
            var staticMods = new[] { settings.PeptideSettings.Modifications.StaticModifications[0].ChangeExplicit(true) };
            settings = settings.ChangePeptideModifications(mods => mods.ChangeStaticModifications(staticMods));
            var docNoStat = docHeavyV.ChangeSettings(settings);

            peptidesOld = docHeavyV.Peptides.ToArray();
            peptidesNew = docNoStat.Peptides.ToArray();

            Assert.AreEqual(peptidesOld.Length, peptidesNew.Length);

            for (int i = 0; i < peptidesOld.Length; i++)
            {
                var peptideOld = peptidesOld[i];
                var peptideNew = peptidesNew[i];
                // Non-explicit cysteines should have changed, but no other peptides
                if (peptideOld.Peptide.Sequence.IndexOf('C') != -1 && !peptideOld.HasExplicitMods)
                    Assert.AreNotSame(peptideOld, peptideNew);
                else
                    Assert.AreSame(peptideOld, peptideNew);
            }
        }
示例#23
0
        public void ModifyExplicitModTest()
        {
            SrmDocument docStudy7 = CreateStudy7Doc();
            var settings = docStudy7.Settings.ChangeTransitionFilter(filter => filter.ChangeAutoSelect(false));
            var listStaticMods = settings.PeptideSettings.Modifications.StaticModifications;
            var listHeavyMods = new List<StaticMod>(settings.PeptideSettings.Modifications.HeavyModifications);

            // Change an explicit heavy modification to something new
            var modV = new StaticMod("Heavy V", "V", null, LabelAtoms.C13|LabelAtoms.N15);
            listHeavyMods.Add(modV);

            IdentityPath path = docStudy7.GetPathTo((int)SrmDocument.Level.Molecules, 0);
            var peptideMod = (PeptideDocNode) docStudy7.FindNode(path);
            var explicitMods = peptideMod.ExplicitMods;
            explicitMods = explicitMods.ChangeHeavyModifications(new[] {explicitMods.HeavyModifications[0].ChangeModification(modV)});
            var docHeavyV = docStudy7.ChangePeptideMods(path, explicitMods, listStaticMods, listHeavyMods);

            var modSettings = docHeavyV.Settings.PeptideSettings.Modifications;
            Assert.AreEqual(5, modSettings.HeavyModifications.Count);
            Assert.AreEqual(4, modSettings.HeavyModifications.Count(mod => mod.Formula != null));
            Assert.AreEqual(1, modSettings.HeavyModifications.Count(mod => mod.Label13C && mod.Label15N));
            Assert.AreEqual(3, docHeavyV.Peptides.Count(peptide => peptide.HasExplicitMods));
            Assert.AreEqual(1, docHeavyV.Peptides.Count(peptide => peptide.HasExplicitMods &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.AAs[0] == 'V' &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.Label13C));
            Assert.AreEqual(1, docHeavyV.Peptides.Count(peptide => peptide.HasExplicitMods &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.AAs[0] == 'V' &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.Label13C &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.Label15N));

            // Change an explicit heavy modification to something new
            listHeavyMods = new List<StaticMod>(settings.PeptideSettings.Modifications.HeavyModifications);
            modV = listHeavyMods[2] = ATOMIC_HEAVY_MODS[2];

            explicitMods = peptideMod.ExplicitMods;
            explicitMods = explicitMods.ChangeHeavyModifications(new[] { explicitMods.HeavyModifications[0].ChangeModification(modV) });
            var doc13V = docStudy7.ChangePeptideMods(path, explicitMods, listStaticMods, listHeavyMods);

            modSettings = doc13V.Settings.PeptideSettings.Modifications;
            Assert.AreEqual(4, modSettings.HeavyModifications.Count);
            Assert.AreEqual(3, modSettings.HeavyModifications.Count(mod => mod.Formula != null));
            Assert.AreEqual(1, modSettings.HeavyModifications.Count(mod => mod.Label13C));
            Assert.AreEqual(3, doc13V.Peptides.Count(peptide => peptide.HasExplicitMods));
            Assert.AreEqual(2, doc13V.Peptides.Count(peptide => peptide.HasExplicitMods &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.AAs[0] == 'V' &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.Label13C));

            // No change to the peptide, but change an orthoganal modification
            path = docStudy7.GetPathTo((int)SrmDocument.Level.Molecules, docStudy7.Peptides.Count() - 1);
            peptideMod = (PeptideDocNode)docStudy7.FindNode(path);
            doc13V = docStudy7.ChangePeptideMods(path, peptideMod.ExplicitMods, listStaticMods, listHeavyMods);

            modSettings = doc13V.Settings.PeptideSettings.Modifications;
            Assert.AreEqual(4, modSettings.HeavyModifications.Count);
            Assert.AreEqual(3, modSettings.HeavyModifications.Count(mod => mod.Formula != null));
            Assert.AreEqual(1, modSettings.HeavyModifications.Count(mod => mod.Label13C));
            Assert.AreEqual(3, doc13V.Peptides.Count(peptide => peptide.HasExplicitMods));
            Assert.AreEqual(2, doc13V.Peptides.Count(peptide => peptide.HasExplicitMods &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.AAs[0] == 'V' &&
                peptide.ExplicitMods.HeavyModifications[0].Modification.Label13C));

            // No change to the peptide, but remove all other modifications from global lists
            var docClear = docStudy7.ChangePeptideMods(path, peptideMod.ExplicitMods,
                new StaticMod[0], new[] {listHeavyMods[3]});
            Assert.AreSame(docClear, docStudy7);

            // Remove explicit modifications from the global lists
            listHeavyMods.RemoveRange(2, 2);
            // Mimic the way PeptideSettingsUI would change the settings
            var docRemoveExplicit = docStudy7.ChangeSettings(docStudy7.Settings.ChangePeptideModifications(
                mods => mods.ChangeHeavyModifications(listHeavyMods)
                    .DeclareExplicitMods(docStudy7, listStaticMods, listHeavyMods)));
            // Test expected changes
            modSettings = docRemoveExplicit.Settings.PeptideSettings.Modifications;
            Assert.AreEqual(2, modSettings.HeavyModifications.Count);
            Assert.AreEqual(3, docRemoveExplicit.Peptides.Count(peptide => peptide.HasExplicitMods));
            // Should leave no heavy modifications on the explicitly modified peptides
            Assert.AreEqual(0, docRemoveExplicit.Peptides.Count(peptide => peptide.HasExplicitMods &&
                peptide.ExplicitMods.HeavyModifications.Count > 0));
        }
示例#24
0
 public bool Equals(StaticMod obj)
 {
     if (ReferenceEquals(null, obj)) return false;
     if (ReferenceEquals(this, obj)) return true;
     return EquivalentAll(obj) &&
         obj.IsExplicit.Equals(IsExplicit);
 }
示例#25
0
        private bool EquivalentFormulas(char aa, StaticMod obj)
        {
            SequenceMassCalc modCalc = new SequenceMassCalc(MassType.Monoisotopic);

            double unexplainedMassThis, unexplainedMassObj;

            string formulaThis = modCalc.GetModFormula(aa, this, out unexplainedMassThis);
            string formulaObj = modCalc.GetModFormula(aa, obj, out unexplainedMassObj);

            // If either is null, both must be null.
            if (formulaThis == null || formulaObj == null)
                return formulaThis == null && formulaObj == null;

            return unexplainedMassThis == unexplainedMassObj &&
                   ArrayUtil.EqualsDeep(GetFormulaModCounts(formulaThis).ToArray(),
                                        GetFormulaModCounts(formulaObj).ToArray());
        }
示例#26
0
        protected override void DoTest()
        {
            // Create modifications used in this test
            var aquaMods = new[]
            {
                new StaticMod("Heavy K", "K", ModTerminus.C, null, LabelAtoms.C13|LabelAtoms.N15, null, null),
                new StaticMod("Heavy R", "R", ModTerminus.C, null, LabelAtoms.C13|LabelAtoms.N15, null, null)
            };
            var explicitMod = new StaticMod("13C L", "L", null, null, LabelAtoms.C13, null, null);
            var variableMod = new StaticMod("Methionine Oxidized", "M", null, true, "O",
                LabelAtoms.None, RelativeRT.Matching, null, null, null);

            Settings.Default.HeavyModList.Clear();
            Settings.Default.HeavyModList.AddRange(aquaMods);
            Settings.Default.HeavyModList.Add(explicitMod);
            Settings.Default.StaticModList.Clear();
            Settings.Default.StaticModList.AddRange(StaticModList.GetDefaultsOn());
            var carbMod = Settings.Default.StaticModList[0];
            Settings.Default.StaticModList.Add(variableMod);

            // Clean-up before running the test
            var settings = SrmSettingsList.GetDefault().ChangePeptideModifications(mod =>
                mod.ChangeHeavyModifications(aquaMods));
            RunUI(() => SkylineWindow.ModifyDocument("Set test settings",
                                                     doc => doc.ChangeSettings(settings)));

            // Add FASTA sequence
            RunUI(() => SkylineWindow.Paste(TEXT_FASTA_YEAST_39));

            // Check and save original document information
            var docOrig = WaitForProteinMetadataBackgroundLoaderCompletedUI();
            var pathPeptide = docOrig.GetPathTo((int) SrmDocument.Level.Molecules, docOrig.PeptideCount - 3);
            var peptideOrig = (PeptideDocNode) docOrig.FindNode(pathPeptide);
            Assert.AreEqual(2, peptideOrig.Children.Count);
            Assert.IsNull(peptideOrig.ExplicitMods);

            // Add methionine oxidation variable modification
            SetStaticModifications(names => new List<string>(names) { variableMod.Name });
            var docVarMod = WaitForDocumentChange(docOrig);

            // Check that variable modification worked, and that the peptide of
            // interest is variably modified.
            Assert.IsTrue(docOrig.PeptideCount < docVarMod.PeptideCount);
            pathPeptide = docVarMod.GetPathTo((int)SrmDocument.Level.Molecules, docVarMod.PeptideCount - 4);
            var peptideVarMod = (PeptideDocNode)docVarMod.FindNode(pathPeptide);
            Assert.AreEqual(2, peptideVarMod.Children.Count);
            Assert.IsTrue(peptideVarMod.HasVariableMods,
                string.Format("No variable modifications found on the peptide {0}", peptideVarMod.Peptide.Sequence));
            Assert.IsFalse(peptideVarMod.ExplicitMods.IsModified(IsotopeLabelType.heavy));
            AssertPrecursorMzIsModified(peptideVarMod, 0, peptideVarMod, 1, -5, 0.2);

            // Select the peptide of interest
            RunUI(() => SkylineWindow.SequenceTree.SelectedPath = pathPeptide);

            // Make sure the explicit modifications dialog does not modify the
            // peptide when nothing is changed.
            string sequence = peptideVarMod.Peptide.Sequence;
            RunDlg<EditPepModsDlg>(SkylineWindow.ModifyPeptide, dlg =>
            {
                for (int i = 0; i < sequence.Length; i++)
                {
                    dlg.SelectModification(IsotopeLabelType.light, i, "");
                    dlg.SelectModification(IsotopeLabelType.heavy, i, "");
                }
                dlg.ResetMods();
                dlg.OkDialog();
            });
            Assert.AreSame(docVarMod, SkylineWindow.Document);

            // Explicitly change the heavy modification
            RunDlg<EditPepModsDlg>(SkylineWindow.ModifyPeptide, dlg =>
            {
                dlg.SelectModification(IsotopeLabelType.heavy, sequence.Length - 1, "");
                dlg.SelectModification(IsotopeLabelType.heavy, sequence.LastIndexOf('L'),
                                       explicitMod.Name);
                dlg.OkDialog();
            });

            // Check for correct response to modification
            var docExplicit = WaitForDocumentChange(docOrig);
            var peptideExplicit = (PeptideDocNode) docExplicit.FindNode(pathPeptide);
            Assert.AreEqual(2, peptideExplicit.Children.Count);
            // Precursor m/z for light should be same
            AssertPrecursorMzAreEqaul(peptideVarMod, 0, peptideExplicit, 0);
            // Heavy should have changed
            AssertPrecursorMzIsModified(peptideExplicit, 0, peptideExplicit, 1, -3, 0.2);
            // Heavy should now be explicitly modified
            Assert.IsTrue(peptideExplicit.ExplicitMods.IsModified(IsotopeLabelType.heavy));

            // Remove carbamidomethyl cysteine implicit modification
            SetStaticModifications(names => new[] { variableMod.Name });
            var docNoImplicit = WaitForDocumentChange(docExplicit);
            var peptideNoImplicit = (PeptideDocNode)docNoImplicit.FindNode(pathPeptide);
            // Light should have gotten 57.0 lighter
            const double modCarbMz = 57.0/2;
            AssertPrecursorMzIsModified(peptideExplicit, 0, peptideNoImplicit, 0, modCarbMz, 0.1);
            // Heavy delta should not have changed
            AssertPrecursorMzIsModified(peptideNoImplicit, 0, peptideNoImplicit, 1, -3, 0.2);

            // Reset should still return to implicit heavy mods without removing
            // variable mods.
            RunDlg<EditPepModsDlg>(SkylineWindow.ModifyPeptide, dlg =>
            {
                dlg.ResetMods();
                dlg.OkDialog();
            });
            var docReset = WaitForDocumentChange(docNoImplicit);
            var peptideReset = (PeptideDocNode)docReset.FindNode(pathPeptide);
            Assert.IsTrue(peptideReset.HasExplicitMods);
            Assert.IsFalse(peptideReset.ExplicitMods.IsModified(IsotopeLabelType.heavy));
            AssertPrecursorMzIsModified(peptideReset, 0, peptideReset, 1, -5, 0.2);

            // Explicitly add back the Carbamidomethyl Cysteine
            // Reset should still return to implicit heavy mods
            RunDlg<EditPepModsDlg>(SkylineWindow.ModifyPeptide, dlg =>
            {
                dlg.SelectModification(IsotopeLabelType.light, sequence.IndexOf('C'), carbMod.Name);
                dlg.OkDialog();
            });
            var docExCarb = WaitForDocumentChange(docReset);
            var peptideExCarb = (PeptideDocNode)docExCarb.FindNode(pathPeptide);
            Assert.IsTrue(peptideExCarb.HasExplicitMods);
            Assert.IsFalse(peptideExCarb.HasVariableMods);
            AssertPrecursorMzAreEqaul(peptideVarMod, 0, peptideExCarb, 0);
            AssertPrecursorMzAreEqaul(peptideVarMod, 1, peptideExCarb, 1);

            // Reset at this point should completely remove explicit modifications
            // including oxidized M.
            RunDlg<EditPepModsDlg>(SkylineWindow.ModifyPeptide, dlg =>
            {
                dlg.ResetMods();
                dlg.OkDialog();
            });
            var docResetImplicit = WaitForDocumentChange(docExCarb);
            var peptideResetImplicit = (PeptideDocNode) docResetImplicit.FindNode(pathPeptide);
            Assert.IsFalse(peptideResetImplicit.HasExplicitMods);
            AssertPrecursorMzIsModified(peptideOrig, 0, peptideResetImplicit, 0, modCarbMz, 0.1);
            AssertPrecursorMzIsModified(peptideOrig, 1, peptideResetImplicit, 1, modCarbMz, 0.1);

            // Turn off the variable modifications and explicitly modify using a variable mod
            RunDlg<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI, dlg =>
            {
                dlg.PickedStaticMods = new string[0];
                dlg.OkDialog();
            });

            var docNoStaticMods = WaitForDocumentChange(docResetImplicit);

            // Explicitly modify the first peptide
            var pathPeptideFirst = docNoStaticMods.GetPathTo((int) SrmDocument.Level.Molecules, 0);
            var peptideUnmod = (PeptideDocNode) docNoStaticMods.FindNode(pathPeptideFirst);
            RunUI(() => SkylineWindow.SelectedPath = pathPeptideFirst);
            RunDlg<EditPepModsDlg>(SkylineWindow.ModifyPeptide, dlg =>
            {
                var sequenceUnmod = peptideUnmod.Peptide.Sequence;
                dlg.SelectModification(IsotopeLabelType.light, sequenceUnmod.IndexOf('M'), variableMod.Name);
                dlg.OkDialog();
            });

            var docExplicitVarMod = WaitForDocumentChange(docNoStaticMods);
            var peptideExplicitVarMod = (PeptideDocNode) docExplicitVarMod.FindNode(pathPeptideFirst);
            Assert.IsTrue(peptideExplicitVarMod.HasExplicitMods);
            if (peptideExplicitVarMod.ExplicitMods.StaticModifications == null)
            {
                Assert.IsNotNull(peptideExplicitVarMod.ExplicitMods.StaticModifications);
                return; // For ReSharper
            }
            var varModPeptide = peptideExplicitVarMod.ExplicitMods.StaticModifications[0].Modification;
            Assert.AreEqual(variableMod.Name, varModPeptide.Name);
            // The modification instance on the peptide should not be marked as variable
            Assert.IsFalse(varModPeptide.IsVariable);
            var varModSettings = docExplicitVarMod.Settings.PeptideSettings.Modifications.StaticModifications[0];
            Assert.AreEqual(variableMod.Name, varModSettings.Name);
            Assert.IsTrue(varModSettings.IsExplicit);
            Assert.IsFalse(varModSettings.IsVariable);

            // Make sure this did not turn on the variable modification in the settings UI
            RunDlg<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI, dlg =>
            {
                Assert.AreEqual(0, dlg.PickedStaticMods.Length);
                dlg.OkDialog();
            });

            Directory.CreateDirectory(TestContext.TestDir);
            string saveFilePath = TestContext.GetTestPath("TestExplicitVariable.sky");
            WaitForProteinMetadataBackgroundLoaderCompletedUI(); // make sure doc is complete before save

            RunUI(() =>
                {
                    Assert.IsTrue(SkylineWindow.SaveDocument(saveFilePath));
                    SkylineWindow.NewDocument();
                    Assert.IsTrue(SkylineWindow.OpenFile(saveFilePath));
                });

            WaitForProteinMetadataBackgroundLoaderCompletedUI();
            var docRestored = SkylineWindow.Document;
            var pathPeptideFirstNew = docRestored.GetPathTo((int) SrmDocument.Level.Molecules, 0);
            var peptideExplicitVarModNew = docRestored.FindNode(pathPeptideFirstNew);
            Assert.AreEqual(peptideExplicitVarMod, peptideExplicitVarModNew,
                "Saved peptide with explicit variable modification was not restored correctly.");
            Assert.IsTrue(Settings.Default.StaticModList.Contains(variableMod),
                "Expected variable modification has been removed from the global list.");
        }
 public void RemoveModification(StaticMod mod, IsotopeLabelType labelType)
 {
     if (MatcherPepMods.GetModificationTypes().Contains(labelType))
     {
         var newMods = MatcherPepMods.GetModifications(labelType)
             .Where(existingMod => !existingMod.Equivalent(mod)).ToArray();
         MatcherPepMods = MatcherPepMods.ChangeModifications(labelType, newMods);
     }
     MatchesUpdated = true;
 }
 public static double GetDefaultModMass(char aa, StaticMod mod)
 {
     return CALC_DEFAULT.GetModMass(aa, mod);
 }
 private static string GetMatchString(AAModKey key, StaticMod staticMod, bool structural)
 {
     string formatString = structural ? "{0}[{1}{2}]" : "{0}{{{1}{2}}}"; // Not L10N
     var modMass = Math.Round(GetDefaultModMass(key.AA, staticMod), key.RoundedTo);
     return string.Format(formatString, key.AA, (modMass > 0 ? "+" : string.Empty), modMass); // Not L10N
 }
示例#30
0
 /// <summary>
 /// Equality minus the <see cref="IsExplicit"/> flag.
 /// </summary>
 public bool EquivalentAll(StaticMod obj)
 {
     return Equivalent(obj)
         && base.Equals(obj)
         && obj.IsVariable.Equals(IsVariable)
         && Equals(obj.UnimodId, UnimodId)
         && Equals(obj.ShortName, ShortName)
         && ArrayUtil.EqualsDeep(obj._losses, _losses);
 }