Template:LBGA/GroupTable: Difference between revisions

No edit summary
No edit summary
Line 4: Line 4:
  local Ts = {}
  local Ts = {}
  local S0 = {}; S1 = {}; S2= {}; S3 = {}
  local S0 = {}; S1 = {}; S2= {}; S3 = {}
local dup = {}


  function printTable(T, title)  
  function printTable(T, title)  
Line 20: Line 21:
   if (string.match(group,"Polar")) then Tp[id] = seq end
   if (string.match(group,"Polar")) then Tp[id] = seq end
   if (string.match(group,"Sugar")) then Ts[id] = seq end
   if (string.match(group,"Sugar")) then Ts[id] = seq end
   s = string.sub(id,7,7)
   d = 0
  if (s == "0") then table.insert(S0, id)
  for k,v in ipairs(dup) do
  elseif (s == "1") then table.insert(S1, id)
    if (string.match(id, v)) then
  elseif (s == "2") then table.insert(S2, id)
      d = 1
  else table.insert(S3, id) end
      break
    end
  end
  table.insert(dup, id)
  if (d == 0) then
    s = string.sub(id,7,7)
    if (s == "0") then table.insert(S0, id)
    elseif (s == "1") then table.insert(S1, id)
    elseif (s == "2") then table.insert(S2, id)
    else table.insert(S3, id) end
  end
  end
  end



Revision as of 06:00, 6 December 2013

{{#lua:

local Tp = {}
local Ts = {}
local S0 = {}; S1 = {}; S2= {}; S3 = {}
local dup = {}
function printTable(T, title) 
  print('==' .. title .. '==\n{| class="wikitable sortable"\n! ID || Polar group
Gro: glycerol || Sugar group
Glc: glucose Gul: gulose') for k,v in ipairs(T) do s = "\n|-\n| " .. v .. " || " if (Tp[v] ~= nil) then s = s .. Tp[v] end s = s .. " || " if (Ts[v] ~= nil) then s = s .. Ts[v] end print(s) end print("\n|}") end
for id, group, seq in stdin:gmatch("||([^\n]+)|([%w]+)Group=([^\n]+)") do
  if (string.match(group,"Polar")) then Tp[id] = seq end
  if (string.match(group,"Sugar")) then Ts[id] = seq end
  d = 0
  for k,v in ipairs(dup) do
    if (string.match(id, v)) then
      d = 1
      break
    end
  end
  table.insert(dup, id)
  if (d == 0) then
    s = string.sub(id,7,7)
    if (s == "0") then table.insert(S0, id)
    elseif (s == "1") then table.insert(S1, id)
    elseif (s == "2") then table.insert(S2, id)
    else table.insert(S3, id) end
  end
end
printTable(S0, "No Sugar")
printTable(S1, "One Sugar including inositol")
printTable(S2, "Two Sugars including inositol")
printTable(S3, "Three or more including inositol")

| SugarGroup=|PolarGroup= }}