5 public readonly
string Name;
10 public ChemicalElement(
string name,
string fullName,
double monoMass,
double avgMass)
21 public readonly
string Name;
24 private readonly
double AverageMass;
25 private readonly
double MonoisotopicMass;
28 public double Mass(
bool mono)
30 return mono ? MonoisotopicMass : AverageMass;
33 public AminoAcid(
char oneLetter,
string threeLetter,
string name,
double monoisotopicMass,
double avgMass,
double immoniumMass)
35 AverageMass = avgMass;
36 MonoisotopicMass = monoisotopicMass;
43 public AminoAcid(
char oneLetter,
string threeLetter,
string name,
double monoisotopicMass,
double avgMass,
bool mono =
true)
45 AverageMass = avgMass;
46 MonoisotopicMass = monoisotopicMass;
51 ImmoniumMass = MonoisotopicMass + ChemicalUtils.Chemicals[
"H"].MonoMass -
52 ChemicalUtils.Chemicals[
"C"].MonoMass - ChemicalUtils.Chemicals[
"O"].MonoMass;
54 ImmoniumMass = AverageMass + ChemicalUtils.Chemicals[
"H"].AvgMass -
55 ChemicalUtils.Chemicals[
"C"].AvgMass - ChemicalUtils.Chemicals[
"O"].AvgMass;
61 public int N {
get;
set; }
62 public int K {
get;
set; }
70 int[] data =
new int[k];
71 for (
int i = 0; i < k; ++i)
80 string[] s = key.Split(
'_');
81 N = Int32.Parse(s[0]);
82 K = Int32.Parse(s[1]);
88 if (previous.Length == 0 || previous[0] ==
this.N -
this.K)
91 int[] next =
new int[
K];
94 for (i = 0; i < this.
K; ++i)
95 next[i] = previous[i];
97 for (i = this.K - 1; i > 0 && next[i] == this.N - this.K + i; --i) { }
101 for (
int j = i; j < this.K - 1; ++j)
102 next[j + 1] = next[j] + 1;
121 return (
N == other.
N &&
K == other.
K);
125 public static class ChemicalUtils
127 public static Dictionary<string, ChemicalElement> Chemicals =
new Dictionary<string, ChemicalElement>() {
128 {
"H",
new ChemicalElement(
"H",
"Hydrogen", 1.007825035, 1.00794)},
129 {
"C",
new ChemicalElement(
"C",
"Carbon", 12.0, 12.0107)},
130 {
"N",
new ChemicalElement(
"N",
"Nitrogen", 14.003074, 14.0067)},
131 {
"O",
new ChemicalElement(
"O",
"Oxygen", 15.99491463, 15.9994)},
132 {
"p",
new ChemicalElement(
"p",
"Proton", 1.007276466812, 1.007276466812)},
133 {
"i",
new ChemicalElement(
"i",
"C13IsotopeDiff", 1.00335, 1.00335)}
136 public static Dictionary<char, AminoAcid> AminoAcids =
new Dictionary<char, AminoAcid>() {
137 {
'A',
new AminoAcid(
'A',
"Ala",
"Alanine", 71.037114, 71.0779)},
138 {
'R',
new AminoAcid(
'R',
"Arg",
"Arginine", 156.101111, 156.1857)},
139 {
'N',
new AminoAcid(
'N',
"Asn",
"Asparagine", 114.042927, 114.1026)},
140 {
'D',
new AminoAcid(
'D',
"Asp",
"Aspartic acid", 115.026943, 115.0874)},
141 {
'C',
new AminoAcid(
'C',
"Cys",
"Cysteine", 103.009185, 103.1429)},
142 {
'E',
new AminoAcid(
'E',
"Glu",
"Glutamic acid", 129.042593, 129.114)},
143 {
'Q',
new AminoAcid(
'Q',
"Gln",
"Glutamine", 128.058578, 128.1292)},
144 {
'G',
new AminoAcid(
'G',
"Gly",
"Glycine", 57.021464, 57.0513)},
145 {
'H',
new AminoAcid(
'H',
"His",
"Histidine", 137.058912, 137.1393)},
146 {
'I',
new AminoAcid(
'I',
"Ile",
"Isoleucine", 113.084064, 113.1576)},
147 {
'L',
new AminoAcid(
'L',
"Leu",
"Leucine", 113.084064, 113.1576)},
148 {
'K',
new AminoAcid(
'K',
"Lys",
"Lysine", 128.094963, 128.1723)},
149 {
'M',
new AminoAcid(
'M',
"Met",
"Methionine", 131.040485, 131.1961)},
150 {
'F',
new AminoAcid(
'F',
"Phe",
"Phenylalanine", 147.068414, 147.1739)},
151 {
'P',
new AminoAcid(
'P',
"Pro",
"Proline", 97.052764, 97.1152)},
152 {
'S',
new AminoAcid(
'S',
"Ser",
"Serine", 87.032028, 87.0773)},
153 {
'T',
new AminoAcid(
'T',
"Thr",
"Threonine", 101.047679, 101.1039)},
154 {
'U',
new AminoAcid(
'U',
"Sec",
"Selenocysteine", 150.95363, 150.0379)},
155 {
'W',
new AminoAcid(
'W',
"Trp",
"Tryptophane", 186.079313, 186.2099)},
156 {
'Y',
new AminoAcid(
'Y',
"Tyr",
"Tyrosine", 163.06332, 163.1733)},
157 {
'V',
new AminoAcid(
'V',
"Val",
"Valine", 99.068414, 99.1311)},
158 {
'J',
new AminoAcid(
'J',
"LeI",
"Leu_Isoleu", 113.084064, 113.1576)},
159 {
'O',
new AminoAcid(
'O',
"Pyl",
"Pyrrolysin", 237.14772677, 237.300713363271)},
160 {
'$',
new AminoAcid(
'$',
"",
"N-Term", 0.0, 0.0)},
161 {
'^',
new AminoAcid(
'^',
"",
"C-Term", 0.0, 0.0)}
165 public static Dictionary<string, Permutations> Combinations =
new Dictionary<string, Permutations>();
167 public static int GetMassIndex(
double mass)
169 return (
int)(mass * 10000);
172 public static double GetMassDoubleKey(
double moverz)
174 return Math.Round(moverz, 7);
177 public static double CalculatePeptideMass(
string sequence,
bool mono)
179 double pepMass = Chemicals[
"H"].MonoMass * 2 + Chemicals[
"O"].MonoMass;
181 pepMass = Chemicals[
"H"].AvgMass * 2 + Chemicals[
"O"].AvgMass;
182 for (
int i = 0; i < sequence.Length; ++i)
184 pepMass += AminoAcids[sequence[i]].Mass(mono);
194 public static double CalculatePrecursorMassToCharge(
int charge,
double mass,
bool mono)
197 return (mass + charge * Chemicals[
"p"].MonoMass) / charge;
199 return (mass + charge * Chemicals[
"p"].AvgMass) / charge;
202 public static double CalculateUnchargedMass(
double mass,
int charge,
bool mono)
205 return ((mass * charge) - (charge) * Chemicals[
"p"].MonoMass);
207 return ((mass * charge) - (charge) * Chemicals[
"p"].AvgMass);
210 public static Permutations GetAscendingPermutations(
int n,
int k)
212 string key = n +
"_" + k;
215 if (Combinations.ContainsKey(key))
216 return Combinations[key];
219 Permutations m =
new Permutations(n, k);
222 if (!Combinations.ContainsKey(key))
224 Combinations.Add(key, m);
232 public static double CalculateMassDiffInPPM(
double expMass,
double theoMass)
234 double ppm = (Math.Abs(expMass - theoMass) / theoMass) * (1000000.0);