Template:Pathway/Metabolic
From Metabolomics.JP
< Template:Pathway(Difference between revisions)
Line 4: | Line 4: | ||
{{#lua: | {{#lua: | ||
local list = {}; | local list = {}; | ||
− | local | + | ---Set the first line |
+ | local line = stdin:match("([^\n]+)"); | ||
+ | for v in string.gmatch(line, "(%d%d?)") do | ||
+ | table.add(list,v); | ||
+ | end | ||
+ | ---From the second line, leave connected positions only | ||
for line in stdin:gmatch("([^\n]+)") do | for line in stdin:gmatch("([^\n]+)") do | ||
print("\n" .. line .. "\n"); | print("\n" .. line .. "\n"); | ||
if (string.sub(line,1,1) == 'R') then | if (string.sub(line,1,1) == 'R') then | ||
line = string.sub(line,2); | line = string.sub(line,2); | ||
+ | local map = {}; | ||
for k, v in string.gmatch(line, "(%d%d?) (%d%d?) %d?%d? ?;") do | for k, v in string.gmatch(line, "(%d%d?) (%d%d?) %d?%d? ?;") do | ||
− | + | map[v] = k; | |
− | + | print(v .. "-" .. k .. " "); | |
+ | end | ||
+ | for k, v in pairs(list) do | ||
+ | if (map[v] == nil) then | ||
+ | table.remove(list,k); | ||
+ | else | ||
+ | list[k] = map[v]; | ||
+ | end | ||
end | end | ||
else | else | ||
+ | local map = {}; | ||
for k, v in string.gmatch(line, "(%d%d?) (%d%d?) %d?%d? ?;") do | for k, v in string.gmatch(line, "(%d%d?) (%d%d?) %d?%d? ?;") do | ||
− | + | map[k] = v; | |
− | + | print(k .. "-" .. v .. " "); | |
+ | end | ||
+ | for k, v in pairs(list) do | ||
+ | if (map[v] == nil) then | ||
+ | table.remove(list,k); | ||
+ | else | ||
+ | list[k] = map[v]; | ||
+ | end | ||
end | end | ||
end | end |
Revision as of 06:33, 16 March 2009
./lua: /tmp/mw_ex_lua_Po9HEU:4: bad argument #1 to 'gmatch' (string expected, got nil)