Module:LBGA: Difference between revisions

(Created page with "local getArgs = require('Module:Arguments').getArgs; local defArgs = require('Module:Arguments').defaultArgs; local lbga = {}; function lbga.RegisteredSpecies( frame ) local args = defArgs(getArgs(frame), 1, ""); local arg = args[1]; isIn = {} T = {} for ref, sp, id in arg:gmatch("&?&?([%w\. ]+)&&([%w]+)[%w\., ]*&&([^\n]+)") do if (isIn[sp] == nil) then isIn[sp] = true table.insert(T, sp) end end table.sort(T) s = "" for i,v in pairs(T) do s = s...")
 
No edit summary
Line 142: Line 142:


   return frame:preprocess(r);
   return frame:preprocess(r);
end
local function createTable(T, title, Tp, Ts)
  local text = '==' .. title .. '==\n{& class="wikitable sortable"\n! ID && Polar group<br/><small>Gro: glycerol </small> && Sugar group<br/><small>Glc: glucose Gul: gulose</small>'
  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
    text = text .. s
  end
  text = text .. "\n&}"
  return text
end
function lbga.GroupTable( frame )
  local args = defArgs(getArgs(frame), 1, "");
  local arg = args[1];
  local Tp = {}
  local Ts = {}
  local S0 = {}; S1 = {}; S2= {}; S3 = {}
  local dup = {}
  local text = ""
  for id, group, seq in arg: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
  text = createTable(S0, "No Sugar", Tp, Ts)
  text = text .. createTable(S1, "One Sugar <small>including inositol</small>", Tp, Ts)
  text = text .. createTable(S2, "Two Sugars <small>including inositol</small>", Tp, Ts)
  text = text .. createTable(S3, "Three or more <small>including inositol</small>", Tp, Ts)
  return text
end
end


return lbga
return lbga

Revision as of 00:10, 30 January 2023

Documentation for this module may be created at Module:LBGA/doc

local getArgs = require('Module:Arguments').getArgs;
local defArgs = require('Module:Arguments').defaultArgs;
local lbga = {};

function lbga.RegisteredSpecies( frame )
  local args = defArgs(getArgs(frame), 1, "");
  local arg = args[1];

  isIn = {} T = {}
  for ref, sp, id in arg:gmatch("&?&?([%w\. ]+)&&([%w]+)[%w\., ]*&&([^\n]+)") do
    if (isIn[sp] == nil) then isIn[sp] = true table.insert(T, sp) end
  end
  table.sort(T)
  s = ""
  for i,v in pairs(T) do
    s = s .. "{{#volatile:ListMolByReference|" .. v .. "|" .. v .. "}} "
  end
  return frame:preprocess(s)
end

local function createBucket()
  return { {A={},C={} },{ N={},I={} },{ G={},X={} } }
end

local function printRow(name, T, reg)
  local r;
  if (string.find(name, "cenarchaea") ~= nil)
    then r = '\n&- align="right" style="background-color:#fa3"';
  elseif (string.find(name, "halobacter") ~= nil)
    then r = '\n&- align="right" style="background-color:#ddf"';
  elseif (string.find(name, "methano") == nil)
    then r = '\n&- align="right" style="background-color:#fdd"';
  else
    r = '\n&- align="right"';
  end

  if (string.find(name, "cenarchaeales") ~= nil)
    then r = r .. '\n! rowspan="1" style="background-color:#ddd" & <b>thaumarchaeota</b>'; end
  if (string.find(name, "desulfurococcales") ~= nil)
    then r = r .. '\n! rowspan="3" style="background-color:#ddd" & <b>crenarchaeota</b>'; end
  if (string.find(name, "thermococcales") ~= nil)
    then r = r .. '\n! rowspan="8" style="background-color:#ddd" & <b>euryarchaeota</b>'; end

  r = r .. "\n& {{#volatile:ListMolByReference|"..name.."|"..reg.."}} && ";
  r = r .. table.getn(T[1]["A"]).."\n&&"..table.getn(T[1]["C"]).."\n&&";
    T[1]["A"] = nil;
    T[1]["C"] = nil;
  for k,v in pairs(T[1]) do
    r = r .. k.."("..table.getn(v)..") ";
  end
  r = r .. " && ";
  r = r .. table.getn(T[2]["N"]).."\n&&"..table.getn(T[2]["I"]).."\n&&";
    T[2]["N"] = nil;
    T[2]["I"] = nil;
  for k,v in pairs(T[2]) do
    r = r .. k.."("..table.getn(v)..") ";
  end
  r = r .. " && ";
  r = r .. table.getn(T[3]["G"]).."\n&&"..table.getn(T[3]["X"]).."\n&&";
    T[3]["G"] = nil;
    T[3]["X"] = nil;
  for k,v in pairs(T[3]) do
    r = r .. k.."("..table.getn(v)..") ";
  end

  return r;
end

local function addTable(T, id)
  exist = false
  for k,v in pairs(T) do if (id == v) then exist = true end end
  if (not exist) then table.insert(T, id) end
end
  
local function register(T, id)
  local s = string.sub(id,5,5)
  if (T[1][s] == nil) then T[1][s] = {} end addTable(T[1][s], id)
  s = string.sub(id,6,6)
  if (T[2][s] == nil) then T[2][s] = {} end addTable(T[2][s], id)
  s = string.sub(id,8,8)
  if (T[3][s] == nil) then T[3][s] = {} end addTable(T[3][s], id)
end

