Sandbox

From Metabolomics.JP
(Difference between revisions)
Jump to: navigation, search
m
m
Line 1: Line 1:
 +
{| class ="wikitable"
 
{{#replace:
 
{{#replace:
 
{{#lua:
 
{{#lua:
 +
  function atomicNum(atom, str)
 +
    if (str == "") then return 0; end
 +
    if (str == atom) then return 1; end
 +
    return tonumber(string.sub(str,2));
 +
  end
 +
 +
  function mass(str)
 +
    local c,h,n,o=string.match(str,"(C?[1-9]?[0-9]?)(H?[1-9]?[0-9]?)(N?[1-9]?[0-9]?)(O?[1-9]?[0-9]?)");
 +
    c = atomicNum("C", c) * 12;
 +
    h = atomicNum("H", h);
 +
    n = atomicNum("N", n) * 14;
 +
    o = atomicNum("O", o) * 16;
 +
    return c + h + n + o;
 +
  end
 +
 +
  function diff(str1, str2)
 +
    ---computes str1 - str2. If negative, returns nil.---
 +
    local c1,h1,n1,o1=string.match(str1,"(C?[1-9]?[0-9]?)(H?[1-9]?[0-9]?)(N?[1-9]?[0-9]?)(O?[1-9]?[0-9]?)");
 +
    local c2,h2,n2,o2=string.match(str2,"(C?[1-9]?[0-9]?)(H?[1-9]?[0-9]?)(N?[1-9]?[0-9]?)(O?[1-9]?[0-9]?)");
 +
    c1 = atomicNum("C", c1);
 +
    h1 = atomicNum("H", h1);
 +
    n1 = atomicNum("N", n1);
 +
    o1 = atomicNum("O", o1);
 +
    c2 = atomicNum("C", c2);
 +
    h2 = atomicNum("H", h2);
 +
    n2 = atomicNum("N", n2);
 +
    o2 = atomicNum("O", o2);
 +
    if (c2 > c1) then return nil; else c1 = c1 - c2; end
 +
    if (h2 > h1) then return nil; else h1 = h1 - h2; end
 +
    if (n2 > n1) then return nil; else n1 = n1 - n2; end
 +
    if (o2 > o1) then return nil; else o1 = o1 - o2; end
 +
    local ret = "";
 +
    if (c1 > 1) then ret = ret .. "C" .. c1;
 +
      else if (c1 == 1) then ret = ret .. "C"; end end
 +
    if (h1 > 1) then ret = ret .. "H" .. h1;
 +
      else if (h1 == 1) then ret = ret .. "H"; end end
 +
    if (n1 > 1) then ret = ret .. "N" .. n1;
 +
      else if (n1 == 1) then ret = ret .. "N"; end end
 +
    if (o1 > 1) then ret = ret .. "O" .. o1;
 +
      else if (o1 == 1) then ret = ret .. "O"; end end
 +
    return ret;
 +
  end
 +
 
   local ruler = stdin:match("[%S ,]+");
 
   local ruler = stdin:match("[%S ,]+");
 
   local axis  = {};
 
   local axis  = {};
Line 9: Line 53:
 
   end
 
   end
 
   print("#-\n");
 
   print("#-\n");
   print("## sample");
+
   print("## sample \n");
 
   for i=1, table.getn(axis) do
 
   for i=1, table.getn(axis) do
     print("## " .. axis[i]);
+
     print("#style='text-align:right'# " .. mass(axis[i]) .. "<br/>" .. axis[i]);
 
   end
 
   end
 +
  local s;
 
   for i=1, table.getn(axis) do
 
   for i=1, table.getn(axis) do
 
     print("#-\n");
 
     print("#-\n");
     print("##" .. axis[i]);
+
     print("#style='text-align:right'# " .. mass(axis[i]) .. "<br/>" .. axis[i]);
 
     for j=1, table.getn(axis) do
 
     for j=1, table.getn(axis) do
      print("## ");
 
 
       if (j < i) then
 
       if (j < i) then
         print(j .. " " .. i);
+
         s = diff(axis[j],axis[i]);
 +
        if (s == nil) then print('#style="background-color:gray"# ');
 +
        else print("## " .. s);
 +
        end
 +
      else print('#style="background-color:white"# ');
 
       end
 
       end
 
     end
 
     end
Line 27: Line 75:
 
}}
 
}}
 
|#|{{#bar:}}}}
 
|#|{{#bar:}}}}
 +
|}
  
 
<!----
 
<!----

Revision as of 11:25, 12 May 2009

sample 160
C7H14NO3
143
C7H11O3
114
C5H8NO2
102
C4H8NO2
97
C7H13
88
C4H10NO
83
C6H11
79
C6H7
71
C4H7O
69
C5H9
58
C3H8N
55
C4H7
160
C7H14NO3


143
C7H11O3
H3N


114
C5H8NO2
C2H6O


102
C4H8NO2
C3H6O C


97
C7H13
HNO3


88
C4H10NO
C3H4O2


83
C6H11
CH3NO3 CO3 CH2


79
C6H7
CH7NO3 CH4O3 CH6 H4


71
C4H7O
C3H7NO2 C3H4O2 CHNO HNO H3N


69
C5H9
C2H5NO3 C2H2O3 C2H4 CH2


58
C3H8N
C4H6O3 C2O2 CO2 CH2O


55
C4H7
C3H7NO3 C3H4O3 CHNO2 HNO2 C3H6 H3NO C2H4 C2 O CH2


Personal tools
Namespaces

Variants
Actions
Navigation
metabolites
Toolbox