| 1 |
// =========================================================================== |
| 2 |
// |
| 3 |
// PUBLIC DOMAIN NOTICE |
| 4 |
// National Center for Biotechnology Information (NCBI) |
| 5 |
// |
| 6 |
// This software/database is a "United States Government Work" under the |
| 7 |
// terms of the United States Copyright Act. It was written as part of |
| 8 |
// the author's official duties as a United States Government employee and |
| 9 |
// thus cannot be copyrighted. This software/database is freely available |
| 10 |
// to the public for use. The National Library of Medicine and the U.S. |
| 11 |
// Government do not place any restriction on its use or reproduction. |
| 12 |
// We would, however, appreciate having the NCBI and the author cited in |
| 13 |
// any work or product based on this material. |
| 14 |
// |
| 15 |
// Although all reasonable efforts have been taken to ensure the accuracy |
| 16 |
// and reliability of the software and data, the NLM and the U.S. |
| 17 |
// Government do not and cannot warrant the performance or results that |
| 18 |
// may be obtained by using this software or data. The NLM and the U.S. |
| 19 |
// Government disclaim all warranties, express or implied, including |
| 20 |
// warranties of performance, merchantability or fitness for any particular |
| 21 |
// purpose. |
| 22 |
// |
| 23 |
// =========================================================================== |
| 24 |
// |
| 25 |
// File Name: molwt.go |
| 26 |
// |
| 27 |
// Author: Jonathan Kans |
| 28 |
// |
| 29 |
// ========================================================================== |
| 30 |
|
| 31 |
package eutils |
| 32 |
|
| 33 |
import ( |
| 34 |
"strconv" |
| 35 |
"strings" |
| 36 |
) |
| 37 |
|
| 38 |
// numC is number of carbon atoms per amino acid |
| 39 |
var numC = map[rune]int{ |
| 40 |
'A': 3, |
| 41 |
'B': 4, |
| 42 |
'C': 3, |
| 43 |
'D': 4, |
| 44 |
'E': 5, |
| 45 |
'F': 9, |
| 46 |
'G': 2, |
| 47 |
'H': 6, |
| 48 |
'I': 6, |
| 49 |
'J': 6, |
| 50 |
'K': 6, |
| 51 |
'L': 6, |
| 52 |
'M': 5, |
| 53 |
'N': 4, |
| 54 |
'O': 12, |
| 55 |
'P': 5, |
| 56 |
'Q': 5, |
| 57 |
'R': 6, |
| 58 |
'S': 3, |
| 59 |
'T': 4, |
| 60 |
'U': 3, |
| 61 |
'V': 5, |
| 62 |
'W': 11, |
| 63 |
'X': 0, |
| 64 |
'Y': 9, |
| 65 |
'Z': 5, |
| 66 |
} |
| 67 |
|
| 68 |
// numH is number of hydrogen atoms per amino acid |
| 69 |
var numH = map[rune]int{ |
| 70 |
'A': 5, |
| 71 |
'B': 5, |
| 72 |
'C': 5, |
| 73 |
'D': 5, |
| 74 |
'E': 7, |
| 75 |
'F': 9, |
| 76 |
'G': 3, |
| 77 |
'H': 7, |
| 78 |
'I': 11, |
| 79 |
'J': 11, |
| 80 |
'K': 12, |
| 81 |
'L': 11, |
| 82 |
'M': 9, |
| 83 |
'N': 6, |
| 84 |
'O': 19, |
| 85 |
'P': 7, |
| 86 |
'Q': 8, |
| 87 |
'R': 12, |
| 88 |
'S': 5, |
| 89 |
'T': 7, |
| 90 |
'U': 5, |
| 91 |
'V': 9, |
| 92 |
'W': 10, |
| 93 |
'X': 0, |
| 94 |
'Y': 9, |
| 95 |
'Z': 7, |
| 96 |
} |
| 97 |
|
| 98 |
// numN is number of nitrogen atoms per amino acid |
| 99 |
var numN = map[rune]int{ |
| 100 |
'A': 1, |
| 101 |
'B': 1, |
| 102 |
'C': 1, |
| 103 |
'D': 1, |
| 104 |
'E': 1, |
| 105 |
'F': 1, |
| 106 |
'G': 1, |
| 107 |
'H': 3, |
| 108 |
'I': 1, |
| 109 |
'J': 1, |
| 110 |
'K': 2, |
| 111 |
'L': 1, |
| 112 |
'M': 1, |
| 113 |
'N': 2, |
| 114 |
'O': 3, |
| 115 |
'P': 1, |
| 116 |
'Q': 2, |
| 117 |
'R': 4, |
| 118 |
'S': 1, |
| 119 |
'T': 1, |
| 120 |
'U': 1, |
| 121 |
'V': 1, |
| 122 |
'W': 2, |
| 123 |
'X': 0, |
| 124 |
'Y': 1, |
| 125 |
'Z': 1, |
| 126 |
} |
| 127 |
|
| 128 |
// numO is number of oxygen atoms per amino acid |
| 129 |
var numO = map[rune]int{ |
| 130 |
'A': 1, |
| 131 |
'B': 3, |
| 132 |
'C': 1, |
| 133 |
'D': 3, |
| 134 |
'E': 3, |
| 135 |
'F': 1, |
| 136 |
'G': 1, |
| 137 |
'H': 1, |
| 138 |
'I': 1, |
| 139 |
'J': 1, |
| 140 |
'K': 1, |
| 141 |
'L': 1, |
| 142 |
'M': 1, |
| 143 |
'N': 2, |
| 144 |
'O': 2, |
| 145 |
'P': 1, |
| 146 |
'Q': 2, |
| 147 |
'R': 1, |
| 148 |
'S': 2, |
| 149 |
'T': 2, |
| 150 |
'U': 1, |
| 151 |
'V': 1, |
| 152 |
'W': 1, |
| 153 |
'X': 0, |
| 154 |
'Y': 2, |
| 155 |
'Z': 3, |
| 156 |
} |
| 157 |
|
| 158 |
// numS is number of sulfur atoms per amino acid |
| 159 |
var numS = map[rune]int{ |
| 160 |
'A': 0, |
| 161 |
'B': 0, |
| 162 |
'C': 1, |
| 163 |
'D': 0, |
| 164 |
'E': 0, |
| 165 |
'F': 0, |
| 166 |
'G': 0, |
| 167 |
'H': 0, |
| 168 |
'I': 0, |
| 169 |
'J': 0, |
| 170 |
'K': 0, |
| 171 |
'L': 0, |
| 172 |
'M': 1, |
| 173 |
'N': 0, |
| 174 |
'O': 0, |
| 175 |
'P': 0, |
| 176 |
'Q': 0, |
| 177 |
'R': 0, |
| 178 |
'S': 0, |
| 179 |
'T': 0, |
| 180 |
'U': 0, |
| 181 |
'V': 0, |
| 182 |
'W': 0, |
| 183 |
'X': 0, |
| 184 |
'Y': 0, |
| 185 |
'Z': 0, |
| 186 |
} |
| 187 |
|
| 188 |
// numSe is number of selenium atoms per amino acid |
| 189 |
var numSe = map[rune]int{ |
| 190 |
'A': 0, |
| 191 |
'B': 0, |
| 192 |
'C': 0, |
| 193 |
'D': 0, |
| 194 |
'E': 0, |
| 195 |
'F': 0, |
| 196 |
'G': 0, |
| 197 |
'H': 0, |
| 198 |
'I': 0, |
| 199 |
'J': 0, |
| 200 |
'K': 0, |
| 201 |
'L': 0, |
| 202 |
'M': 0, |
| 203 |
'N': 0, |
| 204 |
'O': 0, |
| 205 |
'P': 0, |
| 206 |
'Q': 0, |
| 207 |
'R': 0, |
| 208 |
'S': 0, |
| 209 |
'T': 0, |
| 210 |
'U': 1, |
| 211 |
'V': 0, |
| 212 |
'W': 0, |
| 213 |
'X': 0, |
| 214 |
'Y': 0, |
| 215 |
'Z': 0, |
| 216 |
} |
| 217 |
|
| 218 |
// ProteinWeight calculates the molecular weight of a peptide sequence |
| 219 |
func ProteinWeight(str string, trimLeadingMet, isFormylMet bool) string { |
| 220 |
|
| 221 |
// Start with water (H2O) |
| 222 |
c := 0 |
| 223 |
h := 2 |
| 224 |
n := 0 |
| 225 |
o := 1 |
| 226 |
s := 0 |
| 227 |
se := 0 |
| 228 |
|
| 229 |
str = strings.ToUpper(str) |
| 230 |
|
| 231 |
if trimLeadingMet { |
| 232 |
// leading methionine usually removed by post-translational modification |
| 233 |
str = strings.TrimPrefix(str, "M") |
| 234 |
} else if strings.HasPrefix(str, "M") && isFormylMet { |
| 235 |
// bacteria and organelles use formyl-methionine (fMet) for initiation |
| 236 |
c++ |
| 237 |
o++ |
| 238 |
} |
| 239 |
|
| 240 |
// add number of carbon, hydrogen, nitrogen, oxygen, sulfur, and selenium atoms per amino acid |
| 241 |
for _, ch := range str { |
| 242 |
c += numC[ch] |
| 243 |
h += numH[ch] |
| 244 |
n += numN[ch] |
| 245 |
o += numO[ch] |
| 246 |
s += numS[ch] |
| 247 |
se += numSe[ch] |
| 248 |
} |
| 249 |
|
| 250 |
// calculate molecular weight |
| 251 |
wt := 12.01115*float64(c) + |
| 252 |
1.0079*float64(h) + |
| 253 |
14.0067*float64(n) + |
| 254 |
15.9994*float64(o) + |
| 255 |
32.064*float64(s) + |
| 256 |
78.96*float64(se) |
| 257 |
|
| 258 |
str = strconv.Itoa(int(wt + 0.5)) |
| 259 |
|
| 260 |
return str |
| 261 |
} |