function lbga.Species2Structure_Relationship( frame )
  local args = defArgs(getArgs(frame), 1, "");
  local arg = args[1];
  local r = "";

  cenarchaeales      = createBucket()
  desulfurococcales  = createBucket()
  sulfolobales       = createBucket()
  thermoproteales    = createBucket()
  thermococcales     = createBucket()
  thermoplasmatales  = createBucket()
  halobacteriales    = createBucket()
  methanobacteriales = createBucket()
  methanococcales    = createBucket()
  methanomicrobiales = createBucket()
  methanopyrales     = createBucket()
  methanosarcinales  = createBucket()

  for ref, sp, id in arg:gmatch("&?&?([%w\. ]+)&&([%w]+)[%w\., ]+&&([^\n]+)") do
    if (string.match(sp,"Cenarchaeum") or string.find(sp,"Nitroso") or string.match(sp,"Giganthauma"))
      then register(cenarchaeales, id)
    elseif (string.match(sp,"Aeropyrum") or string.match(sp,"Desulfurococcus") or string.match(sp,"Pyrolobus"))
      then register(desulfurococcales, id)
    elseif (string.match(sp,"Acidianus") or string.match(sp,"Sulfolobus") or string.match(sp,"Desulfurolobus"))
      then register(sulfolobales, id)
    elseif (string.match(sp,"Pyrobaculum") or string.match(sp,"Thermoproteus"))
      then register(thermoproteales, id)
    elseif (string.match(sp,"Pyrococcus") or string.match(sp,"Thermococcus"))
      then register(thermococcales, id)
    elseif (string.match(sp,"Thermoplasma"))
      then register(thermoplasmatales, id)
    elseif (string.match(sp,"Haloarcula") or string.match(sp,"Halobacterium") or string.match(sp,"Halococcus") or string.match(sp,"Haloferax") or string.match(sp,"Halorubrum") or string.match(sp,"Natrialba") or string.match(sp,"Natronobacterium") or string.match(sp,"Natronococcus") or string.match(sp,"Halarchaeum"))
      then register(halobacteriales, id)
    elseif (string.match(sp,"Methanothermobacter") or string.match(sp,"Methanobrevibacter") or string.match(sp,"Methanosphaera") or string.match(sp,"Methanothermobacter"))
      then register(methanobacteriales, id)
    elseif (string.match(sp,"Methanothermococcus") or string.match(sp,"Methanococcus") or string.match(sp,"Methanocaldococcus"))
      then register(methanococcales, id)
    elseif (string.match(sp,"Methanomicrobium") or string.match(sp,"Methanospirillum"))
      then register(methanomicrobiales, id)
    elseif (string.match(sp,"Methanopyrus"))
      then register(methanopyrales, id)
    elseif (string.match(sp,"Methanococcoides") or string.match(sp,"Methanohalophilus") or string.match(sp,"Methanolobus") or string.match(sp,"Methanosarcina"))
      then register(methanosarcinales, id)
    end
  end

  r = r .. printRow("cenarchaeales", cenarchaeales, "Cenarchaeum~Nitroso~Giganthauma")
  r = r .. printRow("desulfurococcales", desulfurococcales, "Aeropyrum~Desulfurococcus~Pyrolobus")
  r = r .. printRow("sulfolobales",sulfolobales, "Acidianus~Sulfolobus~Desulfurolobus")
  r = r .. printRow("thermoproteales",thermoproteales, "Pyrobaculum~Thermoproteus")
  r = r .. printRow("thermococcales",thermococcales, "Pyrococcus~Thermococcus")
  r = r .. printRow("thermoplasmatales",thermoplasmatales, "Thermoplasma")
  r = r .. printRow("halobacteriales",halobacteriales, "Haloarcula~Halobacterium~Halococcus~Haloferax~Halorubrum~Natrialba~Natronobacterium~Natronococcus~Halarchaeum")
  r = r .. printRow("methanobacteriales",methanobacteriales, "Methanothermobacter~Methanobrevibacter~Methanosphaera")
  r = r .. printRow("methanococcales",methanococcales, "Methanothermococcus~Methanococcus~Methanocaldococcus")
  r = r .. printRow("methanomicrobiales",methanomicrobiales, "Methanomicrobium~Methanospirillum")
  r = r .. printRow("methanopyrales",methanopyrales, "Methanopyrus")
  r = r .. printRow("methanosarcinales",methanosarcinales, "Methanococcoides~Methanohalophilus~Methanolobus~Methanosarcina")

  return frame:preprocess(r);
end

local function createTable(T, title, Tp, Ts) 
  local text = '==' .. title .. '==\n{& class="wikitable sortable"\n! ID && Polar group<br/><small>Gro: glycerol </small> && Sugar group<br/><small>Glc: glucose Gul: gulose</small>'
  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
    text = text .. s
  end
  text = text .. "\n&}"

  return text
end

function lbga.GroupTable( frame )
  local args = defArgs(getArgs(frame), 1, "");
  local arg = args[1];

  local Tp = {}
  local Ts = {}
  local S0 = {}; S1 = {}; S2= {}; S3 = {}
  local dup = {}
  local text = ""

  for id, group, seq in arg: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

  text = createTable(S0, "No Sugar", Tp, Ts)
  text = text .. createTable(S1, "One Sugar <small>including inositol</small>", Tp, Ts)
  text = text .. createTable(S2, "Two Sugars <small>including inositol</small>", Tp, Ts)
  text = text .. createTable(S3, "Three or more <small>including inositol</small>", Tp, Ts)

  return text
end

return lbga