Debian Codegraph @

texmf-dist/source/lualatex/pgfmolbio/pgfmolbio.dtx

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2024 by Wolfgang Esser-Skala
4 %
5 % This work may be distributed and/or modified under the
6 % conditions of the LaTeX Project Public License, either version 1.3c
7 % of this license or (at your option) any later version.
8 % The latest version of this license is in
9 % https://www.latex-project.org/lppl.txt
10 % and version 1.3c or later is part of all distributions of LaTeX
11 % version 2008/05/04 or later.
12 %
13 % \fi
14 %
15 % \iffalse
16 %<pgfmolbio-tex>\ProvidesPackage{pgfmolbio}[2024/06/17 v0.21a Molecular biology graphs with TikZ]
17 %<pgfmolbio-tex>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
18 %<pgfmolbio-lua>module("pgfmolbio", package.seeall)
19 %<pmb-chr-tex>\ProvidesFile{pgfmolbio.chromatogram.tex}[2024/06/17 v0.21a SCF chromatograms]
20 %<pmb-chr-lua>module("pgfmolbio.chromatogram", package.seeall)
21 %<pmb-dom-tex>\ProvidesFile{pgfmolbio.domains.tex}[2024/06/17 v0.21a Protein domains]
22 %<pmb-dom-lua>module("pgfmolbio.domains", package.seeall)
23 %<pmb-con-tex>\ProvidesFile{pgfmolbio.convert.tex}[2024/06/17 v0.21a pgfmolbio graph conversion]
24 %
25 %<*driver>
26 \documentclass[captions=tableheading,cleardoublepage=empty,titlepage=false]{scrreprt}
27 \setkomafont{title}{\rmfamily\bfseries}
28 \addtokomafont{sectioning}{\rmfamily}
29
30 \usepackage[ngerman,english]{babel}
31 \usepackage[hdivide={2cm,*,5cm}]{geometry}
32 \usepackage{fontspec}
33 \usepackage{array,booktabs,tabularx}
34 \usepackage[chromatogram,domains]{pgfmolbio}
35 \usetikzlibrary{patterns,backgrounds,decorations.pathreplacing}
36
37 \usepackage{ydoc-doc,ydoc-code,ydoc-desc,ydoc-expl}
38 \AlsoImplementation
39 \hypersetup{%
40 colorlinks=false,%
41 bookmarksnumbered,%
42 bookmarksopen,%
43 bookmarksopenlevel=1,%
44 breaklinks,%
45 pdfborder=0 0 0,%
46 pdfhighlight=/N,%
47 }
48 \AtBeginDocument{%
49 \lstMakeShortInline[style=latex-expl,basicstyle=\ttfamily,numbers=none,firstnumber=last]|%
50 \lstMakeShortInline[style=lua-doc,basicstyle=\ttfamily,frame=none,numbers=none]§%
51 }
52 \makeatletter
53 \newcommand\DescribeOption[4][=]{%
54 \gdef\OptDefault{\textcolor{black!50}{Default:}~\texttt{#4}}%
55 \DescribeMacros
56 \let\DescribeMacros\y@egroup
57 \optionalon
58 \def\after@Macro@args{\y@egroup\PrintOptions\endgroup}%
59 \hbox\y@bgroup
60 \texttt{\textcolor{opt!50}{/pgfmolbio/#2}\textcolor{opt}{#3}~#1}%
61 \ydoc@macrocatcodes
62 \macroargsstyle
63 \read@Macro@arg%
64 }
65 \def\PrintOptions{%
66 \par\vspace\beforedescskip
67 \begingroup
68 \sbox\@tempboxa{\descframe{\usebox{\descbox}}}%
69 \Needspace*{\dimexpr\ht\@tempboxa+2\baselineskip\relax}%
70 \par\noindent
71 \ifdim\wd\@tempboxa>\dimexpr\linewidth-2\descindent\relax
72 \makebox[\linewidth][c]{\usebox\@tempboxa}%
73 \else
74 \hspace*{\descindent}%
75 \usebox\@tempboxa
76 \fi
77 \endgroup
78 \par\medskip\makebox{\kern10pt\OptDefault}
79 \vspace\afterdescskip
80 \par\noindent
81 }
82 \def\PrintExample{%
83 \begingroup
84 \BoxExample
85 \@tempdima\textwidth
86 \advance\@tempdima-\wd\examplecodebox\relax
87 \advance\@tempdima-\wd\exampleresultbox\relax
88 \advance\@tempdima-1cm\relax
89 \ifdim\@tempdima>0pt
90 \@tempdimb\wd\exampleresultbox
91 \advance\@tempdimb2\fboxsep
92 \advance\@tempdimb2\fboxrule
93 \par\bigskip\noindent%
94 \centerline{%
95 \parbox[c]{\@tempdimb}{\fbox{\usebox\exampleresultbox}}
96 \hskip1cm
97 \parbox[c]{\wd\examplecodebox}{\usebox\examplecodebox}
98 }%
99 \par\bigskip
100 \else
101 \par\bigskip\noindent%
102 \vbox{%
103 \centerline{\fbox{\usebox\exampleresultbox}}%
104 \vspace{\bigskipamount}%
105 \centerline{\usebox\examplecodebox}%
106 }%
107 \par\bigskip
108 \fi
109 \endgroup
110 }
111 \newcommand\DescribeFeature{\@ifstar\DescribeFeatureNoAlias\DescribeFeatureAlias}
112 \newcommand\DescribeFeatureAlias[2]{\paragraph{Feature \texttt{#1}} (\textit{alias} \texttt{#2})\\}
113 \newcommand\DescribeFeatureNoAlias[1]{\paragraph{Feature \texttt{#1}} (\textit{no alias})\\}
114 \makeatother
115 \def\ometa#1{{\optional\meta{#1}}}
116 \lstdefinestyle{exampleextract}{gobble=2}
117 \lstdefinestyle{examplecode}{style=latex-expl}
118 \def\ydoclistingssettings{\lstset{style=latex-expl}}
119 \definecolor{opt}{named}{OliveGreen}
120 \definecolor{mod}{named}{black}
121 \definecolor{macrodesc}{named}{ProcessBlue}
122 \definecolor{macroimpl}{named}{ProcessBlue}
123 \newcommand\module[1]{\textsf{\textcolor{mod}{#1}}}
124 \renewcommand*\optstyle[1]{\texttt{\textcolor{opt}{#1}}}
125
126 \lstdefinestyle{latex-expl}{
127 language=[AlLaTeX]TeX,
128 columns=fullflexible,
129 keepspaces=true,
130 tabsize=2,
131 numbers=left,
132 numberstyle=\sffamily\tiny\color{gray},
133 numbersep=5pt,
134 firstnumber=auto,
135 prebreak={},
136 basicstyle=\ttfamily\small,
137 texcsstyle=*\color{MidnightBlue},
138 texcsstyle=*[2]\color{ProcessBlue},
139 keywordstyle=\color{RedOrange},
140 commentstyle=\itshape\color{black!50},
141 morekeywords={tikzpicture,pgfinterruptboundingbox,pgfinterruptpicture,pmbdomains,scope},
142 moretexcs=[1]{
143 @empty,@ifundefined,@nameuse,clip,colorlet,definecolor,directlua,draw,ifluatex,
144 luaescapestring,node,path,pdfdraftmode,pgf@protocolsizes,pgf@x,pgf@y,pgfdeclareverticalshading,
145 pgfkeys,pgfkeysalso,pgfkeysdef,pgfkeyssetvalue,pgfkeysvalueof,pgfmathsetmacro,pgfpoint,pgfqkeys,
146 ProcessOptions,RequireLuaModule,textcolor,tikzset,useasboundingbox,usetikzlibrary
147 },
148 moretexcs=[2]{
149 @pmb@chr@getkey,@pmb@chr@keydef,@pmb@chr@stylekeydef,
150 @pmb@dom@feature@default@shape,@pmb@dom@helixsegment,@pmb@dom@helixhalfsegment,@pmb@dom@keydef,
151 @pmb@toksa,@pmb@toksb,@tempa,adddisulfidefeatures,addfeature,featureSequence,currentResidue,
152 pmb@chr@tikzpicturefalse,pmb@chr@tikzpicturetrue,ifpmb@chr@showbasenumbers,ifpmb@chr@tikzpicture,
153 ifpmb@con@includedescription,ifpmb@con@outputtikzcode,ifpmb@dom@showname,ifpmb@dom@showruler,
154 ifpmb@dom@showsecstructure,ifpmb@dom@tikzpicture,ifpmb@loadmodule@chromatogram,ifpmb@loadmodule@convert,
155 ifpmb@loadmodule@domains,inputuniprot,inputgff,
156 pgfmolbioset,pmb@con@outputtikzcodefalse,pmb@con@outputtikzcodetrue,
157 pmb@dom@addfeature,pmb@dom@inputgff,pmb@dom@inputuniprot,pmb@dom@tikzpicturetrue,pmb@dom@tikzpicturefalse,
158 pmb@loadmodule@chromatogramtrue,pmb@loadmodule@converttrue,
159 pmb@loadmodule@domainstrue,pmb@magnifiedsequence@width,pmbchromatogram,pmbdomdrawfeature,
160 pmbdomvalueof,pmbprotocolsizes,removedisulfidefeatures,removefeatureprintfunction,
161 residueNumber,setdisulfidefeatures,setfeaturealias,
162 setfeatureprintfunction,setfeatureshape,setfeatureshapealias,setfeaturestyle,setfeaturestylealias,
163 turnXradius,turnYradius,xLeft,xLowerLeft,xLowerRight,xMid,xRight,xUpperLeft,xUpperRight,
164 yLower,yMid,yShift,yUpper
165 },
166 escapebegin=\begin{rmfamily}\color{black!50},
167 escapeend=\end{rmfamily}
168 }
169
170 \lstdefinestyle{latex-doc}{
171 style=latex-expl,
172 showlines,
173 firstnumber=last,
174 breaklines,
175 frame=single,
176 frameround=tttt,
177 rulecolor=\color{black!50}
178 }
179
180 \lstdefinestyle{lua-doc}{
181 language=lua,
182 columns=fullflexible,
183 keepspaces=true,
184 tabsize=2,
185 basicstyle=\ttfamily\small\color{ForestGreen},
186 keywordstyle=\color{MidnightBlue},
187 keywordstyle=[2]\color{ProcessBlue},
188 stringstyle=\color{Red},
189 identifierstyle=\color{Black},
190 emphstyle=\color{BurntOrange!50!Black},
191 showstringspaces=false,
192 numbers=left,
193 numberstyle=\sffamily\tiny\color{gray},
194 numbersep=5pt,
195 firstnumber=last,
196 breaklines,
197 showlines,
198 frame=single,
199 frameround=tttt,
200 rulecolor=\color{black!50},
201 belowskip=\bigskipamount
202 }
203
204 \lstdefinelanguage{lua}{
205 morekeywords={and,break,do,else,elseif,end,false,for,function,if,in,local,
206 nil,not,or,repeat,return,then,true,until,while},
207 morekeywords=[2]{arg,assert,collectgarbage,dofile,error,_G,format,getfenv,
208 getmetatable,__index,ipairs,load,loadfile,loadstring,next,pairs,pcall,print,
209 rawequal,rawget,rawset,select,self,setfenv,setmetatable,tonumber,tostring,__tostring,
210 type,unpack,_VERSION,xpcall},
211 morekeywords=[2]{module,require,package,seeall},
212 morekeywords=[2]{string,byte,char,dump,find,
213 format,gmatch,string,gsub,len,lower,
214 match,rep,reverse,sub,trim,upper},
215 morekeywords=[2]{table,concat,insert,maxn,remove,sort},
216 morekeywords=[2]{math,min},
217 morekeywords=[2]{io,input,open,output,close,flush,
218 lines,read,seek,setvbuf,write},
219 morekeywords=[2]{os.clock,os.date,os.difftime,os.execute,os.exit,os.getenv,
220 os.remove,os.rename,os.setlocale,os.time,os.tmpname},
221 morekeywords=[2]{tex,sprint},
222 emph={addFeature,aliasFeatureStyle,calculateDisulfideLevels,Chromatogram,clearKeys,dimToString,findBasesInStr,
223 getBaseKey,getMinMaxProbability,getParameters,getRange,getSampleAndPeakIndex,new,packageError,
224 packageWarning,printSequenceFeature,printHelixFeature,printTikzChromatogram,printTikzDomains,Protein,
225 readGffFile,readInt,readScfFile,readUniprotFile,selectStyleFromList,setCoordinateFormat,
226 setFeatureStyle,setKeys,setParameters,SpecialKeys,stdProbStyle,stringToDim,toAbsoluteResidueNumber},
227 sensitive=true,
228 alsoletter={0123456789},
229 morecomment=[l]{--},
230 morecomment=[s]{--[[}{]]--},
231 morestring=[b]{"},
232 morestring=[d]{'}
233 }
234
235 \def\TikZ{Ti\textit{k}Z}
236
237 \usepackage{caption}
238 \captionsetup{format=plain,indention=1em,labelsep=colon,font={footnotesize,sf},labelfont={bf},skip=0pt}
239 \makeatletter\@addtoreset{example}{chapter}\makeatother
240 \renewcommand\theexample{\arabic{chapter}.\arabic{example}}
241
242 \pdfpageattr{/Group <</S /Transparency /I true /CS /DeviceRGB>>}
243
244
245 \begin{document}
246 \DocInput{pgfmolbio.dtx}
247 \end{document}
248 %</driver>
249 % \fi
250 %
251 %
252 %
253 % \CharacterTable
254 % {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
255 % Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
256 % Digits \0\1\2\3\4\5\6\7\8\9
257 % Exclamation \! Double quote \" Hash (number) \#
258 % Dollar \$ Percent \% Ampersand \&
259 % Acute accent \' Left paren \( Right paren \)
260 % Asterisk \* Plus \+ Comma \,
261 % Minus \- Point \. Solidus \/
262 % Colon \: Semicolon \; Less than \<
263 % Equals \= Greater than \> Question mark \?
264 % Commercial at \@ Left bracket \[ Backslash \\
265 % Right bracket \] Circumflex \^ Underscore \_
266 % Grave accent \` Left brace \{ Vertical bar \|
267 % Right brace \} Tilde \~}
268 %
269 %
270 % \GetFileInfo{pgfmolbio.sty}
271 %
272 % \CheckSum{1254}
273 %
274 % \pagenumbering{roman}
275 % \title{The \texttt{pgfmolbio} package --\texorpdfstring{\\}{}Molecular Biology Graphs with \TikZ\texorpdfstring{\footnote{This document describes version \fileversion, dated \filedate.}}{}}
276 % \author{\texorpdfstring{Wolfgang Esser-Skala\thanks{Computational Systems Biology Group, Department of Biosciences and Medical Biology, University of Salzburg, Austria; \texttt{[email protected]}}}{Wolfgang Esser-Skala}}
277 % \date{\filedate}
278 % \maketitle
279 %
280 % \begin{abstract}
281 % The experimental package \pkg{pgfmolbio} draws graphs typically found in molecular biology texts. Currently, the package contains three modules: \module{chromatogram} creates DNA sequencing chromatograms from files in standard chromatogram format (\file{scf}); \module{domains} draws protein domain diagrams; \module{convert} integrates \pkg{pgfmolbio} with \TeX\ engines that lack Lua support.
282 % \end{abstract}
283 %
284 % \tableofcontents
285 %
286 %
287 % \chapter{Introduction}
288 % \label{cha:Introduction}
289 % \pagenumbering{arabic}
290 %
291 %
292 % \section{About \texorpdfstring{\pkg{pgfmolbio}}{pgfmolbio}}
293 % \label{sec:IntroAbout}
294 %
295 % Over the decades, \TeX\ has gained popularity across a large number of disciplines. Although originally designed as a mere typesetting system, packages such as \pkg{pgf}\footnote{\url{https://ctan.org/pkg/pgf}} and \pkg{pstricks}\footnote{\url{https://ctan.org/pkg/pstricks}} have strongly extended its \textit{drawing} abilities. Thus, one can create complicated charts that perfectly integrate with the text.
296 %
297 % Texts on molecular biology include a range of special graphs, e.\,g. multiple sequence alignments, membrane protein topologies, DNA sequencing chromatograms, protein domain diagrams, plasmid maps and others. The \pkg{texshade}\footnote{\url{https://ctan.org/pkg/texshade}} and \pkg{textopo}\footnote{\url{https://ctan.org/pkg/textopo}} packages cover alignments and topologies, respectively, but packages dedicated to the remaining graphs are absent. Admittedly, one may create those images with various external programs and then include them in the \TeX\ document. Nevertheless, purists (like the author of this document) might prefer a \TeX-based approach.
298 %
299 % The \pkg{pgfmolbio} package aims at becoming such a purist solution. In the current development release, \pkg{pgfmolbio} is able to
300 % \begin{itemize}
301 % \item read DNA sequencing files in standard chromatogram format (\file{scf}) and draw the corresponding chromatogram;
302 % \item read protein domain information from Uniprot or general feature format files (\file{gff}) and draw domain diagrams.
303 % \end{itemize}
304 % To this end, \pkg{pgfmolbio} relies on routines from \pkg{pgf}'s \TikZ\ frontend and on the Lua scripting language implemented in Lua\TeX. Consequently, the package will not work directly with traditional engines like pdf\TeX. However, a converter module ensures a high degree of backward compatibility.
305 %
306 % Since this is a development release, \pkg{pgfmolbio} presumably includes a number of bugs, and its commands and features are likely to change in future versions. Moreover, the current version is far from complete, but since time is scarce, I am unable to predict when (and if) additional functions become available. Nevertheless, I would greatly appreciate any comments or suggestions.
307 %
308 %
309 % \section{Getting Started}
310 % \label{sec:IntroGettingStarted}
311 %
312 % Before you consider using \pkg{pgfmolbio}, please make sure that both your Lua\TeX\ (at least 0.70.2) and \pkg{pgf} (at least 2.10) installations are up-to-date. Once your \TeX\ system meets these requirements, just load \pkg{pgfmolbio} as usual, i.\,e. by
313 %
314 % \DescribeMacro\usepackage[<module>]{pgfmolbio}
315 %
316 % The package is divided into \textit{modules}, each of which produces a certain type of graph. Currently, three \ometa{module}s are available:
317 % \begin{itemize}
318 % \item \module{chromatogram} (chapter~\ref{cha:Chromatogram}) allows you to draw DNA sequencing chromatograms obtained by the Sanger sequencing method.
319 % \item \module{domains} (chapter~\ref{cha:Domains}) provides macros for drawing protein domain diagrams and is also able to read domain information from files in Uniprot or general feature format.
320 % \item Furthermore, \module{convert} (chapter~\ref{cha:Convert}) is used with one of the modules above and generates ``pure'' \TikZ\ code suitable for \TeX\ engines lacking Lua support.
321 % \end{itemize}
322 %
323 % \DescribeMacro\pgfmolbioset[<module>]{<key-value list>}
324 % Fine-tunes the graphs produced by each \pkg{pgfmolbio} module. The possible keys are described in the sections on the respective modules.
325 %
326 %
327 %
328 %
329 % \chapter{The \texorpdfstring{\module{chromatogram}}{chromatogram} module}
330 % \label{cha:Chromatogram}
331 %
332 %
333 % \section{Overview}
334 % \label{sec:ChrOverview}
335 %
336 % The \module{chromatogram} module draws DNA sequencing chromatograms stored in standard chromatogram format (\file{scf}), which was developed by Simon Dear and Rodger Staden\footnote{Dear, S. and Staden, R. (1992). A standard file format for data from DNA sequencing instruments. \textit{DNA Seq.} \textbf{3}(2), 107--110.}. The documentation for the Staden package\footnote{\url{https://staden.sourceforge.net/}} describes the current version of the \file{scf} format in detail. As far as they are crucial to understanding the Lua code, we will discuss some details of this file format in the documented source code (section~\ref{sec:DocChrLua}). Note that \pkg{pgfmolbio} only supports \file{scf} version 3.00.
337 %
338 %
339 % \section{Drawing Chromatograms}
340 % \label{sec:ChrDrawingChromatograms}
341 %
342 % \DescribeMacro\pmbchromatogram[<key-value list>]{<scf file>}
343 % The \module{chromatogram} module defines a single command, which reads a chromatogram from an \meta{scf file} and draws it with routines from \TikZ\ (Example~\ref{exa:ChrTikzpicture}). The options, which are set in the \ometa{key-value list}, configure the appearance of the chromatogram. The following sections will elaborate on the available keys.
344 % \begin{exampletable}
345 % \caption{}
346 % \label{exa:ChrTikzpicture}
347 % \begin{examplecode}
348 % \begin{tikzpicture} % optional
349 % \pmbchromatogram{SampleScf.scf}
350 % \end{tikzpicture} % optional
351 % \end{examplecode}
352 % \end{exampletable}
353 %
354 % Although you will often put |\pmbchromatogram| into a |tikzpicture| environment, you may actually use the macro on its own. \pkg{pgfmolbio} checks whether the command is surrounded by a |tikzpicture| and adds this environment if necessary.
355 %
356 %
357 % \section{Displaying Parts of the Chromatogram}
358 % \label{sec:ChrDisplayingParts}
359 %
360 % \DescribeOption{chromatogram/}{sample range}{1-500 step 1}<lower>'-'<upper>[' step '<int>]\relax
361 % \opt{sample range} selects the part of the chromatogram which \pkg{pgfmolbio} should display. The value for this key consists of two or three parts, separated by the keywords |-| and |step|. The package will draw the chromatogram data between the \meta{lower} and \meta{upper} boundary. There are two ways of specifying these limits:
362 % \begin{enumerate}
363 % \item If you enter a number, \pkg{pgfmolbio} includes the data from the \meta{lower} to the \meta{upper} sample point (Example~\ref{exa:ChrLimitsSamplePoints}). A \textit{sample point} represents one measurement of the fluorescence signal along the time axis, where the first sample point has index 1. One peak comprises about 20 sample points.
364 % \begin{exampletable}
365 % \caption{}
366 % \label{exa:ChrLimitsSamplePoints}
367 % \begin{examplecode}
368 % \pmbchromatogram[sample range=200-600]{SampleScf.scf}
369 % \end{examplecode}
370 % \end{exampletable}
371 % \item If you enter the keyword |base| followed by an optional space and a number, the chromatogram starts or stops at the peak corresponding to the respective base. The first detected base peak has index 1. Compare Examples~\ref{exa:ChrLimitsSamplePoints} and~\ref{exa:ChrLimitsBases} to see the difference.
372 % \end{enumerate}
373 % The optional third part of the value for \opt{sample range} orders the package to draw every \ometa{int}th sample point. If your document contains large chromatograms or a great number of them, drawing fewer sample points increases typesetting time at the cost of image quality (Example~\ref{exa:ChrSampleStep}). Nevertheless, the key may be especially useful while optimizing the layout of complex chromatograms.
374 %
375 % \begin{exampletable}[p]
376 % \caption{}
377 % \label{exa:ChrLimitsBases}
378 % \begin{examplecode}
379 % \pmbchromatogram[%
380 % sample range=base 50-base60
381 % ]{SampleScf.scf}
382 % \end{examplecode}
383 % \end{exampletable}
384 %
385 % \begin{exampletable}[p]
386 % \caption{}
387 % \label{exa:ChrSampleStep}
388 % \pgfmolbioset[chromatogram]{canvas height=1cm}
389 % \begin{examplecode}
390 % \pmbchromatogram[%
391 % sample range=base 20-base 50 step 1
392 % ]{SampleScf.scf}
393 % \end{examplecode}
394 % \begin{examplecode}
395 % \pmbchromatogram[%
396 % sample range=base 20-base 50 step 2
397 % ]{SampleScf.scf}
398 % \end{examplecode}
399 % \begin{examplecode}
400 % \pmbchromatogram[%
401 % sample range=base 20-base 50 step 4
402 % ]{SampleScf.scf}
403 % \end{examplecode}
404 % \end{exampletable}
405 %
406 %
407 % \section{General Layout}
408 % \label{sec:ChrGeneralLayout}
409 %
410 % \DescribeOption{chromatogram/}{x unit}{0.2mm}<dimension>
411 % \DescribeOption{chromatogram/}{y unit}{0.01mm}<dimension>
412 % These keys set the horizontal distance between two consecutive sample points and the vertical distance between two fluorescence intensity values, respectively. Example~\ref{exa:Chrxyunit} illustrates how you can enlarge a chromatogram twofold by doubling these values.
413 % \begin{exampletable}
414 % \caption{}
415 % \label{exa:Chrxyunit}
416 % \begin{examplecode}
417 % \pmbchromatogram[%
418 % sample range=base 50-base 60,
419 % x unit=0.4mm,
420 % y unit=0.02mm
421 % ]{SampleScf.scf}
422 % \end{examplecode}
423 % \end{exampletable}
424
425 % \DescribeOption{chromatogram/}{samples per line}{500}<number>
426 % \DescribeOption{chromatogram/}{baseline skip}{3cm}<dimension>
427 % A new chromatogram ``line'' starts after \meta{number} sample points, and the baselines of adjacent lines (i.\,e., the $y$-value of fluorescence signals with zero intensity) are separated by \meta{dimension}. In Example~\ref{exa:ChrSamplesPerLine}, you see two lines, each of which contains 250 of the 500 sample points drawn. Furthermore, the baselines are 3.5~cm apart.
428 % \begin{exampletable}
429 % \caption{}
430 % \label{exa:ChrSamplesPerLine}
431 % \begin{examplecode}
432 % \begin{tikzpicture}%
433 % [decoration=brace]
434 % \pmbchromatogram[%
435 % sample range=401-900,
436 % samples per line=250,
437 % baseline skip=3.5cm
438 % ]{SampleScf.scf}
439 % \draw[decorate]
440 % (-0.1cm, -3.5cm) -- (-0.1cm, 0cm)
441 % node[pos=0.5, rotate=90, above=5pt]
442 % {baseline skip};
443 % \end{tikzpicture}
444 % \end{examplecode}
445 % \end{exampletable}
446 %
447 % \DescribeOption[/.style=]{chromatogram/}{canvas style}{draw=none, fill=none}<style>\newpage
448 % \DescribeOption{chromatogram/}{canvas height}{2cm}<dimension>
449 %
450 % The \textit{canvas} is the background of the trace area. Its left and right boundaries coincide with the start and the end of the chromatogram, respectively. Its lower boundary is the baseline, and its upper border is separated from the lower one by \meta{dimension}. Although the canvas is usually transparent, its \meta{style} can be changed. In Example~\ref{exa:ChrCanvasStyle}, we decrease the height of the canvas and color it light gray.
451 % \begin{exampletable}
452 % \caption{}
453 % \label{exa:ChrCanvasStyle}
454 % \begin{examplecode}
455 % \pmbchromatogram[%
456 % sample range=base 50-base 60,
457 % canvas style/.style={draw=none, fill=black!10},
458 % canvas height=1.6cm
459 % ]{SampleScf.scf}
460 % \end{examplecode}
461 % \end{exampletable}
462 %
463 %
464 % \section{Traces}
465 % \label{sec:ChrTraces}
466 %
467 % \DescribeOption[/.style=]{chromatogram/}{trace A style}{pmbTraceGreen}<style>
468 % \DescribeOption[/.style=]{chromatogram/}{trace C style}{pmbTraceBlue}<style>
469 % \DescribeOption[/.style=]{chromatogram/}{trace G style}{pmbTraceBlack}<style>
470 % \DescribeOption[/.style=]{chromatogram/}{trace T style}{pmbTraceRed}<style>
471 % \DescribeOption{chromatogram/}{trace style}{\textrm{(none)}}<style>
472 % The \textit{traces} indicate variations in fluorescence intensity during chromatography, and each trace corresponds to a base. The first four keys set the respective \meta{style} basewise, whereas \opt{trace style} changes all styles simultaneously. Note the syntax differences between \opt{trace style} and \opt{trace A style} etc. The standard styles simply color the traces; Table~\ref{tab:pmbColors} lists the color specifications.
473 %
474 % \begin{table}[h]
475 % \centering
476 % \caption{Colors defined by the \module{chromatogram} module.}
477 % \label{tab:pmbColors}
478 % \begin{tabular}{*3{>{\ttfamily}l}l}
479 % \toprule
480 % Name & \pkg{xcolor} model & Values & Example \\
481 % \midrule
482 % pmbTraceGreen & RGB & ~34, 114, ~46 & \color{pmbTraceGreen}\rule{3cm}{1ex} \\
483 % pmbTraceBlue & RGB & ~48, ~37, 199 & \color{pmbTraceBlue}\rule{3cm}{1ex} \\
484 % pmbTraceBlack & RGB & ~~0, ~~0, ~~0 & \color{pmbTraceBlack}\rule{3cm}{1ex} \\
485 % pmbTraceRed & RGB & 191, ~27, ~27 & \color{pmbTraceRed}\rule{3cm}{1ex} \\
486 % pmbTraceYellow & RGB & 233, 230, ~~0 & \color{pmbTraceYellow}\rule{3cm}{1ex} \\
487 % \bottomrule
488 % \end{tabular}
489 % \end{table}
490 %
491 % In Example~\ref{exa:ChrTraceStyle}, we change the style of all traces to a thin line and then add some patterns and colors to the A and T trace.
492 % \begin{exampletable}[h]
493 % \caption{}
494 % \label{exa:ChrTraceStyle}
495 % \begin{examplecode}
496 % \pmbchromatogram[%
497 % sample range=base 50-base 60,
498 % trace style=thin,
499 % trace A style/.append style={dashdotted, green},
500 % trace T style/.style={thick, dashed, purple}
501 % ]{SampleScf.scf}
502 % \end{examplecode}
503 % \end{exampletable}
504 %
505 % \DescribeOption{chromatogram/}{traces drawn}{ACGT}'A|C|G|T|'!\textrm{any combination thereof}!
506 % The value of this key governs which traces appear in the chromatogram. Any combination of the single-letter abbreviations for the standard bases will work. Example~\ref{exa:ChrTracesDrawn} only draws the cytosine and guanine traces.
507 % \begin{exampletable}
508 % \caption{}
509 % \label{exa:ChrTracesDrawn}
510 % \begin{examplecode}
511 % \pmbchromatogram[%
512 % sample range=base 50-base 60,
513 % traces drawn=CG
514 % ]{SampleScf.scf}
515 % \end{examplecode}
516 % \end{exampletable}
517 %
518 %
519 % \section{Ticks}
520 % \label{sec:ChrTicks}
521 %
522 % \DescribeOption[/.style=]{chromatogram/}{tick A style}{thin, pmbTraceGreen}<style>
523 % \DescribeOption[/.style=]{chromatogram/}{tick C style}{thin, pmbTraceBlue}<style>
524 % \DescribeOption[/.style=]{chromatogram/}{tick G style}{thin, pmbTraceBlack}<style>
525 % \DescribeOption[/.style=]{chromatogram/}{tick T style}{thin, pmbTraceRed}<style>
526 % \DescribeOption{chromatogram/}{tick style}{\textrm{(none)}}<style>
527 % \textit{Ticks} below the baseline indicate the maxima of the trace peaks. The first four keys set the respective \meta{style} basewise, whereas \opt{tick style} changes all styles simultaneously. Note the syntax differences between \opt{tick style} and \opt{tick A style} etc. Example~\ref{exa:ChrTickStyle} illustrates how one can draw thick ticks, which are red if they indicate a cytosine peak.
528 % \begin{exampletable}[ht]
529 % \caption{}
530 % \label{exa:ChrTickStyle}
531 % \begin{examplecode}
532 % \pmbchromatogram[%
533 % sample range=base 50-base 60,
534 % tick style=thick,
535 % tick C style/.append style={red}
536 % ]{SampleScf.scf}
537 % \end{examplecode}
538 % \end{exampletable}
539 %
540 % \DescribeOption{chromatogram/}{tick length}{1mm}<dimension>
541 % This key determines the length of each tick. In Example~\ref{exa:ChrTickLength}, the ticks are twice as long as usual.
542 % \begin{exampletable}
543 % \caption{}
544 % \label{exa:ChrTickLength}
545 % \begin{examplecode}
546 % \pmbchromatogram[%
547 % sample range=base 50-base 60,
548 % tick length=2mm
549 % ]{SampleScf.scf}
550 % \end{examplecode}
551 % \end{exampletable}
552 %
553 % \DescribeOption{chromatogram/}{ticks drawn}{ACGT}'A|C|G|T|'!\textrm{any combination thereof}!
554 % The value of this key governs which ticks appear in the chromatogram. Any combination of the single-letter abbreviations for the standard bases will work. Example~\ref{exa:ChrTicksDrawn} only displays the cytosine and guanine ticks.
555 % \begin{exampletable}
556 % \caption{}
557 % \label{exa:ChrTicksDrawn}
558 % \begin{examplecode}
559 % \pmbchromatogram[%
560 % sample range=base 50-base 60,
561 % ticks drawn=CG
562 % ]{SampleScf.scf}
563 % \end{examplecode}
564 % \end{exampletable}
565 %
566 %
567 % \section{Base Labels}
568 % \label{sec:ChrBaseLabels}
569 %
570 % \DescribeOption{chromatogram/}{base label A text}{\cs{strut} A}<text>
571 % \DescribeOption{chromatogram/}{base label C text}{\cs{strut} C}<text>
572 % \DescribeOption{chromatogram/}{base label G text}{\cs{strut} G}<text>
573 % \DescribeOption{chromatogram/}{base label T text}{\cs{strut} T}<text>
574 % \textit{Base labels} below each tick spell the nucleotide sequence deduced from the traces. By default, the \meta{text} that appears in these labels equals the single-letter abbreviation of the respective base. The |\strut| macro ensures equal vertical spacing. In Example~\ref{exa:ChrBaseLabelText}, we print lowercase letters beneath adenine and thymine.
575 % \begin{exampletable}
576 % \caption{}
577 % \label{exa:ChrBaseLabelText}
578 % \begin{examplecode}
579 % \pmbchromatogram[%
580 % sample range=base 50-base 60,
581 % base label A text=\strut a,
582 % base label T text=\strut t
583 % ]{SampleScf.scf}
584 % \end{examplecode}
585 % \end{exampletable}
586 %
587 % \DescribeOption[/.style=]{chromatogram/}{base label A style}{below=4pt, font=\cs{ttfamily}\cs{footnotesize}, pmbTraceGreen}<style>
588 % \DescribeOption[/.style=]{chromatogram/}{base label C style}{below=4pt, font=\cs{ttfamily}\cs{footnotesize}, pmbTraceBlue}<style>
589 % \DescribeOption[/.style=]{chromatogram/}{base label G style}{below=4pt, font=\cs{ttfamily}\cs{footnotesize}, pmbTraceBlack}<style>
590 % \DescribeOption[/.style=]{chromatogram/}{base label T style}{below=4pt, font=\cs{ttfamily}\cs{footnotesize}, pmbTraceRed}<style>
591 % \DescribeOption{chromatogram/}{base label style}{\textrm{(none)}}<style>
592 % The first four keys set the respective \meta{style} basewise, whereas \opt{base label style} changes all styles simultaneously. Each base label is a \TikZ\ node anchored to the lower end of the respective tick. Thus, the \meta{style} should contain placement keys such as |below| or |anchor=south|. Example~\ref{exa:ChrBaseLabelStyle} shows some (imaginative) base label styles.
593 % \begin{exampletable}
594 % \caption{}
595 % \label{exa:ChrBaseLabelStyle}
596 % \begin{examplecode}
597 % \pmbchromatogram[%
598 % sample range=base 50-base 60,
599 % base label style=%
600 % {below=2pt, font=\sffamily\footnotesize},
601 % base label T style/.append style=%
602 % {below=4pt, font=\tiny}
603 % ]{SampleScf.scf}
604 % \end{examplecode}
605 % \end{exampletable}
606 %
607 % \DescribeOption{chromatogram/}{base labels drawn}{ACGT}'A|C|G|T|'!\textrm{any combination thereof}!
608 % The value of this key governs which base labels appear in the chromatogram. Any combination of the single-letter abbreviations for the standard bases will work. Example~\ref{exa:ChrBaseLabelsDrawn} only displays cytosine and guanine base labels.
609 % \begin{exampletable}[ht]
610 % \caption{}
611 % \label{exa:ChrBaseLabelsDrawn}
612 % \begin{examplecode}
613 % \pmbchromatogram[%
614 % sample range=base 50-base 60,
615 % base labels drawn=CG
616 % ]{SampleScf.scf}
617 % \end{examplecode}
618 % \end{exampletable}
619 %
620 %
621 % \section{Base Numbers}
622 % \label{sec:ChrBaseNumbers}
623 %
624 % \DescribeOption{chromatogram/}{show base numbers}{true}<boolean>
625 % Turns the \textit{base numbers} on or off, which indicate the indices of the base peaks below the traces.
626 % \DescribeOption[/.style=]{chromatogram/}{base number style}{pmbTraceBlack, below=-3pt, font=\cs{sffamily}\cs{tiny}}<style>
627 % Determines the placement and appearance of the base numbers. Example~\ref{exa:ChrBaseNumberStyle} contains bold red base numbers that are shifted slightly upwards.
628 % \begin{exampletable}
629 % \caption{}
630 % \label{exa:ChrBaseNumberStyle}
631 % \begin{examplecode}
632 % \pmbchromatogram[%
633 % sample range=base 40-base 50,
634 % base number style/.style={below=-3pt,%
635 % font=\rmfamily\bfseries\tiny, red}
636 % ]{SampleScf.scf}
637 % \end{examplecode}
638 % \end{exampletable}
639 %
640 % \DescribeOption{chromatogram/}{base number range}{auto-auto step 10}<lower>'-'<upper>[' step '<interval>]
641 % This key decides that every \ometa{interval}th base number from \meta{lower} to \meta{upper} should show up in the output; the |step| part is optional. If you specify the keyword |auto| instead of a number for \meta{lower} or \meta{upper}, the base numbers start or finish at the leftmost or rightmost base peak shown, respectively. In Example~\ref{exa:ChrBaseNumberRange}, only peaks 42 to 46 receive a number.
642 % \begin{exampletable}
643 % \caption{}
644 % \label{exa:ChrBaseNumberRange}
645 % \begin{examplecode}
646 % \pmbchromatogram[%
647 % sample range=base 40-base 50,
648 % base number range=42-46 step 1,
649 % ]{SampleScf.scf}
650 % \end{examplecode}
651 % \end{exampletable}
652 %
653 %
654 % \section{Probabilities}
655 % \label{sec:ChrProbabilities}
656 %
657 % Programs such as \file{phred}\footnote{Ewing, B., Hillier, L., Wendl, M.\,C., and Green, P. (1998). Base-calling of automated sequencer traces using phred. I. Accuracy assessment. \textit{Genome Res.} \textbf{8}(3), 175--185.} assign a \textit{probability} or \textit{quality value} $Q$ to each called base after chromatography. $Q$ is calculated from the error probability $P_e$ by $Q = -10 \log_{10} P_e$. For example, a $Q$ value of 20 means that 1 in 100 base calls is wrong.
658 %
659 % \DescribeOption{chromatogram/}{probability distance}{0.8cm}<dimension>
660 % Sets the distance between the base probability rules and the baseline.
661 % \DescribeOption{chromatogram/}{probabilities drawn}{ACGT}'A|C|G|T|'!\textrm{any combination thereof}!
662 % Governs which probabilities appear in the chromatogram. Any combination of the single-letter abbreviations for the standard bases will work. In Example~\ref{exa:ChrProbabilities}, we shift the probability indicator upwards and only show the quality values of cytosine and thymine peaks.
663 % \begin{exampletable}
664 % \caption{}
665 % \label{exa:ChrProbabilities}
666 % \begin{examplecode}
667 % \pmbchromatogram[%
668 % sample range=base 10-base 30,
669 % probabilities drawn=CT,
670 % probability distance=1mm
671 % ]{SampleScf.scf}
672 % \end{examplecode}
673 % \end{exampletable}
674 %
675 % \DescribeOption{chromatogram/}{probability style function}{nil}<Lua function name>
676 % By default, the probability rules are colored black, red, yellow and green for quality scores $<10$, $<20$, $<30$ and $\geq30$, respectively. However, you can override this behavior by providing a \meta{Lua function name} to \opt{probability style function}. This Lua function must read a single argument of type number and return a string appropriate for the optional argument of \TikZ's |\draw| command. For instance, the function shown in Example~\ref{exa:ChrProbStyleFunction} determines the lowest and highest probability and colors intermediate values according to a red--yellow--green gradient.
677 % \begin{exampletable}[htp]
678 % \caption{}
679 % \label{exa:ChrProbStyleFunction}
680 % \begin{examplecode}
681 % \directlua{
682 % function probabilityGradient (prob)
683 % local minProb, maxProb = pmbChromatogram:getMinMaxProbability()
684 % local scaledProb = prob / maxProb * 100
685 % local color = ''
686 % if scaledProb < 50 then
687 % color = 'yellow!' .. scaledProb * 2 .. '!red'
688 % else
689 % color = 'green!' .. (scaledProb - 50) * 2 .. '!yellow'
690 % end
691 % return 'ultra thick, ' .. color
692 % end
693 % }
694 % \pmbchromatogram[%
695 % samples per line=1000,
696 % sample range=base 1-base 50,
697 % probability style function=probabilityGradient
698 % ]{SampleScf.scf}
699 % \end{examplecode}
700 % \end{exampletable}
701 %
702 %
703 % \section{Miscellaneous Keys}
704 % \label{sec:ChrMiscKeys}
705 %
706 % \DescribeOption{chromatogram/}{bases drawn}{ACGT}'A|C|G|T|'!\textrm{any combination thereof}!
707 % This key simultaneously sets \opt{traces drawn}, \opt{ticks drawn}, \opt{base labels drawn} and \opt{probabilities drawn} (see Example~\ref{exa:ChrBasesDrawn}).
708 % \begin{exampletable}[p]
709 % \caption{}
710 % \label{exa:ChrBasesDrawn}
711 % \begin{examplecode}
712 % \pmbchromatogram[%
713 % sample range=base 50-base 60,
714 % bases drawn=AC
715 % ]{SampleScf.scf}
716 % \end{examplecode}
717 % \end{exampletable}
718 %
719 %
720 %
721 % \chapter{The \texorpdfstring{\module{domains}}{domains} module}
722 % \label{cha:Domains}
723 %
724 % \section{Overview}
725 % \label{sec:DomOverview}
726 %
727 % Protein domain diagrams appear frequently in databases such as Pfam\footnote{Finn, R.\,D., Mistry, J. \textit{et al.} (2010). The Pfam protein families database. \textit{Nucleic Acids Res.} \textbf{38}, D211--D222.} or \textsc{prosite}\footnote{Sigrist, C.\,J.\,A., Cerutti, L. \textit{et al.} (2010). \textsc{prosite}, a protein domain database for functional characterization and annotation. \textit{Nucleic Acids Res.} \textbf{38}, D161--D166.}. Domain diagrams are often drawn using standard graphics software or tools such as \textsc{prosite}'s MyDomains image creator\footnote{\url{https://prosite.expasy.org/mydomains/}}. However, the \module{domains} module provides an integrated approach for generating domain diagrams from \TeX\ code or from external files.
728 %
729 %
730 % \section{Domain Diagrams and Their Features}
731 % \label{sec:DomDiagrams}
732 %
733 % \DescribeEnv[\meta{features}]{pmbdomains}[<key-value list>]{<sequence length>}
734 % Draws a domain diagram with the \meta{features} given. The \ometa{key-value list} configures its appearance. \meta{sequence length} is the total number of residues in the protein. (Although you must eventually specify a sequence length, you may actually leave the mandatory argument empty and use the \opt{sequence length} key instead; see section~\ref{sec:DomFileInput}).
735 %
736 % You can put a |pmbdomains| environment into a |tikzpicture|, but you also may use the environment on its own. \pkg{pgfmolbio} checks whether it is surrounded by a |tikzpicture| and adds this environment if necessary.
737 %
738 % \DescribeOption{domains/}{name}{Protein}<text>
739 % The name of the protein, which usually appears centered above the diagram.
740 %
741 % \DescribeOption{domains/}{show name}{true}<boolean>
742 % Determines whether both the name and sequence length are shown.
743 %
744 % \DescribeMacro\addfeature[<key-value list>]{<type>}{<start>}{<stop>}
745 % Adds a feature of the given \meta{type} to the current domain diagram (only defined inside |pmbdomains|). The feature spans the residues from \meta{start} to \meta{stop}. These arguments are either numbers, which refer to residues in the relative numbering scheme, or numbers in parentheses, which refer to absolute residue numbers (see section~\ref{sec:DomGeneralLayout}).
746 %
747 % \DescribeOption{domains/}{description}{\textrm{(none)}}<text>
748 % Sets the feature description (Example~\ref{exa:DomTikzpicture}).
749 %
750 % \begin{exampletable}
751 % \caption{}
752 % \label{exa:DomTikzpicture}
753 % \begin{examplecode}
754 % \begin{tikzpicture} % optional
755 % \begin{pmbdomains}[name=\TeX ase]{200}
756 % \addfeature{disulfide}{40}{129}
757 % \addfeature{disulfide}{53}{65}
758 % \addfeature[description=Domain 1]{domain}{30}{80}
759 % \addfeature[description=Domain 2]{domain}{93}{163}
760 % \addfeature{domain}{168}{196}
761 % \end{pmbdomains}
762 % \end{tikzpicture} % optional
763 % \end{examplecode}
764 % \end{exampletable}
765 %
766 %
767 % \section{General Layout}
768 % \label{sec:DomGeneralLayout}
769 %
770 % \DescribeOption{domains/}{x unit}{0.5mm}<dimension>
771 % The width of a single residue.
772 %
773 % \DescribeOption{domains/}{y unit}{6mm}<dimension>
774 % The height of a default \texttt{domain} feature.
775 %
776 % \DescribeOption{domains/}{residues per line}{200}<number>
777 % A new domain diagram ``line'' starts after \meta{number} residues.
778 %
779 % \DescribeOption{domains/}{baseline skip}{3}<factor>
780 % The baselines of consecutive lines (i.\,e., the main chain $y$-coordinates) are separated by \meta{factor} times the value of \opt{y unit}. In Example~\ref{exa:DomResiduesPerLine}, you see four lines, each of which contains up to 30~residues. Note how domains are correctly broken across lines. Furthermore, the baselines are $2 \times 4 = 8$~mm apart.
781 %
782 % \begin{exampletable}
783 % \caption{}
784 % \label{exa:DomResiduesPerLine}
785 % \begin{examplecode}
786 % \begin{pmbdomains}%
787 % [show name=false, x unit=2mm, y unit=4mm,
788 % residues per line=30, baseline skip=2]{110}
789 % \addfeature[description=Domain 1]{domain}{10}{23}
790 % \addfeature[description=Domain 2]{domain}{29}{71}
791 % \addfeature[description=Domain 3]{domain}{80}{105}
792 % \end{pmbdomains}
793 % \end{examplecode}
794 % \end{exampletable}
795 %
796 % \DescribeOption{domains/}{residue numbering}{auto}<numbering scheme>
797 % A protein's amino acid residues are usually numbered consecutively starting from~1. However, there are different numbering schemes. For example, residue numbering in a serine protease related to chymotrypsin typically follows the numbering in chymotrypsinogen\footnote{Bode, W., Mayr, I. \textit{et al.} (1989). The refined 1.9 Å crystal structure of human $\alpha$-thrombin: interaction with \textsc{d}-Phe-Pro-Arg chloromethylketone and significance of the Tyr-Pro-Pro-Trp insertion segment. \textit{EMBO J.} \textbf{8}(11), 3467--3475.}. The target protease sequence is aligned to the chymotrypsinogen sequence, and equivalent residues receive the same number. Insertions into the target sequence are indicated by appending letters to the last aligned residue (e.\,g., 186, \textit{186A}, \textit{186B}, 187), whereas gaps in the target sequence cause gaps in the numbering (e.\,g., 124, 125, 128, 129).
798 %
799 % In \pkg{pgfmolbio}, you can specify a relative \meta{numbering scheme} via the \opt{residue numbering} key. The keyword |auto| indicates that residues are numbered from 1 to (sequence length), i.\,e. absolute and relative numberings coincide. This is the case in all examples above. The complete syntax for the key is
800 % \begin{quote}
801 % \meta{numbering scheme} := \MacroArgs{<range>[','<range>', ...']}\\
802 % \meta{range} := \MacroArgs<start>'-'<end>' | '<start>\\
803 % \meta{start} := \MacroArgs<number>' | '<number><letter>\\
804 % \meta{end} := \MacroArgs<number>' | '<letter>
805 % \end{quote}
806 %
807 % Example~\ref{exa:DomResidueNumbering} shows a custom \meta{numbering scheme}, in this case for kallikrein-related peptidase 2 (KLK2), a chymotrypsin-like serine proteases. (In the following explanation, the subscripts `abs' and `rel' denote absolute and relative numbering, respectively).
808 % \begin{itemize}
809 % \item Residue 1\textsubscript{abs} is labeled 16\textsubscript{rel}, residue 2\textsubscript{abs} is labeled 17\textsubscript{rel} etc. until residue 24\textsubscript{abs}, which is labeled 39\textsubscript{rel} (range |16-39|).
810 % \item Residue 25\textsubscript{abs} corresponds to 41\textsubscript{rel} etc. until residue 57\textsubscript{abs}/73\textsubscript{rel} (range |41-73|).
811 % \item Residue 40\textsubscript{rel} is missing -- no residue in KLK2 is equivalent to residue 40 in chymotrypsinogen.
812 % \item An insertion of 11 amino acids follows residue 95\textsubscript{rel}. These residues are numbered from 95A\textsubscript{rel} to 95K\textsubscript{rel}. Note that both |95A-K| and |95A-95K| are valid ranges.
813 % \item The number of the last residue is 245A\textsubscript{rel}(range |245A|).
814 % \end{itemize}
815 %
816 % \begin{exampletable}
817 % \caption{}
818 % \label{exa:DomResidueNumbering}
819 % \begin{examplecode}
820 % \begin{pmbdomains}[%
821 % sequence=IVGGWECEKHSQPWQVAVYSHGWAHCGGVLVHPQWVLTAAHCLK%
822 % KNSQVWLGRHNLFEPEDTGQRVPVSHSFPHPLYNMSLLKHQSLRPDEDSSH%
823 % DLMLLRLSEPAKITDVVKVLGLPTQEPALGTTCYASGWGSIEPEEFLRPRS%
824 % LQCVSLHLLSNDMCARAYSEKVTEFMLCAGLWTGGKDTCGGDSGGPLVCNG%
825 % VLQGITSWGPEPCALPEKPAVYTKVVHYRKWIKDTIAANP,
826 % residue numbering={16-39,41-73,75-95,95A-K,96-125,%
827 % 128-186,186A-186B,187-203,208-223,223A,224-245,245A},
828 % x unit=4mm,
829 % residues per line=40,
830 % show name=false,
831 % ruler range=auto-auto step 1,
832 % ruler distance=-.3,
833 % baseline skip=2
834 % ]{237}
835 % \setfeaturestyle{other/main chain}{*1{draw, line width=2pt, black!10}}
836 % \addfeature{other/sequence}{16}{245A}
837 % \end{pmbdomains}
838 % \end{examplecode}
839 % \end{exampletable}
840 %
841 % \DescribeOption{domains/}{residue range}{auto-auto}<lower>'-'<upper>
842 % All residues from \meta{lower} to \meta{upper} will appear in the output. Possible values for \meta{lower} and \meta{upper} are:
843 % \begin{itemize}
844 % \item |auto|, which indicates the first or last residue, respectively;
845 % \item a plain number, which denotes a residue in the \textit{relative} numbering scheme set by \opt{residue numbering};
846 % \item a parenthesized number, which denotes a residue in the \textit{absolute} numbering scheme.
847 % \end{itemize}
848 % In Example~\ref{exa:DomResidueRange}, only residues 650\textsubscript{abs} to 850\textsubscript{rel} are shown. If a domain boundary lies outside of the range shown, only the appropriate part of the domain appears.
849 %
850 % \begin{exampletable}
851 % \caption{}
852 % \label{exa:DomResidueRange}
853 % \begin{examplecode}
854 % \begin{pmbdomains}[%
855 % show name=false, residue range=(650)-850,
856 % residue numbering={1-500,601-1100}]{1000}
857 % \addfeature[description=Domain 1]{domain}{(630)}{(660)}
858 % \addfeature[description=Domain 2]{domain}{(680)}{(710)}
859 % \addfeature[description=Domain 3]{domain}{840}{1000}
860 % \addfeature[description=Domain 4 (invisible)]{domain}{1010}{1040}
861 % \end{pmbdomains}
862 % \end{examplecode}
863 % \end{exampletable}
864 %
865 % \DescribeOption{domains/}{enlarge left}{0cm}<dimension>
866 % \DescribeOption{domains/}{enlarge right}{0cm}<dimension>
867 % \DescribeOption{domains/}{enlarge top}{1cm}<dimension>
868 % \DescribeOption{domains/}{enlarge bottom}{0cm}<dimension>
869 % % \pkg{pgfmolbio} clips features that would protrude into the left or right margin. However, limits in the \TikZ\ clipping mechanism prevent correct automatic updates of the bounding box for the domain diagram. Although the package tries hard to establish a bounding box that is sufficiently large, the process may require manual intervention. To this end, each \opt{enlarge ...} key enlarges the bounding box at the respective side (Example~\ref{exa:DomEnlargeBB}).
870 %
871 % \begin{exampletable}
872 % \caption{}
873 % \label{exa:DomEnlargeBB}
874 % \begin{examplecode}
875 % \tikzset{%
876 % baseline, tight background,%
877 % background rectangle/.style={draw=red, thick}%
878 % }
879 % \pgfmolbioset[domains]{show name=false, y unit=1cm, show ruler=false}
880 %
881 % \begin{tikzpicture}[show background rectangle]
882 % \begin{pmbdomains}{80}
883 % \addfeature[description=Oops!]{domain}{20}{60}
884 % \end{pmbdomains}
885 % \end{tikzpicture}
886 % \begin{tikzpicture}[show background rectangle]
887 % \begin{pmbdomains}[enlarge bottom=-5mm]{80}
888 % \addfeature[description=Better!]{domain}{20}{60}
889 % \end{pmbdomains}
890 % \end{tikzpicture}
891 % \end{examplecode}
892 % \end{exampletable}
893 %
894 %
895 % \section{Feature Styles and Shapes}
896 % \label{sec:DomFeatureStylesAndShapes}
897 %
898 % Each (implicit and explicit) feature of a domain chart has a certain \textit{shape} and \textit{style}. For instance, you can see five different feature \textit{shapes} in Example~\ref{exa:DomTikzpicture}: We explicitly added two features of shape (and type) \texttt{disulfide} and three features of shape \texttt{domain}. Furthermore, the package implicitly included features of shape \texttt{other/name}, \texttt{other/main chain} and \texttt{other/ruler}.
899 %
900 % Although the three \texttt{domain} features agree in shape, they differ in color, or (more generally) \textit{style}. Since \pkg{pgfmolbio} distinguishes between shapes and styles, you may draw equally shaped features with different colors, strokes, shadings etc.
901 %
902 % \DescribeMacro\setfeaturestyle{<type>}{<style list>}
903 % Specifies a \meta{style list} for the given feature \meta{type}. The complete syntax ist
904 %
905 % \begin{quote}
906 % \meta{style list} := \MacroArgs{<style list item>[','<style list item>', ...']}\\
907 % \meta{style list item} := \MacroArgs<multiplier><style>\\
908 % \meta{multiplier} := \MacroArgs['*'<number>]\\
909 % \meta{style} := \MacroArgs<single key-value pair>' | '{<key-value list>}
910 % \end{quote}
911 %
912 % A style list item of the general form |*|\meta{n}|{|\meta{style}|}| instructs the package to repeat the \meta{style} \meta{n}-times. (This syntax is reminiscent of column specifications in a |tabular| environment. However, do \textit{not} enclose numbers with more than one digit in curly braces!) You may omit the trivial multiplier |*1|, but never forget the curly braces surrounding a \meta{style} that contains two or more key-value pairs. Furthermore, \pkg{pgfmolbio} loops over the style list until all features have been drawn.
913 %
914 % For instance, the style list in Example~\ref{exa:DomFeatureStyle} fills the first feature red, then draws a green one with a thick stroke, and finally draws two dashed blue features.
915 %
916 % \begin{exampletable}
917 % \caption{}
918 % \label{exa:DomFeatureStyle}
919 % \begin{examplecode}
920 % \begin{pmbdomains}[show name=false]{200}
921 % \setfeaturestyle{domain}%
922 % {fill=red, {thick, fill=green}, *2{blue, dashed}}
923 % \addfeature{domain}{11}{30}
924 % \addfeature{domain}{41}{60}
925 % \addfeature{domain}{71}{90}
926 % \addfeature{domain}{101}{120}
927 % \addfeature{domain}{131}{150}
928 % \addfeature{domain}{161}{180}
929 % \addfeature{domain}{191}{200}
930 % \end{pmbdomains}
931 % \end{examplecode}
932 % \end{exampletable}
933
934 % \DescribeOption{domains/}{style}{\textrm{(empty)}}<style>
935 % Although |\setfeaturestyle| may appear in a |pmbdomains| environment, changes introduced in this way are not limited to the current \TeX\ group (since feature styles are stored in Lua variables). Instead, use the \opt{style} key to locally override a feature style (Example~\ref{exa:DomFeatureStyleKey}).
936 %
937 % \begin{exampletable}
938 % \caption{}
939 % \label{exa:DomFeatureStyleKey}
940 % \begin{examplecode}
941 % \begin{pmbdomains}[show name=false]{100}
942 % \addfeature{domain}{11}{30}
943 % \begingroup
944 % \setfeaturestyle{domain}{{thick, fill=red}}
945 % \addfeature{domain}{41}{60}
946 % \endgroup
947 % \addfeature{domain}{71}{90} % the new style persists ...
948 % \end{pmbdomains}
949 %
950 % \begin{pmbdomains}[show name=false]{100}
951 % \addfeature{domain}{11}{30}
952 % \addfeature[style={thick, fill=red}]{domain}{41}{60}
953 % \addfeature{domain}{71}{90} % correct solution
954 % \end{pmbdomains}
955 % \end{examplecode}
956 % \end{exampletable}
957 %
958 % \DescribeMacro\setfeaturestylealias{<new type>}{<existing type>}
959 % After calling this macro, the \meta{new type} and \meta{existing type} share a common style, while they still differ in their shapes.
960 %
961 % \DescribeMacro\setfeatureshape{<type>}{<TikZ code>}\relax
962 % Defines a new feature shape named \meta{type} or changes an existing one. \textbf{Caution:} If you change a shape within |pmbdomains|, you will also change the features of equal type that you already added. Thus, it is best to use |\setfeatureshape| only outside of this environment.
963 %
964 % \begin{exampletable}[p]
965 % \caption{}
966 % \label{exa:DomFeatureShape1}
967 % \begin{examplecode}
968 % \setfeatureshape{domain}{%
969 % \draw [/pgfmolbio/domains/current style]
970 % (\xLeft, \yMid + .5 * \pmbdomvalueof{y unit}) rectangle
971 % (\xRight, \yMid - .5 * \pmbdomvalueof{y unit});
972 % \node at (\xMid, \yMid) {\pmbdomvalueof{description}};
973 % }
974 %
975 % \begin{pmbdomains}[show name=false]{200}
976 % \addfeature[description=Domain 1]{domain}{30}{80}
977 % \addfeature[description=Domain 2]{domain}{93}{163}
978 % \addfeature[description=Domain 3]{domain}{168}{196}
979 % \end{pmbdomains}
980 % \end{examplecode}
981 % \end{exampletable}
982 %
983 % \begin{exampletable}[p]
984 % \caption{}
985 % \label{exa:DomFeatureShape2}
986 % \begin{examplecode}
987 % \setfeatureshape{domain}{%
988 % \pgfmathsetmacro\middlecorners{%
989 % \xLeft + (\xRight - \xLeft) * .618%
990 % }
991 % \draw [/pgfmolbio/domains/current style]
992 % (\xLeft, \yMid + 2mm) --
993 % (\middlecorners pt, \yMid + 3mm) --
994 % (\xRight, \yMid) --
995 % (\middlecorners pt, \yMid - 3mm) --
996 % (\xLeft, \yMid - 2mm) --
997 % cycle;
998 % }
999 %
1000 % \begin{pmbdomains}[show name=false]{200}
1001 % \addfeature[description=Domain 1]{domain}{30}{80}
1002 % \addfeature[description=Domain 2]{domain}{93}{163}
1003 % \addfeature[description=Domain 3]{domain}{168}{196}
1004 % \end{pmbdomains}
1005 % \end{examplecode}
1006 % \end{exampletable}
1007 %
1008 % \begin{exampletable}
1009 % \caption{}
1010 % \label{exa:DomFeatureShape3}
1011 % \begin{examplecode}
1012 % \pgfdeclareverticalshading[bordercolor,middlecolor]{mydomain}{100bp}{
1013 % color(0bp)=(bordercolor);
1014 % color(25bp)=(bordercolor);
1015 % color(40bp)=(middlecolor);
1016 % color(60bp)=(middlecolor);
1017 % color(75bp)=(bordercolor);
1018 % color(100bp)=(bordercolor)
1019 % }
1020 %
1021 % \tikzset{%
1022 % domain middle color/.code=\colorlet{middlecolor}{#1},%
1023 % domain border color/.code=\colorlet{bordercolor}{#1}%
1024 % }
1025 %
1026 % \setfeatureshape{domain}{%
1027 % \draw [shading=mydomain, rounded corners=2mm,
1028 % /pgfmolbio/domains/current style]
1029 % (\xLeft, \yMid + .5 * \pmbdomvalueof{y unit}) rectangle
1030 % (\xRight, \yMid - .5 * \pmbdomvalueof{y unit});
1031 % \node [above=3mm] at (\xMid, \yMid)
1032 % {\pmbdomvalueof{domain font}{\pmbdomvalueof{description}}};
1033 % }
1034 %
1035 % \begin{pmbdomains}[show name=false]{200}
1036 % \setfeaturestyle{domain}{%
1037 % {domain middle color=yellow!85!orange,%
1038 % domain border color=orange},%
1039 % {domain middle color=green,%
1040 % domain border color=green!50!black}%
1041 % {domain middle color=cyan,%
1042 % domain border color=cyan!50!black}%
1043 % }
1044 % \addfeature[description=Domain 1]{domain}{30}{80}
1045 % \addfeature[description=Domain 2]{domain}{93}{163}
1046 % \addfeature[description=Domain 3]{domain}{168}{196}
1047 % \end{pmbdomains}
1048 % \end{examplecode}
1049 % \end{exampletable}
1050 %
1051 % Several commands that are only available in the \meta{TikZ code} allow you to design generic feature shapes:
1052 % \begin{itemize}
1053 % \item |\xLeft|, |\xMid| and |\xRight| expand to the left, middle and right $x$-coordinate of the feature. The coordinates are in a format suitable for |\draw| and similar commands.
1054 % \item |\yMid| expands to the $y$-coordinate of the feature, i.\,e. the $y$-coordinate of the current line.
1055 % \item You can access any values stored in the package’s \meta{key}s with the macro |\pmbdomvalueof{|\meta{key}|}|.
1056 % \item The style key \opt{/pgfmolbio/domains/current style} represents the current feature style selected from the associated style list.
1057 % \end{itemize}
1058 % The commands above are available for all features. By contrast, the following macros are limited to certain feature types:
1059 % \begin{itemize}
1060 % \item |\featureSequence| provides the amino acid sequence of the current feature. This macro is only available for explicitly added features and for \texttt{other/main chain}.
1061 % \item |\residueNumber| equals the current residue number. This macro is only available for shape \texttt{other/ruler} (see section~\ref{sec:DomRuler}).
1062 % \item |\currentResidue| expands to a single letter amino acid abbreviation. This macro is only available for shape \texttt{other/sequence} (see section~\ref{sec:DomSequences}).
1063 % \end{itemize}
1064 %
1065 % In Example~\ref{exa:DomFeatureShape1}, we develop a simple \texttt{domain} shape, which is a rectangle containing a centered label with the feature description. Example~\ref{exa:DomFeatureShape2} calculates an additional coordinate for a pentagonal domain shape and stores this coordinate in |\middlecorners|. Note that you have to insert ``pt'' after |\middlecorners| when using the stored coordinate. The domains in Example~\ref{exa:DomFeatureShape3} display a custom shading and inherit their style from the style list.
1066 %
1067 % \DescribeMacro\setfeatureshapealias{<new type>}{<existing type>}
1068 % After calling this macro, the \meta{new type} and \meta{existing type} share a common shape, while they still differ in their styles.
1069 %
1070 % \DescribeMacro\setfeaturealias{<new type>}{<existing type>}
1071 % This is a shorthand for calling both |\setfeatureshape| and |\setfeaturestyle|.
1072 %
1073 %
1074 % \section{Standard Features}
1075 % \label{sec:DomStandardFeatures}
1076 %
1077 % \pkg{pgfmolbio} provides a range of standard features. This section explains simple features (i.\,e., those that support no or only few options), while later sections cover advanced ones. Some features include predefined aliases, which facilitate inclusion of external files (see section~\ref{sec:DomFileInput}).
1078 %
1079 % \DescribeFeature*{default}
1080 % A fallback for undefined features, in which case \TeX\ issues a warning (Example~\ref{exa:DomFeatureDefault}).
1081 %
1082 % \begin{exampletable}
1083 % \caption{}
1084 % \label{exa:DomFeatureDefault}
1085 % \begin{examplecode}
1086 % \begin{pmbdomains}[show name=false]{100}
1087 % \addfeature{default}{21}{50}
1088 % \addfeature{unknown}{61}{90} % i.e. default shape/style
1089 % \end{pmbdomains}
1090 % \end{examplecode}
1091 % \end{exampletable}
1092 %
1093 % \DescribeFeature{domain}{DOMAIN}
1094 % A generic feature for protein domains. It consists of a rectangle with rounded corners and a label in the center, which shows the value of \opt{description}.
1095 %
1096 % \DescribeOption{domains/}{domain font}{\string\footnotesize}<font commands>
1097 % Sets the font for the label of a \texttt{domain} feature. The last command may take a single argument (Example~\ref{exa:DomFeatureDomain}).
1098 %
1099 % \begin{exampletable}
1100 % \caption{}
1101 % \label{exa:DomFeatureDomain}
1102 % \begin{examplecode}
1103 % \begin{pmbdomains}[show name=false]{100}
1104 % \addfeature[description=Domain 1]{domain}{21}{50}
1105 % \addfeature[description=Domain 2,%
1106 % domain font=\tiny\textit]{DOMAIN}{61}{90}
1107 % \end{pmbdomains}
1108 % \end{examplecode}
1109 % \end{exampletable}
1110 %
1111 % \DescribeFeature{signal peptide}{SIGNAL}
1112 % Adds a signal peptide (Example~\ref{exa:DomFeatureProSignal}).
1113 %
1114 % \DescribeFeature{propeptide}{PROPEP}
1115 % Adds a propeptide (Example~\ref{exa:DomFeatureProSignal}).
1116 %
1117 % \begin{exampletable}
1118 % \caption{}
1119 % \label{exa:DomFeatureProSignal}
1120 % \begin{examplecode}
1121 % \begin{pmbdomains}[show name=false]{100}
1122 % \addfeature{signal peptide}{1}{15}
1123 % \addfeature{propeptide}{16}{50}
1124 % \end{pmbdomains}
1125 % \end{examplecode}
1126 % \end{exampletable}
1127 %
1128 % \DescribeFeature{carbohydrate}{CARBOHYD}
1129 % Adds glycosylation (Example~\ref{exa:DomFeatureCarbohyd}).
1130 %
1131 % \begin{exampletable}
1132 % \caption{}
1133 % \label{exa:DomFeatureCarbohyd}
1134 % \begin{examplecode}
1135 % \begin{pmbdomains}[show name=false]{100}
1136 % \addfeature[description=GlcNAc]{carbohydrate}{25}{25}
1137 % \addfeature[description=Xyl]{CARBOHYD}{60}{60}
1138 % \addfeature[description=Domain 1]{domain}{21}{50}
1139 % \end{pmbdomains}
1140 % \end{examplecode}
1141 % \end{exampletable}
1142 %
1143 % \DescribeFeature*{other/main chain}
1144 % This feature is automatically added to the feature list at the end of each |pmbdomains| environment. It represents the protein main chain, which appears as a grey line by default. Nevertheless, you can alter the backbone just like any other feature (Example~\ref{exa:DomFeatureMainchain}).
1145 %
1146 % \begin{exampletable}[p]
1147 % \caption{}
1148 % \label{exa:DomFeatureMainchain}
1149 % \begin{examplecode}
1150 % \setfeatureshape{other/main chain}{%
1151 % \draw [/pgfmolbio/domains/current style]
1152 % (\xLeft, \yMid + .5 * \pmbdomvalueof{y unit}) rectangle
1153 % (\xRight, \yMid - .5 * \pmbdomvalueof{y unit});
1154 % \draw (\xLeft, \yMid) --
1155 % (\xLeft - 2mm, \yMid)
1156 % node [left] {\tiny H$_2$N};
1157 % \draw (\xRight, \yMid) --
1158 % (\xRight + 2mm, \yMid)
1159 % node [right] {\tiny COOH};
1160 % }
1161 % \begin{pmbdomains}%
1162 % [show name=false, enlarge left=-0.8cm, enlarge right=1.2cm]{100}
1163 % \setfeaturestyle{other/main chain}{{draw=black,fill=black!20}}
1164 % \addfeature[description=1]{domain}{10}{25}
1165 % \addfeature[description=2]{domain}{30}{55}
1166 % \end{pmbdomains}
1167 % \end{examplecode}
1168 % \end{exampletable}
1169 %
1170 % \DescribeFeature*{other/name}
1171 % This feature is automatically added to the feature list at the end of each |pmbdomains| environment. It relates to the protein name, which is normally displayed at the top center of the chart, together with the number of residues (Example~\ref{exa:DomFeatureName}). The following auxiliary commands are available for the feature style \TikZ\ code: |\xLeft|, |\xMid|, |\xRight| and \opt{current style}.
1172 %
1173 % \begin{exampletable}[p]
1174 % \caption{}
1175 % \label{exa:DomFeatureName}
1176 % \begin{examplecode}
1177 % \setfeatureshape{other/name}{%
1178 % \node [/pgfmolbio/domains/current style]
1179 % at (\xLeft, \pmbdomvalueof{baseline skip}
1180 % * \pmbdomvalueof{y unit} / 2)
1181 % {A \pmbdomvalueof{sequence length} residues long protein
1182 % called `\pmbdomvalueof{name}'};
1183 % }
1184 % \begin{pmbdomains}[name=\TeX ase]{150}
1185 % \setfeaturestyle{other/name}{{font=\bfseries, right}}
1186 % \addfeature[description=1]{domain}{10}{25}
1187 % \addfeature[description=2]{domain}{55}{123}
1188 % \end{pmbdomains}
1189 % \end{examplecode}
1190 % \end{exampletable}
1191 %
1192 %
1193 % \section{Disulfides and Ranges}
1194 % \label{sec:DomDisulfides}
1195 %
1196 % \DescribeFeature{disulfide}{DISULFID}
1197 % \pkg{pgfmolbio} indicates disulfide bridges by brackets above the main chain. Since disulfides are often interleaved in linear representations of proteins, the package automatically stacks them in order to avoid overlaps (Example~\ref{exa:DomFeatureDisulfide}).
1198 %
1199 % \DescribeOption{domains/}{level}{\textrm{(empty)}}<number>
1200 % Manually sets the level of a disulfide feature.
1201 %
1202 % \DescribeOption{domains/}{disulfide base distance}{1}<number>
1203 % The distance (as a multiple of $y$-units) between the main chain and the first level.
1204 %
1205 % \DescribeOption{domains/}{disulfide level distance}{.2}<number>
1206 % The space (as a multiple of $y$-units) between levels (see the figure below).
1207 %
1208 % \begin{center}
1209 % \begin{tikzpicture}[decoration=brace]
1210 % \begin{pmbdomains}[show name=false, disulfide level distance=.6]{100}
1211 % \setfeaturestyle{disulfide}{draw=red, draw=blue, draw=violet}
1212 % \addfeature{disulfide}{2}{10}
1213 % \addfeature{disulfide}{5}{50}
1214 % \addfeature{disulfide}{8}{15}
1215 % \addfeature{disulfide}{20}{45}
1216 % \addfeature[level=1]{disulfide}{70}{85}
1217 % \addfeature[level=1]{disulfide}{80}{92}
1218 % \addfeature{domain}{25}{60}
1219 % \draw [dashed, black!80]
1220 % (-5 * \pmbdomvalueof{x unit},
1221 % \pmbdomvalueof{disulfide base distance} * \pmbdomvalueof{y unit}) --
1222 % (105 * \pmbdomvalueof{x unit},
1223 % \pmbdomvalueof{disulfide base distance} * \pmbdomvalueof{y unit})
1224 % node [right] {\small Level 1};
1225 % \draw [dashed, black!60]
1226 % (-5 * \pmbdomvalueof{x unit},
1227 % \pmbdomvalueof{disulfide base distance} * \pmbdomvalueof{y unit} +
1228 % \pmbdomvalueof{disulfide level distance} * \pmbdomvalueof{y unit}) --
1229 % (105 * \pmbdomvalueof{x unit},
1230 % \pmbdomvalueof{disulfide base distance} * \pmbdomvalueof{y unit} +
1231 % \pmbdomvalueof{disulfide level distance} * \pmbdomvalueof{y unit})
1232 % node [right] {\small Level 2};
1233 % \draw [dashed, black!40]
1234 % (-5 * \pmbdomvalueof{x unit},
1235 % \pmbdomvalueof{disulfide base distance} * \pmbdomvalueof{y unit} +
1236 % 2 * \pmbdomvalueof{disulfide level distance} * \pmbdomvalueof{y unit}) --
1237 % (105 * \pmbdomvalueof{x unit},
1238 % \pmbdomvalueof{disulfide base distance} * \pmbdomvalueof{y unit} +
1239 % 2 * \pmbdomvalueof{disulfide level distance} * \pmbdomvalueof{y unit})
1240 % node [right] {\small Level 3};
1241 % \draw [decorate]
1242 % (-6 * \pmbdomvalueof{x unit},
1243 % 0) --
1244 % (-6 * \pmbdomvalueof{x unit},
1245 % \pmbdomvalueof{disulfide base distance} * \pmbdomvalueof{y unit})
1246 % node [pos=.5, left] {\small\texttt{disulfide base distance}};
1247 % \draw [decorate]
1248 % (-6 * \pmbdomvalueof{x unit},
1249 % \pmbdomvalueof{disulfide base distance} * \pmbdomvalueof{y unit} +
1250 % \pmbdomvalueof{disulfide level distance} * \pmbdomvalueof{y unit}) --
1251 % (-6 * \pmbdomvalueof{x unit},
1252 % \pmbdomvalueof{disulfide base distance} * \pmbdomvalueof{y unit} +
1253 % 2 * \pmbdomvalueof{disulfide level distance} * \pmbdomvalueof{y unit})
1254 % node [pos=.5, left] {\small\texttt{disulfide level distance}};
1255 % \end{pmbdomains}
1256 % \end{tikzpicture}
1257 % \end{center}
1258 %
1259 % \begin{exampletable}
1260 % \caption{}
1261 % \label{exa:DomFeatureDisulfide}
1262 % \begin{examplecode}
1263 % \begin{pmbdomains}[show name=false,
1264 % disulfide base distance=.7,
1265 % disulfide level distance=.4]{100}
1266 % \setfeaturestyle{disulfide}{draw=red, draw=blue, draw=violet}
1267 % \addfeature{disulfide}{2}{10}
1268 % \addfeature{disulfide}{5}{50}
1269 % \addfeature{disulfide}{8}{15}
1270 % \addfeature{disulfide}{20}{45}
1271 % \addfeature[level=1]{disulfide}{70}{85}
1272 % \addfeature[level=1]{disulfide}{80}{92}
1273 % \addfeature{domain}{25}{60}
1274 % \end{pmbdomains}
1275 % \end{examplecode}
1276 % \end{exampletable}
1277 %
1278 % \begin{DescribeMacros}
1279 % \Macro\setdisulfidefeatures{<key list>}
1280 % \Macro\adddisulfidefeatures{<key list>}
1281 % \Macro\removedisulfidefeatures{<key list>}
1282 % \end{DescribeMacros}
1283 % These macros edit the list of ``disulfide-like'' features, i.\,e. those subject to the automatic stacking mechanism. |\setdisulfidefeatures| renews this list, replacing any previous contents. |\adddisulfidefeatures| adds the features in its \meta{key list} to an existing list, while |\removedisulfidefeatures| removes selected features. By default, there are three disulfide-like features: \texttt{disulfide}, \texttt{DISULFID} and \texttt{range}. Note that |\setfeaturealias| and its relatives do not influence the list.
1284 %
1285 % \DescribeFeature*{range}
1286 % Indicates a range of residues. \texttt{range} features are disulfide-like in order to prevent them from overlapping.
1287 %
1288 % \DescribeOption{domains/}{range font}{\string\sffamily\string\scriptsize}<font commands>
1289 % Changes the font for the range label. The last command may take a single argument (Example~\ref{exa:DomFeatureRange}).
1290 %
1291 % \begin{exampletable}
1292 % \caption{}
1293 % \label{exa:DomFeatureRange}
1294 % \begin{examplecode}
1295 % \begin{pmbdomains}[show name=false]{100}
1296 % \addfeature[description=1]{domain}{10}{25}
1297 % \addfeature[description=2]{domain}{40}{70}
1298 % \addfeature[description=Range 1]{range}{15}{30}
1299 % \addfeature[description=Range 2]{range}{25}{60}
1300 % \addfeature[description=Range 3,%
1301 % style={very thick, draw=black},%
1302 % range font=\tiny\textcolor{red}]{range}{68}{86}
1303 % \end{pmbdomains}
1304 % \end{examplecode}
1305 % \end{exampletable}
1306 %
1307 %
1308 % \section{Ruler}
1309 % \label{sec:DomRuler}
1310 %
1311 % \DescribeFeature*{other/ruler}
1312 % This feature is automatically added to the feature list at the end of each |pmbdomains| environment. It draws a ruler below the main chain, which indicates the residue numbers (Example~\ref{exa:DomFeatureRuler}). The following auxiliary commands are available for the feature style \TikZ\ code: |\xMid|, |\yMid|, |\residueNumber| and \opt{current style}.
1313 %
1314 % \DescribeOption{domains/}{show ruler}{true}<boolean>
1315 % Determines whether the rule is drawn.
1316 %
1317 % \DescribeOption{domains/}{ruler range}{auto-auto}<ruler range list>
1318 % The complete syntax for \opt{ruler range} is
1319 % \begin{quote}
1320 % \meta{ruler range list} := \MacroArgs{<ruler range>[','<ruler range>', ...']}\\
1321 % \meta{ruler range} := \MacroArgs<lower>'-'<upper>[' step '<interval>]\\
1322 % \meta{lower} := \MacroArgs'auto | '<number>[<letter>]' | '(<number>)\\
1323 % \meta{upper} := \MacroArgs'auto | '<number>[<letter>]' | '(<number>)\\
1324 % \meta{interval} := \MacroArgs<number>
1325 % \end{quote}
1326 % Each \meta{ruler range} tells the package to mark every \ometa{interval}th residue from \meta{lower} to \meta{upper} by an \texttt{other/ruler} feature; the |step| part is optional. Possible values for \meta{lower} and \meta{upper} are:
1327 % \begin{itemize}
1328 % \item |auto|, which indicates the leftmost or rightmost residue shown, respectively;
1329 % \item a plain number (with an optional letter), which denotes a residue in the \textit{relative} numbering scheme set by \opt{residue numbering};
1330 % \item a parenthesized number, which denotes a residue in the \textit{absolute} numbering scheme.
1331 % \end{itemize}
1332 %
1333 % \DescribeOption{domains/}{default ruler step size}{50}<number>
1334 % Step size for a \meta{ruler range} that lacks the optional |step| part.
1335 %
1336 % \DescribeOption{domains/}{ruler distance}{-.5}<factor>
1337 % Separation (multiples of the $y$-unit) between ruler and main chain (Example~\ref{exa:DomFeatureRuler}).
1338 %
1339 % \begin{exampletable}
1340 % \caption{}
1341 % \label{exa:DomFeatureRuler}
1342 % \begin{examplecode}
1343 % \begin{pmbdomains}[x unit=2mm,
1344 % show name=false,
1345 % residue numbering={1-40,101-120},
1346 % ruler range={auto-10 step 1, 31-(41), 110-120 step 2},
1347 % default ruler step size=5,
1348 % ruler distance=-.7]{60}
1349 % \addfeature{domain}{10}{25}
1350 % \addfeature{domain}{40}{(50)}
1351 % \end{pmbdomains}
1352 % \end{examplecode}
1353 % \end{exampletable}
1354 %
1355 %
1356 % \section{Sequences}
1357 % \label{sec:DomSequences}
1358 %
1359 % \DescribeOption{domains/}{sequence}{\textrm{empty}}<sequence>
1360 % Sets the amino acid \meta{sequence} of a protein (single-letter abbreviations).
1361 %
1362 % \DescribeFeature*{other/sequence}
1363 % Displays a sequence which is vertically centered at the main chain. Since a residue is only 0.5~mm wide by default, you should increase the \opt{x unit} when showing \texttt{sequence} features (Example~\ref{exa:DomFeatureSequence}).
1364 %
1365 % \begin{exampletable}
1366 % \caption{}
1367 % \label{exa:DomFeatureSequence}
1368 % \begin{examplecode}
1369 % \begin{pmbdomains}[%
1370 % sequence=MGSKRSVPSRHRSLTTYEVMFAVLFVILV%
1371 % ALCAGLIAVSWLSIQGSVKDAAFGKSHEARGTL,
1372 % residues per line=50,
1373 % x unit=2mm, show name=false,
1374 % ruler range=auto-auto step 10]{50}
1375 % \setfeaturestyle{other/sequence}{font=\ttfamily\footnotesize}
1376 % \addfeature{domain}{20}{35}
1377 % \addfeature{other/sequence}{7}{42}
1378 % \end{pmbdomains}
1379 % \end{examplecode}
1380 % \end{exampletable}
1381 %
1382 % \begin{DescribeMacros}
1383 % \Macro\setfeatureprintfunction{<key list>}{<Lua function>}
1384 % \Macro\removefeatureprintfunction{<key list>}
1385 % \Macro\pmbdomdrawfeature{<type>}
1386 % \end{DescribeMacros}
1387 % Some features require sophisticated coordinate calculations. Hence, you might ocasionally want to call a Lua function as ``preprocessor'' before executing the \meta{TikZ code} of |\setfeatureshape|. For this purpose, |\setfeatureprintfunction| registers such a \meta{Lua function} and |\removefeatureprintfunction| deletes the preprocessing function(s) for all features in the \meta{key list}.
1388 %
1389 % A suitable Lua function
1390 % \begin{itemize}
1391 % \item receives up to six arguments in the following order (see also section~\ref{ssc:DocDomLuaPrintFunctions}):
1392 % \begin{enumerate}
1393 % \item A table describing the feature (see section~\ref{ssc:DocDomLuaProteinClass} for its fields);
1394 % \item the left $x$-coordinate of the feature (an integer);
1395 % \item its right $x$-coordinate (an integer);
1396 % \item the $y$-coordinate of the current line (an integer);
1397 % \item the dimension stored in \opt{x unit}, converted to scaled points (an integer);
1398 % \item the dimension stored in \opt{y unit}, converted to scaled points (an integer);
1399 % \end{enumerate}
1400 % \item performs all necessary calculations and defines all \TeX\ macros required by |\setfeatureshape|;
1401 % \item may execute |\pmbdomdrawfeature| with the appropriate feature \meta{type} to draw the feature.
1402 % \end{itemize}
1403 %
1404 %
1405 % Example~\ref{exa:DomPrintFunction} devises a new print function, §printFunnySequence§ (lines 2--17). It is similar to the default print function for \texttt{other/sequence} features, but adds random values to the $y$-coordinate of the individual letters.
1406 %
1407 % §printFunnySequence§ is a function with six arguments (line 2). We add the width of half a residue to the left $x$-coordinate, §xLeft§ (line 3), since each letter should be horizontally centered. We iterate over each letter in the §sequence§ field of the §feature§ table (lines 4--16). In each loop, calculated coordinates are stored in the \TeX\ macros |\xMid| (lines 5--7) and |\yMid| (lines 8--10). The construction |\string\\...| is expanded to |\\...| when §tex.sprint§ passes its argument back to \TeX. §pgfmolbio.dimToString§ converts a number representing a dimension in scaled points to a string (e.\,g., 65536 to ``1pt'', see section~\ref{sec:DocPkgLua}). The letter of the current residue is stored in |\currentResidue| (lines 11--13). Finally, each letter is drawn by calling |\pmbdomdrawfeature{other/sequence}| (line 14), and the $x$-coordinate increases by one (line 15). Line 25 registers §printFunnySequence§ for \texttt{other/sequence} features.
1408 %
1409 % \begin{exampletable}
1410 % \caption{}
1411 % \label{exa:DomPrintFunction}
1412 % \begin{examplecode}
1413 % \directlua{
1414 % function printFunnySequence (feature, xLeft, xRight, yMid, xUnit, yUnit)
1415 % xLeft = xLeft + 0.5
1416 % for currResidue in feature.sequence:gmatch(".") do
1417 % tex.sprint("\string\\def\string\\xMid{" ..
1418 % pgfmolbio.dimToString(xLeft * xUnit) ..
1419 % "}")
1420 % tex.sprint("\string\\def\string\\yMid{" ..
1421 % pgfmolbio.dimToString((yMid + math.random(-5, 5) / 20) * yUnit) ..
1422 % "}")
1423 % tex.sprint("\string\\def\string\\currentResidue{" ..
1424 % currResidue ..
1425 % "}")
1426 % tex.sprint("\string\\pmbdomdrawfeature{other/sequence}")
1427 % xLeft = xLeft + 1
1428 % end
1429 % end
1430 % }
1431 %
1432 % \begin{pmbdomains}[%
1433 % sequence=MGSKRSVPSRHRSLTTYEVMFAVLFVILVALCAGLIAVSWLSIQGSVKDAAF,
1434 % x unit=2mm, show name=false,
1435 % ruler range=auto-auto step 10]{40}
1436 % \setfeaturestyle{other/sequence}{font=\ttfamily\footnotesize}
1437 % \setfeatureprintfunction{other/sequence}{printFunnySequence}
1438 % \addfeature{domain}{20}{30}
1439 % \addfeature{other/sequence}{7}{38}
1440 % \end{pmbdomains}
1441 % \end{examplecode}
1442 % \end{exampletable}
1443 %
1444 % \DescribeFeature*{other/magnified sequence above}
1445 % Displays its sequence as a single string above the main chain, with dashed lines indicating the sequence start and stop on the backbone. This feature allows you to show sequences without the need to increase the \opt{x unit}.
1446 %
1447 % \DescribeFeature*{other/magnified sequence below}
1448 % Displays the sequence \textit{below} the backbone.
1449 %
1450 % \DescribeOption{domains/}{magnified sequence font}{\string\ttfamily\string\footnotesize}<font commands>
1451 % The font used for a magnified sequence (Example~\ref{exa:DomFeatureMagnifiedSequence}).
1452 %
1453 % \begin{exampletable}
1454 % \caption{}
1455 % \label{exa:DomFeatureMagnifiedSequence}
1456 % \begin{examplecode}
1457 % \begin{pmbdomains}[%
1458 % sequence=MGSKRSVPSRHRSLTTYEVMFAVLFVIL%
1459 % VALCAGLIAVSWLSIQGSVKDAAFGKSHEARGTL,
1460 % enlarge left=-1cm, enlarge right=1cm, enlarge bottom=-1cm,
1461 % show name=false, show ruler=false]{50}
1462 % \addfeature{other/magnified sequence above}{7}{20}
1463 % \addfeature[magnified sequence font=\scriptsize\sffamily]%
1464 % {other/magnified sequence below}{34}{42}
1465 % \end{pmbdomains}
1466 % \end{examplecode}
1467 % \end{exampletable}
1468 %
1469 %
1470 % \section{Secondary Structure}
1471 % \label{sec:DomSecondaryStructure}
1472 %
1473 % \DescribeOption{domains/}{show secondary structure}{false}<boolean>
1474 % Determines whether the secondary structure is shown.
1475 %
1476 % \DescribeOption{domains/}{secondary structure distance}{1}<factor>
1477 % Secondary structures appear along a thin line \meta{factor} times the value of \opt{y unit} above the main chain. In accordance with the categories established by the Dictionary of Protein Secondary Structure\footnote{Kabsch, W. and Sander, C. (1983). Dictionary of protein secondary structure: pattern recognition of hydrogen-bonded and geometrical features. \textit{Biopolymers} \textbf{22}(12), 2577--2637.}, \pkg{pgfmolbio} provides seven features for displaying secondary structure types (Example~\ref{exa:DomShowSecStructure}):
1478 %
1479 % \begin{exampletable}
1480 % \caption{}
1481 % \label{exa:DomShowSecStructure}
1482 % \begin{examplecode}
1483 % \begin{pmbdomains}[%
1484 % show name=false,
1485 % sequence=MGSKRSVPSRHRSLTTYEVMFAVLFVILVALCAGL,
1486 % x unit=2.5mm,
1487 % enlarge top=1.5cm,
1488 % ruler range=auto-auto step 1,
1489 % show secondary structure=true,
1490 % secondary structure distance=1.5
1491 % ]{35}
1492 % \setfeaturestyle{other/sequence}{{font=\ttfamily\small}}
1493 % \addfeature{alpha helix}{2}{8}
1494 % \addfeature{pi helix}{9}{11}
1495 % \addfeature{310 helix}{13}{18}
1496 % \addfeature{beta strand}{20}{23}
1497 % \addfeature{beta bridge}{25}{28}
1498 % \addfeature{beta turn}{30}{31}
1499 % \addfeature{bend}{33}{34}
1500 % \addfeature{other/sequence}{1}{35}
1501 % \end{pmbdomains}
1502 % \end{examplecode}
1503 % \end{exampletable}
1504 %
1505 % \DescribeFeature{alpha helix}{HELIX}
1506 % Shows an $\alpha$-helix.
1507 %
1508 % \DescribeFeature*{pi helix}
1509 % Shows a $\pi$-helix.
1510 %
1511 % \DescribeFeature*{310 helix}
1512 % Shows a $3_{10}$-helix.
1513 %
1514 % \DescribeFeature{beta strand}{STRAND}
1515 % Shows a $\beta$-strand.
1516 %
1517 % \DescribeFeature{beta turn}{TURN}
1518 % Shows a $\beta$-turn.
1519 %
1520 % \DescribeFeature*{beta bridge}
1521 % Shows a $\beta$-bridge.
1522 %
1523 % \DescribeFeature*{bend}
1524 % Shows a bend.
1525 %
1526 % \begin{figure}
1527 % \centering
1528 % \caption{Shading colors of helix features.}
1529 % \label{fig:DomHelixColors}
1530 % \begin{tabular}{*4{>{\ttfamily}l}}
1531 % \toprule
1532 % \rmfamily\itshape Name & \multicolumn{3}{c}{\itshape \pkg{xcolor} definition} \\
1533 % \cmidrule(lr){2-4}
1534 % & \rmfamily $\alpha$-helix & \rmfamily $\pi$-helix & \rmfamily $3_{10}$-helix \\
1535 % \midrule
1536 % helix back border color & \multicolumn{3}{c}{\ttfamily white!50!black \color{white!50!black}\rule{1ex}{1ex}} \\
1537 % helix back main color & \multicolumn{3}{c}{\ttfamily white!90!black \color{white!90!black}\rule{1ex}{1ex}} \\
1538 % helix back middle color & \multicolumn{3}{c}{\ttfamily white \color{white}\rule{1ex}{1ex}} \\
1539 % \midrule
1540 % helix front border color & red!50!black \color{red!50!black}\rule{1ex}{1ex}
1541 % & yellow!50!black \color{yellow!50!black}\rule{1ex}{1ex}
1542 % & magenta!50!black \color{magenta!50!black}\rule{1ex}{1ex} \\
1543 % helix front main color & red!90!black \color{red!90!black}\rule{1ex}{1ex}
1544 % & yellow!70!red~~ \color{yellow!70!red}\rule{1ex}{1ex}
1545 % & magenta!90!black \color{magenta!90!black}\rule{1ex}{1ex} \\
1546 % helix front middle color & red!10!white \color{red!10!white}\rule{1ex}{1ex}
1547 % & yellow!10!white \color{yellow!10!white}\rule{1ex}{1ex}
1548 % & magenta!10!white \color{magenta!10!white}\rule{1ex}{1ex} \\
1549 % \bottomrule
1550 % \end{tabular}\hspace*{-67pt}\par\bigskip
1551 % \begin{tikzpicture}[font=\ttfamily\scriptsize]
1552 % \makeatletter
1553 % \draw [shading=helix full back] (1.5, 0) \@pmb@dom@helixsegment{1.5mm};
1554 % \tikzset{left}
1555 % \draw [->] (0, 0) node {helix back border color} -- (.5, 0);
1556 % \draw [->] (0, .225) node {helix back main color} -- (.5, .225);
1557 % \draw [->] (0, .675) node {helix back middle color} -- (.5, .675);
1558 % \draw [->] (0, 1.575) node {helix back main color} -- (.5, 1.575);
1559 % \draw [->] (0, 2.25) node {helix back border color} -- (.5, 2.25);
1560 % \tikzset{right}
1561 % \draw [shading=helix full front] (4, 0) [xscale=-1] \@pmb@dom@helixsegment{1.5mm};
1562 % \draw [<-] (5, 0) -- (5.5, 0) node {helix front border color};
1563 % \draw [<-] (5, .675) -- (5.5, .675) node {helix front main color};
1564 % \draw [<-] (5, 1.575) -- (5.5, 1.575) node {helix front middle color};
1565 % \draw [<-] (5, 2.025) -- (5.5, 2.025) node {helix front main color};
1566 % \draw [<-] (5, 2.25) -- (5.5, 2.25) node {helix front border color};
1567 % \tikzset{font=\rmfamily\scriptsize}
1568 % \draw (-4, -.2) -- (-4, -.5) -- (2.5, -.5)
1569 % node [pos=.5, below] {Shading \texttt{helix full back}}
1570 % -- (2.5, -.2);
1571 % \draw (3, -.2) -- (3, -.5) -- (9.5, -.5)
1572 % node [pos=.5, below] {Shading \texttt{helix full front}}
1573 % -- (9.5, -.2);
1574 % \end{tikzpicture}
1575 % \end{figure}
1576 %
1577 % \begin{table}[p]
1578 % \centering
1579 % \caption{Customizing helices in the \module{domains} module.}
1580 % \label{tab:DomHelixHelperFeatures}
1581 % \begin{tabular}{*2{>{\ttfamily}l} *2{>{\ttfamily\color{ProcessBlue}}l}}
1582 % \toprule
1583 % \rmfamily\itshape (a) Subfeatures
1584 % & \rmfamily\itshape (b) Corresponding shadings
1585 % & \multicolumn{2}{l}{\itshape (c) Coordinates} \\
1586 % \cmidrule(r){1-1}\cmidrule(r){2-2}\cmidrule{3-4}
1587 % helix/half upper back & helix half upper back & \string\xLeft & \string\yMid \\
1588 % helix/half lower back & helix half lower back & \string\xRight & \string\yMid \\
1589 % helix/full back & helix full back & \string\xMid & \string\yLower \\
1590 % helix/half upper front & helix half upper front & \string\xRight & \string\yMid \\
1591 % helix/full front & helix full front & \string\xMid & \string\yLower \\
1592 % \bottomrule
1593 % \end{tabular}
1594 % \end{table}
1595 %
1596 % \begin{exampletable}[p]
1597 % \caption{}
1598 % \label{exa:DomHelixColors}
1599 % \begin{examplecode}
1600 % \begin{pmbdomains}[%
1601 % show name=false,
1602 % x unit=2.5mm,
1603 % enlarge top=1.5cm,
1604 % ruler range=auto-auto step 5,
1605 % show secondary structure
1606 % ]{35}
1607 % \setfeaturestyle{alpha helix}{%
1608 % *1{helix front border color=blue!50!black,%
1609 % helix front main color=orange,%
1610 % helix front middle color=yellow!50},%
1611 % *1{helix front border color=olive,%
1612 % helix front main color=magenta,%
1613 % helix front middle color=green!50}%
1614 % }
1615 % \addfeature{alpha helix}{2}{8}
1616 % \addfeature{alpha helix}{9}{15}
1617 % \addfeature{alpha helix}{20}{27}
1618 % \addfeature{alpha helix}{30}{34}
1619 % \end{pmbdomains}
1620 % \end{examplecode}
1621 % \end{exampletable}
1622 %
1623 % \begin{exampletable}[p]
1624 % \caption{}
1625 % \label{exa:DomHelixHelperFeature}
1626 % \begin{examplecode}[basicstyle=\ttfamily\tiny]
1627 % \pgfmathsetmacro\yShift{%
1628 % \pmbdomvalueof{secondary structure distance}
1629 % * \pmbdomvalueof{y unit}%
1630 % }
1631 %
1632 % \setfeatureshape{helix/half upper back}{%
1633 % \draw [shading=helix half upper back]
1634 % (\xLeft, \yMid + \yShift pt) --
1635 % (\xLeft + .5 * \pmbdomvalueof{x unit},
1636 % \yMid + 1.5 * \pmbdomvalueof{x unit} + \yShift pt) --
1637 % (\xLeft + 1.5 * \pmbdomvalueof{x unit},
1638 % \yMid + 1.5 * \pmbdomvalueof{x unit} + \yShift pt) --
1639 % (\xLeft + \pmbdomvalueof{x unit}, \yMid + \yShift pt) --
1640 % cycle;
1641 % }
1642 %
1643 % \setfeatureshape{helix/half lower back}{%
1644 % \draw [shading=helix half lower back]
1645 % (\xRight, \yMid + \yShift pt) --
1646 % (\xRight - .5 * \pmbdomvalueof{x unit},
1647 % \yMid - 1.5 * \pmbdomvalueof{x unit} + \yShift pt) --
1648 % (\xRight - 1.5 * \pmbdomvalueof{x unit},
1649 % \yMid - 1.5 * \pmbdomvalueof{x unit} + \yShift pt) --
1650 % (\xRight - \pmbdomvalueof{x unit}, \yMid + \yShift pt) --
1651 % cycle;
1652 % }
1653 %
1654 % \setfeatureshape{helix/full back}{%
1655 % \draw [shading=helix full back]
1656 % (\xMid, \yLower + \yShift pt) --
1657 % (\xMid - \pmbdomvalueof{x unit}, \yLower + \yShift pt) --
1658 % (\xMid, \yLower + 3 * \pmbdomvalueof{x unit} + \yShift pt) --
1659 % (\xMid + \pmbdomvalueof{x unit},
1660 % \yLower + 3 * \pmbdomvalueof{x unit} + \yShift pt) --
1661 % cycle;
1662 % }
1663 %
1664 % \setfeatureshape{helix/half upper front}{%
1665 % \draw [shading=helix half upper front]
1666 % (\xRight, \yMid + \yShift pt) --
1667 % (\xRight - .5 * \pmbdomvalueof{x unit},
1668 % \yMid + 1.5 * \pmbdomvalueof{x unit} + \yShift pt) --
1669 % (\xRight - 1.5 * \pmbdomvalueof{x unit},
1670 % \yMid + 1.5 * \pmbdomvalueof{x unit} + \yShift pt) --
1671 % (\xRight - \pmbdomvalueof{x unit}, \yMid + \yShift pt) --
1672 % cycle;
1673 % }
1674 %
1675 % \setfeatureshape{helix/full front}{%
1676 % \draw [shading=helix full front]
1677 % (\xMid, \yLower + \yShift pt) --
1678 % (\xMid + \pmbdomvalueof{x unit}, \yLower + \yShift pt) --
1679 % (\xMid, \yLower + 3 * \pmbdomvalueof{x unit} + \yShift pt) --
1680 % (\xMid - \pmbdomvalueof{x unit},
1681 % \yLower + 3 * \pmbdomvalueof{x unit} + \yShift pt) --
1682 % cycle;
1683 % }
1684 %
1685 % \begin{pmbdomains}[%
1686 % show name=false, sequence=MGSKRSVPSR,
1687 % x unit=2.5mm, enlarge top=1.5cm,
1688 % ruler range=auto-auto step 1,
1689 % show secondary structure
1690 % ]{10}
1691 % \setfeaturestyle{other/sequence}{{font=\ttfamily\small}}
1692 % \addfeature{alpha helix}{2}{6}
1693 % \addfeature{alpha helix}{8}{9}
1694 % \addfeature{other/sequence}{1}{10}
1695 % \end{pmbdomains}
1696 % \end{examplecode}
1697 % \end{exampletable}
1698 %
1699 % \bigskip While changing the appearance of nonhelical secondary structure elements is simple, the complex helical features employ the print function §printHelixFeature§ (section~\ref{ssc:DocDomLuaPrintFunctions}). However, their appearance can be customized on several levels:
1700 % \begin{enumerate}
1701 % \item The elements of a helical feature are drawn by five ``subfeatures'', which are called by §printHelixFeature§ (Table~\ref{tab:DomHelixHelperFeatures}a).
1702 % \item For each subfeature, there is a corresponding shading (Table~\ref{tab:DomHelixHelperFeatures}b; see section~\ref{ssc:DocDomTexSecondaryStructure} and section~83 of the \TikZ\ manual for their definitions).
1703 % \item These shadings use six colors in total, three for front and three for back shadings (Figure~\ref{fig:DomHelixColors}). For each color, there is a key of the same name, so you can change helix colors in feature style lists (Example~\ref{exa:DomHelixColors}).
1704 % \end{enumerate}
1705 %
1706 %
1707 % \section{File Input}
1708 % \label{sec:DomFileInput}
1709 %
1710 % \begin{DescribeMacros}
1711 % \Macro\inputuniprot{<Uniprot file>}
1712 % \Macro\inputgff{<gff file>}
1713 % \end{DescribeMacros}
1714 % Include the features defined in an \meta{Uniprot file} or \meta{gff file}, respectively (Example~\ref{exa:DomInputExternalFiles}). These macros are only defined in |pmbdomains|.
1715 %
1716 % \begin{exampletable}[hb]
1717 % \caption{}
1718 % \label{exa:DomInputExternalFiles}
1719 % \begin{examplecode}
1720 % \begin{pmbdomains}[show secondary structure]{}
1721 % \setfeaturestyle{disulfide}{{draw=olive,thick}}
1722 % \inputuniprot{SampleUniprot.txt}
1723 % \end{pmbdomains}
1724 % \end{examplecode}
1725 % \begin{examplecode}
1726 % \begin{pmbdomains}[show name=false,show secondary structure]{200}
1727 % \setfeaturestyle{disulfide}{{draw=olive,thick}}
1728 % \inputgff{SampleGff.gff}
1729 % \end{pmbdomains}
1730 % \end{examplecode}
1731 % \end{exampletable}
1732 %
1733 % \DescribeOption{domains/}{sequence length}{\textrm{(empty)}}<number>
1734 % Note that in Example~\ref{exa:DomInputExternalFiles}, we had to set a sequence length for the |pmbdomains| environment that contains the |\inputgff| macro. \file{gff} files lack a sequence length field. By contrast, \pkg{pgfmolbio} reads the sequence length from an Uniprot file, and thus the mandatory argument of |pmbdomains| may remain empty. In general, the sequence length is stored in the key of the same name.
1735 %
1736 %
1737 %
1738 % \chapter{The \texorpdfstring{\module{convert}}{convert} module}
1739 % \label{cha:Convert}
1740 %
1741 %
1742 % \section{Overview}
1743 % \label{sec:ConOverview}
1744 %
1745 % The \module{convert} module supports users who wish to include \pkg{pgfmolbio} graphs, but who do not want to typeset their documents with a \TeX\ engine that implements Lua. To this end, the \module{convert} workflow comprises two steps: (1) Running Lua\LaTeX\ on an input file that contains at least one |\pmbchromatogram| or similar macros/environments. This will generate one \file{tex} file per graph macro/environment that contains only \TikZ\ commands. (2) Including this file in another \TeX\ document (via |\input|) which is then processed by any \TeX\ engine that supports \TikZ.
1746 %
1747 %
1748 % \section{Converting Chromatograms}
1749 % \label{sec:ConChromatograms}
1750 %
1751 % In order to create the external \TikZ\ file, run an input file like the one below through Lua\LaTeX:
1752 % \begin{lstlisting}[style=latex-expl,gobble=2]
1753 % \documentclass{article}
1754 % \usepackage[chromatogram,convert]{pgfmolbio}
1755 %
1756 % \begin{document}
1757 % \pmbchromatogram[sample range=base 50-base 60]{SampleScf.scf}
1758 % \pmbchromatogram[/pgfmolbio/convert/output file name=mytikzfile]%
1759 % {SampleScf.scf}
1760 % \pmbchromatogram[sample range=base 60-base 70]{SampleScf.scf}
1761 % \end{document}
1762 % \end{lstlisting}
1763 % The \module{convert} module disables \file{pdf} output and introduces the following keys:
1764 %
1765 % \DescribeOption{convert/}{output file name}{(auto)}<text>\relax
1766 % \DescribeOption{convert/}{output file extension}{tex}<text>\relax
1767 % With the default value for \opt{output file name} (``|(auto)|''), \pkg{pgfmolbio} creates files that are named \file{pmbconverted} and numbered consecutively (\file{pmbconverted0.tex}, \file{pmbconverted1.tex} etc.). Both keys can be changed locally (e.\,g., in the optional argument of |\pmbchromatogram|), but this turns off automatic numbering.
1768 %
1769 % The code above produces the files \file{pmbconverted0.tex}, \file{mytikzfile.tex} and \file{pmbconverted2.tex}. Below is an annotated excerpt from \file{pmbconverted0.tex}:
1770 % \begin{lstlisting}[style=latex-expl,gobble=2,escapeinside=`',basicstyle=\ttfamily\scriptsize,breaklines]
1771 % \begin{tikzpicture}
1772 % `[canvas section]'
1773 % \draw [/pgfmolbio/chromatogram/canvas style] (0mm, -0mm) rectangle (25mm, 20mm);
1774 % `[traces section]'
1775 % \draw [/pgfmolbio/chromatogram/trace A style] (0mm, 6.37mm) -- (0.2mm, 6.66mm) -- `[many coordinates]' -- (25mm, 0mm);
1776 % \draw [/pgfmolbio/chromatogram/trace C style] (0mm, 0.06mm) -- (0.2mm, 0.05mm) -- `[...]' -- (25mm, 6.27mm);
1777 % \draw [/pgfmolbio/chromatogram/trace G style] (0mm, 0.01mm) -- (0.2mm, 0.01mm) -- `[...]' -- (25mm, 0.05mm);
1778 % \draw [/pgfmolbio/chromatogram/trace T style] (0mm, 0mm) -- (0.2mm, 0mm) -- `[...]' -- (25mm, 0.06mm);
1779 % `[ticks/base labels/probabilities section]'
1780 % \draw [/pgfmolbio/chromatogram/tick A style] (0mm, -0mm) -- (0mm, -1mm) node [/pgfmolbio/chromatogram/base label A style] {\pgfkeysvalueof{/pgfmolbio/chromatogram/base label A text}} node [/pgfmolbio/chromatogram/base number style] {\strut 50};
1781 % \draw [ultra thick, pmbTraceGreen] (0mm, -8mm) -- (0.9mm, -8mm);
1782 % \draw [/pgfmolbio/chromatogram/tick T style] (1.8mm, -0mm) -- (1.8mm, -1mm) node [/pgfmolbio/chromatogram/base label T style] {\pgfkeysvalueof{/pgfmolbio/chromatogram/base label T text}};
1783 % \draw [ultra thick, pmbTraceGreen] (0.9mm, -8mm) -- (3mm, -8mm);
1784 % \draw [/pgfmolbio/chromatogram/tick A style] (4.2mm, -0mm) -- (4.2mm, -1mm) node [/pgfmolbio/chromatogram/base label A style] {\pgfkeysvalueof{/pgfmolbio/chromatogram/base label A text}};
1785 % \draw [ultra thick, pmbTraceGreen] (3mm, -8mm) -- (5.4mm, -8mm);
1786 % `[...]'
1787 % `[more ticks, base labels and probability rules]'
1788 % \end{tikzpicture}
1789 % \end{lstlisting}
1790 %
1791 % You can change the format of the coordinates by the following keys:
1792 %
1793 % \DescribeOption{}{coordinate unit}{mm}<unit>
1794 % \DescribeOption{}{coordinate format string}{\letterpercent s\letterpercent s}<format string>\relax
1795 % \pkg{pgfmolbio} internally calculates dimensions in scaled points, but usually converts them before returning them to \TeX. To this end, it selects the \meta{unit} stored in \opt{coordinate unit} (any of the standard \TeX\ units of measurement: \texttt{bp}, \texttt{cc}, \texttt{cm}, \texttt{dd}, \texttt{in}, \texttt{mm}, \texttt{pc}, \texttt{pt} or \texttt{sp}). In addition, the package formats the dimension according to the \meta{format string} given by \opt{coordinate format string}. This string basically follows the syntax of C's \texttt{printf} function, as described in the Lua reference manual. (Note: Use |\letterpercent| instead of \texttt{\%}, since \TeX\ treats anything following a percent character as comment.)
1796 %
1797 % Depending on the values of \opt{coordinate unit} and \opt{coordinate format string}, dimensions will be printed in different ways (Table~\ref{tab:CoordFormat}).
1798 %
1799 % \begin{table}
1800 % \centering
1801 % \caption{Effects of \texttt{\color{opt}coordinate unit} and \texttt{\color{opt}coordinate format string} when converting an internal \pkg{pgfmolbio} dimension of 200000~[sp].}
1802 % \label{tab:CoordFormat}
1803 % \begin{tabularx}{\textwidth}{*3{>{\ttfamily}l}X}
1804 % \toprule
1805 % \multicolumn{2}{c}{\itshape Values} & \multicolumn{1}{l}{\itshape Output} & \itshape Notes \\
1806 % \cmidrule(r){1-2}\cmidrule(r){3-3}\cmidrule{4-4}
1807 % sp & \%s\%s & 200000sp & simple conversion \\
1808 % mm & \%s\%s & 1.0725702011554mm & default settings, may lead to a large number of decimal places \\
1809 % mm & \%.3f\%s & 1.073mm & round to three decimal places \\
1810 % cm & \%.3f & 0.107 & don't print any unit, i.\,e. use \TikZ's \texttt{xyz} coordinate system \\
1811 % \bottomrule
1812 % \end{tabularx}
1813 % \end{table}
1814 %
1815 % \bigskip
1816 % The output files can be included in a file which is processed by pdf\LaTeX:
1817 % \begin{lstlisting}[style=latex-expl,gobble=2]
1818 % \documentclass{article}
1819 % \usepackage[chromatogram]{pgfmolbio}
1820 %
1821 % \begin{document}
1822 % \input{pmbconverted.tex}
1823 % \end{document}
1824 % \end{lstlisting}
1825 %
1826 % Several keys of the \module{chromatogram} module must contain their final values before conversion, while others can be changed afterwards, i.\,e., before the generated file is loaded with |\input| (Table~\ref{tab:ConvertChrKeys}).
1827 %
1828 % \begin{table}[ht]
1829 % \centering
1830 % \caption{Keys of the \module{chromatogram} module that require final values prior to conversion.}
1831 % \label{tab:ConvertChrKeys}
1832 % \begin{tabular}{*3{>{\ttfamily\color{opt}}l}}
1833 % \toprule
1834 % \multicolumn{2}{c}{\itshape Required} & \multicolumn{1}{c}{\itshape Not required} \\
1835 % \cmidrule(r){1-2}\cmidrule(l){3-3}
1836 % base labels drawn & sample range & base label style \\
1837 % base number range & samples per line & base label X style \\
1838 % baseline skip & show base numbers & base label X text \\
1839 % bases drawn & tick length & base number style \\
1840 % canvas height & ticks drawn & canvas style \\
1841 % probabilities drawn & traces drawn & tick style \\
1842 % probability distance & x unit & tick X style \\
1843 % probability style function & y unit & trace style \\
1844 % & & trace X style \\
1845 % \bottomrule
1846 % \end{tabular}
1847 % \end{table}
1848 %
1849 %
1850 % \section{Converting Domain Diagrams}
1851 % \label{sec:ConDomains}
1852 %
1853 % \DescribeOption{convert/}{output code}{tikz}'pgfmolbio | tikz'
1854 % In principle, domain diagrams are converted like sequencing chromatograms (section~\ref{sec:ConChromatograms}). However, \opt{output code} lets you choose the kind of code \module{convert} writes to the output file: |pgfmolbio| generates a |pmbdomains| environment containing |\addfeature| commands, |tikz| produces \TikZ\ code.
1855 %
1856 % ``Converting'' one |pmbdomains| environment in the input file to another one in the output file might seem pointless. Nonetheless, this conversion mechanism can be highly useful for extracting features from a Uniprot or \file{gff} file. For example, consider the following input file:
1857 % \begin{lstlisting}[style=latex-expl,gobble=2]
1858 % \documentclass{article}
1859 % \usepackage[domains,convert]{pgfmolbio}
1860 %
1861 % \begin{document}
1862 % \pgfmolbioset[convert]{output code=pgfmolbio}
1863 % \begin{pmbdomains}{}
1864 % \inputuniprot{SampleUniprot.txt}
1865 % \end{pmbdomains}
1866 % \end{document}
1867 % \end{lstlisting}
1868 % The corresponding output is
1869 % \begin{lstlisting}[style=latex-expl,gobble=2,escapeinside=`']
1870 % \begin{pmbdomains}
1871 % [name={TestProtein},
1872 % sequence=MGSKRSVPSRHRSL`[...]'PLATPGNVSIECP]{200}
1873 % \addfeature[description={Disulfide 1}]{DISULFID}{5}{45}
1874 % \addfeature[description={Disulfide 2}]{DISULFID}{30}{122}
1875 % \addfeature[description={Disulfide 3}]{DISULFID}{51}{99}
1876 % \addfeature[description={Domain 1}]{DOMAIN}{10}{40}
1877 % \addfeature[description={Domain 2}]{DOMAIN}{60}{120}
1878 % \addfeature[description={Domain 3}]{DOMAIN}{135}{178}
1879 % \addfeature[description={Strand 1}]{STRAND}{15}{23}
1880 % \addfeature[description={Strand 2}]{STRAND}{25}{32}
1881 % \addfeature[description={Helix 1}]{HELIX}{60}{75}
1882 % \addfeature[description={Helix 2}]{HELIX}{80}{108}
1883 % \addfeature[description={Sugar 1}]{CARBOHYD}{151}{151}
1884 % \addfeature[description={Sugar 2}]{CARBOHYD}{183}{183}
1885 % \end{pmbdomains}
1886 % \end{lstlisting}
1887 % Obviously, this method is particularly suitable for Uniprot files containing many features.
1888 %
1889 % \DescribeOption{convert/}{include description}{true}<boolean>
1890 % Decides whether the feature description obtained from the input should appear in the output. Since the description field in FT entries of Uniprot files can be quite long, you may not wish to show it in the output. For example, the output of the example above with \opt{include description}|=false| looks like
1891 % \begin{lstlisting}[style=latex-expl,gobble=2,escapeinside=`']
1892 % \begin{pmbdomains}
1893 % [name={TestProtein},
1894 % sequence=MGSKRSVPSRHRSL`[...]'PLATPGNVSIECP]{200}
1895 % \addfeature{DISULFID}{5}{45}
1896 % \addfeature{DISULFID}{30}{122}
1897 % \addfeature{DISULFID}{51}{99}
1898 % `[...]'
1899 % \end{pmbdomains}
1900 % \end{lstlisting}
1901 %
1902 % \bigskip
1903 % With \opt{output code}|=tikz|, we obtain the following (annotated) output file:
1904 % \begin{lstlisting}[style=latex-expl,gobble=2,escapeinside=`',basicstyle=\ttfamily\scriptsize,breaklines]
1905 % `[set relevant keys]'
1906 % \pgfmolbioset[domains]{name={TestProtein},sequence={MGSKRS`[...]'VSIECP},sequence length=200}
1907 % `[the actual \TikZ\ picture]'
1908 % \begin{tikzpicture}
1909 % `[each feature appears within its own scope]'
1910 % \begin{scope}\begin{pgfinterruptboundingbox}
1911 % \def\xLeft{0mm}
1912 % \def\xMid{50mm}
1913 % \def\xRight{100mm}
1914 % \def\yMid{-0mm}
1915 % \def\featureSequence{MGSKRS`[...]'VSIECP}
1916 % \clip (-50mm, \yMid + 100mm) rectangle (150mm, \yMid - 100mm);
1917 % \pgfmolbioset[domains]{style={{draw, line width=2pt, black!25}},@layer=1}
1918 % \pmbdomdrawfeature{other/main chain}
1919 % \end{pgfinterruptboundingbox}\end{scope}
1920 % `[more features]'
1921 % `[...]'
1922 % `[helix features require additional drawing commands]'
1923 % \begin{scope}\begin{pgfinterruptboundingbox}
1924 % \def\xLeft{29.5mm}
1925 % \def\xMid{33.5mm}
1926 % \def\xRight{37.5mm}
1927 % \def\yMid{-0mm}
1928 % \def\featureSequence{GTLKIISGATYNPHLQ}
1929 % \clip (-50mm, \yMid + 100mm) rectangle (87.5mm, \yMid - 100mm);
1930 % \pgfmolbioset[domains]{style={{helix front border color=red!50!black,helix front main color=red!90!black,helix front middle color=red!10!white}},description={Helix 1}}
1931 % \pgfmolbioset[domains]{current style}
1932 % \def\xLeft{29.5mm}
1933 % \def\yMid{-0mm}
1934 % \pmbdomdrawfeature{helix/half upper back}
1935 % \def\xMid{30.75mm}
1936 % \def\yLower{-0.75mm}
1937 % \pmbdomdrawfeature{helix/full back}
1938 % `[more helix parts]'
1939 % \end{pgfinterruptboundingbox}\end{scope}
1940 % `[...]'
1941 % `[ruler section]'
1942 % \begin{scope}
1943 % \pgfmolbioset[domains]{current style/.style={black}}
1944 % \def\xMid{0.25mm}
1945 % \let\xLeft\xMid\let\xRight\xMid
1946 % \def\yMid{-0mm}
1947 % \def\residueNumber{1}
1948 % \pmbdomdrawfeature{other/ruler}
1949 % \pgfmolbioset[domains]{current style/.style={black!50}}
1950 % \def\xMid{25.25mm}
1951 % \let\xLeft\xMid\let\xRight\xMid
1952 % \def\yMid{-0mm}
1953 % \def\residueNumber{51}
1954 % \pmbdomdrawfeature{other/ruler}
1955 % `[more ruler numbers]'
1956 % `[...]'
1957 % \end{scope}
1958 % `[name section]'
1959 % \begin{scope}
1960 % \pgfmolbioset[domains]{current style/.style={font=\sffamily }}
1961 % \def\xLeft{0mm}
1962 % \def\xMid{50mm}
1963 % \def\xRight{100mm}
1964 % \def\yMid{0mm}
1965 % \pmbdomdrawfeature{other/name}
1966 % \end{scope}
1967 % `[adjust picture size]'
1968 % \pmbprotocolsizes{\pmbdomvalueof{enlarge left}}{\pmbdomvalueof{enlarge top}}
1969 % \pmbprotocolsizes{100mm + \pmbdomvalueof{enlarge right}}{-0mm + \pmbdomvalueof{enlarge bottom}}
1970 % \end{tikzpicture}
1971 % \end{lstlisting}
1972 %
1973 % Several keys of the \module{domains} module must contain their final values before conversion, and some macros can't be used afterwards (Table~\ref{tab:ConvertDomKeysAndMacros}).
1974 %
1975 % \begin{table}[ht]
1976 % \caption{Keys and macros of the \module{domain} module that require final values prior to conversion or can't be used afterwards, respectively.}
1977 % \label{tab:ConvertDomKeysAndMacros}\small
1978 % \begin{tabular}{*3{>{\ttfamily\color{opt}}l}}
1979 % \toprule
1980 % \multicolumn{2}{c}{\itshape Required} & \multicolumn{1}{c}{\itshape Not required} \\
1981 % \cmidrule(r){1-2}\cmidrule(l){3-3}
1982 % baseline skip & ruler distance & domain font \\
1983 % default ruler step size & ruler range & enlarge bottom \\
1984 % description & secondary structure distance & enlarge left \\
1985 % disulfide base distance & sequence & enlarge right \\
1986 % disulfide level distance & sequence length & enlarge top \\
1987 % level & show ruler & magnified sequence font \\
1988 % name & style & range font \\
1989 % residue numbering & x unit & show secondary structure \\
1990 % residue range & y unit & \\
1991 % residues per line & & \\
1992 % \cmidrule(r){1-2}\cmidrule(l){3-3}
1993 % \color{ProcessBlue}\string\adddisulfidefeatures
1994 % & \color{ProcessBlue}\string\setfeatureprintfunction
1995 % & \color{ProcessBlue}\string\setfeaturealias \\
1996 % \color{ProcessBlue}\string\removedisulfidefeatures
1997 % & \color{ProcessBlue}\string\setfeaturestyle
1998 % & \color{ProcessBlue}\string\setfeatureshape \\
1999 % \color{ProcessBlue}\string\removefeatureprintfunction
2000 % & \color{ProcessBlue}\string\setfeaturestylealias
2001 % & \color{ProcessBlue}\string\setfeatureshapealias \\
2002 % \color{ProcessBlue}\string\setdisulfidefeatures & & \\
2003 % \bottomrule
2004 % \end{tabular}\hspace*{-53pt}
2005 % \end{table}
2006 %
2007 %
2008 % \StopEventually{}
2009 % \chapter{Implementation}
2010 % \label{cha:Implementation}
2011 % \renewcommand*\thelstnumber{\arabic{section}.\arabic{lstnumber}}
2012 %
2013 % \iffalse
2014 %<*pgfmolbio-tex>
2015 % \fi
2016 %
2017 % \section{\texorpdfstring{\file{pgfmolbio.sty}}{pgfmolbio.sty}}
2018 % \label{sec:DocPkgTex}
2019 %
2020 % \def\ydoclistingssettings{\lstset{style=latex-doc}}
2021 % The options for the main style file determine which module(s) should be loaded.
2022 %
2023 % \begin{macrocode}
2024 \newif\ifpmb@loadmodule@chromatogram
2025 \newif\ifpmb@loadmodule@domains
2026 \newif\ifpmb@loadmodule@convert
2027
2028 \DeclareOption{chromatogram}{%
2029 \pmb@loadmodule@chromatogramtrue%
2030 }
2031 \DeclareOption{domains}{%
2032 \pmb@loadmodule@domainstrue%
2033 }
2034 \DeclareOption{convert}{%
2035 \pmb@loadmodule@converttrue%
2036 }
2037
2038 \ProcessOptions
2039
2040 % \end{macrocode}
2041 % The main style file also loads the following packages and \TikZ\ libraries.
2042 % \begin{macrocode}
2043 \RequirePackage{ifluatex}
2044 \ifluatex
2045 \RequirePackage{luatexbase-modutils}
2046 \RequireLuaModule{lualibs}
2047 \RequireLuaModule{pgfmolbio}
2048 \fi
2049 \RequirePackage[svgnames,dvipsnames]{xcolor}
2050 \RequirePackage{tikz}
2051 \usetikzlibrary{positioning,svg.path}
2052
2053 % \end{macrocode}
2054 % \begin{macro}{\pgfmolbioset}[2]{The \ometa{module} to which the options apply.}{A \meta{key-value list} which configures the graphs.}
2055 % \begin{macrocode}
2056 \newcommand\pgfmolbioset[2][]{%
2057 \def\@tempa{#1}%
2058 \ifx\@tempa\@empty%
2059 \pgfqkeys{/pgfmolbio}{#2}%
2060 \else%
2061 \pgfqkeys{/pgfmolbio/#1}{#2}%
2062 \fi%
2063 }
2064
2065 % \end{macrocode}
2066 % \end{macro}
2067 % We introduce two package-wide keys.
2068 % \begin{macrocode}
2069 \pgfkeyssetvalue{/pgfmolbio/coordinate unit}{mm}
2070 \pgfkeyssetvalue{/pgfmolbio/coordinate format string}{\letterpercent s\letterpercent s}
2071
2072 % \end{macrocode}
2073 % Furthermore, we define two scratch token registers. Strictly speaking, the two conditionals belong to the \module{convert} module, but all modules need to know them.
2074 % \begin{macrocode}
2075 \newtoks\@pmb@toksa
2076 \newtoks\@pmb@toksb
2077 \newif\ifpmb@con@includedescription
2078 \newif\ifpmb@con@outputtikzcode
2079
2080 % \end{macrocode}
2081 % \begin{macro}{\pmbprotocolsizes}[2]{$x$-coordinate.}{$y$-coordinate.}
2082 % An improved version of |\pgf@protocolsizes| that accepts coordinate calculations.
2083 % \begin{macrocode}
2084 \def\pmbprotocolsizes#1#2{%
2085 \pgfpoint{#1}{#2}%
2086 \pgf@protocolsizes{\pgf@x}{\pgf@y}%
2087 }
2088
2089 % \end{macrocode}
2090 % \end{macro}
2091 % Finally, we load the modules requested by the user.
2092 % \begin{macrocode}
2093 \ifpmb@loadmodule@chromatogram
2094 \input{pgfmolbio.chromatogram.tex}
2095 \fi
2096 \ifpmb@loadmodule@domains
2097 \input{pgfmolbio.domains.tex}
2098 \fi
2099 \ifpmb@loadmodule@convert
2100 \input{pgfmolbio.convert.tex}
2101 \fi
2102 % \end{macrocode}
2103 %
2104 % \iffalse
2105 %</pgfmolbio-tex>
2106 %<*pgfmolbio-lua>
2107 % \fi
2108 %
2109 %
2110 % \section{\texorpdfstring{\file{pgfmolbio.lua}}{pgfmolbio.lua}}
2111 % \label{sec:DocPkgLua}
2112 %
2113 % \def\ydoclistingssettings{\lstset{style=lua-doc}}\setcounter{lstnumber}{1}
2114 % Identification of the Lua module.
2115 % \begin{macrocode}
2116 if luatexbase then
2117 luatexbase.provides_module({
2118 name = "pgfmolbio",
2119 version = "0.21a",
2120 date = "2014/06/17",
2121 description = "Molecular biology graphs wit LuaLaTeX",
2122 author = "Wolfgang Esser-Skala",
2123 copyright = "Wolfgang Esser-Skala",
2124 license = "LPPL",
2125 })
2126 end
2127
2128 % \end{macrocode}
2129 % §setCoordinateFormat§ sets the output format of §dimToString§ (see below). Both its parameters §unit§ and §fmtString§ are strings, which correspond to the values of \opt{coordinate unit} and \opt{coordinate format string}.
2130 % \begin{macrocode}
2131 local coordUnit, coordFmtStr
2132
2133 function setCoordinateFormat(unit, fmtString)
2134 coordUnit = unit
2135 coordFmtStr = fmtString
2136 end
2137
2138 % \end{macrocode}
2139 % §stringToDim§ converts a string describing a \TeX\ dimension to a number corresponding to scaled points. §dimToString§ converts a dimension in scaled points to a string, formatting it according to the values of the local variables §coordUnit§ and §coordFmtString§.
2140 % \begin{macrocode}
2141 function stringToDim(x)
2142 if type(x) == "string" then
2143 return dimen(x)[1]
2144 end
2145 end
2146
2147 function dimToString(x)
2148 return number.todimen(x, coordUnit, coordFmtStr)
2149 end
2150
2151 % \end{macrocode}
2152 % §getRange§ extracts a variable number of strings from §rangeInput§ by applying the regular expressions in the table §matchStrings§, which derives from the varargs. §rangeInput§ contains the values of any of the \opt{... range} keys.
2153 % \begin{macrocode}
2154 function getRange(rangeInput, ...)
2155 if type(rangeInput) ~= "string" then return end
2156 local result = {}
2157 local matchStrings = table.pack(...)
2158 for i = 1, matchStrings.n do
2159 if type(matchStrings[i]) == "string" then
2160 table.insert(result, rangeInput:match(matchStrings[i]))
2161 end
2162 end
2163 return unpack(result)
2164 end
2165
2166 % \end{macrocode}
2167 % §packageWarning§ and §packageError§ throw \TeX\ warnings and errors, respectively. §packageError§ also sets the global variable §errorCatched§ to §true§. Some Lua functions check the value of this variable and terminate if an error has occurred.
2168 % \begin{macrocode}
2169 function packageWarning(message)
2170 tex.sprint("\\PackageWarning{pgfmolbio}{" .. message .. "}")
2171 end
2172
2173 function packageError(message)
2174 tex.error("Package pgfmolbio Error: " .. message)
2175 errorCatched = true
2176 end
2177
2178 errorCatched = false
2179
2180 % \end{macrocode}
2181 % We extend the §string§ table by the function §string.trim§, which removes leading and trailing spaces.
2182 % \begin{macrocode}
2183 if not string.trim then
2184 string.trim = function(self)
2185 return self:match("^%s*(.-)%s*$")
2186 end
2187 end
2188
2189 % \end{macrocode}
2190 % §outputFileId§ is a counter to enumerate several output files by the \module{convert} module.
2191 % \begin{macrocode}
2192 outputFileId = 0
2193 % \end{macrocode}
2194 % \iffalse
2195 %</pgfmolbio-lua>
2196 %<*pmb-chr-tex>
2197 % \fi
2198 %
2199 % \section{\texorpdfstring{\file{pgfmolbio.chromatogram.tex}}{pgfmolbio.chromatogram.tex}}
2200 % \label{sec:DocChrTex}
2201 %
2202 % \def\ydoclistingssettings{\lstset{style=latex-doc}}\setcounter{lstnumber}{1}
2203 % Since the Lua script of the \module{chromatogram} module does the bulk of the work, we can keep the \TeX\ file relatively short.
2204 %
2205 % \begin{macrocode}
2206 \ifluatex
2207 \RequireLuaModule{pgfmolbio.chromatogram}
2208 \fi
2209
2210 % \end{macrocode}
2211 % We define five custom colors for the traces and probability indicators (see Table~\ref{tab:pmbColors}).
2212 % \begin{macrocode}
2213 \definecolor{pmbTraceGreen}{RGB}{34,114,46}
2214 \definecolor{pmbTraceBlue}{RGB}{48,37,199}
2215 \definecolor{pmbTraceBlack}{RGB}{0,0,0}
2216 \definecolor{pmbTraceRed}{RGB}{191,27,27}
2217 \definecolor{pmbTraceYellow}{RGB}{233,230,0}
2218
2219 % \end{macrocode}
2220 % \begin{macro}{\@pmb@chr@keydef}[2]{\meta{key} name}{default \meta{value}}
2221 % Most of the keys simply store their value. |\@pmb@chr@keydef| simplifies the declaration of such keys by calling |\pgfkeyssetvalue| with the appropriate path, \meta{key} and \meta{value}.
2222 % \begin{macrocode}
2223 \def\@pmb@chr@keydef#1#2{%
2224 \pgfkeyssetvalue{/pgfmolbio/chromatogram/#1}{#2}%
2225 }
2226 % \end{macrocode}
2227 % \end{macro}
2228 % \begin{macro}{\@pmb@chr@stylekeydef}[2]{\meta{key} name}{default \meta{value}}
2229 % This macro initializes a style \meta{key} with a \meta{value}.
2230 % \begin{macrocode}
2231 \def\@pmb@chr@stylekeydef#1#2{%
2232 \pgfkeys{/pgfmolbio/chromatogram/#1/.style={#2}}%
2233 }
2234 % \end{macrocode}
2235 % \end{macro}
2236 % \begin{macro}{\@pmb@chr@getkey}[1]{\meta{key} name}
2237 % |\@pmb@chr@getkey| retrieves the value stored by the \meta{key}.
2238 % \begin{macrocode}
2239 \def\@pmb@chr@getkey#1{%
2240 \pgfkeysvalueof{/pgfmolbio/chromatogram/#1}%
2241 }
2242
2243 % \end{macrocode}
2244 % \end{macro}
2245 % After providing these auxiliary macros, we define all keys of the \module{chromatogram} module.
2246 % \begin{macrocode}
2247 \@pmb@chr@keydef{sample range}{1-500 step 1}
2248
2249 \@pmb@chr@keydef{x unit}{0.2mm}
2250 \@pmb@chr@keydef{y unit}{0.01mm}
2251 \@pmb@chr@keydef{samples per line}{500}
2252 \@pmb@chr@keydef{baseline skip}{3cm}
2253 \@pmb@chr@stylekeydef{canvas style}{draw=none, fill=none}
2254 \@pmb@chr@keydef{canvas height}{2cm}
2255
2256 \@pmb@chr@stylekeydef{trace A style}{pmbTraceGreen}
2257 \@pmb@chr@stylekeydef{trace C style}{pmbTraceBlue}
2258 \@pmb@chr@stylekeydef{trace G style}{pmbTraceBlack}
2259 \@pmb@chr@stylekeydef{trace T style}{pmbTraceRed}
2260 \pgfmolbioset[chromatogram]{%
2261 trace style/.code=\pgfkeysalso{
2262 trace A style/.style={#1},
2263 trace C style/.style={#1},
2264 trace G style/.style={#1},
2265 trace T style/.style={#1}
2266 }%
2267 }
2268 \@pmb@chr@keydef{traces drawn}{}
2269
2270 \@pmb@chr@stylekeydef{tick A style}{thin, pmbTraceGreen}
2271 \@pmb@chr@stylekeydef{tick C style}{thin, pmbTraceBlue}
2272 \@pmb@chr@stylekeydef{tick G style}{thin, pmbTraceBlack}
2273 \@pmb@chr@stylekeydef{tick T style}{thin, pmbTraceRed}
2274 \pgfmolbioset[chromatogram]{%
2275 tick style/.code=\pgfkeysalso{
2276 tick A style/.style={#1},
2277 tick C style/.style={#1},
2278 tick G style/.style={#1},
2279 tick T style/.style={#1}
2280 }%
2281 }
2282 \@pmb@chr@keydef{tick length}{1mm}
2283 \@pmb@chr@keydef{ticks drawn}{}
2284
2285 \@pmb@chr@keydef{base label A text}{\strut A}
2286 \@pmb@chr@keydef{base label C text}{\strut C}
2287 \@pmb@chr@keydef{base label G text}{\strut G}
2288 \@pmb@chr@keydef{base label T text}{\strut T}
2289 \@pmb@chr@stylekeydef{base label A style}%
2290 {below=4pt, font=\ttfamily\footnotesize, pmbTraceGreen}
2291 \@pmb@chr@stylekeydef{base label C style}%
2292 {below=4pt, font=\ttfamily\footnotesize, pmbTraceBlue}
2293 \@pmb@chr@stylekeydef{base label G style}%
2294 {below=4pt, font=\ttfamily\footnotesize, pmbTraceBlack}
2295 \@pmb@chr@stylekeydef{base label T style}%
2296 {below=4pt, font=\ttfamily\footnotesize, pmbTraceRed}
2297 \pgfmolbioset[chromatogram]{%
2298 base label style/.code=\pgfkeysalso{
2299 base label A style/.style={#1},
2300 base label C style/.style={#1},
2301 base label G style/.style={#1},
2302 base label T style/.style={#1}
2303 }%
2304 }
2305 \@pmb@chr@keydef{base labels drawn}{}
2306
2307 \newif\ifpmb@chr@showbasenumbers
2308 \pgfmolbioset[chromatogram]{%
2309 show base numbers/.is if=pmb@chr@showbasenumbers,
2310 show base numbers
2311 }
2312 \@pmb@chr@stylekeydef{base number style}%
2313 {pmbTraceBlack, below=-3pt, font=\sffamily\tiny}
2314 \@pmb@chr@keydef{base number range}{auto-auto step 10}
2315
2316 \@pmb@chr@keydef{probability distance}{0.8cm}
2317 \@pmb@chr@keydef{probabilities drawn}{}
2318 \@pmb@chr@keydef{probability style function}{nil}
2319
2320 \pgfmolbioset[chromatogram]{
2321 bases drawn/.code=\pgfkeysalso{
2322 traces drawn=#1,
2323 ticks drawn=#1,
2324 base labels drawn=#1,
2325 probabilities drawn=#1
2326 },
2327 bases drawn=ACGT
2328 }
2329
2330 % \end{macrocode}
2331 % If \pkg{pgfmolbio} is used with a \TeX\ engine that does not support Lua, the package ends here.
2332 % \begin{macrocode}
2333 \ifluatex\else\expandafter\endinput\fi
2334
2335 % \end{macrocode}
2336 % \begin{macro}{\pmbchromatogram}[2]{A \ometa{key-value list} that configures the chromatogram.}{The name of an \meta{scf file}.}
2337 % If |\pmbchromatogram| appears outside of a |tikzpicture|, we implicitly start this environment, otherwise we begin a new group. ``Within a |tikzpicture|'' means that |\useasboundingbox| is defined.
2338 % \begin{macrocode}
2339 \newif\ifpmb@chr@tikzpicture
2340
2341 \newcommand\pmbchromatogram[2][]{%
2342 \@ifundefined{useasboundingbox}%
2343 {\pmb@chr@tikzpicturefalse\begin{tikzpicture}}%
2344 {\pmb@chr@tikzpicturetrue\begingroup}%
2345 % \end{macrocode}
2346 % Of course, we consider the \ometa{key-value list} before drawing the chromatogram.
2347 % \begin{macrocode}
2348 \pgfmolbioset[chromatogram]{#1}%
2349 % \end{macrocode}
2350 % We generate a new §Chromatogram§ object and invoke several Lua functions: (1) §readScfFile§ reads the given \meta{scf file} (section~\ref{ssc:DocChrLuaReadScfFile}). (2) §setParameters§ passes the values stored by the keys to the Lua script. Note that this function is called twice, since §baseNumberRange§ requires that §sampleRange§ has been already set, and the implementation of §setParameters§ does not ensure this (section~\ref{ssc:DocChrLuaSetParameters}). (3) §pgfmolbio.setCoordinateFormat§ sets the coordinate output format (section~\ref{sec:DocPkgLua}).
2351 % \begin{macrocode}
2352 \directlua{
2353 pmbChromatogram = pgfmolbio.chromatogram.Chromatogram:new()
2354 pmbChromatogram:readScfFile("#2")
2355 pmbChromatogram:setParameters{
2356 sampleRange = "\@pmb@chr@getkey{sample range}",
2357 xUnit = "\@pmb@chr@getkey{x unit}",
2358 yUnit = "\@pmb@chr@getkey{y unit}",
2359 samplesPerLine = "\@pmb@chr@getkey{samples per line}",
2360 baselineSkip = "\@pmb@chr@getkey{baseline skip}",
2361 canvasHeight = "\@pmb@chr@getkey{canvas height}",
2362 tracesDrawn = "\@pmb@chr@getkey{traces drawn}",
2363 tickLength = "\@pmb@chr@getkey{tick length}",
2364 ticksDrawn = "\@pmb@chr@getkey{ticks drawn}",
2365 baseLabelsDrawn = "\@pmb@chr@getkey{base labels drawn}",
2366 showBaseNumbers = "\ifpmb@chr@showbasenumbers true\else false\fi",
2367 probDistance = "\@pmb@chr@getkey{probability distance}",
2368 probabilitiesDrawn = "\@pmb@chr@getkey{probabilities drawn}",
2369 probStyle = \@pmb@chr@getkey{probability style function}
2370 }
2371 pmbChromatogram:setParameters{
2372 baseNumberRange = "\@pmb@chr@getkey{base number range}",
2373 }
2374 pgfmolbio.setCoordinateFormat(
2375 "\pgfkeysvalueof{/pgfmolbio/coordinate unit}",
2376 "\pgfkeysvalueof{/pgfmolbio/coordinate format string}"
2377 )
2378 % \end{macrocode}
2379 % If the \module{convert} module is loaded, we open the appropriate output file, change §tex.sprint§ so that the function writes to this file and then call §printTikzChromatogram§. Without the \module{convert} module, §printTikzChromatogram§ simply returns the drawing commands for the chromatogram to the \TeX\ input stream (section~\ref{ssc:DocChrLuaPrint}).
2380 % \begin{macrocode}
2381 \ifpmb@loadmodule@convert
2382 local filename =
2383 "\pgfkeysvalueof{/pgfmolbio/convert/output file name}"
2384 if filename == "(auto)" then
2385 filename = "pmbconverted" .. pgfmolbio.outputFileId
2386 end
2387 filename = filename ..
2388 ".\pgfkeysvalueof{/pgfmolbio/convert/output file extension}"
2389 outputFile, ioError = io.open(filename, "w")
2390 if ioError then
2391 tex.error(ioError)
2392 end
2393 tex.sprint = function (a) outputFile:write(a) end
2394 tex.sprint("\string\\begin{tikzpicture}")
2395 pmbChromatogram:printTikzChromatogram()
2396 tex.sprint("\string\n\string\\end{tikzpicture}")
2397 outputFile:close()
2398 pgfmolbio.outputFileId = pgfmolbio.outputFileId + 1
2399 \else
2400 pmbChromatogram:printTikzChromatogram()
2401 \fi
2402 }%
2403 % \end{macrocode}
2404 % At the end of |\pmbchromatogram|, we either close the |tikzpicture| or the group, depending on how we started.
2405 % \begin{macrocode}
2406 \ifpmb@chr@tikzpicture\endgroup\else\end{tikzpicture}\fi%
2407 }
2408 % \end{macrocode}
2409 % \end{macro}
2410 %
2411 % \iffalse
2412 %</pmb-chr-tex>
2413 %<*pmb-chr-lua>
2414 % \fi
2415 %
2416 % \section{\texorpdfstring{\file{pgfmolbio.chromatogram.lua}}{pgfmolbio.chromatogram.lua}}
2417 % \label{sec:DocChrLua}
2418 %
2419 % \def\ydoclistingssettings{\lstset{style=lua-doc}}\setcounter{lstnumber}{1}
2420 % This Lua script is the true workhorse of the \module{chromatogram} module. Remember that the documentation for the Staden package\footnote{\url{https://staden.sourceforge.net/}} is the definite source for information on the \file{scf} file format.
2421 % \begin{macrocode}
2422 if luatexbase then
2423 luatexbase.provides_module{
2424 name = "pgfmolbio.chromatogram",
2425 version = "0.21a",
2426 date = "2014/06/17",
2427 description = "DNA sequencing chromatograms",
2428 author = "Wolfgang Esser-Skala",
2429 copyright = "Wolfgang Esser-Skala",
2430 license = "LPPL",
2431 }
2432 end
2433
2434 % \end{macrocode}
2435 %
2436 % \subsection{Module-Wide Variables and Auxiliary Functions}
2437 % \label{ssc:DocChrLuaAuxiliaryFunctions}
2438 %
2439 % \begin{itemize}
2440 % \item §ALL_BASES§: A table of four indexed string fields, which represent the nucleotide single-letter abbreviations.
2441 % \item §PGFKEYS_PATH§: A string that contains the \pkg{pgfkeys} path for \module{chromatogram} keys.
2442 % \end{itemize}
2443 % \begin{macrocode}
2444 local ALL_BASES = {"A", "C", "G", "T"}
2445 local PGFKEYS_PATH = "/pgfmolbio/chromatogram/"
2446
2447 % \end{macrocode}
2448 % These local functions point to functions in \file{pgfmolbio.lua} (section~\ref{sec:DocPkgLua}).
2449 % \begin{macrocode}
2450 local stringToDim = pgfmolbio.stringToDim
2451 local dimToString = pgfmolbio.dimToString
2452 local packageError = pgfmolbio.packageError
2453 local packageWarning = pgfmolbio.packageWarning
2454 local getRange = pgfmolbio.getRange
2455
2456 % \end{macrocode}
2457 % §stdProbStyle§ is the default \opt{probability style function}. It returns a string representing an optional argument of |\draw|. Depending on the value of §prob§, the probability rule thus drawn is colored black, red, yellow or green for quality scores $< 10$, $< 20$, $< 30$ or $\geq 30$, respectively (see also section~\ref{sec:ChrProbabilities}).
2458 % \begin{macrocode}
2459 local function stdProbStyle(prob)
2460 local color = ""
2461 if prob >= 0 and prob < 10 then
2462 color = "black"
2463 elseif prob >= 10 and prob < 20 then
2464 color = "pmbTraceRed"
2465 elseif prob >= 20 and prob < 30 then
2466 color = "pmbTraceYellow"
2467 else
2468 color = "pmbTraceGreen"
2469 end
2470 return "ultra thick, " .. color
2471 end
2472
2473 % \end{macrocode}
2474 % §findBasesInStr§ searches for nucleotide single-letter abbreviations in its string argument. It returns a table of zero to four indexed string fields (one field per character found, which contains that letter).
2475 % \begin{macrocode}
2476 local function findBasesInStr(target)
2477 if not target then return end
2478 local result = {}
2479 for _, v in ipairs(ALL_BASES) do
2480 if target:upper():find(v) then
2481 table.insert(result, v)
2482 end
2483 end
2484 return result
2485 end
2486
2487 % \end{macrocode}
2488 % §readInt§ reads §n§ bytes from a §file§, starting at §offset§ or at the current position if §offset§ is §nil§. By assuming big-endian byte order, the byte sequence is converted to a number and returned.
2489 % \begin{macrocode}
2490 local function readInt(file, n, offset)
2491 if offset then file:seek("set", offset) end
2492 local result = 0
2493 for i = 1, n do
2494 result = result * 0x100 + file:read(1):byte()
2495 end
2496 return result
2497 end
2498
2499 % \end{macrocode}
2500 %
2501 % \subsection{The \texorpdfstring{\texttt{Chromatogram}}{Chromatogram} Class}
2502 % \label{ssc:DocChrLuaClass}
2503 %
2504 % The §Chromatogram§ class (table) represents a single \file{scf} chromatogram. The constructor §Chromatogram:new§ returns a new instance and initializes its variables, which store the values of \module{chromatogram} keys. Most variables are self-explanatory, since their name is similar to their corresponding key.
2505 % \begin{macrocode}
2506 Chromatogram = {}
2507
2508 function Chromatogram:new()
2509 newChromatogram = {
2510 sampleMin = 1,
2511 sampleMax = 500,
2512 sampleStep = 1,
2513 peakMin = -1,
2514 peakMax = -1,
2515 xUnit = stringToDim("0.2mm"),
2516 yUnit = stringToDim("0.01mm"),
2517 samplesPerLine = 500,
2518 baselineSkip = stringToDim("3cm"),
2519 canvasHeight = stringToDim("2cm"),
2520 traceStyle = {
2521 A = PGFKEYS_PATH .. "trace A style",
2522 C = PGFKEYS_PATH .. "trace C style",
2523 G = PGFKEYS_PATH .. "trace G style",
2524 T = PGFKEYS_PATH .. "trace T style"
2525 },
2526 tickStyle = {
2527 A = PGFKEYS_PATH .. "tick A style",
2528 C = PGFKEYS_PATH .. "tick C style",
2529 G = PGFKEYS_PATH .. "tick G style",
2530 T = PGFKEYS_PATH .. "tick T style"
2531 },
2532 tickLength = stringToDim("1mm"),
2533 baseLabelText = {
2534 A = "\\pgfkeysvalueof{" .. PGFKEYS_PATH .. "base label A text}",
2535 C = "\\pgfkeysvalueof{" .. PGFKEYS_PATH .. "base label C text}",
2536 G = "\\pgfkeysvalueof{" .. PGFKEYS_PATH .. "base label G text}",
2537 T = "\\pgfkeysvalueof{" .. PGFKEYS_PATH .. "base label T text}"
2538 },
2539 baseLabelStyle = {
2540 A = PGFKEYS_PATH .. "base label A style",
2541 C = PGFKEYS_PATH .. "base label C style",
2542 G = PGFKEYS_PATH .. "base label G style",
2543 T = PGFKEYS_PATH .. "base label T style"
2544 },
2545 showBaseNumbers = true,
2546 baseNumberMin = -1,
2547 baseNumberMax = -1,
2548 baseNumberStep = 10,
2549 probDistance = stringToDim("0.8cm"),
2550 probStyle = stdProbStyle,
2551 tracesDrawn = ALL_BASES,
2552 ticksDrawn = "ACGT",
2553 baseLabelsDrawn = "ACGT",
2554 probabilitiesDrawn = "ACGT",
2555 }
2556 setmetatable(newChromatogram, self)
2557 self.__index = self
2558 return newChromatogram
2559 end
2560
2561 % \end{macrocode}
2562 % §getMinMaxProbability§ returns the minimum and maximum probability value in the current chromatogram.
2563 % \begin{macrocode}
2564 function Chromatogram:getMinMaxProbability()
2565 local minProb = 0
2566 local maxProb = 0
2567 for _, currPeak in ipairs(self.selectedPeaks) do
2568 for __, currProb in pairs(currPeak.prob) do
2569 if currProb > maxProb then maxProb = currProb end
2570 if currProb < minProb then minProb = currProb end
2571 end
2572 end
2573 return minProb, maxProb
2574 end
2575
2576 % \end{macrocode}
2577 % §getSampleAndPeakIndex§ returns the sample (§sampleId§) and peak index (§peakId§) that correspond to §baseIndex§. If §baseIndex§ is a number, the function simply returns it as sample index. However, if §baseIndex§ is a string of the form §"base§ \meta{number}§"§ (as in a valid value for the \opt{sample range} key), the function returns the offset of the \meta{number}-th peak. §isLowerLimit§ must be §true§ if the function should return the indices of the lower end of a range.
2578 % \begin{macrocode}
2579 function Chromatogram:getSampleAndPeakIndex(baseIndex, isLowerLimit)
2580 local sampleId, peakId
2581
2582 sampleId = tonumber(baseIndex)
2583 if sampleId then
2584 for i, v in ipairs(self.peaks) do
2585 if isLowerLimit then
2586 if v.offset >= sampleId then
2587 peakId = i
2588 break
2589 end
2590 else
2591 if v.offset == sampleId then
2592 peakId = i
2593 break
2594 elseif v.offset > sampleId then
2595 peakId = i - 1
2596 break
2597 end
2598 end
2599 end
2600 else
2601 peakId = tonumber(baseIndex:match("base%s*(%d+)"))
2602 if peakId then
2603 sampleId = self.peaks[peakId].offset
2604 end
2605 end
2606 return sampleId, peakId
2607 end
2608
2609 % \end{macrocode}
2610 %
2611 % \subsection{Read the \texorpdfstring{\file{scf}}{scf} File}
2612 % \label{ssc:DocChrLuaReadScfFile}
2613 %
2614 % §Chromatogram:readScfFile§ introduces three further fields to §Chromatogram§:
2615 % \begin{itemize}
2616 % \item §header§: A table of 14 named number fields that save the information in the \file{scf} header.
2617 % \item §samples§: A table of four named subtables §A§, §C§, §G§, §T§. Each subtable contains §header.samplesNumber§ indexed number fields that represent the fluorescence intensities along a trace.
2618 % \item §peaks§: A table of §header.basesNumber§ indexed subtables which in turn contain three named fields:
2619 % \begin{itemize}
2620 % \item §offset§: A number indicating the offset of the current peak.
2621 % \item §prob§: A table of four named number fields §A§, §C§, §G§, §T§. These numbers store the probability that the current peak is one of the four bases.
2622 % \item §base§: A string that states the base represented by the current peak.
2623 % \end{itemize}
2624 % \end{itemize}
2625 %
2626 % §Chromatogram:readScfFile§ checks whether the requested \file{scf} file ``§filename§'' corresponds to the most recently opened one (via §lastScfFile§). In this case, the variables §peaks§ and §samples§ already contain the relevant data, so we can refrain from re-reading the file. Otherwise, the program tries to open and evaluate the specified file, raising an error on failure.
2627 % \begin{macrocode}
2628 function Chromatogram:readScfFile(filename)
2629 if filename ~= self.lastScfFile then
2630 self.lastScfFile = filename
2631 local scfFile, errorMsg = io.open(filename, "rb")
2632 if not scfFile then packageError(errorMsg) end
2633
2634 self.samples = {A = {}, C = {}, G = {}, T = {}}
2635 self.peaks = {}
2636 % \end{macrocode}
2637 % The function collects the relevant data from the file. \textit{Firstly}, §header§ saves the information in the file header:
2638 % \begin{itemize}
2639 % \item §magicNumber§: Each \file{scf} file must start with the four bytes §2E736366§, which is the string ``§.scf§''. If this sequence is absent, the \module{chromatogram} module raises an error.
2640 % \item §samplesNumber§: The number of sample points.
2641 % \item §samplesOffset§: The offset of the sample data start.
2642 % \item §basesNumber§: The number of recognized bases.
2643 % \item §version§: Since the \module{chromatogram} module currently only supports \file{scf} version 3.00 (the string ``§3.00§'' equals §332E3030§), \TeX\ stops with an error message if the file version is different.
2644 % \item §sampleSize§: The size of each sample point in bytes.
2645 % \end{itemize}
2646 % \begin{macrocode}
2647 self.header = {
2648 magicNumber = readInt(scfFile, 4, 0),
2649 samplesNumber = readInt(scfFile, 4),
2650 samplesOffset = readInt(scfFile, 4),
2651 basesNumber = readInt(scfFile, 4),
2652 leftClip = readInt(scfFile, 4),
2653 rightClip = readInt(scfFile, 4),
2654 basesOffset = readInt(scfFile, 4),
2655 comments = readInt(scfFile, 4),
2656 commentsOffset = readInt(scfFile, 4),
2657 version = readInt(scfFile, 4),
2658 sampleSize = readInt(scfFile, 4),
2659 codeSet = readInt(scfFile, 4),
2660 privateSize = readInt(scfFile, 4),
2661 privateOffset = readInt(scfFile, 4)
2662 }
2663 if self.header.magicNumber ~= 0x2E736366 then
2664 packageError(
2665 "Magic number in scf scfFile '" ..
2666 self.lastScfFile ..
2667 "' corrupt!"
2668 )
2669 end
2670 if self.header.version ~= 0x332E3030 then
2671 packageError(
2672 "Scf scfFile '" ..
2673 self.lastScfFile ..
2674 "' is not version 3.00!"
2675 )
2676 end
2677 % \end{macrocode}
2678 % \textit{Secondly}, §samples§ receives the samples data from the file. Note that the values of the sample points are stored as unsigned integers representing second derivatives (i.\,e., differences between differences between two consecutive sample points). Hence, we convert them back to signed, absolute values.
2679 % \begin{macrocode}
2680 scfFile:seek("set", self.header.samplesOffset)
2681 for baseIndex, baseName in ipairs(ALL_BASES) do
2682 for i = 1, self.header.samplesNumber do
2683 self.samples[baseName][i] =
2684 readInt(scfFile, self.header.sampleSize)
2685 end
2686
2687 for _ = 1, 2 do
2688 local preValue = 0
2689 for i = 1, self.header.samplesNumber do
2690 self.samples[baseName][i] = self.samples[baseName][i] + preValue
2691 if self.samples[baseName][i] > 0xFFFF then
2692 self.samples[baseName][i] = self.samples[baseName][i] - 0x10000
2693 end
2694 preValue = self.samples[baseName][i]
2695 end
2696 end
2697 end
2698 % \end{macrocode}
2699 % \textit{Finally}, we store the peak information in §peaks§.
2700 % \begin{macrocode}
2701 for i = 1, self.header.basesNumber do
2702 self.peaks[i] = {
2703 offset = readInt(scfFile, 4),
2704 prob = {A, C, G, T},
2705 base
2706 }
2707 end
2708
2709 for i = 1, self.header.basesNumber do
2710 self.peaks[i].prob.A = readInt(scfFile, 1)
2711 end
2712
2713 for i = 1, self.header.basesNumber do
2714 self.peaks[i].prob.C = readInt(scfFile, 1)
2715 end
2716
2717 for i = 1, self.header.basesNumber do
2718 self.peaks[i].prob.G = readInt(scfFile, 1)
2719 end
2720
2721 for i = 1, self.header.basesNumber do
2722 self.peaks[i].prob.T = readInt(scfFile, 1)
2723 end
2724
2725 for i = 1, self.header.basesNumber do
2726 self.peaks[i].base = string.char(readInt(scfFile, 1))
2727 end
2728
2729 scfFile:close()
2730 end
2731 end
2732
2733 % \end{macrocode}
2734 %
2735 % \subsection{Set Chromatogram Parameters}
2736 % \label{ssc:DocChrLuaSetParameters}
2737 %
2738 % §Chromatogram:setParameters§ passes options from the \module{chromatogram} module to the Lua script. Each field of the table §keyHash§ is named after a §Chromatogram§ attribute and represents a function that receives one string parameter (the value of a \LaTeX\ key). For instance, §keyHash.sampleRange§ extracts the range and step values from the value stored in the \opt{sample range} key.
2739 % \begin{macrocode}
2740 function Chromatogram:setParameters(newParms)
2741 local keyHash = {
2742 sampleRange = function(v)
2743 local sampleRangeMin, sampleRangeMax, sampleRangeStep =
2744 getRange(
2745 v:trim(),
2746 "^([base]*%s*%d+)%s*%-",
2747 "%-%s*([base]*%s*%d+)",
2748 "step%s*(%d+)$"
2749 )
2750 self.sampleMin, self.peakMin =
2751 self:getSampleAndPeakIndex(sampleRangeMin, true)
2752 self.sampleMax, self.peakMax =
2753 self:getSampleAndPeakIndex(sampleRangeMax, false)
2754 if self.sampleMin >= self.sampleMax then
2755 packageError("Sample range is smaller than 1.")
2756 end
2757 self.sampleStep = sampleRangeStep or self.sampleStep
2758 end,
2759 xUnit = stringToDim,
2760 yUnit = stringToDim,
2761 samplesPerLine = tonumber,
2762 baselineSkip = stringToDim,
2763 canvasHeight = stringToDim,
2764 tickLength = stringToDim,
2765 showBaseNumbers = function(v)
2766 if v == "true" then return true else return false end
2767 end,
2768 baseNumberRange = function(v)
2769 local baseNumberRangeMin, baseNumberRangeMax, baseNumberRangeStep =
2770 getRange(
2771 v:trim(),
2772 "^([auto%d]*)%s+%-",
2773 "%-%s+([auto%d]*$)"
2774 )
2775 if tonumber(baseNumberRangeMin) then
2776 self.baseNumberMin = tonumber(baseNumberRangeMin)
2777 else
2778 self.baseNumberMin = self.peakMin
2779 end
2780 if tonumber(baseNumberRangeMax) then
2781 self.baseNumberMax = tonumber(baseNumberRangeMax)
2782 else
2783 self.baseNumberMax = self.peakMax
2784 end
2785 if self.baseNumberMin >= self.baseNumberMax then
2786 packageError("Base number range is smaller than 1.")
2787 end
2788 if self.baseNumberMin < self.peakMin then
2789 self.baseNumberMin = self.peakMin
2790 packageWarning("Lower base number range is smaller than lower sample range. It was adjusted to " .. self.baseNumberMin .. ".")
2791 end
2792 if self.baseNumberMax > self.peakMax then
2793 self.baseNumberMax = self.peakMax
2794 packageWarning("Upper base number range exceeds upper sample range. It was adjusted to " .. self.baseNumberMax .. ".")
2795 end
2796 self.baseNumberStep = tonumber(baseNumberRangeStep)
2797 or self.baseNumberStep
2798 end,
2799 probDistance = stringToDim,
2800 probStyle = function(v) return v end,
2801 tracesDrawn = findBasesInStr,
2802 ticksDrawn = function(v) return v end,
2803 baseLabelsDrawn = function(v) return v end,
2804 probabilitiesDrawn = function(v) return v end,
2805 probStyle = function(v) return v end
2806 }
2807 % \end{macrocode}
2808 % We iterate over all fields in the argument of §setParameters§. If a field of the same name exists in §keyHash§, we call this field with the value of the corresponding field in §newParms§ as parameter.
2809 % \begin{macrocode}
2810 for key, value in pairs(newParms) do
2811 if keyHash[key] then
2812 self[key] = keyHash[key](value)
2813 end
2814 end
2815 end
2816
2817 % \end{macrocode}
2818 %
2819 % \subsection{Print the Chromatogram}
2820 % \label{ssc:DocChrLuaPrint}
2821 %
2822 % §Chromatogram:printTikzChromatogram§ writes all commands that draw the chromatogram to the \TeX\ input stream (via §tex.sprint§), but only if no error has occurred previously.
2823 % \begin{macrocode}
2824 function Chromatogram:printTikzChromatogram()
2825 if pgfmolbio.errorCatched then return end
2826 % \end{macrocode}
2827 % \paragraph{(1) Select peaks to draw} In order to simplify the drawing operations, we select the peaks that appear in the final output and store information on them in §selectedPeaks§. §selectedPeaks§ is a table of zero to §header.basesNumber§ indexed subtables. It is similar to §peaks§ but only describes the peaks in the displayed part of the chromatogram, which is selected by the \opt{samples range} key. Each subtable of §selectedPeaks§ consists of the following five named fields:
2828 % \begin{itemize}
2829 % \item §offset§: A number indicating the offset of the current peak in ``transformed'' coordinates (i.\,e., the $x$-coordinate of the first sample point shown equals 1).
2830 % \item §base§: See §peaks.base§ (section~\ref{ssc:DocChrLuaReadScfFile}).
2831 % \item §prob§: See §peaks.prob§ (section~\ref{ssc:DocChrLuaReadScfFile}).
2832 % \item §baseIndex§: A number that stores the index of the current peak. The first detected peak in the chromatogram has index~1.
2833 % \item §probXRight§: A number corresponding to the right $x$-coordinate of the probability indicator.
2834 % \end{itemize}
2835 % \begin{macrocode}
2836 self.selectedPeaks = {}
2837 local tIndex = 1
2838 for rPeakIndex, currPeak in ipairs(self.peaks) do
2839 if currPeak.offset >= self.sampleMin
2840 and currPeak.offset <= self.sampleMax then
2841 self.selectedPeaks[tIndex] = {
2842 offset = currPeak.offset + 1 - self.sampleMin,
2843 base = currPeak.base,
2844 prob = currPeak.prob,
2845 baseIndex = rPeakIndex,
2846 probXRight = self.sampleMax + 1 - self.sampleMin
2847 }
2848 % \end{macrocode}
2849 % The right $x$-coordinate of the probability indicator (§probXRight§) is the mean between the offsets of the adjacent peaks. For the last peak, §probXRight§ equals the largest transformed $x$-coordinate.
2850 % \begin{macrocode}
2851 if tIndex > 1 then
2852 self.selectedPeaks[tIndex-1].probXRight =
2853 (self.selectedPeaks[tIndex-1].offset
2854 + self.selectedPeaks[tIndex].offset) / 2
2855 end
2856 tIndex = tIndex + 1
2857 end
2858 end
2859
2860 % \end{macrocode}
2861 % Furthermore, we adjust §baseNumberMin§ and §baseNumberMax§ if any peak was detected in the displayed part of the chromatogram. The value §-1§, which indicates the keyword |auto|, is replaced by the index of the first or last peak, respectively.
2862 % \begin{macrocode}
2863 if tIndex > 1 then
2864 if self.baseNumberMin == -1 then
2865 self.baseNumberMin = self.selectedPeaks[1].baseIndex
2866 end
2867 if self.baseNumberMax == -1 then
2868 self.baseNumberMax = self.selectedPeaks[tIndex-1].baseIndex
2869 end
2870 end
2871
2872 % \end{macrocode}
2873 % \paragraph{(2) Canvas} For each line, we draw a rectangle in \opt{canvas style} whose left border coincides with the $y$-axis.\\
2874 % §yLower§, §yUpper§, §xRight§: rectangle coordinates;\\
2875 % §currLine§: current line, starting from 0;\\
2876 % §samplesLeft§: sample points left to draw after the end of the current line.
2877 % \begin{macrocode}
2878 local samplesLeft = self.sampleMax - self.sampleMin + 1
2879 local currLine = 0
2880 while samplesLeft > 0 do
2881 local yLower = -currLine * self.baselineSkip
2882 local yUpper = -currLine * self.baselineSkip + self.canvasHeight
2883 local xRight =
2884 (math.min(self.samplesPerLine, samplesLeft) - 1) * self.xUnit
2885 tex.sprint(
2886 "\n\t\\draw [" .. PGFKEYS_PATH .. "canvas style] (" ..
2887 dimToString(0) ..
2888 ", " ..
2889 dimToString(yLower) ..
2890 ") rectangle (" ..
2891 dimToString(xRight) ..
2892 ", " ..
2893 dimToString(yUpper) ..
2894 ");"
2895 )
2896 samplesLeft = samplesLeft - self.samplesPerLine
2897 currLine = currLine + 1
2898 end
2899
2900 % \end{macrocode}
2901 % \paragraph{(3) Traces} The traces in §tracesDrawn§ are drawn sequentially.\\
2902 % §currSampleIndex§: original $x$-coordinate of a sample point;\\
2903 % §sampleX§: transformed $x$-coordinate of a sample point, starting at 1;\\
2904 % §x§ and §y§: ``real'' coordinates (in scaled points) of a sample point;\\
2905 % §currLine§: current line, starting at 0;\\
2906 % §firstPointInLine§: boolean that indicates if the current sample point is the first in the line.
2907 % \begin{macrocode}
2908 for _, baseName in ipairs(self.tracesDrawn) do
2909 tex.sprint("\n\t\\draw [" .. self.traceStyle[baseName] .. "] ")
2910 local currSampleIndex = self.sampleMin
2911 local sampleX = 1
2912 local x = 0
2913 local y = 0
2914 local currLine = 0
2915 local firstPointInLine = true
2916
2917 % \end{macrocode}
2918 % We iterate over each sample point. As long as the current sample point is within the selected range, we calculate the real coordinates of the sample point; add the lineto operator |--| if at least one sample point has already appeared in the current line; and write the point to the \TeX\ input stream.
2919 % \begin{macrocode}
2920 while currSampleIndex <= self.sampleMax do
2921 x = ((sampleX - 1) % self.samplesPerLine) * self.xUnit
2922 y = self.samples[baseName][currSampleIndex] * self.yUnit
2923 - currLine * self.baselineSkip
2924 if sampleX % self.sampleStep == 0 then
2925 if not firstPointInLine then
2926 tex.sprint(" -- ")
2927 else
2928 firstPointInLine = false
2929 end
2930 tex.sprint(
2931 "(" ..
2932 dimToString(x) ..
2933 ", " ..
2934 dimToString(y) ..
2935 ")"
2936 )
2937 end
2938 % \end{macrocode}
2939 % Besides, we add line breaks at the appropriate positions.
2940 % \begin{macrocode}
2941 if sampleX ~= self.sampleMax + 1 - self.sampleMin then
2942 if sampleX >= (currLine + 1) * self.samplesPerLine then
2943 currLine = currLine + 1
2944 tex.sprint(";\n\t\\draw [" .. self.traceStyle[baseName] .. "] ")
2945 firstPointInLine = true
2946 end
2947 else
2948 tex.sprint(";")
2949 end
2950 sampleX = sampleX + 1
2951 currSampleIndex = currSampleIndex + 1
2952 end
2953 end
2954
2955 % \end{macrocode}
2956 % \paragraph{(4) Annotations} We iterate over each selected peak and start by finding the line in which the first peak resides.\\
2957 % §currLine§: current line, starting at 0;\\
2958 % §lastProbX§: right $x$-coordinate of the probability rule of the last peak;\\
2959 % §probRemainder§: string that draws the remainder of a probability indicator following a line break;\\
2960 % §x§, §yUpper§, §yLower§: ``real'' tick coordinates;\\
2961 % §tickOperation§: string that equals either \TikZ's moveto or lineto operation, depending on whether the current peak should be marked with a tick.
2962 % \begin{macrocode}
2963 local currLine = 0
2964 local lastProbX = 1
2965 local probRemainder = false
2966
2967 for _, currPeak in ipairs(self.selectedPeaks) do
2968 while currPeak.offset > (currLine + 1) * self.samplesPerLine do
2969 currLine = currLine + 1
2970 end
2971
2972 local x = ((currPeak.offset - 1) % self.samplesPerLine) * self.xUnit
2973 local yUpper = -currLine * self.baselineSkip
2974 local yLower = -currLine * self.baselineSkip - self.tickLength
2975 local tickOperation = ""
2976 if self.ticksDrawn:upper():find(currPeak.base) then
2977 tickOperation = "--"
2978 end
2979
2980 % \end{macrocode}
2981 % \paragraph{(4a) Ticks and labels} Having calculated all coordinates, we draw the tick and the base label, given the latter has been specified by \opt{base labels drawn}.
2982 % \begin{macrocode}
2983 tex.sprint(
2984 "\n\t\\draw [" ..
2985 self.tickStyle[currPeak.base] ..
2986 "] (" ..
2987 dimToString(x) ..
2988 ", " ..
2989 dimToString(yUpper) ..
2990 ") " ..
2991 tickOperation ..
2992 " (" ..
2993 dimToString(x) ..
2994 ", " ..
2995 dimToString(yLower) ..
2996 ")"
2997 )
2998 if self.baseLabelsDrawn:upper():find(currPeak.base) then
2999 tex.sprint(
3000 " node [" ..
3001 self.baseLabelStyle[currPeak.base] ..
3002 "] {" ..
3003 self.baseLabelText[currPeak.base] ..
3004 "}"
3005 )
3006 end
3007
3008 % \end{macrocode}
3009 % \paragraph{(4b) Base numbers} If \opt{show base numbers} is true and the current base number is within the interval given by \opt{base number range}, a base number is printed.
3010 % \begin{macrocode}
3011 if self.showBaseNumbers
3012 and currPeak.baseIndex >= self.baseNumberMin
3013 and currPeak.baseIndex <= self.baseNumberMax
3014 and (currPeak.baseIndex - self.baseNumberMin)
3015 % self.baseNumberStep == 0 then
3016 tex.sprint(
3017 " node [" ..
3018 PGFKEYS_PATH ..
3019 "base number style] {\\strut " ..
3020 currPeak.baseIndex ..
3021 "}"
3022 )
3023 end
3024 tex.sprint(";")
3025
3026 % \end{macrocode}
3027 % \paragraph{(4c) Probabilities} First, we draw the remainder of the last probability rule. Such a remainder has been stored in §probRemainder§ if the last rule had protruded into the right margin (see below). Furthermore, we determine if a probability rule should appear beneath the current peak.
3028 % \begin{macrocode}
3029 if probRemainder then
3030 tex.sprint(probRemainder)
3031 probRemainder = false
3032 end
3033 local drawCurrProb =
3034 self.probabilitiesDrawn:upper():find(currPeak.base)
3035 % \end{macrocode}
3036 % Now comes the tricky part. Whenever we choose to paint a probability rule, we may envision three scenarios. \textit{Firstly}, the probability rule starts in the left margin of the current line (i.\,e., §xLeft§ is negative). This means that the part protruding into the left margin must instead appear at the end of the last line. Therefore, we calculate the coordinates of this part (storing them in §xLeftPrev§, §xRightPrev§ and §yPrev§) and draw the segment. Since the remainder of the rule necessarily starts at the left border of the current line, we set §xLeft§ to zero.
3037 % \begin{macrocode}
3038 local xLeft = lastProbX - 1 - currLine * self.samplesPerLine
3039 if xLeft < 0 then
3040 local xLeftPrev = (self.samplesPerLine + xLeft) * self.xUnit
3041 local xRightPrev = (self.samplesPerLine - 1) * self.xUnit
3042 local yPrev = -(currLine-1) * self.baselineSkip - self.probDistance
3043 if drawCurrProb then
3044 tex.sprint(
3045 "\n\t\\draw [" ..
3046 self.probStyle(currPeak.prob[currPeak.base]) ..
3047 "] (" ..
3048 dimToString(xLeftPrev) ..
3049 ", " ..
3050 dimToString(yPrev) ..
3051 ") -- (" ..
3052 dimToString(xRightPrev) ..
3053 ", " ..
3054 dimToString(yPrev) ..
3055 ");"
3056 )
3057 end
3058 xLeft = 0
3059 else
3060 xLeft = xLeft * self.xUnit
3061 end
3062
3063 % \end{macrocode}
3064 % \textit{Secondly}, the probability rule ends in the right margin of the current line (i.\,e., §xRight§ at least equals §samplesPerLine§). This means that the part protruding into the right margin must instead appear at the start of the following line. Therefore, we calculate the coordinates of this part (storing them in §xRightNext§ and §yNext§) and save the drawing command in §probRemainder§ (whose contents were printed above). Since the remainder of the rule necessarily ends at the right border of the current line, we set §xRight§ to this coordinate.
3065 % \begin{macrocode}
3066 local xRight = currPeak.probXRight - 1 - currLine * self.samplesPerLine
3067 if xRight >= self.samplesPerLine then
3068 if drawCurrProb then
3069 local xRightNext = (xRight - self.samplesPerLine) * self.xUnit
3070 local yNext = -(currLine+1) * self.baselineSkip - self.probDistance
3071 probRemainder =
3072 "\n\t\\draw [" ..
3073 self.probStyle(currPeak.prob[currPeak.base]) ..
3074 "] (" ..
3075 dimToString(0) ..
3076 ", " ..
3077 dimToString(yNext) ..
3078 ") -- (" ..
3079 dimToString(xRightNext) ..
3080 ", " ..
3081 dimToString(yNext) ..
3082 ");"
3083 end
3084 xRight = (self.samplesPerLine - 1) * self.xUnit
3085 else
3086 xRight = xRight * self.xUnit
3087 end
3088
3089 % \end{macrocode}
3090 % \textit{Thirdly}, the probability rule starts and ends within the boundaries of the current line. In this lucky case, the $y$-coordinate is the only one missing, since we previously calculated §xLeft§ (case~1) and §xRight§ (case~2). Drawing of the probability rule proceeds as usual.
3091 % \begin{macrocode}
3092 local y = -currLine * self.baselineSkip - self.probDistance
3093 if drawCurrProb then
3094 tex.sprint(
3095 "\n\t\\draw [" ..
3096 self.probStyle(currPeak.prob[currPeak.base]) ..
3097 "] (" ..
3098 dimToString(xLeft) ..
3099 ", " ..
3100 dimToString(y) ..
3101 ") -- (" ..
3102 dimToString(xRight) ..
3103 ", " ..
3104 dimToString(y) ..
3105 ");"
3106 )
3107 end
3108 lastProbX = currPeak.probXRight
3109 end
3110 end
3111 % \end{macrocode}
3112 % \iffalse
3113 %</pmb-chr-lua>
3114 %<*pmb-dom-tex>
3115 % \fi
3116 %
3117 %
3118 % \section{\texorpdfstring{\file{pgfmolbio.domains.tex}}{pgfmolbio.domains.tex}}
3119 % \label{sec:DocDomTex}
3120 %
3121 % \def\ydoclistingssettings{\lstset{style=latex-doc}}\setcounter{lstnumber}{1}
3122 % \begin{macrocode}
3123 \ProvidesFile{pgfmolbio.domains.tex}[2012/10/01 v0.2 Protein Domains]
3124
3125 % \end{macrocode}
3126 % If the \module{domains} module is requested by Lua\TeX\, it loads the corresponding Lua module and generates a new §SpecialKeys§ object, which will store all feature styles, disulfide keys and print functions (section~\ref{ssc:DocDomLuaSpecialKeysClass}).
3127 % \begin{macrocode}
3128 \ifluatex
3129 \RequireLuaModule{pgfmolbio.domains}
3130 \directlua{pmbSpecialKeys = pgfmolbio.domains.SpecialKeys:new()}
3131 \fi
3132
3133 % \end{macrocode}
3134 %
3135 % \subsection{Keys}
3136 % \label{ssc:DocDomTexKeys}
3137 %
3138 % \begin{macro}{\@pmb@dom@keydef}[2]{\meta{key} name}{default \meta{value}}
3139 % |\@pmb@dom@keydef| declares a \meta{key} in path |/pgfmolbio/domains| and assigns a default \meta{value}.
3140 % \begin{macrocode}
3141 \def\@pmb@dom@keydef#1#2{%
3142 \pgfkeyssetvalue{/pgfmolbio/domains/#1}{#2}%
3143 }
3144
3145 % \end{macrocode}
3146 % \end{macro}
3147 % \begin{macro}{\pmbdomvalueof}[1]{\meta{key} name}
3148 % |\pmbdomvalueof| retrieves the value of a \meta{key} in path |/pgfmolbio/domains|. Note that the control word lacks an |@| and is thus freely accessible within a \LaTeX\ document (see section~\ref{sec:DomFeatureStylesAndShapes}).
3149 % \begin{macrocode}
3150 \def\pmbdomvalueof#1{%
3151 \pgfkeysvalueof{/pgfmolbio/domains/#1}%
3152 }
3153
3154 % \end{macrocode}
3155 % \end{macro}
3156 % Aided by these auxiliary macros, we define all keys of the \module{domains} module.
3157 % \begin{macrocode}
3158 \@pmb@dom@keydef{name}{Protein}
3159 \newif\ifpmb@dom@showname
3160 \pgfmolbioset[domains]{%
3161 show name/.is if=pmb@dom@showname,
3162 show name
3163 }
3164 \@pmb@dom@keydef{description}{}
3165
3166 \@pmb@dom@keydef{x unit}{.5mm}
3167 \@pmb@dom@keydef{y unit}{6mm}
3168 \@pmb@dom@keydef{residues per line}{200}
3169 \@pmb@dom@keydef{baseline skip}{3}
3170 \@pmb@dom@keydef{residue numbering}{auto}
3171 \@pmb@dom@keydef{residue range}{auto-auto}
3172 \@pmb@dom@keydef{enlarge left}{0cm}
3173 \@pmb@dom@keydef{enlarge right}{0cm}
3174 \@pmb@dom@keydef{enlarge top}{1cm}
3175 \@pmb@dom@keydef{enlarge bottom}{0cm}
3176
3177 \pgfmolbioset[domains]{%
3178 style/.code=\pgfmolbioset[domains]{current style/.style={#1}}
3179 }
3180
3181 \@pmb@dom@keydef{domain font}{\footnotesize}
3182
3183 \@pmb@dom@keydef{level}{}
3184 \@pmb@dom@keydef{disulfide base distance}{1}
3185 \@pmb@dom@keydef{disulfide level distance}{.2}
3186 \@pmb@dom@keydef{range font}{\sffamily\scriptsize}
3187
3188 \newif\ifpmb@dom@showruler
3189 \pgfmolbioset[domains]{%
3190 show ruler/.is if=pmb@dom@showruler,
3191 show ruler
3192 }
3193 \@pmb@dom@keydef{ruler range}{auto-auto}
3194 \@pmb@dom@keydef{default ruler step size}{50}
3195 \@pmb@dom@keydef{ruler distance}{-.5}
3196
3197 \@pmb@dom@keydef{sequence}{}
3198 \@pmb@dom@keydef{magnified sequence font}{\ttfamily\footnotesize}
3199
3200
3201 \newif\ifpmb@dom@showsecstructure
3202 \pgfmolbioset[domains]{%
3203 show secondary structure/.is if=pmb@dom@showsecstructure,
3204 show secondary structure=false
3205 }
3206 \@pmb@dom@keydef{secondary structure distance}{1}
3207 \pgfmolbioset[domains]{%
3208 helix back border color/.code=\colorlet{helix back border color}{#1},
3209 helix back main color/.code=\colorlet{helix back main color}{#1},
3210 helix back middle color/.code=\colorlet{helix back middle color}{#1},
3211 helix front border color/.code=\colorlet{helix front border color}{#1},
3212 helix front main color/.code=\colorlet{helix front main color}{#1},
3213 helix front middle color/.code=\colorlet{helix front middle color}{#1},
3214 helix back border color=white!50!black,
3215 helix back main color=white!90!black,
3216 helix back middle color=white,
3217 helix front border color=red!50!black,
3218 helix front main color=red!90!black,
3219 helix front middle color=red!10!white
3220 }
3221
3222 \@pmb@dom@keydef{sequence length}{}
3223
3224 \@pmb@dom@keydef{@layer}{}
3225
3226 % \end{macrocode}
3227 %
3228 % \subsection{Feature Shapes}
3229 % \label{ssc:DocDomTexFeatureShapes}
3230 %
3231 % \begin{macro}{\setfeatureshape}[2]{Shape \meta{name}.}{\TikZ\ \meta{code}.}
3232 % Stores the \meta{code} for a shape in the macro |\@pmb@dom@feature@|\meta{name}|@shape|.
3233 % \begin{macrocode}
3234 \newcommand\setfeatureshape[2]{%
3235 \expandafter\def\csname @pmb@dom@feature@#1@shape\endcsname{#2}%
3236 }
3237
3238 % \end{macrocode}
3239 % \end{macro}
3240 % \begin{macro}{\setfeatureshapealias}[2]{New shape.}{Existing shape.}
3241 % Links a new shape to an existing one.
3242 % \begin{macrocode}
3243 \newcommand\setfeatureshapealias[2]{%
3244 \expandafter\def\csname @pmb@dom@feature@#1@shape\endcsname{%
3245 \@nameuse{@pmb@dom@feature@#2@shape}%
3246 }%
3247 }
3248
3249 % \end{macrocode}
3250 % \end{macro}
3251 % \begin{macro}{\setfeaturestylealias}[2]{New style.}{Existing style.}
3252 % This macro and the next one are only defined in Lua\TeX\. Depending on whether |\setfeaturestylealias| occurs within a |pmbdomains| environment, it either sets the feature styles of the §SpecialKeys§ object in the current §Protein§ (§pmbProtein.specialKeys§) or of the global §SpecialKeys§ object (§pmbSpecialKeys§).
3253 % \begin{macro}{\setfeaturealias}[2]{New feature.}{Existing feature.}
3254 % Calls |\setfeatureshapealias| and possibly |\setfeaturestylealias|.
3255 % \begin{macrocode}
3256 \ifluatex
3257 \newcommand\setfeaturestylealias[2]{%
3258 \directlua{
3259 if pmbProtein then
3260 pmbProtein.specialKeys:aliasFeatureStyle("#1", "#2")
3261 else
3262 pmbSpecialKeys:aliasFeatureStyle("#1", "#2")
3263 end
3264 }%
3265 }
3266 \newcommand\setfeaturealias[2]{%
3267 \setfeatureshapealias{#1}{#2}%
3268 \setfeaturestylealias{#1}{#2}%
3269 }
3270 \else
3271 \let\setfeaturealias\setfeatureshapealias%
3272 \fi
3273
3274 % \end{macrocode}
3275 % \end{macro}\end{macro}
3276 % \begin{macro}{\pmbdomdrawfeature}[1]{The feature \meta{type} that should be drawn.}
3277 % If a feature \meta{type} (i.\,e., the corresponding macro) is undefined, we issue a warning and draw feature \texttt{default}.
3278 % \begin{macrocode}
3279 \newcommand\pmbdomdrawfeature[1]{%
3280 \@ifundefined{@pmb@dom@feature@#1@shape}{%
3281 \PackageWarning{pgfmolbio}%
3282 {Feature shape `#1' unknown, using `default'.}%
3283 \@pmb@dom@feature@default@shape%
3284 }{%
3285 \@nameuse{@pmb@dom@feature@#1@shape}%
3286 }%
3287 }
3288
3289 % \end{macrocode}
3290 % \end{macro}
3291 % Definitions of standard features and their aliases.
3292 % \begin{macrocode}
3293 \setfeatureshape{default}{%
3294 \path [/pgfmolbio/domains/current style]
3295 (\xLeft, \yMid + .5 * \pmbdomvalueof{y unit}) rectangle
3296 (\xRight, \yMid - .5 * \pmbdomvalueof{y unit});
3297 }
3298
3299 \setfeatureshape{domain}{
3300 \draw [/pgfmolbio/domains/current style, rounded corners=2pt]
3301 (\xLeft, \yMid + .5 * \pmbdomvalueof{y unit}) rectangle
3302 (\xRight, \yMid - .5 * \pmbdomvalueof{y unit});
3303 \node at (\xMid, \yMid)
3304 {\pmbdomvalueof{domain font}{\pmbdomvalueof{description}}};
3305 }
3306 \setfeaturealias{DOMAIN}{domain}
3307
3308 \setfeatureshape{signal peptide}{%
3309 \path [/pgfmolbio/domains/current style]
3310 (\xLeft, \yMid + \pmbdomvalueof{y unit} / 5) rectangle
3311 (\xRight, \yMid - \pmbdomvalueof{y unit} / 5);
3312 }
3313 \setfeaturealias{SIGNAL}{signal peptide}
3314
3315 \setfeatureshape{propeptide}{%
3316 \path [/pgfmolbio/domains/current style]
3317 (\xLeft, \yMid + .5 * \pmbdomvalueof{y unit}) rectangle
3318 (\xRight, \yMid - .5 * \pmbdomvalueof{y unit});
3319 }
3320 \setfeaturealias{PROPEP}{propeptide}
3321
3322 \setfeatureshape{carbohydrate}{%
3323 \draw [/pgfmolbio/domains/current style]
3324 (\xMid, \yMid) --
3325 (\xMid, \yMid + .7 * \pmbdomvalueof{y unit})
3326 node [above] {\tiny\strut\pmbdomvalueof{description}};
3327 \fill [/pgfmolbio/domains/current style]
3328 (\xMid, \yMid + .7 * \pmbdomvalueof{y unit}) circle [radius=1pt];
3329 }
3330 \setfeaturealias{CARBOHYD}{carbohydrate}
3331
3332 \setfeatureshape{other/main chain}{%
3333 \ifpmb@dom@showsecstructure%
3334 \pgfmathsetmacro\yUpper{%
3335 \yMid + \pmbdomvalueof{secondary structure distance}
3336 * \pmbdomvalueof{y unit}%
3337 }
3338 \draw [thin]
3339 (\xLeft, \yUpper pt) --
3340 (\xRight, \yUpper pt);%
3341 \fi%
3342 \path [/pgfmolbio/domains/current style]
3343 (\xLeft, \yMid) --
3344 (\xRight, \yMid);%
3345 }
3346
3347 \setfeatureshape{other/name}{%
3348 \ifpmb@dom@showname%
3349 \node [/pgfmolbio/domains/current style]
3350 at (\xMid, \pmbdomvalueof{baseline skip} * \pmbdomvalueof{y unit})
3351 {\pmbdomvalueof{name} (\pmbdomvalueof{sequence length} residues)};
3352 \fi%
3353 }
3354
3355 \setfeatureshape{disulfide}{%
3356 \pgfmathsetmacro\yUpper{%
3357 \yMid + (
3358 \pmbdomvalueof{disulfide base distance} +
3359 (\pmbdomvalueof{level} - 1) *
3360 \pmbdomvalueof{disulfide level distance}
3361 ) * \pmbdomvalueof{y unit}
3362 }
3363 \path [/pgfmolbio/domains/current style]
3364 (\xLeft, \yMid) --
3365 (\xLeft, \yUpper pt) --
3366 (\xRight, \yUpper pt) --
3367 (\xRight, \yMid);
3368 }
3369 \setfeaturealias{DISULFID}{disulfide}
3370
3371 \setfeatureshape{range}{%
3372 \pgfmathsetmacro\yUpper{%
3373 \yMid + (
3374 \pmbdomvalueof{disulfide base distance} +
3375 (\pmbdomvalueof{level} - 1) *
3376 \pmbdomvalueof{disulfide level distance}
3377 ) * \pmbdomvalueof{y unit}
3378 }
3379 \path [/pgfmolbio/domains/current style]
3380 (\xLeft, \yUpper pt) --
3381 (\xRight, \yUpper pt)
3382 node [pos=.5, above]
3383 {\pmbdomvalueof{range font}{\pmbdomvalueof{description}}};
3384 }
3385
3386 \setfeatureshape{other/ruler}{%
3387 \draw [/pgfmolbio/domains/current style]
3388 (\xMid,
3389 \yMid + \pmbdomvalueof{ruler distance} *
3390 \pmbdomvalueof{y unit}) --
3391 (\xMid,
3392 \yMid + \pmbdomvalueof{ruler distance} *
3393 \pmbdomvalueof{y unit} - 1mm)
3394 node [below=-1mm] {\tiny\sffamily\strut\residueNumber};
3395 }
3396
3397
3398 \setfeatureshape{other/sequence}{%
3399 \node [/pgfmolbio/domains/current style]
3400 at (\xMid, \yMid) {\strut\currentResidue};
3401 }
3402
3403 \newlength\pmb@magnifiedsequence@width
3404
3405 \setfeatureshape{other/magnified sequence above}{%
3406 \settowidth\pmb@magnifiedsequence@width{%
3407 \begin{pgfinterruptpicture}%
3408 \pmbdomvalueof{magnified sequence font}%
3409 \featureSequence%
3410 \end{pgfinterruptpicture}%
3411 }%
3412 \pgfmathsetmacro\xUpperLeft{\xMid - \pmb@magnifiedsequence@width / 2}
3413 \pgfmathsetmacro\xUpperRight{\xMid + \pmb@magnifiedsequence@width / 2}
3414
3415 \draw [/pgfmolbio/domains/current style]
3416 (\xLeft, \yMid) --
3417 (\xLeft, \yMid + \pmbdomvalueof{y unit} / 6) --
3418 (\xUpperLeft pt, \yMid + \pmbdomvalueof{y unit} * 4/6) --
3419 (\xUpperLeft pt, \yMid + \pmbdomvalueof{y unit} * 5/6)
3420 (\xUpperRight pt, \yMid + \pmbdomvalueof{y unit} * 5/6) --
3421 (\xUpperRight pt, \yMid + \pmbdomvalueof{y unit} * 4/6) --
3422 (\xRight, \yMid + \pmbdomvalueof{y unit} / 6) --
3423 (\xRight, \yMid);
3424 \node [anchor=mid]
3425 at (\xMid, \yMid + \pmbdomvalueof{y unit})
3426 {\pmbdomvalueof{magnified sequence font}\featureSequence};
3427 }
3428
3429 \setfeatureshape{other/magnified sequence below}{%
3430 \settowidth\pmb@magnifiedsequence@width{%
3431 \begin{pgfinterruptpicture}%
3432 \pmbdomvalueof{magnified sequence font}%
3433 \featureSequence%
3434 \end{pgfinterruptpicture}%
3435 }%
3436 \pgfmathsetmacro\xLowerLeft{\xMid - \pmb@magnifiedsequence@width / 2}
3437 \pgfmathsetmacro\xLowerRight{\xMid + \pmb@magnifiedsequence@width / 2}
3438
3439 \draw [/pgfmolbio/domains/current style]
3440 (\xLeft, \yMid) --
3441 (\xLeft, \yMid - \pmbdomvalueof{y unit} / 6) --
3442 (\xLowerLeft pt, \yMid - \pmbdomvalueof{y unit}) --
3443 (\xLowerLeft pt, \yMid - \pmbdomvalueof{y unit} * 7/6)
3444 (\xLowerRight pt, \yMid - \pmbdomvalueof{y unit} * 7/6) --
3445 (\xLowerRight pt, \yMid - \pmbdomvalueof{y unit}) --
3446 (\xRight, \yMid - \pmbdomvalueof{y unit} / 6) --
3447 (\xRight, \yMid);
3448 \node [anchor=mid]
3449 at (\xMid, \yMid - \pmbdomvalueof{y unit} * 8/6)
3450 {\pmbdomvalueof{magnified sequence font}\featureSequence};
3451 }
3452
3453
3454 % \end{macrocode}
3455 %
3456 % \subsection{Secondary Structure Elements}
3457 % \label{ssc:DocDomTexSecondaryStructure}
3458 %
3459 % \begin{macro}{\@pmb@dom@helixsegment}[1]{Scale factor for \TikZ's \texttt{svg} action.}
3460 % Draws a full helix segment at the current canvas position. We use the (unusual) \file{svg} syntax since the helix segment was designed in Inkscape, and the \file{svg} commands were copied from the resulting vector graphics file.
3461 % \begin{macrocode}
3462 \newcommand\@pmb@dom@helixsegment[1]{%
3463 svg [scale=#1] "%
3464 c 0.30427 0
3465 0.62523 0.59174
3466 0.79543 0.96646
3467 c 0.97673 2.15039
3468 1.34005 4.49858
3469 1.84538 6.6178
3470 c 0.56155 2.35498
3471 0.99602 4.514
3472 1.82948 6.72355
3473 c 0.11069 0.29346
3474 0.23841 0.69219
3475 0.56172 0.69219
3476 l -5 0
3477 c -0.27235 0.0237
3478 -0.55793 -0.51373
3479 -0.65225 -0.76773
3480 c -0.98048 -2.64055
3481 -1.40233 -5.46534
3482 -2.06809 -8.00784
3483 c -0.50047 -1.91127
3484 -0.94696 -3.73368
3485 -1.68631 -5.43929
3486 c -0.14066 -0.3245
3487 -0.34516 -0.78514
3488 -0.69997 -0.78514
3489 z"
3490 }
3491
3492 % \end{macrocode}
3493 % \end{macro}
3494 % \begin{macro}{\@pmb@dom@helixhalfsegment}[1]{Scale factor for \TikZ's \texttt{svg} action.}
3495 % Draws a half helix segment.
3496 % \begin{macrocode}
3497 \newcommand\@pmb@dom@helixhalfsegment[1]{%
3498 svg [scale=#1] "%
3499 c 0.50663 2.18926
3500 0.96294 4.51494
3501 1.78125 6.71875
3502 c 0.09432 0.254
3503 0.35265 0.80495
3504 0.625 0.78125
3505 l 5 0
3506 c -0.32331 0
3507 -0.45181 -0.42529
3508 -0.5625 -0.71875
3509 c -0.83346 -2.20955
3510 -1.2822 -4.36377
3511 -1.84375 -6.78125
3512 l -5 0
3513 z"
3514 }
3515
3516 % \end{macrocode}
3517 % \end{macro}
3518 % Shadings for helix segments.
3519 % \begin{macrocode}
3520 \pgfdeclareverticalshading[%
3521 helix back border color,%
3522 helix back main color,%
3523 helix back middle color%
3524 ]{helix half upper back}{100bp}{
3525 color(0bp)=(helix back middle color);
3526 color(5bp)=(helix back middle color);
3527 color(45bp)=(helix back main color);
3528 color(75bp)=(helix back border color);
3529 color(100bp)=(helix back border color)
3530 }
3531
3532 \pgfdeclareverticalshading[%
3533 helix back border color,%
3534 helix back main color,%
3535 helix back middle color%
3536 ]{helix half lower back}{100bp}{
3537 color(0bp)=(helix back border color);
3538 color(25bp)=(helix back border color);
3539 color(35bp)=(helix back main color);
3540 color(55bp)=(helix back middle color);
3541 color(95bp)=(helix back main color);
3542 color(100bp)=(helix back main color)
3543 }
3544
3545 \pgfdeclareverticalshading[%
3546 helix back border color,%
3547 helix back main color,%
3548 helix back middle color%
3549 ]{helix full back}{100bp}{
3550 color(0bp)=(helix back border color);
3551 color(25bp)=(helix back border color);
3552 color(30bp)=(helix back main color);
3553 color(40bp)=(helix back middle color);
3554 color(60bp)=(helix back main color);
3555 color(75bp)=(helix back border color);
3556 color(100bp)=(helix back border color)
3557 }
3558
3559 \pgfdeclareverticalshading[%
3560 helix front border color,%
3561 helix front main color,%
3562 helix front middle color%
3563 ]{helix half upper front}{100bp}{
3564 color(0bp)=(helix front main color);
3565 color(5bp)=(helix front main color);
3566 color(45bp)=(helix front middle color);
3567 color(65bp)=(helix front main color);
3568 color(75bp)=(helix front border color);
3569 color(100bp)=(helix front border color)
3570 }
3571
3572 \pgfdeclareverticalshading[%
3573 helix front border color,%
3574 helix front main color,%
3575 helix front middle color%
3576 ]{helix full front}{100bp}{
3577 color(0bp)=(helix front border color);
3578 color(25bp)=(helix front border color);
3579 color(40bp)=(helix front main color);
3580 color(60bp)=(helix front middle color);
3581 color(70bp)=(helix front main color);
3582 color(75bp)=(helix front border color);
3583 color(100bp)=(helix front border color)
3584 }
3585
3586 % \end{macrocode}
3587 % The following features print single helical turns. They are drawn with appropriate coordinates by §printHelixFeature§ (section~\ref{ssc:DocDomLuaPrintFunctions}).
3588 % \begin{macrocode}
3589 \setfeatureshape{helix/half upper back}{%
3590 \ifpmb@dom@showsecstructure%
3591 \pgfmathsetmacro\yShift{%
3592 \pmbdomvalueof{secondary structure distance} *
3593 \pmbdomvalueof{y unit}%
3594 }
3595 \draw [shading=helix half upper back]
3596 (\xLeft, \yMid + \yShift pt)
3597 \@pmb@dom@helixhalfsegment{\pmbdomvalueof{x unit} / 5};
3598 \fi%
3599 }
3600
3601 \setfeatureshape{helix/half lower back}{%
3602 \ifpmb@dom@showsecstructure%
3603 \pgfmathsetmacro\yShift{%
3604 \pmbdomvalueof{secondary structure distance} *
3605 \pmbdomvalueof{y unit}%
3606 }
3607 \draw [shading=helix half lower back]
3608 (\xRight, \yMid + \yShift pt) [rotate=180]
3609 \@pmb@dom@helixhalfsegment{\pmbdomvalueof{x unit} / 5};
3610 \fi%
3611 }
3612
3613 \setfeatureshape{helix/full back}{%
3614 \ifpmb@dom@showsecstructure%
3615 \pgfmathsetmacro\yShift{%
3616 \pmbdomvalueof{secondary structure distance} *
3617 \pmbdomvalueof{y unit}%
3618 }
3619 \draw [shading=helix full back]
3620 (\xMid, \yLower + \yShift pt)
3621 \@pmb@dom@helixsegment{\pmbdomvalueof{x unit} / 5};
3622 \fi%
3623 }
3624
3625 \setfeatureshape{helix/half upper front}{%
3626 \ifpmb@dom@showsecstructure%
3627 \pgfmathsetmacro\yShift{%
3628 \pmbdomvalueof{secondary structure distance} *
3629 \pmbdomvalueof{y unit}%
3630 }
3631 \draw [shading=helix half upper front]
3632 (\xRight, \yMid + \yShift pt) [xscale=-1]
3633 \@pmb@dom@helixhalfsegment{\pmbdomvalueof{x unit} / 5};
3634 \fi%
3635 }
3636
3637 \setfeatureshape{helix/full front}{%
3638 \ifpmb@dom@showsecstructure%
3639 \pgfmathsetmacro\yShift{%
3640 \pmbdomvalueof{secondary structure distance} *
3641 \pmbdomvalueof{y unit}%
3642 }
3643 \draw [shading=helix full front]
3644 (\xMid, \yLower + \yShift pt) [xscale=-1]
3645 \@pmb@dom@helixsegment{\pmbdomvalueof{x unit} / 5};
3646 \fi%
3647 }
3648
3649 % \end{macrocode}
3650 % Definitions of the remaining secondary structure features.
3651 % \begin{macrocode}
3652 \definecolor{strand left color}{RGB}{42,127,255}
3653 \definecolor{strand right color}{RGB}{128,179,255}
3654
3655 \setfeatureshape{beta strand}{%
3656 \ifpmb@dom@showsecstructure%
3657 \pgfmathsetmacro\yShift{%
3658 \pmbdomvalueof{secondary structure distance} *
3659 \pmbdomvalueof{y unit}%
3660 }
3661 \draw [/pgfmolbio/domains/current style]
3662 (\xLeft, \yMid + \pmbdomvalueof{x unit} + \yShift pt) --
3663 (\xRight - 1.5 * \pmbdomvalueof{x unit},
3664 \yMid + \pmbdomvalueof{x unit} + \yShift pt) --
3665 (\xRight - 1.5 * \pmbdomvalueof{x unit},
3666 \yMid + 1.5 * \pmbdomvalueof{x unit} + \yShift pt) --
3667 (\xRight, \yMid + \yShift pt) --
3668 (\xRight - 1.5 * \pmbdomvalueof{x unit},
3669 \yMid - 1.5 * \pmbdomvalueof{x unit} + \yShift pt) --
3670 (\xRight - 1.5 * \pmbdomvalueof{x unit},
3671 \yMid - \pmbdomvalueof{x unit} + \yShift pt) --
3672 (\xLeft, \yMid - \pmbdomvalueof{x unit} + \yShift pt) --
3673 cycle;%
3674 \fi%
3675 }
3676 \setfeaturealias{STRAND}{beta strand}
3677
3678 \setfeatureshape{beta turn}{%
3679 \ifpmb@dom@showsecstructure%
3680 \pgfmathsetmacro\yShift{%
3681 \pmbdomvalueof{secondary structure distance} *
3682 \pmbdomvalueof{y unit}%
3683 }
3684 \pgfmathsetmacro\turnXradius{(\xRight - \xLeft) / 2}%
3685 \pgfmathsetmacro\turnYradius{\pmbdomvalueof{x unit} * 1.5}%
3686 \fill [white]
3687 (\xLeft, \yMid + 1mm + \yShift pt) rectangle
3688 (\xRight, \yMid - 1mm + \yShift pt);%
3689 \draw [/pgfmolbio/domains/current style]
3690 (\xLeft - .5pt, \yMid + \yShift pt) --
3691 (\xLeft, \yMid + \yShift pt) arc
3692 [start angle=180, end angle=0,
3693 x radius=\turnXradius pt, y radius=\turnYradius pt] --
3694 (\xRight + .5pt, \yMid + \yShift pt);%
3695 \fi%
3696 }
3697 \setfeaturealias{TURN}{beta turn}
3698
3699 \setfeatureshape{beta bridge}{%
3700 \ifpmb@dom@showsecstructure%
3701 \pgfmathsetmacro\yShift{%
3702 \pmbdomvalueof{secondary structure distance} *
3703 \pmbdomvalueof{y unit}%
3704 }
3705 \draw [/pgfmolbio/domains/current style]
3706 (\xLeft, \yMid + .25 * \pmbdomvalueof{x unit} + \yShift pt) --
3707 (\xRight - 1.5 * \pmbdomvalueof{x unit},
3708 \yMid + .25 * \pmbdomvalueof{x unit} + \yShift pt) --
3709 (\xRight - 1.5 * \pmbdomvalueof{x unit},
3710 \yMid + 1.5 * \pmbdomvalueof{x unit} + \yShift pt) --
3711 (\xRight, \yMid + \yShift pt) --
3712 (\xRight - 1.5 * \pmbdomvalueof{x unit},
3713 \yMid - 1.5 * \pmbdomvalueof{x unit} + \yShift pt) --
3714 (\xRight - 1.5 * \pmbdomvalueof{x unit},
3715 \yMid - .25 * \pmbdomvalueof{x unit} + \yShift pt) --
3716 (\xLeft, \yMid - .25 * \pmbdomvalueof{x unit} + \yShift pt) --
3717 cycle;%
3718 \fi%
3719 }
3720
3721 \setfeatureshape{bend}{%
3722 \ifpmb@dom@showsecstructure%
3723 \pgfmathsetmacro\yShift{%
3724 \pmbdomvalueof{secondary structure distance} *
3725 \pmbdomvalueof{y unit}%
3726 }
3727 \fill [white]
3728 (\xLeft, \yMid + 1mm + \yShift pt) rectangle
3729 (\xRight, \yMid - 1mm + \yShift pt);%
3730 \draw [/pgfmolbio/domains/current style]
3731 (\xLeft - .5pt, \yMid + \yShift pt) --
3732 (\xLeft, \yMid + \yShift pt) --
3733 (\xMid, \yMid + .5 * \pmbdomvalueof{y unit} + \yShift pt) --
3734 (\xRight, \yMid + \yShift pt) --
3735 (\xRight + .5pt, \yMid + \yShift pt);%
3736 \fi%
3737 }
3738
3739 % \end{macrocode}
3740 % This concludes the part of the package that is always loaded. The remaining code is only executed within Lua\TeX.
3741 % \begin{macrocode}
3742 \ifluatex\else\expandafter\endinput\fi
3743
3744
3745 % \end{macrocode}
3746 %
3747 % \subsection{Adding Features}
3748 % \label{ssc:DocDomTexAddingFeatures}
3749 %
3750 % \begin{macro}{\pmb@dom@inputuniprot}[1]{The \meta{name} of a Uniprot file.}
3751 % |\pmb@dom@inputuniprot| reads some attributes and all features from a Uniprot file (§readUniprotFile§, section~\ref{ssc:DocDomLuaReadFiles}). It then updates some keys of the \module{domains} module (§getParameters§, section~\ref{ssc:DocDomLuaParameters}) and then passes the value of \opt{residue numbering} to the §pmbProtein§ object.
3752 % \begin{macrocode}
3753 \newcommand\pmb@dom@inputuniprot[1]{%
3754 \directlua{
3755 pmbProtein:readUniprotFile("#1")
3756 pmbProtein:getParameters()
3757 pmbProtein:setParameters{
3758 residueNumbering = "\pmbdomvalueof{residue numbering}"
3759 }
3760 }%
3761 }
3762
3763 % \end{macrocode}
3764 % \end{macro}
3765 % \begin{macro}{\pmb@dom@inputgff}[1]{The \meta{name} of a General Feature Format (\file{gff}) file.}
3766 % This macro reads all features from a \file{gff} file (§readGffFile§, section~\ref{ssc:DocDomLuaReadFiles}). It then passes the value of residue numbering to §pmbProtein§.
3767 % \begin{macrocode}
3768 \newcommand\pmb@dom@inputgff[1]{%
3769 \directlua{
3770 pmbProtein:readGffFile("#1")
3771 pmbProtein:setParameters{
3772 residueNumbering = "\pmbdomvalueof{residue numbering}"
3773 }
3774 }%
3775 }
3776
3777 % \end{macrocode}
3778 % \end{macro}
3779 % \begin{macro}{\pmb@dom@addfeature}[4]{A \ometa{key-value list} that is locally applied to the feature.}{The feature \meta{key}.}{The \meta{first} \dots}{and \meta{last} residue covered by the feature.}
3780 % This macro adds a feature to §pmbProtein§ by calling its §addFeature§ method. The \ometa{key-value list} should be stored without any expansion in the §kvList§ field of §addFeature§'s single argument table. To this end, we first store the \ometa{key-value list} in the token register |\@pmb@toksa| and then access its contents by the construction |\directlua{|[...]|\the\@pmb@toksa|[...]|}|. This code behaves similarly to |\the| inside an |\edef|, i.\,e. the contents of the token register are not further expanded.
3781 % \begin{macrocode}
3782 \newcommand\pmb@dom@addfeature[4][]{%
3783 \begingroup%
3784 \pgfmolbioset[domains]{#1}%
3785 \@pmb@toksa{#1}%
3786 \directlua{
3787 pmbProtein:addFeature{
3788 key = "#2",
3789 start = "#3",
3790 stop = "#4",
3791 kvList = "\luaescapestring{\the\@pmb@toksa}",
3792 level = tonumber("\pmbdomvalueof{level}"),
3793 layer = tonumber("\pmbdomvalueof{@layer}")
3794 }
3795 }%
3796 \endgroup%
3797 }
3798
3799 % \end{macrocode}
3800 % \end{macro}
3801 %
3802 % \subsection{The Main Environment}
3803 % \label{ssc:DocDomTexMainEnvironment}
3804 %
3805 % % \begin{environment}{pmbdomains}[2]{A \ometa{key-value list} that configures the domain diagram.}{The \meta{sequence length}.}
3806 % If |pmbdomains| appears outside of a |tikzpicture|, we implicitly start this environment, otherwise we begin a new group. ``Within a |tikzpicture|'' means that |\useasboundingbox| is defined. The \ometa{key-value list} is processed.
3807 % \begin{macrocode}
3808 \newif\ifpmb@dom@tikzpicture
3809
3810 \newenvironment{pmbdomains}[2][]{%
3811 \@ifundefined{useasboundingbox}%
3812 {\pmb@dom@tikzpicturefalse\begin{tikzpicture}}%
3813 {\pmb@dom@tikzpicturetrue}%
3814 \pgfmolbioset[domains]{sequence length=#2, #1}%
3815 % \end{macrocode}
3816 % The macros |\inputuniprot|, |\inputgff| and |\addfeature| only point to their respective internal macros (section~\ref{ssc:DocDomTexAddingFeatures}) within |pmbdomains|.
3817 % \begin{macrocode}
3818 \let\inputuniprot\pmb@dom@inputuniprot%
3819 \let\inputgff\pmb@dom@inputgff%
3820 \let\addfeature\pmb@dom@addfeature%
3821 % \end{macrocode}
3822 % §pmbProtein§ is a new §Protein§ object whose §specialKeys§ attribute is initialized with the values from the package-wide §SpecialKeys§ object. Since §pmbProtein§ must know the sequence length and residue numbering before the environment's body is processed, we call §setParameters§ twice to ensure that §sequenceLength§ is set prior to §residueNumbering§.
3823 % \begin{macrocode}
3824 \directlua{
3825 pmbProtein = pgfmolbio.domains.Protein:new()
3826 pmbProtein.specialKeys =
3827 pgfmolbio.domains.SpecialKeys:new(pmbSpecialKeys)
3828 pmbProtein:setParameters{
3829 sequenceLength = "\pmbdomvalueof{sequence length}"
3830 }
3831 pmbProtein:setParameters{
3832 residueNumbering = "\pmbdomvalueof{residue numbering}"
3833 }
3834 }%
3835 }{%
3836 % \end{macrocode}
3837 % At the end of |pmbdomains|'s body, §pmbProtein§ stores all features that have been defined there. We add one more feature, \texttt{other/main chain}, which spans the whole protein and occupies the lowermost layer (this is the only instance where we need the \opt{@layer} key).
3838 % \begin{macrocode}
3839 \pmb@dom@addfeature[@layer=1]{other/main chain}%
3840 {(1)}{(\pmbdomvalueof{sequence length})}%
3841 % \end{macrocode}
3842 % The following syntactical gem ensures that the token register |\@pmb@toksa| contains the value of the \opt{name} key without expansion of any macros within the value.
3843 % \begin{macrocode}
3844 \@pmb@toksa=%
3845 \expandafter\expandafter\expandafter\expandafter%
3846 \expandafter\expandafter\expandafter{%
3847 \pgfkeysvalueof{/pgfmolbio/domains/name}%
3848 }%
3849 % \end{macrocode}
3850 % Set the remaining attributes of §pmbProtein§.
3851 % \begin{macrocode}
3852 \directlua{
3853 pmbProtein:setParameters{
3854 residueRange = "\pmbdomvalueof{residue range}",
3855 defaultRulerStepSize = "\pmbdomvalueof{default ruler step size}"
3856 }
3857 pmbProtein:setParameters{
3858 name = "\luaescapestring{\the\@pmb@toksa}",
3859 xUnit = "\pmbdomvalueof{x unit}",
3860 yUnit = "\pmbdomvalueof{y unit}",
3861 residuesPerLine = "\pmbdomvalueof{residues per line}",
3862 baselineSkip = "\pmbdomvalueof{baseline skip}",
3863 showRuler = "\ifpmb@dom@showruler true\else false\fi",
3864 rulerRange = "\pmbdomvalueof{ruler range}",
3865 sequence = "\pmbdomvalueof{sequence}"
3866 }
3867 % \end{macrocode}
3868 % Calculate he appropriate levels of disulfide-like features (section~\ref{ssc:DocDomLuaDisulfideLevels}). §pgfmolbio.setCoordinateFormat§ sets the coordinate output format (section~\ref{sec:DocPkgLua}).
3869 % \begin{macrocode}
3870 pmbProtein:calculateDisulfideLevels()
3871 pgfmolbio.setCoordinateFormat(
3872 "\pgfkeysvalueof{/pgfmolbio/coordinate unit}",
3873 "\pgfkeysvalueof{/pgfmolbio/coordinate format string}"
3874 )
3875 % \end{macrocode}
3876 % If the \module{convert} module is loaded, we open the appropriate output file. If we wish to output final \TikZ\ code, we change §tex.sprint§ so that the function writes to this file and then call §printTikzDomains§. Otherwise, we write a string representation of §pmbProtein§ to the file (section~\ref{ssc:DocDomLuaTostring}). Without the \module{convert} module, §printTikzDomains§ simply returns the drawing commands for the chromatogram to the \TeX\ input stream (section~\ref{ssc:DocDomLuaPrintTikzDomains}).
3877 % \begin{macrocode}
3878 \ifpmb@loadmodule@convert
3879 local filename =
3880 "\pgfkeysvalueof{/pgfmolbio/convert/output file name}"
3881 if filename == "(auto)" then
3882 filename = "pmbconverted" .. pgfmolbio.outputFileId
3883 end
3884 filename = filename ..
3885 ".\pgfkeysvalueof{/pgfmolbio/convert/output file extension}"
3886 outputFile, ioError = io.open(filename, "w")
3887 if ioError then
3888 tex.error(ioError)
3889 end
3890 \ifpmb@con@outputtikzcode
3891 tex.sprint = function(a) outputFile:write(a) end
3892 pmbProtein:getParameters()
3893 tex.sprint("\string\n\string\\begin{tikzpicture}")
3894 pmbProtein:printTikzDomains()
3895 tex.sprint("\string\n\string\\end{tikzpicture}")
3896 \else
3897 \ifpmb@con@includedescription
3898 pmbProtein.includeDescription = true
3899 \fi
3900 outputFile:write(tostring(pmbProtein))
3901 \fi
3902 outputFile:close()
3903 pgfmolbio.outputFileId = pgfmolbio.outputFileId + 1
3904 \else
3905 pmbProtein:printTikzDomains()
3906 \fi
3907 pmbProtein = nil
3908 }%
3909 % \end{macrocode}
3910 % At the end of |pmbdomains|, we close an implicitly added |tikzpicture|.
3911 % \begin{macrocode}
3912 \ifpmb@dom@tikzpicture\else\end{tikzpicture}\fi%
3913 }
3914
3915 % \end{macrocode}
3916 % \end{environment}
3917 %
3918 % \subsection{Feature Styles}
3919 % \label{ssc:DocDomTexFeatureStyles}
3920 %
3921 % \begin{macro}{\setdisulfidefeatures}[1]{A list of \meta{features}.}
3922 % Clears the list of disulfide-like features and adds the \meta{features} to the empty list. Disulfide-like features are arranged in non-overlapping layers (section~\ref{sec:DomDisulfides}). Depending on whether this macro appears inside a |pmbdomains| environment or not, the appropriate methods of either §pmbProtein.specialKeys§ or §pmbSpecialKeys§ are called, respectively.
3923 % \begin{macrocode}
3924 \newcommand\setdisulfidefeatures[1]{%
3925 \directlua{
3926 if pmbProtein then
3927 pmbProtein.specialKeys:clearKeys("disulfideKeys")
3928 pmbProtein.specialKeys:setKeys("disulfideKeys", "#1", true)
3929 else
3930 pmbSpecialKeys:clearKeys("disulfideKeys")
3931 pmbSpecialKeys:setKeys("disulfideKeys", "#1", true)
3932 end
3933 }%
3934 }
3935
3936 % \end{macrocode}
3937 % \end{macro}
3938 % \begin{macro}{\adddisulfidefeatures}[1]{A list of \meta{features}.}
3939 % Adds the \meta{features} to the list of disulfide-like features without overwriting the current list.
3940 % \begin{macrocode}
3941 \newcommand\adddisulfidefeatures[1]{%
3942 \directlua{
3943 if pmbProtein then
3944 pmbProtein.specialKeys:setKeys("disulfideKeys", "#1", true)
3945 else
3946 pmbSpecialKeys:setKeys("disulfideKeys", "#1", true)
3947 end
3948 }%
3949 }
3950
3951 % \end{macrocode}
3952 % \end{macro}
3953 % \begin{macro}{\removedisulfidefeatures}[1]{A list of \meta{features}.}
3954 % Removes the \meta{features} from the list of disulfide-like features.
3955 % \begin{macrocode}
3956 \newcommand\removedisulfidefeatures[1]{%
3957 \directlua{
3958 if pmbProtein then
3959 pmbProtein.specialKeys:setKeys("disulfideKeys", "#1", nil)
3960 else
3961 pmbSpecialKeys:setKeys("disulfideKeys", "#1", nil)
3962 end
3963 }%
3964 }
3965
3966 % \end{macrocode}
3967 % \end{macro}
3968 % Declare the default disulfide-like features.
3969 % \begin{macrocode}
3970 \setdisulfidefeatures{DISULFID, disulfide, range}
3971
3972 % \end{macrocode}
3973 % \begin{macro}{\setfeatureprintfunction}[2]{A \meta{list} of features.}{Name of a Lua \meta{function}.}
3974 % Assigns a feature print \meta{function} to each feature in the \meta{list}. Feature print functions are preprocessors which, for instance, calculate coordinates for features (section~\ref{sec:DomSequences}).
3975 % \begin{macrocode}
3976 \newcommand\setfeatureprintfunction[2]{%
3977 \directlua{
3978 if pmbProtein then
3979 pmbProtein.specialKeys:setKeys("printFunctions", "#1", #2)
3980 else
3981 pmbSpecialKeys:setKeys("printFunctions", "#1", #2)
3982 end
3983 }%
3984 }
3985
3986 % \end{macrocode}
3987 % \end{macro}
3988 % \begin{macro}{\removefeatureprintfunction}[1]{A \meta{list} of features.}
3989 % Removes any feature print function from the features in the \meta{list}.
3990 % \begin{macrocode}
3991 \newcommand\removefeatureprintfunction[1]{%
3992 \directlua{
3993 if pmbProtein then
3994 pmbProtein.specialKeys:setKeys("printFunctions", "#1", nil)
3995 else
3996 pmbSpecialKeys:setKeys("printFunctions", "#1", nil)
3997 end
3998 }%
3999 }
4000
4001 % \end{macrocode}
4002 % \end{macro}
4003 % Assign default feature print functions.
4004 % \begin{macrocode}
4005 \setfeatureprintfunction{other/sequence}%
4006 {pgfmolbio.domains.printSequenceFeature}
4007 \setfeatureprintfunction{alpha helix, pi helix, 310 helix, HELIX}%
4008 {pgfmolbio.domains.printHelixFeature}
4009
4010 % \end{macrocode}
4011 %
4012 % \begin{macro}{\setfeaturestyle}[2]{A \meta{feature} name.}{A \meta{style list}.}
4013 % Sets the style of a \meta{feature} to the style described in the \meta{style list}. Note that the contents of \meta{style list} are passed to the Lua function without expansion (via the token register |\@pmb@toksa|).
4014 % \begin{macrocode}
4015 \newcommand\setfeaturestyle[2]{%
4016 \@pmb@toksa{#2}%
4017 \directlua{
4018 if pmbProtein then
4019 pmbProtein.specialKeys:setFeatureStyle(
4020 "#1", "\luaescapestring{\the\@pmb@toksa}"
4021 )
4022 else
4023 pmbSpecialKeys:setFeatureStyle(
4024 "#1", "\luaescapestring{\the\@pmb@toksa}"
4025 )
4026 end
4027 }%
4028 }
4029
4030 % \end{macrocode}
4031 % \end{macro}
4032 % Declare default feature styles.
4033 % \begin{macrocode}
4034 \setfeaturestyle{default}{draw}
4035 \setfeaturestyle{domain}%
4036 {fill=Chartreuse,fill=LightSkyBlue,fill=LightPink,fill=Gold!50}
4037 \setfeaturestyle{signal peptide}{fill=black}
4038 \setfeaturestyle{propeptide}%
4039 {*1{fill=Gold, opacity=.5, rounded corners=4pt}}
4040 \setfeaturestyle{carbohydrate}{red}
4041 \setfeaturestyle{other/main chain}{*1{draw, line width=2pt, black!25}}
4042 \setfeaturestyle{other/name}{font=\sffamily}
4043 \setfeaturestyle{disulfide}{draw=olive}
4044 \setfeaturestyle{range}{*1{draw,decorate,decoration=brace}}
4045 \setfeaturestyle{other/ruler}{black, black!50}
4046 \setfeaturestyle{other/sequence}{*1{font=\ttfamily\tiny}}%
4047 \setfeaturestyle{other/magnified sequence above}%
4048 {*1{draw=black!50, densely dashed}}
4049 \setfeaturestylealias{other/magnified sequence below}%
4050 {other/magnified sequence above}
4051 \setfeaturestyle{alpha helix}{%
4052 *1{helix front border color=red!50!black,%
4053 helix front main color=red!90!black,%
4054 helix front middle color=red!10!white}%
4055 }
4056 \setfeaturestylealias{HELIX}{alpha helix}
4057 \setfeaturestyle{pi helix}{%
4058 *1{helix front border color=yellow!50!black,%
4059 helix front main color=yellow!70!red,%
4060 helix front middle color=yellow!10!white}%
4061 }
4062 \setfeaturestyle{310 helix}{%
4063 *1{helix front border color=magenta!50!black,%
4064 helix front main color=magenta!90!black,%
4065 helix front middle color=magenta!10!white}%
4066 }
4067 \setfeaturestyle{beta strand}{%
4068 *1{left color=strand left color, right color=strand right color}%
4069 }
4070 \setfeaturestyle{beta turn}{*1{draw=violet, thick}}
4071 \setfeaturestyle{beta bridge}{*1{fill=MediumBlue}}
4072 \setfeaturestyle{bend}{*1{draw=magenta, thick}}
4073 % \end{macrocode}
4074 %
4075 % \iffalse
4076 %</pmb-dom-tex>
4077 %<*pmb-dom-lua>
4078 % \fi
4079 %
4080 %
4081 %
4082 % \section{\texorpdfstring{\file{pgfmolbio.domains.lua}}{pgfmolbio.domains.lua}}
4083 % \label{sec:DocDomLua}
4084 %
4085 % \def\ydoclistingssettings{\lstset{style=lua-doc}}\setcounter{lstnumber}{1}
4086 % \begin{macrocode}
4087 if luatexbase then
4088 luatexbase.provides_module({
4089 name = "pgfmolbio.domains",
4090 version = "0.21a",
4091 date = "2014/06/17",
4092 description = "Domain graphs",
4093 author = "Wolfgang Esser-Skala",
4094 copyright = "Wolfgang Esser-Skala",
4095 license = "LPPL",
4096 })
4097 end
4098
4099 % \end{macrocode}
4100 % These local functions point to functions in \file{pgfmolbio.lua} (section~\ref{sec:DocPkgLua}).
4101 % \begin{macrocode}
4102 local stringToDim = pgfmolbio.stringToDim
4103 local dimToString = pgfmolbio.dimToString
4104 local packageError = pgfmolbio.packageError
4105 local packageWarning = pgfmolbio.packageWarning
4106 local getRange = pgfmolbio.getRange
4107
4108 % \end{macrocode}
4109 %
4110 % \subsection{Predefined Feature Print Functions}
4111 % \label{ssc:DocDomLuaPrintFunctions}
4112 %
4113 % §printSequenceFeature§ prints the letters of a sequence between the $x$-coordinates §xLeft§ and §xRight§.
4114 % \begin{macrocode}
4115 function printSequenceFeature(feature, xLeft, xRight, yMid, xUnit, yUnit)
4116 xLeft = xLeft + 0.5
4117 for currResidue in feature.sequence:gmatch(".") do
4118 tex.sprint("\n\t\t\\def\\xMid{" .. dimToString(xLeft * xUnit) .. "}")
4119 tex.sprint("\n\t\t\\def\\yMid{" .. dimToString(yMid * yUnit) .. "}")
4120 tex.sprint("\n\t\t\\def\\currentResidue{" .. currResidue .. "}")
4121 tex.sprint("\n\t\t\\pmbdomdrawfeature{other/sequence}")
4122 xLeft = xLeft + 1
4123 end
4124 end
4125
4126 % \end{macrocode}
4127 %
4128 % §printHelixFeature§ prints a helix feature between the $x$-coordinates §xLeft§ and §xRight§.
4129 % \begin{macrocode}
4130 function printHelixFeature(feature, xLeft, xRight, yMid, xUnit, yUnit)
4131 local residuesLeft, currX
4132 tex.sprint("\n\t\t\\pgfmolbioset[domains]{current style}")
4133
4134 % \end{macrocode}
4135 % \textit{Firstly}, three different background parts are drawn: one \texttt{half upper back} at the left, zero or more \texttt{full back} in the middle and possibly one \texttt{half lower back} at the right.
4136 % \begin{macrocode}
4137 residuesLeft = feature.stop - feature.start + 1
4138 currX = xLeft
4139 tex.sprint("\n\t\t\\def\\xLeft{" .. dimToString(currX * xUnit) .. "}")
4140 tex.sprint("\n\t\t\\def\\yMid{" .. dimToString(yMid * yUnit) .. "}")
4141 tex.sprint("\n\t\t\\pmbdomdrawfeature{helix/half upper back}")
4142 residuesLeft = residuesLeft - 2
4143 currX = currX + 2.5
4144
4145 while residuesLeft > 0 do
4146 if residuesLeft == 1 then
4147 tex.sprint(
4148 "\n\t\t\\def\\xRight{" ..
4149 dimToString((currX + 0.5) * xUnit) ..
4150 "}"
4151 )
4152 tex.sprint("\n\t\t\\def\\yMid{" .. dimToString(yMid * yUnit) .. "}")
4153 tex.sprint("\n\t\t\\pmbdomdrawfeature{helix/half lower back}")
4154 else
4155 tex.sprint("\n\t\t\\def\\xMid{" .. dimToString(currX * xUnit) .. "}")
4156 tex.sprint(
4157 "\n\t\t\\def\\yLower{" ..
4158 dimToString(yMid * yUnit - 1.5 * xUnit) ..
4159 "}"
4160 )
4161 tex.sprint("\n\t\t\\pmbdomdrawfeature{helix/full back}")
4162 end
4163 residuesLeft = residuesLeft - 2
4164 currX = currX + 2
4165 end
4166
4167 % \end{macrocode}
4168 % \textit{Secondly}, two different foreground parts are drawn: at least one \texttt{full front} at the left and in the middle, and possibly one \texttt{half upper front} at the right.
4169 % \begin{macrocode}
4170 residuesLeft = feature.stop - feature.start
4171 currX = xLeft + 1.5
4172 while residuesLeft > 0 do
4173 if residuesLeft == 1 then
4174 tex.sprint(
4175 "\n\t\t\\def\\xRight{" ..
4176 dimToString((currX + 0.5) * xUnit) ..
4177 "}"
4178 )
4179 tex.sprint("\n\t\t\\def\\yMid{" .. dimToString(yMid * yUnit) .. "}")
4180 tex.sprint("\n\t\t\\pmbdomdrawfeature{helix/half upper front}")
4181 else
4182 tex.sprint("\n\t\t\\def\\xMid{" .. dimToString(currX * xUnit) .. "}")
4183 tex.sprint(
4184 "\n\t\t\\def\\yLower{" ..
4185 dimToString(yMid * yUnit - 1.5 * xUnit) ..
4186 "}"
4187 )
4188 tex.sprint("\n\t\t\\pmbdomdrawfeature{helix/full front}")
4189 end
4190 residuesLeft = residuesLeft - 2
4191 currX = currX + 2
4192 end
4193 end
4194
4195 % \end{macrocode}
4196 %
4197 % \subsection{The \texorpdfstring{\texttt{SpecialKeys}}{SpecialKeys} Class}
4198 % \label{ssc:DocDomLuaSpecialKeysClass}
4199 %
4200 % The §SpecialKeys§ class contains three member variables: §disulfideKeys§ (a list of keys that indicate disulfide-like features, like \texttt{disulfide}), §featureStyles§ (a list of feature styles) and §printFunctions§ (a list of keys associated with a feature print function, like \texttt{alpha helix}). Furthermore, it provides methods to manipulate these fields.
4201 %
4202 % The constructor §SpecialKeys:new§ generates a new §SpecialKeys§ object and initializes it with values from §parms§.
4203 % \begin{macrocode}
4204 SpecialKeys = {}
4205
4206 function SpecialKeys:new(parms)
4207 parms = parms or {}
4208 local newSpecialKeys = {
4209 disulfideKeys = {},
4210 featureStyles = {},
4211 printFunctions = {}
4212 }
4213
4214 for keyList, listContents in pairs(parms) do
4215 for key, value in pairs(listContents) do
4216 newSpecialKeys[keyList][key] = value
4217 end
4218 end
4219
4220 setmetatable(newSpecialKeys, self)
4221 self.__index = self
4222 return newSpecialKeys
4223 end
4224
4225 % \end{macrocode}
4226 % §SpecialKeys:setKeys§ sets a §value§ for a §key§ in the §keylist§. Possible values for §keyList§ are §"disulfideKeys"§, §"featureStyles"§ or §"printFunctions"§.
4227 % \begin{macrocode}
4228 function SpecialKeys:setKeys(keylist, keys, value)
4229 for key in keys:gmatch("([^,]+)") do
4230 key = key:trim()
4231 self[keylist][key] = value
4232 end
4233 end
4234
4235 % \end{macrocode}
4236 %
4237 % §SpecialKeys:setFeatureStyle§ parses the style list §style§ and associates it with a certain §key§. In Lua, a style list is an array of tables. Each table contains the fields §cycles§ and §style§. §cycles§ determines how often the §style§ (a string suitable for the mandatory argument of |\pgfmolbioset|) is to be used. In addition, an optional field §alias§ contains a reference to another key, if the current key is an alias of it (see below).
4238 % \begin{macrocode}
4239 function SpecialKeys:setFeatureStyle(key, style)
4240 local newStyleList, styleCycles, styleContents
4241
4242 newStyleList = {}
4243 while style ~= "" do
4244 styleCycles = 1
4245 if style:sub(1,1) == "{" then
4246 styleContents = style:match("%b{}")
4247 style = style:match("%b{}(.*)")
4248 elseif style:sub(1,1) == "*" then
4249 styleCycles, styleContents = style:match("%*(%d*)(%b{})")
4250 if styleCycles == "" then styleCycles = 1 end
4251 style = style:match("%*%d*%b{}(.*)")
4252 elseif style:sub(1,1) == "," or style:sub(1,1) == " " then
4253 style = style:match("[,%s]+(.*)")
4254 styleCycles, styleContents = nil, nil
4255 else
4256 styleContents = style:match("([^,]+),")
4257 if not styleContents then
4258 styleContents = style
4259 style = ""
4260 else
4261 style = style:match("[^,]+,(.*)")
4262 end
4263 end
4264 if styleCycles then
4265 table.insert(
4266 newStyleList,
4267 {cycles = styleCycles, style = styleContents}
4268 )
4269 end
4270 end
4271 self.featureStyles[key] = newStyleList
4272 end
4273
4274 % \end{macrocode}
4275 % §SpecialKeys:aliasFeatureStyle§ sets the §alias§ field of a style list so that feature §newKey§ uses the same feature style as feature §oldKey§.
4276 % \begin{macrocode}
4277 function SpecialKeys:aliasFeatureStyle(newKey, oldKey)
4278 self.featureStyles[newKey] = {alias = oldKey}
4279 end
4280
4281 % \end{macrocode}
4282 % §SpecialKeys:getBaseKey§ returns either the name of §key§ itself or of its parent key if §key§ is an alias.
4283 % \begin{macrocode}
4284 function SpecialKeys:getBaseKey(key)
4285 if self.featureStyles[key] then
4286 if self.featureStyles[key].alias then
4287 return self.featureStyles[key].alias
4288 end
4289 end
4290 return key
4291 end
4292
4293 % \end{macrocode}
4294 % §SpecialKeys:clearKeys§ clears a §keylist§.
4295 % \begin{macrocode}
4296 function SpecialKeys:clearKeys(keylist)
4297 self[keylist] = {}
4298 end
4299
4300 % \end{macrocode}
4301 % §SpecialKeys:selectStyleFromList§ returns the §styleID§-th style from the style list associated with §key§. Firstly, the correct style list is selected.
4302 % \begin{macrocode}
4303 function SpecialKeys:selectStyleFromList(key, styleID)
4304 local styleList
4305
4306 if not self.featureStyles[key] then
4307 packageWarning(
4308 "Feature style `" ..
4309 key ..
4310 "' unknown, using `default'."
4311 )
4312 styleList = self.featureStyles.default
4313 elseif self.featureStyles[key].alias then
4314 styleList = self.featureStyles[self.featureStyles[key].alias]
4315 else
4316 styleList = self.featureStyles[key]
4317 end
4318
4319 % \end{macrocode}
4320 % Secondly, the method choses the appropriate style in the list.
4321 % \begin{macrocode}
4322 while true do
4323 for _, v in ipairs(styleList) do
4324 styleID = styleID - v.cycles
4325 if styleID < 1 then
4326 return v.style
4327 end
4328 end
4329 end
4330 end
4331
4332 % \end{macrocode}
4333 %
4334 % \subsection{The \texorpdfstring{\texttt{Protein}}{Protein} Class}
4335 % \label{ssc:DocDomLuaProteinClass}
4336 %
4337 % The §Protein§ class represents a domain diagram in Lua. Its member variables largely correspond to the keys of the \module{domains} module. In detail:
4338 % \begin{itemize}
4339 % \item §sequenceLength§: A value of §-1§ indicates that the sequence length has not been properly set.
4340 % \item §ft§ is the feature table, i.\,e. an array of tables with the following fields:
4341 % \begin{itemize}
4342 % \item §key§: A string that equals the feature key.
4343 % \item §start§: The start \dots
4344 % \item §stop§: \dots\ and the end residue of the feature, both in \textit{absolute} numbering. (For the difference between absolute and relative numbering, see section~\ref{sec:DomGeneralLayout}.)
4345 % \item §kvList§: A string containing comma-separated key-value pairs, which is passed to |\pgfmolbioset| immediately before the feature is drawn.
4346 % \item §level§: The level of the feature (only relevant for disulfide-like features).
4347 % \end{itemize}
4348 % \item §residueNumbering§: An array of strings. The indices are absolute residue numbers, while the fields represent the corresponding relative residue numbers.
4349 % \item §revResidueNumbering§: The inverse of §residueNumbering§ (i.\,e., a table of numbers).
4350 % \item §rulerRange§: An array of tables. Each table represents one mark of the ruler and has the fields §pos§ (position in absolute residue numbers) and §number§ (relative number of the marked residue).
4351 % \item §currentStyle§: A table whose field names equal feature keys. Each field denotes the index of the style that was last selected from that feature's style list.
4352 % \item §includeDescription§: This boolean field remains uninitialized. Instead, it is directly set in \file{pgfmolbio.domains.tex} if the \module{convert} module is loaded and the user requests a string representation of a §Protein§ object (section~\ref{ssc:DocDomLuaTostring}).
4353 % \end{itemize}
4354 %
4355 % The constructor §Protein:new§ initializes the member variables with default values.
4356 % \begin{macrocode}
4357 Protein = {}
4358
4359 function Protein:new()
4360 local newProtein = {
4361 name = "",
4362 sequenceLength = -1,
4363 ft = {},
4364 sequence = "",
4365 xUnit = stringToDim("0.5mm"),
4366 yUnit = stringToDim("6mm"),
4367 residuesPerLine = 250,
4368 residueRangeMin = 1,
4369 residueRangeMax = 100,
4370 residueNumbering = {},
4371 revResidueNumbering = {},
4372 baselineSkip = 3,
4373 rulerRange = {},
4374 defaultRulerStepSize = 50,
4375 showRuler = true,
4376 currentStyle = {},
4377 specialKeys = SpecialKeys:new()
4378 }
4379 setmetatable(newProtein, self)
4380 self.__index = self
4381 return newProtein
4382 end
4383
4384 % \end{macrocode}
4385 % §Protein:toAbsoluteResidueNumber§ converts a string that either contains an absolute or relative residue number to an absolute residue number.
4386 % \begin{macrocode}
4387 function Protein:toAbsoluteResidueNumber(value)
4388 local result = value:match("%b()")
4389 if result then
4390 result = tonumber(result:sub(2, -2))
4391 else
4392 result = self.revResidueNumbering[(value:gsub("[<>%?]", ""))]
4393 end
4394 if not result then
4395 packageError("Bad or missing start/end point value: " .. value)
4396 end
4397 return result
4398 end
4399
4400 % \end{macrocode}
4401 %
4402 % \subsection{Uniprot and GFF Files}
4403 % \label{ssc:DocDomLuaReadFiles}
4404 %
4405 % §Protein:readUniprotFile§ reads the relevant parts of Uniprot file §filename§\footnote{For a detailed description of this format, see \url{https://web.expasy.org/docs/userman.html}.}.
4406 % \begin{macrocode}
4407 function Protein:readUniprotFile(filename)
4408 local uniprotFile, errorMsg = io.open(filename, "r")
4409 if not uniprotFile then packageError(errorMsg) end
4410
4411 % \end{macrocode}
4412 % Each line in a Uniprot file starts with a line code consisting of two letters. This code determines the syntax of the remainder of the line.
4413 % \begin{macrocode}
4414 local sequence = {}
4415 local inSequence = false
4416 local featureTable = {}
4417
4418 for currLine in uniprotFile:lines() do
4419 local lineCode = currLine:sub(1, 2)
4420 local lineContents = currLine:sub(3)
4421 % \end{macrocode}
4422 % The \texttt{ID} line is the first line in a Uniprot file. It provides two relevant properties of the protein, namely its name and ints sequence length. For example, in the file \file{SampleUniprot.txt} (see section~\ref{sec:DomFileInput}), the \texttt{ID} line reads\\
4423 % |ID TestProtein Reviewed; 200 AA.|\\
4424 % which declares a protein with 200 residues called TestProtein.
4425 % \begin{macrocode}
4426 if lineCode == "ID" then
4427 local name, sequenceLength =
4428 lineContents:match("%s*(%S+)%s*%a+;%s*(%d+)%s*AA%.")
4429 self.name = name
4430 self.sequenceLength = tonumber(sequenceLength)
4431 self.residueRangeMax = self.sequenceLength
4432 % \end{macrocode}
4433 % \texttt{FT} lines describe features of the protein (domains, disulfides, sugars etc.). The first line of a feature always contains its key (columns 6--13) and endpoints (columns 15--20 and 22--27, respectively). The description (columns 35--75) may span several lines, in which case the key columns of consecutive lines are empty. For instance,\\
4434 % |FT DOMAIN 10 40 Domain 1|\\
4435 % declares a \texttt{DOMAIN} feature between residues 10 and 40 with description ``Domain 1''.
4436 % \begin{macrocode}
4437 elseif lineCode == "FT" then
4438 local key = currLine:sub(6, 13):trim()
4439 local start, stop, description =
4440 currLine:sub(15, 20), currLine:sub(22, 27), currLine:sub(35, 75)
4441 if key ~= "" then
4442 table.insert(featureTable, {
4443 key = key,
4444 start = "(" .. start .. ")",
4445 stop = "(" .. stop .. ")",
4446 description = description,
4447 style = "",
4448 kvList = ""
4449 })
4450 else
4451 featureTable[#featureTable].description =
4452 featureTable[#featureTable].description .. description
4453 end
4454 % \end{macrocode}
4455 % The \texttt{SQ} line starts the sequence block. Each of the following sequence data lines lacks a line code and shows the amino acid sequence in one letter code, e.\,g.\\
4456 % |SQ SEQUENCE 200 AA; 22041 MW; 00A52FE2EC5431D9 CRC64;|\\
4457 % | MGSKRSVPSR HRSLTTYEVM FAVLFVILVA LCAGLIAVSW LSIQ| [\dots]
4458 % \begin{macrocode}
4459 elseif lineCode == "SQ" then
4460 inSequence = true
4461 elseif lineCode == " " and inSequence then
4462 table.insert(sequence, (lineContents:gsub("%s+", "")))
4463 % \end{macrocode}
4464 % The |\\| line terminates the Uniprot file.
4465 % \begin{macrocode}
4466 elseif lineCode == "\\\\" then
4467 break
4468 end
4469 end
4470 % \end{macrocode}
4471 % After closing the file, features are converted to the proper format (section~\ref{ssc:DocDomLuaProteinClass}).
4472 % \begin{macrocode}
4473 uniprotFile:close()
4474 if next(sequence) then self.sequence = table.concat(sequence) end
4475 for _, v in ipairs(featureTable) do self:addFeature(v) end
4476 end
4477
4478 % \end{macrocode}
4479 % §Protein:readGffFile§ reads the relevant parts of General Feature Format file §filename§\footnote{\url{https://en.wikipedia.org/wiki/General_feature_format}}.
4480 % \begin{macrocode}
4481 function Protein:readGffFile(filename)
4482 local gffFile, errorMsg = io.open(filename, "r")
4483 local lineContents, fields, lineNumber
4484
4485 if not gffFile then packageError(errorMsg) end
4486 % \end{macrocode}
4487 % Each line in a \file{gff} file describes a feature and consists of up to 9 tabulator-separated fields, of which only fields 3 (key), 4 (start) and 5 (end) are required for the \module{domains} module. Everything following the comment sign (|#|) on a line is ignored.
4488 % \begin{macrocode}
4489 lineNumber = 1
4490 for currLine in gffFile:lines() do
4491 lineContents = currLine:gsub("#.*$", "")
4492 fields = {}
4493 if lineContents ~= "" then
4494 for currField in lineContents:gmatch("([^\t]+)") do
4495 table.insert(fields, currField)
4496 end
4497 if not fields[5] then
4498 packageError("Bad line (" .. lineNumber .. ") in gff file '" ..
4499 filename .. "':\n" .. currLine)
4500 break
4501 end
4502 self:addFeature{
4503 key = fields[3],
4504 start = "(" .. fields[4] .. ")",
4505 stop = "(" .. fields[5] .. ")",
4506 description = fields[9] or "",
4507 style = "",
4508 kvList = ""
4509 }
4510 end
4511 lineNumber = lineNumber + 1
4512 end
4513 gffFile:close()
4514 end
4515
4516 % \end{macrocode}
4517 %
4518 % \subsection{Getter and Setter Methods}
4519 % \label{ssc:DocDomLuaParameters}
4520 %
4521 % §Protein:getParameters§ informs \TeX\ of the protein name, sequence and sequence length. This method is called after reading a Uniprot file (section~\ref{ssc:DocDomTexAddingFeatures}).
4522 % \begin{macrocode}
4523 function Protein:getParameters()
4524 tex.sprint(
4525 "\\pgfmolbioset[domains]{name={" ..
4526 self.name ..
4527 "},sequence={" ..
4528 self.sequence ..
4529 "},sequence length=" ..
4530 self.sequenceLength ..
4531 "}"
4532 )
4533 end
4534
4535 % \end{macrocode}
4536 % §Protein:setParameters§ passes options from the \module{domains} module to the Lua script. Each field of the table §keyHash§ is named after a §Protein§ attribute and represents a function that receives one string parameter (the value of a \LaTeX\ key).
4537 % \begin{macrocode}
4538 function Protein:setParameters(newParms)
4539 local keyHash = {
4540 % \end{macrocode}
4541 % §keyHash.sequenceLength§ checks for an invalid sequence length.
4542 % \begin{macrocode}
4543 sequenceLength = function(v)
4544 v = tonumber(v)
4545 if not v then return self.sequenceLength end
4546 if v < 1 then
4547 packageError("Sequence length must be larger than zero.")
4548 end
4549 return v
4550 end,
4551 % \end{macrocode}
4552 % §keyHash.residueNumbering§ generates the residue numbering array and its inverse (described in section~\ref{ssc:DocDomLuaProteinClass}).
4553 % \begin{macrocode}
4554 residueNumbering = function(v)
4555 local ranges = {}
4556 local start, startNumber, startLetter, stop
4557 self.revResidueNumbering = {}
4558 if v:trim() == "auto" then
4559 for i = 1, self.sequenceLength do
4560 table.insert(ranges, tostring(i))
4561 end
4562 else --example list: `1-4,5,6A-D'
4563 for _, value in ipairs(v:explode(",+")) do
4564 value = value:trim()
4565 start, stop = value:match("(%w*)%s*%-%s*(%w*)$")
4566 if not start then
4567 start = value:match("(%w*)")
4568 end
4569 if not start or start == "" then --invalid range
4570 packageError("Unknown residue numbering range: " .. value)
4571 end
4572 if stop then
4573 if tonumber(start) and tonumber(stop) then
4574 --process range `1-4'
4575 for currNumber = tonumber(start), tonumber(stop) do
4576 table.insert(ranges, tostring(currNumber))
4577 end
4578 else --process range `6A-D'
4579 startNumber, startLetter = start:match("(%d*)(%a)")
4580 stop = stop:match("(%a)")
4581 for currLetter = startLetter:byte(), stop:byte() do
4582 table.insert(ranges,
4583 startNumber .. string.char(currLetter))
4584 end
4585 end
4586 else --process range `5'
4587 table.insert(ranges, start)
4588 end
4589 end
4590 end
4591 for i, value in ipairs(ranges) do
4592 if self.revResidueNumbering[value] then
4593 packageError("The range value " .. value ..
4594 " appears more than once.")
4595 else
4596 self.revResidueNumbering[value] = i
4597 end
4598 end
4599 return ranges
4600 end,
4601 % \end{macrocode}
4602 % §keyHash.residueRange§ sets the residue range, treating possible errors.
4603 % \begin{macrocode}
4604 residueRange = function(v)
4605 local num
4606 local residueRangeMin, residueRangeMax =
4607 getRange(v:trim(), "^([%w%(%)]+)%s*%-", "%-%s*([%w%(%)]+)$")
4608 if residueRangeMin == "auto" then
4609 self.residueRangeMin = 1
4610 else
4611 num = residueRangeMin:match("%b()")
4612 if num then
4613 self.residueRangeMin = tonumber(num:sub(2, -2))
4614 elseif self.revResidueNumbering[residueRangeMin] then
4615 self.residueRangeMin = self.revResidueNumbering[residueRangeMin]
4616 else
4617 packageError("Invalid residue range: " .. residueRangeMin)
4618 end
4619 end
4620
4621 if residueRangeMax == "auto" then
4622 self.residueRangeMax = self.sequenceLength
4623 else
4624 num = residueRangeMax:match("%b()")
4625 if num then
4626 self.residueRangeMax = tonumber(num:sub(2, -2))
4627 elseif self.revResidueNumbering[residueRangeMax] then
4628 self.residueRangeMax = self.revResidueNumbering[residueRangeMax]
4629 else
4630 packageError("Invalid residue range: " .. residueRangeMax)
4631 end
4632 end
4633
4634 if self.residueRangeMin >= self.residueRangeMax then
4635 packageError("Residue range is smaller than 1.")
4636 end
4637 end,
4638 % \end{macrocode}
4639 % The following fields map to functions already defined.
4640 % \begin{macrocode}
4641 defaultRulerStepSize = tonumber,
4642 name = tostring,
4643 sequence = tostring,
4644 xUnit = stringToDim,
4645 yUnit = stringToDim,
4646 residuesPerLine = tonumber,
4647 baselineSkip = tonumber,
4648 % \end{macrocode}
4649 % §keyHash.rulerRange§ sets the ruler range, treating possible errors and inconsistencies (for example, if the upper ruler range exceeds the upper residue range).
4650 % \begin{macrocode}
4651 rulerRange = function(v)
4652 local num
4653 local ranges = {}
4654 local rulerRangeMin, rulerRangeMax, rulerRangeStep
4655 for _, value in ipairs(v:explode(",+")) do
4656 rulerRangeMin, rulerRangeMax, rulerRangeStep =
4657 getRange(value:trim(), "^([%w%(%)]+)",
4658 "%-%s*([%w%(%)]+)", "step%s*(%d+)$")
4659
4660 if rulerRangeMin == "auto" then
4661 rulerRangeMin = self.residueRangeMin
4662 else
4663 num = rulerRangeMin:match("%b()")
4664 if num then
4665 rulerRangeMin = tonumber(num:sub(2, -2))
4666 elseif self.revResidueNumbering[rulerRangeMin] then
4667 rulerRangeMin = self.revResidueNumbering[rulerRangeMin]
4668 else
4669 packageError("Invalid lower ruler range: " .. rulerRangeMin)
4670 end
4671 end
4672
4673 if rulerRangeMax then
4674 if rulerRangeMax == "auto" then
4675 rulerRangeMax = self.residueRangeMax
4676 else
4677 num = rulerRangeMax:match("%b()")
4678 if num then
4679 rulerRangeMax = tonumber(num:sub(2, -2))
4680 elseif self.revResidueNumbering[rulerRangeMax] then
4681 rulerRangeMax = self.revResidueNumbering[rulerRangeMax]
4682 else
4683 packageError("Invalid upper ruler range: " .. rulerRangeMax)
4684 end
4685 end
4686
4687 if rulerRangeMin >= rulerRangeMax then
4688 packageError("Ruler range is smaller than 1.")
4689 end
4690 if rulerRangeMin < self.residueRangeMin then
4691 rulerRangeMin = self.residueRangeMin
4692 packageWarning(
4693 "Lower ruler range is smaller than" ..
4694 "lower residue range. It was adjusted to " ..
4695 rulerRangeMin .. "."
4696 )
4697 end
4698 if rulerRangeMax > self.residueRangeMax then
4699 rulerRangeMax = self.residueRangeMax
4700 packageWarning(
4701 "Upper ruler range exceeds" ..
4702 "upper residue range. It was adjusted to " ..
4703 rulerRangeMax .. "."
4704 )
4705 end
4706 else
4707 rulerRangeMax = rulerRangeMin
4708 end
4709 rulerRangeStep = tonumber(rulerRangeStep)
4710 or self.defaultRulerStepSize
4711
4712 for i = rulerRangeMin, rulerRangeMax, rulerRangeStep do
4713 table.insert(
4714 ranges,
4715 {pos = i, number = self.residueNumbering[i]}
4716 )
4717 end
4718 end
4719 return ranges
4720 end,
4721 % \end{macrocode}
4722 % §keyHash.showRuler§ determines if the ruler is visible.
4723 % \begin{macrocode}
4724 showRuler = function(v)
4725 if v == "true" then return true else return false end
4726 end
4727 }
4728 % \end{macrocode}
4729 % We iterate over all fields in the argument of §setParameters§. If a field of the same name exists in §keyHash§, we call this field with the value of the corresponding field in §newParms§ as parameter.
4730 % \begin{macrocode}
4731 for key, value in pairs(newParms) do
4732 if keyHash[key] then
4733 self[key] = keyHash[key](value)
4734 if pgfmolbio.errorCatched then return end
4735 end
4736 end
4737 end
4738
4739 % \end{macrocode}
4740 %
4741 % \subsection{Adding Feature}
4742 % \label{ssc:DocDomLuaAddFeature}
4743 %
4744 % §Protein:addFeature§ converts raw feature information to the format of §ft§ fields (described in section~\ref{ssc:DocDomLuaProteinClass}). Firstly, the method determines the index of the style that should be used for the current feature.
4745 % \begin{macrocode}
4746 function Protein:addFeature(newFeature)
4747 local baseKey, ftEntry
4748
4749 baseKey = self.specialKeys:getBaseKey(newFeature.key)
4750 if self.currentStyle[baseKey] then
4751 self.currentStyle[baseKey] = self.currentStyle[baseKey] + 1
4752 else
4753 self.currentStyle[baseKey] = 1
4754 end
4755
4756 % \end{macrocode}
4757 % Then, a new field for the feature table is set up.
4758 % \begin{macrocode}
4759 ftEntry = {
4760 key = newFeature.key,
4761 start = self:toAbsoluteResidueNumber(newFeature.start),
4762 stop = self:toAbsoluteResidueNumber(newFeature.stop),
4763 kvList = "style={" ..
4764 self.specialKeys:selectStyleFromList(baseKey,
4765 self.currentStyle[baseKey]) .. "}",
4766 level = newFeature.level or nil
4767 }
4768 % \end{macrocode}
4769 % Finally, the key-value list §kvList§ is modified (if applicable) and the new field is inserted into §ft§.
4770 % \begin{macrocode}
4771 if newFeature.kvList ~= "" then
4772 ftEntry.kvList = ftEntry.kvList .. "," .. newFeature.kvList
4773 end
4774 if newFeature.description then
4775 ftEntry.kvList = ftEntry.kvList ..
4776 ",description={" .. newFeature.description .. "}"
4777 ftEntry.description = newFeature.description
4778 end
4779 table.insert(self.ft, newFeature.layer or #self.ft + 1, ftEntry)
4780 end
4781
4782 % \end{macrocode}
4783 %
4784 % \subsection{Calculate Disulfide Levels}
4785 % \label{ssc:DocDomLuaDisulfideLevels}
4786 %
4787 % §Protein:calculateDisulfideLevels§ arranges disulfide-like features in non-\hskip0ptoverlapping levels.
4788 % \begin{macrocode}
4789 function Protein:calculateDisulfideLevels()
4790 if pgfmolbio.errorCatched then return end
4791 local disulfideGrid, currLevel, levelFree
4792 disulfideGrid = {}
4793
4794 for i, v in ipairs(self.ft) do
4795 if self.specialKeys.disulfideKeys[v.key] then
4796 % \end{macrocode}
4797 % If the §level§ field of a disulfide-like feature is already specified, it overrides the automatic mechanism of level determination. This may lead to clashes.
4798 % \begin{macrocode}
4799 if v.level then
4800 if not disulfideGrid[v.level] then
4801 disulfideGrid[v.level] = {}
4802 end
4803 for currPos = v.start, v.stop do
4804 disulfideGrid[v.level][currPos] = true
4805 end
4806 % \end{macrocode}
4807 % Otherwise, the algorithm looks for the first free level (starting at level 1), i.\,e. the first level the feature may occupy without clashing with another one. (1) If the level currently checked already exists, it has been created by a previous disulfide-like feature. In this case, it is considered free if the previous feature does not overlap with the current one.
4808 % \begin{macrocode}
4809 else
4810 currLevel = 1
4811 repeat
4812 levelFree = true
4813 if disulfideGrid[currLevel] then
4814 for currPos = v.start, v.stop do
4815 levelFree = levelFree
4816 and not disulfideGrid[currLevel][currPos]
4817 end
4818 if levelFree then
4819 self.ft[i].level = currLevel
4820 for currPos = v.start, v.stop do
4821 disulfideGrid[currLevel][currPos] = true
4822 end
4823 end
4824 % \end{macrocode}
4825 % (2) If the level currently checked does not exist, it must be free.
4826 % \begin{macrocode}
4827 else
4828 self.ft[i].level = currLevel
4829 disulfideGrid[currLevel] = {}
4830 for currPos = v.start, v.stop do
4831 disulfideGrid[currLevel][currPos] = true
4832 end
4833 levelFree = true
4834 end
4835 currLevel = currLevel + 1
4836 until levelFree == true
4837 end
4838 end
4839 end
4840 end
4841
4842 % \end{macrocode}
4843 %
4844 % \subsection{Print Domains}
4845 % \label{ssc:DocDomLuaPrintTikzDomains}
4846 %
4847 % §Protein:printTikzDomains§ is the heart of the Lua script, since it converts a §Protein§ object to \TeX\ code.
4848 % \begin{macrocode}
4849 function Protein:printTikzDomains()
4850 if pgfmolbio.errorCatched then return end
4851 local xLeft, xMid, xRight, yMid, xLeftClip, xRightClip,
4852 currLine, residuesLeft, currStyle
4853
4854 % \end{macrocode}
4855 % \paragraph{(1) Features (excluding \texttt{other/ruler} and \texttt{other/name})} For each feature in the feature table, we first calculate its coordinates (§xLeft§, §xMid§, §xRight§ and §yMid§) and clipped areas (§xLeftClip§, §xRightClip§).
4856 % \begin{macrocode}
4857 for _, currFeature in ipairs(self.ft) do
4858 currLine = 0
4859 xLeft = currFeature.start - self.residueRangeMin -
4860 currLine * self.residuesPerLine + 1
4861 while xLeft > self.residuesPerLine do
4862 xLeft = xLeft - self.residuesPerLine
4863 currLine = currLine + 1
4864 end
4865 xLeft = xLeft - 1
4866 xRight = currFeature.stop - self.residueRangeMin -
4867 currLine * self.residuesPerLine + 1
4868 residuesLeft = self.residueRangeMax - self.residueRangeMin -
4869 currLine * self.residuesPerLine + 1
4870 xLeftClip = stringToDim("-5cm")
4871 xRightClip = self.residuesPerLine * self.xUnit
4872
4873 if currFeature.start <= self.residueRangeMax
4874 and currFeature.stop >= self.residueRangeMin then
4875 repeat
4876 if residuesLeft <= self.residuesPerLine then
4877 if residuesLeft < xRight then
4878 xRightClip = residuesLeft * self.xUnit
4879 else
4880 xRightClip = xRight * self.xUnit + stringToDim("5cm")
4881 end
4882 else
4883 if xRight <= self.residuesPerLine then
4884 xRightClip = xRight * self.xUnit + stringToDim("5cm")
4885 end
4886 end
4887 if xLeft < 0 then xLeftClip = stringToDim("0cm") end
4888
4889 xMid = (xLeft + xRight) / 2
4890 yMid = -currLine * self.baselineSkip
4891 % \end{macrocode}
4892 % The current feature is extended by any level and sequence information present.
4893 % \begin{macrocode}
4894 if currFeature.level then
4895 currFeature.kvList = currFeature.kvList ..
4896 ",level=" .. currFeature.level
4897 end
4898 currFeature.sequence =
4899 self.sequence:sub(currFeature.start, currFeature.stop)
4900
4901 % \end{macrocode}
4902 % Each feature appears within its own |scope|. A |pgfinterruptboundingbox| ensures that the bounding box of the picture ignores the feature, since the |\clip| macro would enlarge it too much. Auxiliary macros for |\setfeatureshape| are defined (section~\ref{sec:DomFeatureStylesAndShapes}).
4903 % \begin{macrocode}
4904 tex.sprint("\n\t\\begin{scope}\\begin{pgfinterruptboundingbox}")
4905 tex.sprint("\n\t\t\\def\\xLeft{" ..
4906 dimToString(xLeft * self.xUnit) .. "}")
4907 tex.sprint("\n\t\t\\def\\xMid{" ..
4908 dimToString(xMid * self.xUnit) .. "}")
4909 tex.sprint("\n\t\t\\def\\xRight{" ..
4910 dimToString(xRight * self.xUnit) .. "}")
4911 tex.sprint("\n\t\t\\def\\yMid{" ..
4912 dimToString(yMid * self.yUnit) .. "}")
4913 tex.sprint("\n\t\t\\def\\featureSequence{" ..
4914 currFeature.sequence .. "}")
4915 tex.sprint(
4916 "\n\t\t\\clip (" ..
4917 dimToString(xLeftClip) ..
4918 ", \\yMid + " ..
4919 dimToString(stringToDim("10cm")) ..
4920 ") rectangle (" ..
4921 dimToString(xRightClip) ..
4922 ", \\yMid - " ..
4923 dimToString(stringToDim("10cm")) ..
4924 ");"
4925 )
4926 tex.sprint(
4927 "\n\t\t\\pgfmolbioset[domains]{" ..
4928 currFeature.kvList ..
4929 "}"
4930 )
4931 % \end{macrocode}
4932 % We invoke either the print function associated with the current feature or directly call |\pmbdomdrawfeature|. Afterwards, we close both surrounding environments.
4933 % \begin{macrocode}
4934 if self.specialKeys.printFunctions[currFeature.key] then
4935 self.specialKeys.printFunctions[currFeature.key](
4936 currFeature, xLeft, xRight, yMid, self.xUnit, self.yUnit)
4937 else
4938 tex.sprint("\n\t\t\\pmbdomdrawfeature{" ..
4939 currFeature.key .. "}")
4940 end
4941 tex.sprint("\n\t\\end{pgfinterruptboundingbox}\\end{scope}")
4942
4943 % \end{macrocode}
4944 % Calculate coordinates for the next line of the feature.
4945 % \begin{macrocode}
4946 currLine = currLine + 1
4947 xLeft = xLeft - self.residuesPerLine
4948 xRight = xRight - self.residuesPerLine
4949 residuesLeft = residuesLeft - self.residuesPerLine
4950 until xRight < 1 or residuesLeft < 1
4951 end
4952 end
4953
4954 % \end{macrocode}
4955 % \paragraph{(2) Feature \texttt{other/ruler}} The ruler requires special treatment, buth the algorithm is actually simple: For each marker, calculate its coordinates, select its style and print it.
4956 % \begin{macrocode}
4957 if self.showRuler then
4958 currStyle = 1
4959 tex.sprint("\n\t\\begin{scope}")
4960 for _, currRuler in ipairs(self.rulerRange) do
4961 currLine = 0
4962 xMid = currRuler.pos - self.residueRangeMin -
4963 currLine * self.residuesPerLine + 1
4964 while xMid > self.residuesPerLine do
4965 xMid = xMid - self.residuesPerLine
4966 currLine = currLine + 1
4967 end
4968 xMid = xMid - 0.5
4969 yMid = -currLine * self.baselineSkip
4970 tex.sprint(
4971 "\n\t\t\\pgfmolbioset[domains]{current style/.style={" ..
4972 self.specialKeys:selectStyleFromList("other/ruler", currStyle) ..
4973 "}}"
4974 )
4975 tex.sprint("\n\t\t\t\\def\\xMid{" ..
4976 dimToString(xMid * self.xUnit) .. "}")
4977 tex.sprint("\n\t\t\t\\let\\xLeft\\xMid\\let\\xRight\\xMid")
4978 tex.sprint("\n\t\t\t\\def\\yMid{" ..
4979 dimToString(yMid * self.yUnit) .. "}")
4980 tex.sprint("\n\t\t\t\\def\\residueNumber{" ..
4981 currRuler.number .. "}")
4982 tex.sprint("\n\t\t\t\\pmbdomdrawfeature{other/ruler}")
4983 currStyle = currStyle + 1
4984 end
4985 tex.sprint("\n\t\\end{scope}")
4986 end
4987
4988 % \end{macrocode}
4989 % \paragraph{(3) Feature \texttt{other/name}} Similarly, we calculate the coordinates of the name and print it.
4990 % \begin{macrocode}
4991 xMid =
4992 math.min(
4993 self.residuesPerLine,
4994 self.residueRangeMax - self.residueRangeMin + 1
4995 ) / 2
4996 tex.sprint("\n\t\\begin{scope}")
4997 tex.sprint(
4998 "\n\t\t\\pgfmolbioset[domains]{current style/.style={" ..
4999 self.specialKeys:selectStyleFromList("other/name", 1) ..
5000 "}}"
5001 )
5002 tex.sprint("\n\t\t\\def\\xLeft{0mm}")
5003 tex.sprint("\n\t\t\\def\\xMid{" .. dimToString(xMid * self.xUnit) .. "}")
5004 tex.sprint("\n\t\t\\def\\xRight{" ..
5005 dimToString(self.residuesPerLine * self.xUnit) .. "}")
5006 tex.sprint("\n\t\t\\def\\yMid{0mm}")
5007 tex.sprint("\n\t\t\\pmbdomdrawfeature{other/name}")
5008 tex.sprint("\n\t\\end{scope}")
5009
5010 % \end{macrocode}
5011 % \paragraph{(4) Set bounding box} The bounding box is determined manually in order to prevent excessive enlargement due to clipping. The top left corner of the bounding box is the coordinate (|enlarge left|, |enlarge top|).
5012 % \begin{macrocode}
5013 tex.sprint(
5014 "\n\t\\pmbprotocolsizes{" ..
5015 "\\pmbdomvalueof{enlarge left}}{\\pmbdomvalueof{enlarge top}}"
5016 )
5017 % \end{macrocode}
5018 % The $x$-coordinate of its right border is the largest line width plus the value of |enlarge right|. The $y$-coordinate of its bottom border is that of the lowermost line plus the value of |enlarge bottom|.
5019 % \begin{macrocode}
5020 currLine =
5021 math.ceil(
5022 (self.residueRangeMax - self.residueRangeMin + 1) /
5023 self.residuesPerLine
5024 ) - 1
5025 xRight =
5026 math.min(
5027 self.residuesPerLine,
5028 self.residueRangeMax - self.residueRangeMin + 1
5029 )
5030 tex.sprint(
5031 "\n\t\\pmbprotocolsizes{" ..
5032 dimToString(xRight * self.xUnit) ..
5033 " + \\pmbdomvalueof{enlarge right}}{" ..
5034 dimToString(-currLine * self.baselineSkip * self.yUnit) ..
5035 " + \\pmbdomvalueof{enlarge bottom}}"
5036 )
5037 end
5038
5039 % \end{macrocode}
5040 %
5041 % \subsection{Converting a \texorpdfstring{\texttt{Protein}}{Protein} to a String}
5042 % \label{ssc:DocDomLuaTostring}
5043 %
5044 % §Protein:__tostring§ is required by the \module{convert} module and returns a |pmbdomains| environment that contains all the information stored in the §Protein§ object (section~\ref{sec:ConDomains}). Firstly, we start the environment.
5045 % \begin{macrocode}
5046 function Protein:__tostring()
5047 local result = {}
5048 local currLine
5049
5050 currLine = "\\begin{pmbdomains}\n\t\t[name={" ..
5051 self.name ..
5052 "}"
5053 if self.sequence ~= "" then
5054 currLine = currLine ..
5055 ",\n\t\tsequence=" ..
5056 self.sequence
5057 end
5058 currLine = currLine ..
5059 "]{" ..
5060 self.sequenceLength ..
5061 "}"
5062 table.insert(result, currLine)
5063
5064 % \end{macrocode}
5065 % Afterwards, each feature in the feature table is converted to an |\addfeature| macro. Note the use of the §includeDescription§ field (described in section~\ref{ssc:DocDomLuaProteinClass}).
5066 % \begin{macrocode}
5067 for i, v in ipairs(self.ft) do
5068 if v.key ~= "other/main chain" then
5069 currLine = "\t\\addfeature"
5070 if self.includeDescription and v.description then
5071 currLine =
5072 currLine ..
5073 "[description={" ..
5074 v.description ..
5075 "}]"
5076 end
5077 currLine =
5078 currLine ..
5079 "{" ..
5080 v.key ..
5081 "}{" ..
5082 v.start ..
5083 "}{" ..
5084 v.stop ..
5085 "}"
5086 table.insert(result, currLine)
5087 end
5088 end
5089 % \end{macrocode}
5090 % Finally, we close the environment.
5091 % \begin{macrocode}
5092 table.insert(result,
5093 "\\end{pmbdomains}"
5094 )
5095 return table.concat(result, "\n")
5096 end
5097 % \end{macrocode}
5098 %
5099 % \iffalse
5100 %</pmb-dom-lua>
5101 %<*pmb-con-tex>
5102 % \fi
5103 %
5104 %
5105 %
5106 % \section{\texorpdfstring{\file{pgfmolbio.convert.tex}}{pgfmolbio.convert.tex}}
5107 % \label{sec:DocConTex}
5108 %
5109 % \def\ydoclistingssettings{\lstset{style=latex-doc}}\setcounter{lstnumber}{1}
5110 % The code for the \module{convert} module is short: We only need to declare four options and set |\pdfdraftmode| to 1 in order to prevent pdf\TeX\ from producing any \file{pdf} output.
5111 % \begin{macrocode}
5112 \pdfdraftmode1
5113
5114 \pgfkeyssetvalue{/pgfmolbio/convert/output file name}{(auto)}
5115 \pgfkeyssetvalue{/pgfmolbio/convert/output file extension}{tex}
5116
5117 \pgfmolbioset[convert]{%
5118 output code/.is choice,
5119 output code/tikz/.code=\pmb@con@outputtikzcodetrue,
5120 output code/pgfmolbio/.code=\pmb@con@outputtikzcodefalse,
5121 output code=tikz
5122 }
5123
5124 \pgfmolbioset[convert]{%
5125 include description/.is if=pmb@con@includedescription,
5126 include description
5127 }
5128 % \end{macrocode}
5129 %
5130 % \iffalse
5131 %</pmb-con-tex>
5132 % \fi
5133 %
5134 % \Finale
5135 \endinput