Template:MassBank/Matrix
From Metabolomics.JP
(Difference between revisions)
m |
m |
||
Line 23: | Line 23: | ||
function toFormula(t) | function toFormula(t) | ||
− | for i | + | for i,v in pairs(t) do |
− | if ( | + | if (v == "") |
then t[i] = 0 | then t[i] = 0 | ||
− | else if ( | + | else if (v == ATOMS[i]) |
then t[i] = 1 | then t[i] = 1 | ||
− | else t[i]=tonumber(string.sub( | + | else t[i]=tonumber(string.sub(v,1+string.len(ATOMS[i]))) |
end | end | ||
end | end | ||
Line 36: | Line 36: | ||
function toMass(str) | function toMass(str) | ||
− | local t = | + | local t = toFormula({string.match(str,FORMULA_PAT)}) |
ret = 0; | ret = 0; | ||
− | for i | + | for i,v in pairs(t) do |
− | ret = ret + t[i] * MASS[i] | + | ret = ret + t[i] * MASS[i] |
end | end | ||
return ret; | return ret; | ||
Line 55: | Line 55: | ||
function mass(str) | function mass(str) | ||
+ | return toMass(str) | ||
+ | --[[ | ||
local c,h,cl,n,o,p,s=string.match(str,FORMULA_PAT); | local c,h,cl,n,o,p,s=string.match(str,FORMULA_PAT); | ||
c = atomicNum("C", c) * 12; | c = atomicNum("C", c) * 12; | ||
Line 64: | Line 66: | ||
s = atomicNum("S", s) * 32; | s = atomicNum("S", s) * 32; | ||
return c + h + cl + n + o + p + s; | return c + h + cl + n + o + p + s; | ||
+ | ]]-- | ||
end | end | ||
Revision as of 23:22, 13 May 2009
./lua: /tmp/mw_ex_lua_rHNOrj:39: attempt to perform arithmetic on field '?' (a nil value) No ion information in the form &&(formula)&&(formula)&&...&&
MassBank/Matrix
|