Template:MassBank/Matrix
From Metabolomics.JP
(Difference between revisions)
m |
m |
||
| Line 1: | Line 1: | ||
{{#replace: | {{#replace: | ||
{{#lua: | {{#lua: | ||
| + | FORMULA_PAT = "(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]?)"; | ||
function atomicNum(atom, str) | function atomicNum(atom, str) | ||
if (str == "") then return 0; end | if (str == "") then return 0; end | ||
| Line 11: | Line 12: | ||
function mass(str) | function mass(str) | ||
| − | local c,h,cl,n,o,p,s=string.match(str, | + | local c,h,cl,n,o,p,s=string.match(str,FORMULA_PAT); |
c = atomicNum("C", c) * 12; | c = atomicNum("C", c) * 12; | ||
h = atomicNum("H", h); | h = atomicNum("H", h); | ||
| Line 24: | Line 25: | ||
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,cl1,n1,o1,p1,s1=string.match(str1, | + | local c1,h1,cl1,n1,o1,p1,s1=string.match(str1,FORMULA_PAT); |
| − | local c2,h2,cl2,n2,o2,p2,s2=string.match(str2, | + | local c2,h2,cl2,n2,o2,p2,s2=string.match(str2,FORMULA_PAT); |
c1 = atomicNum("C", c1); | c1 = atomicNum("C", c1); | ||
h1 = atomicNum("H", h1); | h1 = atomicNum("H", h1); | ||
| Line 70: | Line 71: | ||
---Read Data--- | ---Read Data--- | ||
for line in stdin:gmatch("[%S ,]+") do | for line in stdin:gmatch("[%S ,]+") do | ||
| − | if (string.find(line, "^ | + | if (string.find(line, "^&&[&%a%d]+&&$") ~= nil) |
then ruler = string.gsub(line, "&&", " "); | then ruler = string.gsub(line, "&&", " "); | ||
else | else | ||
Revision as of 16:58, 13 May 2009
No ion information in the form &&(formula)&&(formula)&&...&&
| MassBank/Matrix | 64 CHClONSP |
| 64 CHClONSP |
|