Beispiel #1
0
 private static bool ValidateAATextBox(MessageBoxHelper helper, TextBox control, bool allowEmpty, out string aaText)
 {
     aaText = control.Text.Trim().ToUpperInvariant();
     if (aaText.Length == 0)
     {
         if (!allowEmpty)
         {
             helper.ShowTextBoxError(control, Resources.EditMeasuredIonDlg_ValidateAATextBox__0__must_contain_at_least_one_amino_acid);
             return(false);
         }
     }
     else
     {
         StringBuilder  aaBuilder = new StringBuilder();
         HashSet <char> setAA     = new HashSet <char>();
         foreach (char c in aaText)
         {
             if (!AminoAcid.IsAA(c))
             {
                 helper.ShowTextBoxError(control, Resources.EditMeasuredIonDlg_ValidateAATextBox_The_character__0__is_not_a_valid_amino_acid, c);
                 return(false);
             }
             // Silently strip duplicates.
             if (!setAA.Contains(c))
             {
                 aaBuilder.Append(c);
                 setAA.Add(c);
             }
         }
         aaText = aaBuilder.ToString();
     }
     return(true);
 }
Beispiel #2
0
        private void ValidateAACombo()
        {
            // Force proper format
            string aas = comboAA.Text.ToUpperInvariant();

            var sb      = new StringBuilder();
            var seenAas = new bool[128];

            foreach (char c in aas)
            {
                // Ignore all non-amino acid characters and repeats
                if (!AminoAcid.IsAA(c) || seenAas[c])
                {
                    continue;
                }

                if (sb.Length > 0)
                {
                    sb.Append(SEPARATOR_AA).Append(TextUtil.SEPARATOR_SPACE);
                }

                sb.Append(c);

                // Mark this amino acid seen
                seenAas[c] = true;
            }
            comboAA.Text = sb.ToString();
            UpdateMasses();
        }
Beispiel #3
0
        private const char SEPARATOR_AA = ','; // Not L10N

// ReSharper disable MemberCanBeMadeStatic.Local
        private void comboAA_KeyPress(object sender, KeyPressEventArgs e)
        {
            // Force uppercase in this control.
            e.KeyChar = char.ToUpper(e.KeyChar);
            // Only allow amino acid characters space, comma and backspace
            if (!AminoAcid.IsAA(e.KeyChar) && " ,\b".IndexOf(e.KeyChar) == -1) // Not L10N
            {
                e.Handled = true;
            }
        }
