Beispiel #1
0
        private static void AddModification(string modMass, char residue, Modification modType)
        {
            var aminoAcid = StandardAminoAcidSet.GetAminoAcid(residue);
            var modList   = new Tuple <AminoAcid, List <Modification> >(aminoAcid, new List <Modification> {
                modType
            });

            Modifications.Add(modMass, modList);
        }
Beispiel #2
0
        public void TestParsingManyMods(string modDefsFile)
        {
            var methodName = MethodBase.GetCurrentMethod().Name;

            var modFile = Utils.GetTestFile(methodName, modDefsFile.Replace("TEST_FOLDER", Utils.DEFAULT_TEST_FILE_FOLDER));

            if (!modFile.Exists)
            {
                Assert.Ignore("Ignoring test TestParsingManyMods since file not found: " + modFile.FullName);
            }

            var aaSet = new AminoAcidSet(modFile.FullName);
            //aaSet.Display();

            //SequenceLocation.ProteinNTerm
            var residue  = AminoAcid.ProteinNTerm.Residue;
            var location = SequenceLocation.ProteinNTerm;
            var aa       = aaSet.GetAminoAcid(residue, location);

            Console.Write("{0}\t{1}\t{2}", residue, aa.Mass, aa.Composition);
            foreach (var modIndex in aaSet.GetModificationIndices(residue, location))
            {
                var modification = aaSet.GetModificationParams().GetModification(modIndex);
                Console.WriteLine(modification.Mass);
                //Console.Write("\t" + _modificationParams.GetModification(modIndex));
            }
            Console.WriteLine();
            residue  = AminoAcid.ProteinCTerm.Residue;
            location = SequenceLocation.ProteinCTerm;
            aa       = aaSet.GetAminoAcid(residue, location);
            Console.Write("{0}\t{1}\t{2}", residue, aa.Mass, aa.Composition);
            foreach (var modIndex in aaSet.GetModificationIndices(residue, location))
            {
                var modification = aaSet.GetModificationParams().GetModification(modIndex);
                Console.WriteLine(modification.Mass);
                //Console.Write("\t" + _modificationParams.GetModification(modIndex));
            }

            //foreach (var aa in AminoAcid.StandardAminoAcidArr)
            //{

            /*
             * var keys = _locationSpecificResidueMap[location].Keys.ToArray();
             * Array.Sort(keys);
             * foreach (var residue in keys)
             * {
             *  var aa = GetAminoAcid(residue, location);
             *  Console.Write("{0}\t{1}\t{2}", residue, aa.Mass, aa.Composition);
             *  foreach (var modIndex in GetModificationIndices(residue, location))
             *  {
             *      Console.Write("\t" + _modificationParams.GetModification(modIndex));
             *  }
             *  Console.WriteLine();
             * }*/
            //}
        }
