Module:LBGA

Revision as of 04:18, 26 January 2023 by Editor (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

return lbga