Template:LBS/FormatSugar: Difference between revisions

mNo edit summary
No edit summary
Line 2: Line 2:
   local seq = stdin:match("[%S()%[%]]+");
   local seq = stdin:match("[%S()%[%]]+");
   local ret = "";
   local ret = "";
   for o,p,q,r,s,t in string.gmatch(seq, "([%[%(]?)([/%a%$]+)([?ab%-]?)([1-9]?)%-?([1-9]?/?[1-9]?)([%]%)]?)") do
   seq = string.gsub(seq, "a([1-9?]%-[1-9/?]*)", "<sub>&alpha;%1</sub>");
    ---Process ( ---
  seq = string.gsub(seq, "b([1-9?]%-[1-9/?]*)", "<sub>&beta;%1</sub>");
    if (o) then ret = ret .. o end
  seq = string.gsub(seq, "?([1-9?]%-[1-9/?]*)", "<sub>?%1</sub>");
    ---Process sugar name---
  seq = string.gsub(seq, "Cer$", "<b>Cer</b>");
    if (string.match(p, "^%$?Glc")) then
  seq = string.gsub(seq, "(Gal[NAcH234Me]*)", '<span style="color:Gold"><b>%1</b></span>');
      ret = ret .. '<span style="color:Blue"><b>' .. p .. "</b></span>"
  seq = string.gsub(seq, "(Glc[NAcH2]*)", '<span style="color:Blue"><b>%1</b></span>');
    elseif (string.match(p, "^%$?Gal")) then
  seq = string.gsub(seq, "(Man[A]*)", '<span style="color:Green"><b>%1</b></span>');
      ret = ret .. '<span style="color:GoldenRod"><b>' .. p .. "</b></span>"
  seq = string.gsub(seq, "(Rha)", '<span style="color:Green"><b>%1</b></span>');
    elseif (string.match(p, "^%$?Man")) then
  seq = string.gsub(seq, "(Fuc[A]*)", '<span style="color:Red"><b>%1</b></span>');
      ret = ret .. '<span style="color:Green"><b>' .. p .. "</b></span>"
  seq = string.gsub(seq, "(NeuAc[Me489]*)", '<span style="color:Purple"><b>%1</b></span>');
    elseif (string.match(p, "^%$?Fuc")) then
  seq = string.gsub(seq, "(NeuGc[Me489]*)", '<span style="color:Gray"><b>%1</b></span>');
      ret = ret .. '<span style="color:Red"><b>' .. p .. "</b></span>"
  seq = string.gsub(seq, "(Xyl)", '<span style="color:DarkOrange"><b>%1</b></span>');
    elseif (string.match(p, "^%$?Neu")) then
   seq = string.gsub(seq, "(Ara)", '<span style="color:DarkOrange"><b>%1</b></span>');
      ret = ret .. '<span style="color:MediumVioletRed"><b>' .. p .. "</b></span>"
   print(seq);
    else
|{{{1|GlcNAcb1-3Xyla1-4Galb1-3GalNAca1-4(NeuAc?1-2NeuGc4Mea1-3)GalNAcb1-4(EtnP-6)GlcNAcb1-3Manb1-4Glcb1-1Cer}}}}}
      ret = ret .. '<b>' .. p .. '</b>'
    end
    ---Process alpha or beta---
    if (q == "a") then ret = ret .. "<sub>&alpha;"
    elseif (q == "b") then ret = ret .. "<sub>&beta;"
    elseif (q == "-") then ret = ret .. "<sub>*"
    end
    ---Process bond position---
    if (r and s) then
      ret = ret .. r .. "-" .. s .. "</sub>"
    end
    if (t) then ret = ret .. t end
   end
  if (string.match(seq,"Cer$")) then
      ret = ret .. "<b>Cer</b>"
  end
   print(ret)
|{{{1|GlcNAcb1-3Galb1-3GalNAca1-4GalNAcb1-4(EtnP-6)GlcNAcb1-3Manb1-4Glcb1-1Cer}}}}}

Revision as of 14:06, 3 February 2012

{{#lua:

 local seq = stdin:match("[%S()%[%]]+");
 local ret = "";
 seq = string.gsub(seq, "a([1-9?]%-[1-9/?]*)", "α%1");
 seq = string.gsub(seq, "b([1-9?]%-[1-9/?]*)", "β%1");
 seq = string.gsub(seq, "?([1-9?]%-[1-9/?]*)", "?%1");
 seq = string.gsub(seq, "Cer$", "Cer");
 seq = string.gsub(seq, "(Gal[NAcH234Me]*)", '%1');
 seq = string.gsub(seq, "(Glc[NAcH2]*)", '%1');
 seq = string.gsub(seq, "(Man[A]*)", '%1');
 seq = string.gsub(seq, "(Rha)", '%1');
 seq = string.gsub(seq, "(Fuc[A]*)", '%1');
 seq = string.gsub(seq, "(NeuAc[Me489]*)", '%1');
 seq = string.gsub(seq, "(NeuGc[Me489]*)", '%1');
 seq = string.gsub(seq, "(Xyl)", '%1');
 seq = string.gsub(seq, "(Ara)", '%1');
 print(seq);

|GlcNAcb1-3Xyla1-4Galb1-3GalNAca1-4(NeuAc?1-2NeuGc4Mea1-3)GalNAcb1-4(EtnP-6)GlcNAcb1-3Manb1-4Glcb1-1Cer}}