Beispiel #3
0
        static BaseIonType()
        {
            // For A, B, C, X, Y, Z ions: sum of all amino acids + offset
            A  = new BaseIonType("a", true, new Composition(-1, 0, 0, -1, 0)); // -CO
            Ar = new BaseIonType("a.", true, A.OffsetComposition + Composition.Hydrogen);
            B  = new BaseIonType("b", true, Composition.Zero);
            C  = new BaseIonType("c", true, Composition.NH3);

            //X = new BaseIonType("x", false, Composition.H2O + Composition.CO);
            X   = new BaseIonType("x", false, new CompositionWithDeltaMass(44.9977) - Composition.Hydrogen);
            Xr  = new BaseIonType("x.", false, X.OffsetComposition + Composition.Hydrogen);
            Y   = new BaseIonType("y", false, Composition.H2O);
            YM1 = new BaseIonType("y-1", false, Y.OffsetComposition - Composition.Hydrogen);

            Z  = new BaseIonType("z", false, Composition.H2O - Composition.NH2);
            Zr = new BaseIonType("z.", false, Z.OffsetComposition + Composition.Hydrogen);

            var aminoAcidSet = new AminoAcidSet();

            // D ions have additional options for isoleucine and threonine. All offsets defined as sum of previous residues + offset.
            var dIonOffsets = new Dictionary <char, double[]>
            {                                                                                                 // Defined in terms of sum of previous residue weights + offset
                { '*', new [] { 44.0500 - Composition.Hydrogen.Mass } },                                      // For all residues except for V, I and T
                { 'V', new [] { 58.0657 - Composition.Hydrogen.Mass } },
                { 'I', new [] { 58.0657 - Composition.Hydrogen.Mass, 72.0813 - Composition.Hydrogen.Mass } }, // for isoleucine
                { 'T', new [] { 58.0657 - Composition.Hydrogen.Mass, 60.0450 - Composition.Hydrogen.Mass } }  // for threonine
            };

            D = new BaseIonType("d", true, new CompositionWithDeltaMass(44.0500), aminoAcid => DefaultCompositionCalculator(dIonOffsets, aminoAcid));

            // V only has one option for all terminal residues. Sum of previous residues + offset
            V = new BaseIonType("v", false, new CompositionWithDeltaMass(74.0242), r => new List <Composition> {
                r == null ? new CompositionWithDeltaMass(74.0242) : new CompositionWithDeltaMass(74.0242) - r.Composition - Composition.Hydrogen
            });

            // W ions have additional options for isoleucine and threonine. All offsets defined as sum of previous residues + offset.
            var wIonOffsets = new Dictionary <char, double[]>
            {                                                                                                                                       // Defined in terms of sum of previous residue weights + offset
                { '*', new [] { 73.0290 - Composition.Hydrogen.Mass } },                                                                            // For all residues except for V, I and T
                { 'V', new [] { 87.0446 - Composition.Hydrogen.Mass } },
                { 'I', new [] { 87.0446 - Composition.Hydrogen.Mass, aminoAcidSet.GetAminoAcid('I').Mass - 12.0238 - Composition.Hydrogen.Mass } }, // for isoleucine
                { 'T', new [] { 87.0446 - Composition.Hydrogen.Mass, aminoAcidSet.GetAminoAcid('T').Mass - 12.0238 - Composition.Hydrogen.Mass } }  // for threonine
            };

            W = new BaseIonType("w", false, new CompositionWithDeltaMass(73.0290), aminoAcid => DefaultCompositionCalculator(wIonOffsets, aminoAcid));

            AllBaseIonTypes = new List <BaseIonType> {
                A, Ar, B, C, D, V, W, X, Xr, Y, YM1, Z, Zr
            };
        }
Beispiel #4
0
        public void TestParsingManyMods()
        {
            const string modFilePath = @"\\protoapps\UserData\Jungkap\Lewy\db\Mods.txt";
            var          aaSet       = new AminoAcidSet(modFilePath);
            //aaSet.Display();


            //SequenceLocation.ProteinNTerm
            var residue  = AminoAcid.ProteinNTerm.Residue;
            var location = SequenceLocation.ProteinNTerm;
            var aa       = aaSet.GetAminoAcid(residue, location);

            Console.Write("{0}\t{1}\t{2}", residue, aa.Mass, aa.Composition);
            foreach (var modIndex in aaSet.GetModificationIndices(residue, location))
            {
                var modification = aaSet.GetModificationParams().GetModification(modIndex);
                Console.WriteLine(modification.Mass);
                //Console.Write("\t" + _modificationParams.GetModification(modIndex));
            }
            Console.WriteLine();
            residue  = AminoAcid.ProteinCTerm.Residue;
            location = SequenceLocation.ProteinCTerm;
            aa       = aaSet.GetAminoAcid(residue, location);
            Console.Write("{0}\t{1}\t{2}", residue, aa.Mass, aa.Composition);
            foreach (var modIndex in aaSet.GetModificationIndices(residue, location))
            {
                var modification = aaSet.GetModificationParams().GetModification(modIndex);
                Console.WriteLine(modification.Mass);
                //Console.Write("\t" + _modificationParams.GetModification(modIndex));
            }


            //foreach (var aa in AminoAcid.StandardAminoAcidArr)

            /*
             * var keys = _locationSpecificResidueMap[location].Keys.ToArray();
             * Array.Sort(keys);
             * foreach (var residue in keys)
             * {
             *  var aa = GetAminoAcid(residue, location);
             *  Console.Write("{0}\t{1}\t{2}", residue, aa.Mass, aa.Composition);
             *  foreach (var modIndex in GetModificationIndices(residue, location))
             *  {
             *      Console.Write("\t" + _modificationParams.GetModification(modIndex));
             *  }
             *  Console.WriteLine();
             * }
             * }     */
        }
Beispiel #5
0
        private Sequence LoadSequence(string sequenceStr, AminoAcidSet aminoAcidSet)
        {
            var sequence = new List <AminoAcid>();

            for (int i = 0; i < sequenceStr.Length; i++)
            {
                SequenceLocation location;
                if (i == 0)
                {
                    location = SequenceLocation.ProteinNTerm;
                }
                else if (i == sequenceStr.Length - 1)
                {
                    location = SequenceLocation.ProteinCTerm;
                }
                else
                {
                    location = SequenceLocation.Everywhere;
                }

                var aa = aminoAcidSet.GetAminoAcid(sequenceStr[i], location);
                sequence.Add(aa);
            }

            return(new Sequence(sequence));
        }
