https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AImportProtein%2FsandboxModule:ImportProtein/sandbox - Revision history2025-05-30T15:22:33ZRevision history for this page on the wikiMediaWiki 1.45.0-wmf.3https://en.wikipedia.org/w/index.php?title=Module:ImportProtein/sandbox&diff=1149530642&oldid=prevLemondoge: Simplifications, and a use of assert instead of a custom error message2023-04-12T20:13:54Z<p>Simplifications, and a use of assert instead of a custom error message</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 20:13, 12 April 2023</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 24:</td>
<td colspan="2" class="diff-lineno">Line 24:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> ---- include is nil to include everything. If it exists then only what is in it is used.</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> ---- include is nil to include everything. If it exists then only what is in it is used.</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> ---- format is "I want only this" (any junk) "and this" etc. Note weakness - a stray quote would foul up the whole template.</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> ---- format is "I want only this" (any junk) "and this" etc. Note weakness - a stray quote would foul up the whole template.</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> local include=args.include or pargs.include or <del style="font-weight: bold; text-decoration: none;">"all"</del></div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> local include=args.include or pargs.include or <ins style="font-weight: bold; text-decoration: none;">nil</ins></div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if include == "all" then include = nil end</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if include == "all" then include = nil end</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local tinclude={}</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local tinclude={}</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 72:</td>
<td colspan="2" class="diff-lineno">Line 72:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> ---- Check there is a protein sequence file and figure out where the CDS in it starts and ends</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> ---- Check there is a protein sequence file and figure out where the CDS in it starts and ends</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local file=args.file or pargs.file</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local file=args.file or pargs.file</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> <del style="font-weight: bold; text-decoration: none;">if not</del>(file<del style="font-weight: bold; text-decoration: none;">) then return</del> "<del style="font-weight: bold; text-decoration: none;">error: </del>use 'file=some cut-and-pasted NCBI protein sequence' to input a protein to be diagrammed"<del style="font-weight: bold; text-decoration: none;"> end</del></div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> <ins style="font-weight: bold; text-decoration: none;">assert</ins>(file<ins style="font-weight: bold; text-decoration: none;">,</ins> "use 'file=some cut-and-pasted NCBI protein sequence' to input a protein to be diagrammed"<ins style="font-weight: bold; text-decoration: none;">)</ins></div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local cdsstart, cdsend = mw.ustring.match(file,"Protein%s-(%d+)%.%.(%d+)")</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local cdsstart, cdsend = mw.ustring.match(file,"Protein%s-(%d+)%.%.(%d+)")</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> cdsstart=tonumber(cdsstart);cdsend=tonumber(cdsend)</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> cdsstart=tonumber(cdsstart);cdsend=tonumber(cdsend)</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 142:</td>
<td colspan="2" class="diff-lineno">Line 142:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if s<cdsstart then s=cdsstart end</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if s<cdsstart then s=cdsstart end</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if e>cdsend then e=cdsend end</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if e>cdsend then e=cdsend end</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> if s==cdsstart and e==cdsend<del style="font-weight: bold; text-decoration: none;"> then showthismotif=nil end</del></div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> if s==cdsstart and e==cdsend</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> <del style="font-weight: bold; text-decoration: none;">if</del> include and not tinclude[n]<del style="font-weight: bold; text-decoration: none;"> then showthismotif=nil end -- if include is set, and n isn't in it, don't add to table or graphic</del></div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> <ins style="font-weight: bold; text-decoration: none;">or</ins> <ins style="font-weight: bold; text-decoration: none;">(</ins>include and not tinclude[n]<ins style="font-weight: bold; text-decoration: none;">)</ins></div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> <del style="font-weight: bold; text-decoration: none;">if</del> exclude and texclude[n]<del style="font-weight: bold; text-decoration: none;"> then showthismotif=nil end -- if exclude is set and n is in it don't add</del></div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> <ins style="font-weight: bold; text-decoration: none;">or</ins> <ins style="font-weight: bold; text-decoration: none;">(</ins>exclude and texclude[n]<ins style="font-weight: bold; text-decoration: none;">)</ins></div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker"><a class="mw-diff-movedpara-right" title="Paragraph was moved. Click to jump to old location." href="#movedpara_9_0_lhs">⚫</a></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_6_0_rhs"></a> <ins style="font-weight: bold; text-decoration: none;">then</ins> </div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> showthismotif=nil </div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> end</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if showthismotif then</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if showthismotif then</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> ---- update the table output for the legend</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> ---- update the table output for the legend</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 162:</td>
<td colspan="2" class="diff-lineno">Line 165:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if newcolor then tlegend=tlegend..[[<span style="background-color:]] .. c .. [[;">&nbsp;&nbsp;</span> ]] .. nkey .. "\n" end</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if newcolor then tlegend=tlegend..[[<span style="background-color:]] .. c .. [[;">&nbsp;&nbsp;</span> ]] .. nkey .. "\n" end</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> nkey=""</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> nkey=""</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> <del style="font-weight: bold; text-decoration: none;">else</del></div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> <ins style="font-weight: bold; text-decoration: none;">elseif large then</ins></div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> <del style="font-weight: bold; text-decoration: none;">if large then</del></div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> <ins style="font-weight: bold; text-decoration: none;">vertical=tostring(height-toprowheight)</ins></div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> <del style="font-weight: bold; text-decoration: none;"> </del> vertical=tostring(<del style="font-weight: bold; text-decoration: none;">height-</del>toprowheight)</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> <ins style="font-weight: bold; text-decoration: none;">if</ins> <ins style="font-weight: bold; text-decoration: none;">toprow</ins> <ins style="font-weight: bold; text-decoration: none;">then</ins> vertical=<ins style="font-weight: bold; text-decoration: none;">vertical .. "px;top:" .. </ins>tostring(toprowheight)<ins style="font-weight: bold; text-decoration: none;"> end</ins></div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> <del style="font-weight: bold; text-decoration: none;"> if toprow then vertical</del>=<del style="font-weight: bold; text-decoration: none;">vertical</del> .. <del style="font-weight: bold; text-decoration: none;">"px;top:"</del> ..<del style="font-weight: bold; text-decoration: none;"> tostring(toprowheight) end</del></div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> <ins style="font-weight: bold; text-decoration: none;">annot</ins>=<ins style="font-weight: bold; text-decoration: none;">"'''"</ins> .. <ins style="font-weight: bold; text-decoration: none;">nkey</ins> ..<ins style="font-weight: bold; text-decoration: none;">"'''"</ins></div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> <del style="font-weight: bold; text-decoration: none;"> annot</del>="<del style="font-weight: bold; text-decoration: none;">'''</del>" <del style="font-weight: bold; text-decoration: none;">..</del> <del style="font-weight: bold; text-decoration: none;">nkey</del> <del style="font-weight: bold; text-decoration: none;">.."'''"</del></div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> <ins style="font-weight: bold; text-decoration: none;">nkey</ins>="" <ins style="font-weight: bold; text-decoration: none;">--</ins> <ins style="font-weight: bold; text-decoration: none;">no</ins> <ins style="font-weight: bold; text-decoration: none;">vertical text display</ins></div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> <del style="font-weight: bold; text-decoration: none;"> nkey="" -- no vertical text display</del></div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> <ins style="font-weight: bold; text-decoration: none;">else</ins> </div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> <del style="font-weight: bold; text-decoration: none;"> else </del>vertical=tostring(math.floor(height) - toprowheight - largeonlyregion) .. "px;top:" .. tostring(toprowheight + largeonlyregion)</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> <ins style="font-weight: bold; text-decoration: none;"> </ins>vertical=tostring(math.floor(height) - toprowheight - largeonlyregion) .. "px;top:" .. tostring(toprowheight + largeonlyregion)</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;"> </del> nkey=mw.ustring.gsub(nkey,"(.)","%1<br />") -- verticalize the text </div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> nkey=mw.ustring.gsub(nkey,"(.)","%1<br />") -- verticalize the text </div></td>
</tr>
<tr>
<td class="diff-marker"><a class="mw-diff-movedpara-left" title="Paragraph was moved. Click to jump to new location." href="#movedpara_6_0_rhs">⚫</a></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_9_0_lhs"></a> <del style="font-weight: bold; text-decoration: none;"> end</del></div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local z=10000-1*boxwidth --- smaller elements in front of larger ones</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local z=10000-1*boxwidth --- smaller elements in front of larger ones</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 178:</td>
<td colspan="2" class="diff-lineno">Line 180:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- draw annotations vertically below it</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- draw annotations vertically below it</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- don't do at all if no text (nkey=="", such as on the top row)</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- don't do at all if no text (nkey=="", such as on the top row)</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> if<del style="font-weight: bold; text-decoration: none;"> not</del> (nkey<del style="font-weight: bold; text-decoration: none;">=</del>="") then</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> if (nkey<ins style="font-weight: bold; text-decoration: none;">~</ins>="") then</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- first decide if in a replaceregion - if so, don't draw</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- first decide if in a replaceregion - if so, don't draw</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local toreplace;local ri=1</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local toreplace;local ri=1</div></td>
</tr>
</table>Lemondogehttps://en.wikipedia.org/w/index.php?title=Module:ImportProtein/sandbox&diff=1149529993&oldid=prevLemondoge: Create sandbox version of Module:ImportProtein2023-04-12T20:08:51Z<p>Create sandbox version of <a href="/wiki/Module:ImportProtein" title="Module:ImportProtein">Module:ImportProtein</a></p>
<p><b>New page</b></p><div>local p = {}<br />
<br />
function p.main (frame)<br />
---- Set up the initial frame parameters<br />
local debuglog="|}|}"<br />
local args=frame.args<br />
local parent=frame.getParent(frame)<br />
local pargs={}<br />
if parent then pargs=parent.args end<br />
local height=args.height or pargs.height or "50"<br />
local width=args.width or pargs.width or "600"<br />
local background=args.background or pargs.background or "#333333"<br />
local vtext=args.vtext or pargs.vtext or 25 -- characters of legend text to display vertically down from motifs<br />
local largeonlyregion=args.largeonlyregion or pargs.largeonlyregion or 20<br />
local vtext=tonumber(vtext) -- no meaning except as a number<br />
local tableoutput=args.tableoutput or pargs.tableoutput or "mw-collapsed" -- I've decided to use the table as the legend much of the time after all, I think. (previously defaulted to "nil" to suppress)<br />
if tableoutput=="no" then tableoutput=nil end<br />
local vwidth=args.vwidth or pargs.vwidth or 4 -- number of PIXELS to tag as not overwriteable with vertical text.<br />
local vclaim={} --- if vclaim[pixel] is true, that pixel is taken<br />
local vprotest='' --- list of positions not shown separated by spaces<br />
local nowiki=args.nowiki or pargs.nowiki<br />
<br />
---- These parameters send text that needs to be processed into tables<br />
---- include is nil to include everything. If it exists then only what is in it is used.<br />
---- format is "I want only this" (any junk) "and this" etc. Note weakness - a stray quote would foul up the whole template.<br />
local include=args.include or pargs.include or "all"<br />
if include == "all" then include = nil end<br />
local tinclude={}<br />
if include then<br />
for i in mw.ustring.gmatch(include,[[%"(.-)%"]]) do<br />
tinclude[i]=1<br />
end<br />
end<br />
---- replaceregion defines a section with too many features to note individually.<br />
---- Instead you group them with a new text.<br />
---- The format is xx..yy:"Use this text"<br />
local replaceregion=args.replaceregion or pargs.replaceregion or ""<br />
local treplaceregion={}<br />
treplaceregion.s={};treplaceregion.e={};treplaceregion.t={}<br />
for i,j,k in mw.ustring.gmatch(replaceregion,[[(%d+)%.%.(%d+):%"(.-)%"]]) do<br />
table.insert(treplaceregion.s,tonumber(i));table.insert(treplaceregion.e,tonumber(j));table.insert(treplaceregion.t,tostring(k))<br />
end<br />
---- exclude "Forget about this" (junk between ignored).<br />
---- this prevents things from showing up even in the table and all motifs of this kind<br />
local exclude=args.exclude or pargs.exclude or "" -- for these empty arrays will be ignored later.<br />
local texclude={}<br />
for i in mw.ustring.gmatch(exclude,[[%"(.-)%"]]) do<br />
texclude[i]=1<br />
end<br />
---- usenotes "This is a crummy motif name" (junk between ignored). Uses /note entries instead<br />
local usenotes=args.usenotes or pargs.usenotes or ""<br />
local tusenotes={}<br />
for i in mw.ustring.gmatch(usenotes,[[%"(.-)%"]]) do<br />
tusenotes[i]=1<br />
end<br />
---- substitute "Don't like this wording":"That's what I want" (anything between these ignored)<br />
local substitute=args.substitute or pargs.substitute or ""<br />
local tsubstitute={}<br />
for i,j in mw.ustring.gmatch(substitute,[[%"(.-)%":%"(.-)%"]]) do<br />
tsubstitute[i]=j<br />
end<br />
---- toprow "Put this motif in the top row, no vertical annotation"<br />
---- If present, defines an upper part of the graphic to mark certain features by color only - most likely, helices and sheets and turns<br />
local toprowtext=args.toprow or pargs.toprow or ""<br />
local ttoprow={}<br />
local toprowheight=0 -- no height unless one exists<br />
local toprow -- boolean to mark if anything is actually on the top row<br />
for i in mw.ustring.gmatch(toprowtext,[[%"(.-)%"]]) do<br />
ttoprow[i]=1;toprow=true<br />
end<br />
if toprow then toprowheight=args.toprowheight or pargs.toprowheight or 10 end<br />
---- Check there is a protein sequence file and figure out where the CDS in it starts and ends<br />
local file=args.file or pargs.file<br />
if not(file) then return "error: use 'file=some cut-and-pasted NCBI protein sequence' to input a protein to be diagrammed" end<br />
local cdsstart, cdsend = mw.ustring.match(file,"Protein%s-(%d+)%.%.(%d+)")<br />
cdsstart=tonumber(cdsstart);cdsend=tonumber(cdsend)<br />
if ((cdsstart<1) or (cdsend<1)) then return [[error: the module expected a line "Protein: ''start amino acid''..''end amino acid''" to define the CDS.]] end<br />
local cdswidth=cdsend-cdsstart<br />
---- Find and replace Site and Region to create unique separators<br />
---- so that every one of these sections can be individually processed in the main loop<br />
file = mw.ustring.gsub(file,"Site%s+","|##|S") -- there are no pipe characters in the input or it would have choked<br />
file = mw.ustring.gsub(file,"Region%s+","|##|R")<br />
file = mw.ustring.gsub(file,"$","|##|") --- close last feature at the EOF<br />
---- Load a set of colors to use for the different motifs.<br />
---- Any unicode separator changes them. No format expectations.<br />
local colorpage=mw.title.new("Template:ImportProtein/DefaultColors")<br />
local content<br />
local color={}<br />
if colorpage then<br />
content=colorpage.getContent(colorpage)<br />
if content then<br />
for x in mw.ustring.gmatch(content,"(%S+)") do<br />
table.insert(color,x)<br />
end<br />
end<br />
end<br />
if #color<1 then color={"#000055","#000099","#0000CC","#0000FF","#550055","#550099","#5500CC","#5500FF","#990055","#990099","#9900CC","#9900FF","#CC0055","#CC0099","#CC00CC","#CC00FF","#FF0000","#FF0055","#FF0099","#FF00CC","#FF00FF","#005555","#005599","#0055CC","#0055FF","#55555","#555599","#5555CC","#5555FF","#995555","#995599","#9955CC","#9955FF","#CC5555","#CC5599","#CC55CC","#CC55FF","#FF5500","#FF5555","#FF5599","#FF55CC","#FF55FF"} end<br />
local claim={};local nextcolor=1 -- keeps track of the colors assigned to specific nkeys throughout the loop<br />
---- Begin the output and graphics files<br />
local output<br />
local tlegend="" -- legend for top row entries only, shown above table<br />
if tableoutput == "collapsed" then <br />
output=[[{| class="wikitable mw-collapsible mw-collapsed" style="width:]].. width .. [[px;"]] .. "\n" .. [[!colspan=4|List of protein features]] .. "\n" .. [[|-]] <br />
elseif tableoutput=="collapsible" then <br />
output=[[{| class="wikitable collapsible" style="width:]].. width .. [[px;"]] .. "\n" .. [[!colspan=4|List of protein features]] .. "\n" .. [[|-]] <br />
else <br />
output=[[{| class="wikitable"]] <br />
end<br />
local graphics=[[<div style="position:relative;background-color:]].. background .. [[;width:]] .. width .. [[px;height:]] .. height .. [[px;">]]<br />
---- MAIN LOOP ----<br />
---- this goes through features one by one and marks them down in "output" (legend/table) and "graphics" (protein box and vertical annotation)<br />
---- Note that this does NOT create an array of features to sort, but is purely once through.<br />
---- This means, for example, that there is no easy way to reposition adjacent motifs left and right to fit automatically.<br />
---- You could, of course, array the output and retroactively process it ... maybe even turn this into a sortable array of function tail calls??? (My head hurts)<br />
for feature, range in mw.ustring.gmatch(file,"#|(.-)|#") do<br />
local t=mw.ustring.match(feature,"^(%a)") -- S or R placed in previous find/replace<br />
local s=mw.ustring.match(feature,"(%d+)") -- first number is the beginning of site or region<br />
local e=mw.ustring.match(feature,"^.%s-%d+%.%.(%d+)") or s -- second number in xx..yy range ; this needs updating!<br />
<br />
if s then<br />
---- decide on the name to be used for the motif and annotation<br />
local n,c<br />
if t=="R" then n=mw.ustring.match(feature,[[/region_name=%"(.-)%"]]) end<br />
if t=="S" then n=mw.ustring.match(feature,[[/site_type=%"(.-)%"]]) end<br />
n=tostring(n)<br />
if tusenotes[n] then n=mw.ustring.match(feature,[[/note=%"(.-)%"]]) or n end<br />
n=tostring(n)<br />
n=mw.ustring.match(n,"^%s+(.+)%s+$") or n -- kill white space<br />
n=mw.ustring.gsub(n,"\n"," ") or n -- remove line feeds<br />
n=tostring(n) -- am I paranoid?<br />
if tsubstitute[n] then n=tostring(tsubstitute[n]) end<br />
n = mw.ustring.match(n,"(.+)%.") or n -- Don't need the ubiquitous final periods<br />
---- from the name (n) pull out an nkey that excludes parenthesized stuff<br />
---- each unique nkey can claim its own color to use from here on out<br />
local nkey=mw.ustring.match(n,"(.+)[%.;,%(%[]") or n<br />
local newcolor=false; -- is this a new color (if so, then if it is toprow, then add to legend for those)<br />
if claim[nkey] then c=claim[nkey] else c=color[nextcolor];claim[nkey]=c;nextcolor=nextcolor+1;newcolor=true end<br />
local cstyle=[[style="color:]] .. c .. [[;"|]]<br />
---- decide whether to show the motif, and crop it to the CDS<br />
local showthismotif=true<br />
s=tonumber(s);e=tonumber(e)<br />
if s<cdsstart then s=cdsstart end<br />
if e>cdsend then e=cdsend end<br />
if s==cdsstart and e==cdsend then showthismotif=nil end<br />
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<br />
if exclude and texclude[n] then showthismotif=nil end -- if exclude is set and n is in it don't add<br />
if showthismotif then<br />
---- update the table output for the legend<br />
if tostring(t)=="R" then output = output .. "\n|" .. cstyle .. "region\n|" else output = output .. "\n|" .. cstyle .. "site\n|" end<br />
output = output .. cstyle .. tostring(s) .. "\n|" .. cstyle .. tostring(e) .. "\n|" .. cstyle .. n .. "\n|-"<br />
---- update the graphic display: first determine if the block is large to be displayed full height and annotated inside itself<br />
nkey=mw.ustring.sub(nkey,1,vtext) -- for graphics purposes, truncate the string (default 25 characters)<br />
local large<br />
local boxleft=math.floor(width*tonumber(s)/cdswidth)<br />
local boxwidth=math.floor(width*tonumber(e)/cdswidth)-boxleft<br />
if boxwidth>8*tonumber(mw.ustring.len(nkey)) then large=true else large=nil end<br />
---- then work out the horizontal or vertical display<br />
local vertical -- height substring of the drawn block<br />
local annot="" -- text contents of a large block<br />
if ttoprow[n] then<br />
vertical=tostring(toprowheight)<br />
if newcolor then tlegend=tlegend..[[<span style="background-color:]] .. c .. [[;">&nbsp;&nbsp;</span> ]] .. nkey .. "\n" end<br />
nkey=""<br />
else<br />
if large then<br />
vertical=tostring(height-toprowheight)<br />
if toprow then vertical=vertical .. "px;top:" .. tostring(toprowheight) end<br />
annot="'''" .. nkey .."'''"<br />
nkey="" -- no vertical text display<br />
else vertical=tostring(math.floor(height) - toprowheight - largeonlyregion) .. "px;top:" .. tostring(toprowheight + largeonlyregion)<br />
nkey=mw.ustring.gsub(nkey,"(.)","%1<br />") -- verticalize the text <br />
end<br />
end<br />
local z=10000-1*boxwidth --- smaller elements in front of larger ones<br />
if not(large) then z=z+10000 end --- large elements reliably to the back<br />
-- draw graphics within the protein rectangle<br />
graphics = graphics .. [[<div style="position:absolute;overflow:hidden;z-index:]] .. z .. [[;left:]] .. boxleft .. [[px;border-top:0px;border-bottom:0px;border-left:1px;border-right:1px;border-style:solid;border-color:]].. c .. [[;background-color:]].. c .. [[;width:]] .. boxwidth .. [[px;height:]] .. vertical .. [[px;text-align:center;">]] .. annot .. [[</div>]]<br />
-- draw annotations vertically below it<br />
-- don't do at all if no text (nkey=="", such as on the top row)<br />
if not (nkey=="") then<br />
-- first decide if in a replaceregion - if so, don't draw<br />
local toreplace;local ri=1<br />
while treplaceregion.s[ri] do<br />
local rs=treplaceregion.s[ri]<br />
local re=treplaceregion.e[ri]<br />
if s>=rs and e<=re then toreplace=true;break end<br />
ri=ri+1<br />
end <br />
if not toreplace and not large then <br />
--- center vt in the feature; then claim pixels one by one around it.<br />
--- Don't draw in a claimed pixel, but file a protest at bottom.<br />
local vt=math.floor(boxleft+boxwidth/2 - 2) -- vertical text's horizontal position<br />
if not vclaim[vt] then<br />
for i = vt-vwidth,vt+vwidth,1 do<br />
vclaim[i]=true<br />
end<br />
graphics = graphics .. [[<span style="position:absolute;text-align:center;line-height:90%;font-size:85%;overflow:visible;z-index:100;left:]] .. vt .. [[px;top:]] .. math.floor(height+5) .. [[px;">]] .. nkey .. [[</span>]]<br />
else vprotest=vprotest .. s .. "-" .. e .. " "<br />
end -- (if not ttoprow[n])<br />
end -- (if not vclaim)<br />
end -- (if not toreplace)<br />
end -- (if showthismotif)<br />
end -- (if s)<br />
end -- for feature, range<br />
--- we're out of the loop - now draw annotations for the chosen replace regions based on user text<br />
local ri=1<br />
while treplaceregion.s[ri] do<br />
local rs=treplaceregion.s[ri]<br />
local re=treplaceregion.e[ri]<br />
local rt=mw.ustring.gsub(mw.ustring.sub(treplaceregion.t[ri],1,vtext),"(.)","%1<br />") -- verticalize the text<br />
local boxleft=math.floor(width*tonumber(rs)/cdswidth)<br />
local boxwidth=math.floor(width*tonumber(re)/cdswidth)-boxleft<br />
local vt = math.floor(boxleft+boxwidth/2 -2) -- this formula should be synchronized with above, but defining constants seems silly.<br />
-- this ignores vclaim - it's a user input, therefore repositionable field<br />
graphics = graphics .. [[<span style="position:absolute;text-align:center;line-height:90%;font-size:85%;overflow:visible;z-index:100;left:]] .. vt .. [[px;top:]] .. math.floor(height+5) .. [[px;">]] .. rt .. [[</span>]]<br />
ri=ri+1<br />
end<br />
if not(tableoutput) then output = "" end<br />
if tlegend ~= "" then tlegend = [[<div style="width:]]..width..[[;">]] .. [[''Top row:'' ]] .. tlegend .. [[</div>]] end<br />
if vprotest ~= "" then vprotest = "''Overlapping vertical annotations not shown above: " .. vprotest .. "''" end<br />
if debuglog == "|}|}" then debuglog="" else debuglog = debuglog .. "\n" end<br />
if vtext>2 then vtext=vtext-2 end -- make up for extra return required to start a table at the end there.<br />
local output = [=[{| style="width:]=]..width..[[px;"]] .. "\n|".. graphics .. [[</div><div style="line-height:90%;font-size:85%;">]] .. mw.ustring.rep("\n",vtext) .. "</div>" .. tlegend .. vprotest .. "\n" .. output .. "\n|}\n" .. debuglog .. "|}\n"<br />
if nowiki then output = frame.preprocess(frame,"<pre><nowiki>"..output.."</nowiki></pre>") end<br />
return output<br />
end<br />
<br />
return p</div>Lemondoge