Module:ImportProtein and Module:ImportProtein/sandbox: Difference between pages
(Difference between pages)
imported>Lemondoge m Simplified module by flattening unnecessarily nested conditionals |
imported>Lemondoge Simplifications, and a use of assert instead of a custom error message |
||
| Line 24: | Line 24: | ||
---- include is nil to include everything. If it exists then only what is in it is used. | ---- include is nil to include everything. If it exists then only what is in it is used. | ||
---- format is "I want only this" (any junk) "and this" etc. Note weakness - a stray quote would foul up the whole template. | ---- format is "I want only this" (any junk) "and this" etc. Note weakness - a stray quote would foul up the whole template. | ||
local include=args.include or pargs.include or | local include=args.include or pargs.include or nil | ||
if include == "all" then include = nil end | if include == "all" then include = nil end | ||
local tinclude={} | local tinclude={} | ||
| Line 72: | Line 72: | ||
---- Check there is a protein sequence file and figure out where the CDS in it starts and ends | ---- Check there is a protein sequence file and figure out where the CDS in it starts and ends | ||
local file=args.file or pargs.file | local file=args.file or pargs.file | ||
assert(file, "use 'file=some cut-and-pasted NCBI protein sequence' to input a protein to be diagrammed") | |||
local cdsstart, cdsend = mw.ustring.match(file,"Protein%s-(%d+)%.%.(%d+)") | local cdsstart, cdsend = mw.ustring.match(file,"Protein%s-(%d+)%.%.(%d+)") | ||
cdsstart=tonumber(cdsstart);cdsend=tonumber(cdsend) | cdsstart=tonumber(cdsstart);cdsend=tonumber(cdsend) | ||
| Line 142: | Line 142: | ||
if s<cdsstart then s=cdsstart end | if s<cdsstart then s=cdsstart end | ||
if e>cdsend then e=cdsend end | if e>cdsend then e=cdsend end | ||
if s==cdsstart and e==cdsend | if s==cdsstart and e==cdsend | ||
or (include and not tinclude[n]) | |||
or (exclude and texclude[n]) | |||
then | |||
showthismotif=nil | |||
end | |||
if showthismotif then | if showthismotif then | ||
---- update the table output for the legend | ---- update the table output for the legend | ||
| Line 162: | Line 165: | ||
if newcolor then tlegend=tlegend..[[<span style="background-color:]] .. c .. [[;"> </span> ]] .. nkey .. "\n" end | if newcolor then tlegend=tlegend..[[<span style="background-color:]] .. c .. [[;"> </span> ]] .. nkey .. "\n" end | ||
nkey="" | nkey="" | ||
elseif large then | |||
vertical=tostring(height-toprowheight) | |||
if toprow then vertical=vertical .. "px;top:" .. tostring(toprowheight) end | |||
annot="'''" .. nkey .."'''" | |||
nkey="" -- no vertical text display | |||
else | |||
vertical=tostring(math.floor(height) - toprowheight - largeonlyregion) .. "px;top:" .. tostring(toprowheight + largeonlyregion) | |||
nkey=mw.ustring.gsub(nkey,"(.)","%1<br />") -- verticalize the text | |||
end | end | ||
local z=10000-1*boxwidth --- smaller elements in front of larger ones | local z=10000-1*boxwidth --- smaller elements in front of larger ones | ||
| Line 178: | Line 180: | ||
-- draw annotations vertically below it | -- draw annotations vertically below it | ||
-- don't do at all if no text (nkey=="", such as on the top row) | -- don't do at all if no text (nkey=="", such as on the top row) | ||
if | if (nkey~="") then | ||
-- first decide if in a replaceregion - if so, don't draw | -- first decide if in a replaceregion - if so, don't draw | ||
local toreplace;local ri=1 | local toreplace;local ri=1 | ||