Beispiel #6
0
        private int GetNominalMass(AminoAcidSet aaSet, string peptide)
        {
            var           nominalMass    = 0;
            StringBuilder buf            = null;
            var           curNominalMass = 0;

            foreach (var c in peptide)
            {
                if (char.IsUpper(c))
                {
                    curNominalMass = aaSet.GetAminoAcid(c).GetNominalMass();
                    nominalMass   += curNominalMass;
                }
                else if (c == '[')
                {
                    buf = new StringBuilder();
                }
                else if (char.IsNumber(c) && buf != null)
                {
                    buf.Append(c);
                }
                else if (c == ']' && buf != null)
                {
                    nominalMass += Convert.ToInt32(buf.ToString()) - curNominalMass;
                }
            }
            return(nominalMass);
        }
Beispiel #7
0
        public void TestITraqMod()
        {
            var aminoAcidSet = new AminoAcidSet();
            var p            = aminoAcidSet.GetAminoAcid('P');
            var a            = aminoAcidSet.GetAminoAcid('A');
            var q            = aminoAcidSet.GetAminoAcid('Q');

            var itraqMod = Modification.Itraq4Plex;

            Console.WriteLine(itraqMod.Mass);

            var modp     = new ModifiedAminoAcid(p, itraqMod);
            var sequence = new Sequence(new List <AminoAcid> {
                modp, a, q
            });

            Console.WriteLine(sequence.Mass);
        }
Beispiel #8
0
        public static Sequence GenerateSequence(String seqStr, String modStr)
        {
            if (modStr == null || modStr.Equals(""))
            {
                return(new Sequence(seqStr, aaSet));
            }

            int residueIndex = 0;

            string[] ptms             = modStr.Split(',');
            var      modificaitonInfo = new Dictionary <int, Modification>();

            foreach (var ptm in ptms)
            {
                string[] ptmPair = ptm.Split(' ');
                residueIndex = Int32.Parse(ptmPair[1]);
                if (residueIndex == 0)
                {
                    residueIndex++;
                }

                modificaitonInfo.Add(residueIndex, Modification.Get(ptmPair[0]));
            }

            var aaList = new List <AminoAcid>();

            residueIndex = 1;
            foreach (var residue in seqStr)
            {
                var aa = aaSet.GetAminoAcid(residue);
                if (modificaitonInfo.ContainsKey(residueIndex))
                {
                    aaList.Add(new ModifiedAminoAcid(aa, modificaitonInfo[residueIndex]));
                }
                else
                {
                    aaList.Add(aa);
                }

                residueIndex++;
            }
            Sequence sequence = new Sequence(aaList);

            return(sequence);
        }
Beispiel #9
0
        /// <summary>
        /// Update all modifications in the sequence.
        /// </summary>
        public void UpdateModifications()
        {
            var aminoAcidSet = new AminoAcidSet();

            for (int i = 0; i < this.Sequence.Count; i++)
            {
                var modAminoAcid = this.Sequence[i] as ModifiedAminoAcid;
                if (modAminoAcid != null)
                {
                    var modification = Modification.Get(modAminoAcid.Modification.Name);
                    if (modification != null)
                    {
                        this.Sequence[i] = new ModifiedAminoAcid(aminoAcidSet.GetAminoAcid(modAminoAcid.Residue), modification);
                    }
                }
            }

            this.Sequence = new Sequence(this.Sequence);
        }
