Template:MassBank/Matrix
From Metabolomics.JP
(Difference between revisions)
m |
m |
||
Line 10: | Line 10: | ||
function mass(str) | function mass(str) | ||
− | local c,h,n,o,s=string.match(str,"(C?[1-9]?[0-9]?)(H?[1-9]?[0-9]?)(N?[1-9]?[0-9]?)(O?[1-9]?[0-9]?)(S?[ | + | local c,h,cl,n,o,p,s=string.match(str,"(C?[1-9]?[0-9]?)(H?[1-9]?[0-9]?)(C?l?[2-9]?)(N?[1-9]?[0-9]?)(O?[1-9]?[0-9]?)(P?[2-9]?)")(S?[2-9]?)"); |
c = atomicNum("C", c) * 12; | c = atomicNum("C", c) * 12; | ||
h = atomicNum("H", h); | h = atomicNum("H", h); | ||
+ | cl= atomicNum("Cl", cl) * 35; | ||
n = atomicNum("N", n) * 14; | n = atomicNum("N", n) * 14; | ||
o = atomicNum("O", o) * 16; | o = atomicNum("O", o) * 16; | ||
+ | p = atomicNum("P", p) * 31; | ||
s = atomicNum("S", s) * 32; | s = atomicNum("S", s) * 32; | ||
− | return c + h + n + o + s; | + | return c + h + cl + n + o + p + s; |
end | end | ||
function diff(str1, str2) | function diff(str1, str2) | ||
---computes str1 - str2. If negative, returns nil.--- | ---computes str1 - str2. If negative, returns nil.--- | ||
− | local c1,h1,n1,o1,s1=string.match(str1,"(C?[1-9]?[0-9]?)(H?[1-9]?[0-9]?)(N?[1-9]?[0-9]?)(O?[1-9]?[0-9]?)(S?[ | + | local c1,h1,cl1,n1,o1,p1,s1=string.match(str1,"(C?[1-9]?[0-9]?)(H?[1-9]?[0-9]?)(C?l?[2-9]?)(N?[1-9]?[0-9]?)(O?[1-9]?[0-9]?)(P?[2-9]?)(S?[2-9]?)"); |
− | local c2,h2,n2,o2,s2=string.match(str2,"(C?[1-9]?[0-9]?)(H?[1-9]?[0-9]?)(N?[1-9]?[0-9]?)(O?[1-9]?[0-9]?)(S?[ | + | local c2,h2,cl1,n2,o2,p2,s2=string.match(str2,"(C?[1-9]?[0-9]?)(H?[1-9]?[0-9]?)(C?l?[2-9]?)(N?[1-9]?[0-9]?)(O?[1-9]?[0-9]?)(P?[2-9]?)(S?[2-9]?)"); |
c1 = atomicNum("C", c1); | c1 = atomicNum("C", c1); | ||
h1 = atomicNum("H", h1); | h1 = atomicNum("H", h1); | ||
+ | cl1= atomicNum("Cl",cl1); | ||
n1 = atomicNum("N", n1); | n1 = atomicNum("N", n1); | ||
o1 = atomicNum("O", o1); | o1 = atomicNum("O", o1); | ||
+ | p1 = atomicNum("P", p1); | ||
s1 = atomicNum("S", s1); | s1 = atomicNum("S", s1); | ||
c2 = atomicNum("C", c2); | c2 = atomicNum("C", c2); | ||
h2 = atomicNum("H", h2); | h2 = atomicNum("H", h2); | ||
+ | cl2= atomicNum("Cl",cl2); | ||
n2 = atomicNum("N", n2); | n2 = atomicNum("N", n2); | ||
o2 = atomicNum("O", o2); | o2 = atomicNum("O", o2); | ||
+ | p2 = atomicNum("P", p2); | ||
s2 = atomicNum("S", s2); | s2 = atomicNum("S", s2); | ||
if (c2 > c1) then return nil; else c1 = c1 - c2; end | if (c2 > c1) then return nil; else c1 = c1 - c2; end | ||
if (h2 > h1) then return nil; else h1 = h1 - h2; end | if (h2 > h1) then return nil; else h1 = h1 - h2; end | ||
+ | if (cl2>cl1) then return nil; else cl1 = cl1 - cl2; end | ||
if (n2 > n1) then return nil; else n1 = n1 - n2; end | if (n2 > n1) then return nil; else n1 = n1 - n2; end | ||
if (o2 > o1) then return nil; else o1 = o1 - o2; end | if (o2 > o1) then return nil; else o1 = o1 - o2; end | ||
+ | if (p2 > p1) then return nil; else p1 = p1 - p2; end | ||
if (s2 > s1) then return nil; else s1 = s1 - s2; end | if (s2 > s1) then return nil; else s1 = s1 - s2; end | ||
local ret = ""; | local ret = ""; | ||
Line 43: | Line 51: | ||
if (h1 > 1) then ret = ret .. "H" .. h1; | if (h1 > 1) then ret = ret .. "H" .. h1; | ||
else if (h1 == 1) then ret = ret .. "H"; end end | else if (h1 == 1) then ret = ret .. "H"; end end | ||
+ | if (cl1 > 1) then ret = ret .. "Cl" .. cl1; | ||
+ | else if (cl1 == 1) then ret = ret .. "Cl"; end end | ||
if (n1 > 1) then ret = ret .. "N" .. n1; | if (n1 > 1) then ret = ret .. "N" .. n1; | ||
else if (n1 == 1) then ret = ret .. "N"; end end | else if (n1 == 1) then ret = ret .. "N"; end end | ||
if (o1 > 1) then ret = ret .. "O" .. o1; | if (o1 > 1) then ret = ret .. "O" .. o1; | ||
else if (o1 == 1) then ret = ret .. "O"; end end | else if (o1 == 1) then ret = ret .. "O"; end end | ||
+ | if (p1 > 1) then ret = ret .. "P" .. p1; | ||
+ | else if (p1 == 1) then ret = ret .. "P"; end end | ||
if (s1 > 1) then ret = ret .. "S" .. s1; | if (s1 > 1) then ret = ret .. "S" .. s1; | ||
else if (s1 == 1) then ret = ret .. "S"; end end | else if (s1 == 1) then ret = ret .. "S"; end end | ||
Line 58: | Line 70: | ||
if (string.find(line, ":") == nil) then ruler = line; | if (string.find(line, ":") == nil) then ruler = line; | ||
else ---register fragments--- | else ---register fragments--- | ||
− | head, tail = string.match(line, "([ | + | head, tail = string.match(line, "([CHNOPSl0-9]+) *: *([CHNOPSl0-9 ]+)"); |
y = {}; | y = {}; | ||
− | for x in string.gmatch(tail,"[ | + | for x in string.gmatch(tail,"[CHNOPSl0-9]+") do |
y[x] = x; | y[x] = x; | ||
end | end |
Revision as of 14:48, 12 May 2009