Module:ImportProtein and Module:ImportProtein/sandbox: Difference between pages

(Difference between pages)
Jump to navigation Jump to search
Page 1
Page 2
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 "all"
   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
   if not(file) then return "error: use 'file=some cut-and-pasted NCBI protein sequence' to input a protein to be diagrammed" end
   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 then showthismotif=nil end
           if s==cdsstart and e==cdsend
           if include and not tinclude[n] then showthismotif=nil end -- if include is set, and n isn't in it, don't add to table or graphic
           or (include and not tinclude[n])
           if exclude and texclude[n] then showthismotif=nil end -- if exclude is set and n is in it don't add
           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 .. [[;">&nbsp;&nbsp;</span> ]] .. nkey .. "\n" end
                 if newcolor then tlegend=tlegend..[[<span style="background-color:]] .. c .. [[;">&nbsp;&nbsp;</span> ]] .. nkey .. "\n" end
                 nkey=""
                 nkey=""
             else
             elseif large then
                if large then
                vertical=tostring(height-toprowheight)
                    vertical=tostring(height-toprowheight)
                if toprow then vertical=vertical .. "px;top:" .. tostring(toprowheight) end
                    if toprow then vertical=vertical .. "px;top:" .. tostring(toprowheight) end
                annot="'''" .. nkey .."'''"
                    annot="'''" .. nkey .."'''"
                nkey="" -- no vertical text display
                    nkey="" -- no vertical text display
            else  
                else vertical=tostring(math.floor(height) - toprowheight - largeonlyregion) .. "px;top:" .. tostring(toprowheight + largeonlyregion)
            vertical=tostring(math.floor(height) - toprowheight - largeonlyregion) .. "px;top:" .. tostring(toprowheight + largeonlyregion)
                    nkey=mw.ustring.gsub(nkey,"(.)","%1<br />") -- verticalize the text  
                nkey=mw.ustring.gsub(nkey,"(.)","%1<br />") -- verticalize the text  
                end
             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 not (nkey=="") then
             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