Beispiel #10
0
        /// <summary>
        /// Parse a protein/peptide sequence in the LCMSSpectator style.
        /// </summary>
        /// <param name="sequence">The sequence as a string.</param>
        /// <returns>The parsed sequence.</returns>
        public Sequence Read(string sequence)
        {
            if (this.trimAnnotations)
            {
                var firstIndex = sequence.IndexOf('.');
                if (firstIndex >= 0)
                {
                    var index = Math.Min(firstIndex + 1, sequence.Length - 1);
                    sequence = sequence.Substring(index, sequence.Length - index - 1);
                }

                var lastIndex = sequence.LastIndexOf('.');
                if (lastIndex >= 0)
                {
                    var index = Math.Min(lastIndex, sequence.Length - 1);
                    sequence = sequence.Substring(0, index);
                }
            }

            const string AminoAcidRegex = @"[" + AminoAcid.StandardAminoAcidCharacters + "]";
            ////const string modRegex = @"\[([A-Z]|[a-z])+\]";
            const string ModRegex = @"\[([A-Z]|[a-z]|[0-9]|-|>)+\]";

            if (string.IsNullOrEmpty(sequence))
            {
                return(new Sequence(new List <AminoAcid>()));
            }

            if (!Regex.IsMatch(sequence, "(" + AminoAcidRegex + "|" + ModRegex + ")+"))
            {
                return(null);
            }

            var stdAaSet      = new AminoAcidSet();
            var aminoAcidList = new List <AminoAcid>();

            var       matches = Regex.Matches(sequence, "(" + AminoAcidRegex + "|" + ModRegex + ")");
            AminoAcid aa      = null;
            var       mods    = new List <Modification>();

            foreach (Match match in matches)
            {
                var element = match.Value;
                if (element.Length == 0)
                {
                    continue;
                }

                if (element.Length == 1 && char.IsLetter(element[0]))
                { // amino acid
                    if (aa != null)
                    {
                        aa = mods.Aggregate(aa, (current, mod) => new ModifiedAminoAcid(current, mod));
                        aminoAcidList.Add(aa);
                        mods = new List <Modification>();
                    }

                    aa = stdAaSet.GetAminoAcid(element[0]);
                    if (aa == null)
                    {
                        throw new FormatException("Unrecognized amino acid character: " + element[0]);
                    }
                    ////                    Console.WriteLine("{0} {1} {2}", aa.Residue, aa.Composition, aa.GetMass());
                }
                else
                {
                    var modName = element.Substring(1, element.Length - 2);
                    var mod     = Modification.Get(modName);
                    if (mod == null)
                    {
                        throw new FormatException("Unrecognized modification: " + modName);
                    }

                    mods.Add(mod);
                    ////                    Console.WriteLine("{0} {1} {2}", mod.Name, mod.Composition, mod.Composition.AveragineMass);
                }
            }

            if (aa != null)
            {
                aa = mods.Aggregate(aa, (current, mod) => new ModifiedAminoAcid(current, mod));
                aminoAcidList.Add(aa);
            }

            return(new Sequence(aminoAcidList));
        }
Beispiel #11
0
 static MgfSequenceReader()
 {
     StandardAminoAcidSet = new AminoAcidSet(Modification.Carbamidomethylation);
     Modifications        = new Dictionary <string, Tuple <AminoAcid, List <Modification> > >();
     Modifications.Add("99.032",
                       new Tuple <AminoAcid, List <Modification> >(StandardAminoAcidSet.GetAminoAcid('G'),
                                                                   new List <Modification> {
         Modification.Acetylation
     }));
     Modifications.Add("113.048",
                       new Tuple <AminoAcid, List <Modification> >(StandardAminoAcidSet.GetAminoAcid('A'),
                                                                   new List <Modification> {
         Modification.Acetylation
     }));
     Modifications.Add("129.043",
                       new Tuple <AminoAcid, List <Modification> >(StandardAminoAcidSet.GetAminoAcid('S'),
                                                                   new List <Modification> {
         Modification.Acetylation
     }));
     Modifications.Add("141.079",
                       new Tuple <AminoAcid, List <Modification> >(StandardAminoAcidSet.GetAminoAcid('V'),
                                                                   new List <Modification> {
         Modification.Acetylation
     }));
     Modifications.Add("143.059",
                       new Tuple <AminoAcid, List <Modification> >(StandardAminoAcidSet.GetAminoAcid('T'),
                                                                   new List <Modification> {
         Modification.Acetylation
     }));
     Modifications.Add("147.035",
                       new Tuple <AminoAcid, List <Modification> >(StandardAminoAcidSet.GetAminoAcid('M'),
                                                                   new List <Modification> {
         Modification.Oxidation
     }));
     Modifications.Add("157.038",
                       new Tuple <AminoAcid, List <Modification> >(StandardAminoAcidSet.GetAminoAcid('D'),
                                                                   new List <Modification> {
         Modification.Acetylation
     }));
     Modifications.Add("160.03",
                       new Tuple <AminoAcid, List <Modification> >(StandardAminoAcidSet.GetAminoAcid('C'),
                                                                   new List <Modification> {
         Modification.Carbamidomethylation
     }));
     Modifications.Add("171.054",
                       new Tuple <AminoAcid, List <Modification> >(StandardAminoAcidSet.GetAminoAcid('E'),
                                                                   new List <Modification> {
         Modification.Acetylation
     }));
     Modifications.Add("173.051",
                       new Tuple <AminoAcid, List <Modification> >(StandardAminoAcidSet.GetAminoAcid('M'),
                                                                   new List <Modification> {
         Modification.Acetylation
     }));
     Modifications.Add("189.046",
                       new Tuple <AminoAcid, List <Modification> >(StandardAminoAcidSet.GetAminoAcid('F'),
                                                                   new List <Modification> {
         Modification.Acetylation
     }));
     Modifications.Add("202.041",
                       new Tuple <AminoAcid, List <Modification> >(StandardAminoAcidSet.GetAminoAcid('C'),
                                                                   new List <Modification> {
         Modification.Carbamidomethylation,
         Modification.Acetylation
     }));
 }
