Template:Pathway/Metabolic

From Metabolomics.JP
Jump to: navigation, search


<!----
{{#repeat:Pathway/MetabolicTable|4|<!----
4行の出力内訳
1 ... mapping pagetitle
2 ... mapping direction
3 ... mapped position
4 ... target molecular ID
--->{{#lua:
  local list = {};
  local count = 0;
  for line in stdin:gmatch("([^\n]+)") do
    count = count+1;
    if (count % 3 ~= 2) then
      --- do nothing for AtomMaps and metabolite IDs ---
      print(line);
    else
      if (count==2) then
      --- First mapping line ---
        for k, v in string.gmatch(line, "(%d%d?) (%d%d?) %d?%d? ?;") do
          list[k] = v;
        end
      else
      --- Second and later lines ---
        local map = {};
        if (string.sub(line,1,1) == 'R') then
          line = string.sub(line,2);
          --- Create reverse mapping
          for k, v in string.gmatch(line, "(%d%d?) (%d%d?) %d?%d? ?;") do
            map[v] = k;
          end
        else
          --- Create standard mapping
          for k, v in string.gmatch(line, "(%d%d?) (%d%d?) %d?%d? ?;") do
            map[k] = v;
          end
        end
        --- Leave only positions that can be mapped
        local list2 = {};
        local str = "";
        for k, v in pairs(list) do
          if (map[k] ~= nil)
            then list2[map[k]] = map[k]; 
              str = str .. " " .. k .. "->" .. map[k];
          end
        end
        print(str);  -- output 3rd line
        list = list2;
      end
      local str = "";
      for k, v in pairs(list) do
        str = str .. k .. " ";
      end
      print(str); -- output 4th line
    end
  end
|{{#repeat:Pathway/Mapping|1|{{#cdr:{{{list}}}|&&}}|&&}}
}}
}}
|}
Personal tools
Namespaces

Variants
Actions
Navigation
metabolites
Toolbox