Template:MassBank/Matrix

From Metabolomics.JP
(Difference between revisions)
Jump to: navigation, search
m
m
Line 23: Line 23:
  
 
   function toFormula(t)
 
   function toFormula(t)
     for i=1,table.getn(t) do
+
     for i,v in pairs(t) do
       if (t[i] == "")
+
       if (v == "")
 
       then t[i] = 0
 
       then t[i] = 0
       else if (t[i] == ATOMS[i])
+
       else if (v == ATOMS[i])
 
         then t[i] = 1
 
         then t[i] = 1
         else t[i]=tonumber(string.sub(t[i],1+string.len(ATOMS[i])))
+
         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 = {toFormula(string.match(str,FORMULA_PAT))}
+
     local t = toFormula({string.match(str,FORMULA_PAT)})
 
     ret = 0;
 
     ret = 0;
     for i=1, table.getn(t) do
+
     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_zo9ttD:39: attempt to perform arithmetic on field '?' (a nil value) No ion information in the form &&(formula)&&(formula)&&...&&

MassBank/Matrix

Personal tools
Namespaces

Variants
Actions