Template:LBS/FormatSugar: Difference between revisions

mNo edit summary
mNo edit summary
Line 3: Line 3:
   local ret = "";
   local ret = "";
   for o,p,q,r,s,t in string.gmatch(seq, "([%[%(]?)(%a+)([?ab%-])([1-9]?)%-?([1-9])([%]%)]?)") do
   for o,p,q,r,s,t in string.gmatch(seq, "([%[%(]?)(%a+)([?ab%-])([1-9]?)%-?([1-9])([%]%)]?)") do
     if (r == "-") then r = "*" end
     ---Process ( ---
     if (o) then ret = ret .. o end
     if (o) then ret = ret .. o end
    ---Process sugar name---
     if (string.match(p, "^Glc")) then
     if (string.match(p, "^Glc")) then
       ret = ret .. '<span style="color:blue"><b>' .. p .. "</b></span>"
       ret = ret .. '<span style="color:blue"><b>' .. p .. "</b></span>"
Line 18: Line 19:
       ret = ret .. '<b>' .. p .. '</b>'
       ret = ret .. '<b>' .. p .. '</b>'
     end
     end
 
    ---Process alpha or beta---
     if (q == "a") then ret = ret .. "<sub>&alpha;"
     if (q == "a") then ret = ret .. "<sub>&alpha;"
     elseif (q == "b") then ret = ret .. "<sub>&beta;"
     elseif (q == "b") then ret = ret .. "<sub>&beta;"
    elseif (q == "-") then ret = ret .. "<sub>*"
     else ret = ret .. "<sub>" .. q end
     else ret = ret .. "<sub>" .. q end
 
    ---Process bond position---
     ret = ret .. r .. "-" .. s .. "</sub>"
     ret = ret .. r .. "-" .. s .. "</sub>"
     if (t) then ret = ret .. t end
     if (t) then ret = ret .. t end

Revision as of 07:03, 15 April 2011

{{#lua:

 local seq = stdin:match("[%S()%[%]]+");
 local ret = "";
 for o,p,q,r,s,t in string.gmatch(seq, "([%[%(]?)(%a+)([?ab%-])([1-9]?)%-?([1-9])([%]%)]?)") do
   ---Process ( ---
   if (o) then ret = ret .. o end
   ---Process sugar name---
   if (string.match(p, "^Glc")) then
     ret = ret .. '' .. p .. ""
   elseif (string.match(p, "^Gal")) then
     ret = ret .. '' .. p .. ""
   elseif (string.match(p, "^Man")) then
     ret = ret .. '' .. p .. ""
   elseif (string.match(p, "^Fuc")) then
     ret = ret .. '' .. p .. ""
   elseif (string.match(p, "^Neu")) then
     ret = ret .. '' .. p .. ""
   else
     ret = ret .. '' .. p .. ''
   end
   ---Process alpha or beta---
   if (q == "a") then ret = ret .. "α"
   elseif (q == "b") then ret = ret .. "β"
   elseif (q == "-") then ret = ret .. "*"
   else ret = ret .. "" .. q end
   ---Process bond position---
   ret = ret .. r .. "-" .. s .. ""
   if (t) then ret = ret .. t end
 end
 if (string.match(seq,"Cer$")) then
     ret = ret .. "Cer"
 end
 print(ret)

|GlcNAcb1-3Galb1-3GalNAca1-4GalNAcb1-4(EtnP-6)GlcNAcb1-3Manb1-4Glcb1-1Cer}}