Template:MassBank/PPFrequency
From Metabolomics.JP
(Difference between revisions)
m |
m |
||
| Line 3: | Line 3: | ||
{{#repeat:MassBank/IonFrequency/Row|1| | {{#repeat:MassBank/IonFrequency/Row|1| | ||
{{#lua: | {{#lua: | ||
| + | FORMULA_PAT = "(C?[1-9]?[0-9]?)(H?[1-9]?[0-9]?)(C?l?[2-9]?)(F?[2-9]?)(I?[2-9]?)(N?[1-9]?[0-9]?)(O?[1-9]?[0-9]?)(P?[2-9]?)(S?[2-9]?)"; | ||
| + | FORMULA_CHAR = "CHFINOPSl0-9"; | ||
| + | ATOM = {"C", "H", "Cl", "F", "I", "N", "O", "P", "S"}; | ||
| + | MASS = {12, 1, 35, 19, 127, 14, 16, 31, 32}; | ||
| + | |||
| + | function toFormula(t) | ||
| + | for i,v in pairs(t) do | ||
| + | if (v == "") | ||
| + | then t[i] = 0 | ||
| + | else if (v == ATOM[i]) | ||
| + | then t[i] = 1 | ||
| + | else t[i]=tonumber(string.sub(v,1+string.len(ATOM[i]))) | ||
| + | end | ||
| + | end | ||
| + | end | ||
| + | return t | ||
| + | end | ||
| + | |||
| + | function mass(str) | ||
| + | local t = toFormula({string.match(str,FORMULA_PAT)}) | ||
| + | ret = 0; | ||
| + | for i,v in pairs(t) do | ||
| + | ret = ret + t[i] * MASS[i] | ||
| + | end | ||
| + | return ret; | ||
| + | end | ||
| + | |||
F = {}; | F = {}; | ||
for id, fgmts in stdin:gmatch("&&([%a%d]+):([%S ]+)") do | for id, fgmts in stdin:gmatch("&&([%a%d]+):([%S ]+)") do | ||
| Line 18: | Line 45: | ||
for i,v in pairs(F) do | for i,v in pairs(F) do | ||
count = count + 1; | count = count + 1; | ||
| − | print("&&"..i.."&&"..table.getn(v).."&&"..table.concat(v,",")); | + | print("&&"..i.."&&"..mass(i).."&&"..table.getn(v).."&&"..table.concat(v,",")); |
end | end | ||
| | | | ||