Module:JAS

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

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

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

  function SortAndPrint(prefix, T)
    local idx = {}
    local res = ""
    for k,v in pairs(T) do
      table.insert(idx, k)
    end
    table.sort(idx)
    for i=1, #idx do
      res = res .. prefix .. idx[i] .. "<br/>" .. T[idx[i]] .."\n{{#bar:}}"
    end
    return res;
  end

  local text = "";
  local exn = {}
  local inn = {}
  local etc = {}
  local total =0
  for gene in arg:gmatch("&&([-%w]+)\n") do
    total = total+1
    local n = tonumber(string.match(gene,"(%d+)"))
    if (string.match(gene,"exon")) then
      if (exn[n] == nil) then exn[n] = 1 else exn[n] = exn[n]+1 end
    elseif (string.match(gene,"intron")) then
      if (inn[n] == nil) then inn[n] = 1 else inn[n] = inn[n]+1 end
    else
      if (etc[gene] == nil) then etc[gene] = 1 else etc[gene] = etc[gene]+1 end
    end
  end
  text = text .. SortAndPrint("E", exn)
  text = text .. SortAndPrint("I", inn)
  text = text .. SortAndPrint("", etc)
  text = text .. "<b>Total</b><br/>" .. total

  return frame:preprocess(text);
end

function jas.TypeOfMutations( frame )
  local args = defArgs(getArgs(frame), 2, "", "LDLR");
  local arg = args[1];
  local arg1 = args[2];

  local text = "";
  local M=0 D=0 I=0 DI=0 O=0 U=0
  local total =0
  for type in arg:gmatch("&&" .. arg1 .. "/(%w+)/%S+\n") do
    total = total+1
    if (string.match(type,"Mut")) then M = M+1
    elseif (string.match(type,"DelIns")) then DI = DI+1
    elseif (string.match(type,"Ins")) then I = I+1
    elseif (string.match(type,"Del")) then D = D+1
    elseif (string.match(type,"Dup")) then U = U+1
    else O = O+1
    end
  end
  text = text .. "Single-nucleotide<br/>mutation<br/>" .. M .. "\n{{#bar:}}Deletion<br/>" .. D .. "\n{{#bar:}}Insertion<br/>" .. I .. "\n{{#bar:}}Del&Ins<br/>" .. DI .. "\n{{#bar:}}Duplication<br/>" .. U .. "\n{{#bar:}}Others<br/>" .. O
  text = text .. "\n{{#bar:}}<b>Total</b><br/>" .. total

  return frame:preprocess(text);
end

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

  local text = "";
  for aus, au, ja, yr, mut, eff, pos in arg:gmatch("&&((%w+)%S*:,([%w_%(%)]+),(%d+),[^&]+)&&([^&]+)&&([^&\n]+)&&([^&\n]+)") do
      text = text .. "{{#bar:}}" .. mut .. " \n{{#bar:}} " .. eff .. " \n{{#bar:}} " .. pos .. " \n{{#bar:}} [[JASReference:" .. aus .. "{{#bar:}}" .. au .." (".. yr ..") ".. ja .. "]]\n{{#bar:}}-\n"
  end

  return frame:preprocess(text);
end

return jas;