Beispiel #12
0
        /// <summary>
        /// Build the data graph from a sequence graph.
        /// </summary>
        private void BuildGraph()
        {
            var sequenceRev = _sequence.Reverse();
            var sequence    = sequenceRev.Aggregate(string.Empty, (current, aa) => current + aa);

            sequence = "\0" + sequence;
            vertices = new DataVertex[_maxSeqIndex][];
            var mods       = AminoAcidSet.GetModificationParams();
            var id         = 0;
            var ntermIndex = 0;
            var start      = _maxSeqIndex - 2;
            var end        = 0;
            var offset     = 1;

            if (nterminal != null)
            {
                start++;
                sequence += nterminal.Residue;
            }

            if (cterminal != null)
            {
                end--;
                offset   = 0;
                sequence = sequence.Insert(1, cterminal.Residue.ToString(CultureInfo.InvariantCulture));
            }

            // create vertices
            for (var si = start; si > end; si--)
            {
                var graphSi = si - offset;
                vertices[graphSi] = new DataVertex[_graph[si].Length];
                for (var mi = 0; mi < _graph[si].Length; mi++)
                {
                    var node = _graph[si][mi];
                    var mod  = mods.GetModificationCombination(node.ModificationCombinationIndex);
                    SetSink(mi);
                    vertices[graphSi][mi] = new DataVertex
                    {
                        ID                      = id++,
                        NTermIndex              = ntermIndex,
                        ModIndex                = mi,
                        PrefixComposition       = GetComplementaryComposition(si, mi),
                        SuffixComposition       = GetComposition(si, mi),
                        ModificationCombination = mod,
                        Text                    = string.Empty
                    };
                    var vertex = vertices[graphSi][mi];
                    DataGraph.AddVertex(vertex);
                }

                ntermIndex++;
            }

            // connect vertices
            for (var si = start; si > (end + 1); si--)
            {
                var graphSi = si - offset;
                for (var mi = 0; mi < _graph[si].Length; mi++)
                {
                    var node       = _graph[si][mi];
                    var currVertex = vertices[graphSi][mi];
                    foreach (var nextModIndex in node.GetPrevNodeIndices())
                    {
                        var nextVertex     = vertices[graphSi - 1][nextModIndex];
                        var currVertexMods = currVertex.ModificationCombination.Modifications;
                        var nextVertexMods = nextVertex.ModificationCombination.Modifications;
                        var result         = new List <Modification>(currVertexMods);
                        foreach (var mod in nextVertexMods)
                        {
                            if (result.Contains(mod))
                            {
                                result.Remove(mod);
                            }
                        }

                        AminoAcid aminoAcid;
                        if (si == start && nterminal != null)
                        {
                            aminoAcid = nterminal;
                        }
                        else if (si == end + 2 && cterminal != null)
                        {
                            aminoAcid = cterminal;
                        }
                        else
                        {
                            aminoAcid = AminoAcidSet.GetAminoAcid(sequence[graphSi]);
                        }

                        var          modAa        = aminoAcid as ModifiedAminoAcid;
                        Modification aminoAcidMod = null;
                        if (modAa != null)
                        {
                            aminoAcidMod = modAa.Modification;
                        }

                        if (aminoAcidMod != null)
                        {
                            result.Add(aminoAcidMod);
                        }

                        var edgeModifications = new ModificationCombination(result);
                        var edge = new DataEdge(currVertex, nextVertex)
                        {
                            AminoAcid     = aminoAcid,
                            SequenceIndex = graphSi,
                            Modifications = edgeModifications
                        };

                        DataGraph.AddEdge(edge);
                    }
                }
            }
        }