Beispiel #4
0
// ReSharper disable MemberCanBeMadeStatic.Local
        private void comboAA_KeyPress(object sender, KeyPressEventArgs e)
        {
            // Force uppercase in this control.
            e.KeyChar = char.ToUpper(e.KeyChar);
            // Only allow amino acid characters space, comma and backspace
            // ReSharper disable once LocalizableElement
            if (!AminoAcid.IsAA(e.KeyChar) && " ,\b".IndexOf(e.KeyChar) == -1)
            {
                e.Handled = true;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Used to determine if a string contains a valid amino acid
        /// sequence.
        /// </summary>
        /// <param name="seq">The string to inspect.</param>
        /// <returns>True if the string is non-zero length and contains only amino acids.</returns>
        public static bool IsSequence(string seq)
        {
            if (seq.Length == 0)
            {
                return(false);
            }

            foreach (char c in seq)
            {
                if (!AminoAcid.IsAA(c))
                {
                    return(false);
                }
            }
            return(true);
        }
Beispiel #6
0
        private void UpdateMasses()
        {
            string     formula    = null;
            LabelAtoms labelAtoms = LabelAtoms.None;

            if (cbChemicalFormula.Checked)
            {
                formula = Formula;
            }
            else
            {
                labelAtoms = LabelAtoms;
                string aaString = comboAA.Text;
                if (!string.IsNullOrEmpty(aaString) && aaString.Length == 1 &&
                    AminoAcid.IsAA(aaString[0]) && labelAtoms != LabelAtoms.None)
                {
                    formula = SequenceMassCalc.GetHeavyFormula(aaString[0], labelAtoms);
                }
            }

            if (string.IsNullOrEmpty(formula))
            {
                // If the mass edit boxes are already enabled, don't clear what a user
                // may have typed in them.
                if (!_formulaBox.MassEnabled)
                {
                    _formulaBox.MonoMass    = null;
                    _formulaBox.AverageMass = null;
                }
                _formulaBox.MassEnabled = (labelAtoms == LabelAtoms.None);
            }
            else
            {
                _formulaBox.Formula = formula;
            }
        }
Beispiel #7
0
        private static Molecule GetSequenceFormula(ModifiedSequence modifiedSequence, MassType massType, out double unexplainedMassShift)
        {
            unexplainedMassShift = 0;
            var    molecule           = new Dictionary <string, int>();
            string unmodifiedSequence = modifiedSequence.GetUnmodifiedSequence();
            var    modifications      = modifiedSequence.GetModifications().ToLookup(mod => mod.IndexAA);

            for (int i = 0; i < unmodifiedSequence.Length; i++)
            {
                char aminoAcid = unmodifiedSequence[i];
                AddAminoAcidFormula(massType, aminoAcid, molecule, ref unexplainedMassShift);
                foreach (var mod in modifications[i])
                {
                    string formula = mod.Formula;
                    if (formula == null)
                    {
                        var staticMod = mod.StaticMod;
                        var aa        = unmodifiedSequence[i];
                        if ((staticMod.LabelAtoms & LabelAtoms.LabelsAA) != LabelAtoms.None && AminoAcid.IsAA(aa))
                        {
                            formula = SequenceMassCalc.GetHeavyFormula(aa, staticMod.LabelAtoms);
                        }
                    }
                    if (formula != null)
                    {
                        var modFormula = Molecule.ParseExpression(formula);
                        Add(molecule, modFormula);
                    }
                    else
                    {
                        unexplainedMassShift += massType.IsMonoisotopic() ? mod.MonoisotopicMass : mod.AverageMass;
                    }
                }
            }
            return(Molecule.FromDict(molecule));
        }
Beispiel #8
0
        public static Modification MakeModification(string unmodifiedSequence, ExplicitMod explicitMod)
        {
            var staticMod = explicitMod.Modification;
            int i         = explicitMod.IndexAA;
            var monoMass  = staticMod.MonoisotopicMass ??
                            SrmSettings.MonoisotopicMassCalc.GetAAModMass(unmodifiedSequence[i], i,
                                                                          unmodifiedSequence.Length);
            var avgMass = staticMod.AverageMass ??
                          SrmSettings.AverageMassCalc.GetAAModMass(unmodifiedSequence[i], i,
                                                                   unmodifiedSequence.Length);

            if (monoMass == 0 && avgMass == 0)
            {
                char aa = unmodifiedSequence[i];
                if ((staticMod.LabelAtoms & LabelAtoms.LabelsAA) != LabelAtoms.None && AminoAcid.IsAA(aa))
                {
                    string heavyFormula = SequenceMassCalc.GetHeavyFormula(aa, staticMod.LabelAtoms);
                    monoMass = SequenceMassCalc.FormulaMass(BioMassCalc.MONOISOTOPIC, heavyFormula,
                                                            SequenceMassCalc.MassPrecision);
                    avgMass = SequenceMassCalc.FormulaMass(BioMassCalc.AVERAGE, heavyFormula,
                                                           SequenceMassCalc.MassPrecision);
                }
            }
            return(new Modification(explicitMod, monoMass, avgMass));
        }
Beispiel #9
0
        public const string UnimodPrefix = "unimod:"; // Not L10N

        /// <summary>
        /// Constructs a ModifiedSequence from SrmSettings and PeptideDocNode.
        /// </summary>
        public static ModifiedSequence GetModifiedSequence(SrmSettings settings, PeptideDocNode docNode, IsotopeLabelType labelType)
        {
            if (docNode.Peptide.IsCustomMolecule)
            {
                return(null);
            }
            var  unmodifiedSequence          = docNode.Peptide.Sequence;
            bool includeStaticMods           = true;
            bool includeStaticHeavyMods      = false;
            List <Modification> explicitMods = new List <Modification>();

            if (null != docNode.ExplicitMods)
            {
                var staticBaseMods    = docNode.ExplicitMods.GetStaticBaseMods(labelType);
                var labelMods         = docNode.ExplicitMods.GetModifications(labelType);
                var explicitLabelType = labelType;
                if (labelMods == null && !labelType.IsLight)
                {
                    labelMods              = docNode.ExplicitMods.GetModifications(IsotopeLabelType.light);
                    explicitLabelType      = IsotopeLabelType.light;
                    includeStaticHeavyMods = true;
                }
                if (labelMods != null || staticBaseMods != null)
                {
                    IEnumerable <ExplicitMod> modsToAdd = (labelMods ?? Enumerable.Empty <ExplicitMod>())
                                                          .Concat(staticBaseMods ?? Enumerable.Empty <ExplicitMod>());
                    var monoMasses = docNode.ExplicitMods.GetModMasses(MassType.Monoisotopic, explicitLabelType);
                    var avgMasses  = docNode.ExplicitMods.GetModMasses(MassType.Average, explicitLabelType);
                    foreach (var mod in modsToAdd)
                    {
                        explicitMods.Add(new Modification(mod, monoMasses[mod.IndexAA], avgMasses[mod.IndexAA]));
                    }
                    includeStaticMods = docNode.ExplicitMods.IsVariableStaticMods && staticBaseMods == null;
                }
            }

            if (includeStaticMods || includeStaticHeavyMods)
            {
                var peptideModifications = settings.PeptideSettings.Modifications;
                for (int i = 0; i < unmodifiedSequence.Length; i++)
                {
                    IEnumerable <StaticMod> staticMods = peptideModifications.GetModifications(labelType);
                    if (!labelType.IsLight && includeStaticMods)
                    {
                        staticMods = peptideModifications.GetModifications(IsotopeLabelType.light).Concat(staticMods);
                    }
                    foreach (var staticMod in staticMods)
                    {
                        if (staticMod.IsExplicit || staticMod.IsVariable)
                        {
                            continue;
                        }
                        if (staticMod.Terminus.HasValue)
                        {
                            if (staticMod.Terminus == ModTerminus.N && i != 0)
                            {
                                continue;
                            }
                            if (staticMod.Terminus == ModTerminus.C && i != unmodifiedSequence.Length - 1)
                            {
                                continue;
                            }
                        }
                        if (!string.IsNullOrEmpty(staticMod.AAs) && !staticMod.AAs.Contains(unmodifiedSequence[i]))
                        {
                            continue;
                        }
                        var monoMass = staticMod.MonoisotopicMass ??
                                       SrmSettings.MonoisotopicMassCalc.GetAAModMass(unmodifiedSequence[i], i,
                                                                                     unmodifiedSequence.Length);
                        var avgMass = staticMod.AverageMass ??
                                      SrmSettings.AverageMassCalc.GetAAModMass(unmodifiedSequence[i], i,
                                                                               unmodifiedSequence.Length);
                        if (monoMass == 0 && avgMass == 0)
                        {
                            char aa = unmodifiedSequence[i];
                            if ((staticMod.LabelAtoms & LabelAtoms.LabelsAA) != LabelAtoms.None && AminoAcid.IsAA(aa))
                            {
                                string heavyFormula = SequenceMassCalc.GetHeavyFormula(aa, staticMod.LabelAtoms);
                                monoMass = SequenceMassCalc.FormulaMass(BioMassCalc.MONOISOTOPIC, heavyFormula,
                                                                        SequenceMassCalc.MassPrecision);
                                avgMass = SequenceMassCalc.FormulaMass(BioMassCalc.AVERAGE, heavyFormula,
                                                                       SequenceMassCalc.MassPrecision);
                            }
                        }
                        explicitMods.Add(new Modification(new ExplicitMod(i, staticMod), monoMass, avgMass));
                    }
                }
            }
            return(new ModifiedSequence(unmodifiedSequence, explicitMods, settings.TransitionSettings.Prediction.PrecursorMassType));
        }