summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/dnaseq/dnaseq.dtx
blob: e1bc75518697904a0dfa3d92f095241e1f870ee4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
% \iffalse
%% File: dnaseq.dtx Copyright (C) 2002 Bjoern Pedersen
%% mailto:Bjoern.Pedersen@ch.tum.de
%% This file may be distributed and used freely under 
%% the Latex Project Public License
%%
%
%<*dtx>
          \ProvidesFile{dnaseq.dtx}[2002/05/20 v0.01 dna sequence setter]
%</dtx>
%<dnaseq>\NeedsTeXFormat{LaTeX2e}
%<dnaseq>\ProvidesPackage{dnaseq}[2002/05/20 v0.01 dna sequence setter]
%<dnaseq>\RequirePackage{color}
%<driver>\ProvidesFile{dnaseq.drv}
% \fi
%\iffalse
%<*driver>
\documentclass{ltxdoc}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{dnaseq}
\begin{document}
\DocInput{dnaseq.dtx}
\end{document}
%</driver>
%\fi
% \GetFileInfo{dnaseq.dtx}
% \title{The \textsf{dnaseq} package\thanks{This file
%        has version number \fileversion, last
%        revised \filedate.}}
% \author{Bj{\o}rn Pedersen}
% \date{\filedate}
% \maketitle
% \CheckSum{154}
% 
%\section{Introduction}
%\label{sec:intro}

%This package allows easy setting of simple dna-sequences in
%userdefined grouping, with numbering of bases (at the begin of
%each line.
%
%If you need to typeset alignments, have a look at the
%\texttt{texshade}-Package.
%
% The main code has been posted by Andreas Matthias
% \texttt{<amat@kabsi.at>} on \texttt{de.comp.text.tex} and is based
% by itself on old code from Anselm Lingnau.
%\section{Usage}
%\label{sec:usage}
%
%\subsection{DNA}
%\DescribeMacro{\DNA}
%\verb|\DNA| is the main macro of this package. It is used as
%following:
%\begin{verbatim}
%\DNA! actctgctagtcgatgcat!
%\end{verbatim}
%where the delimiting character \verb|!| can be any normal character.
%
%Within the argument you can use \verb|'{<color>}| to change the color
%of your bases. The color names are normal color.sty names. 
%Look at the full example for more info.
%
%\subsection{Configuration}
%
%\DescribeMacro{\DNAblock}The macro \verb|\DNAblock| stores the desired blocking intervall of
%your sequence. Just do a \verb|\renewcommand{\DNAblock}{<some number>}|
%to change the default of 10.
%
%\DescribeMacro{\DNAreserve}The macro defines how much space to reserve
%for the numbering of bases. 
%To change, do a \verb|\renewcommand{\DNAreserve}{<template>}| The
%default template is \verb|0000| allowing for for digit numbering.
%
%\section{Example}
%\label{sec:ex}
%
%\begin{verbatim}
%\noindent\begin{minipage}{100pt}
%
%\noindent\rule{\textwidth}{.5pt}
%\DNA!  ACGT'{red}A CGT'{white}TGCA'{green}x s df'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}TGCA'{green}x sdf '{white}FJKDSLAF
%DSAIOFDSA AC GT'{red}ACGT'{white}TG CA'{green}xsdf'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}T GCA'{green} xs df'{white}FJKDSLA
%FDSAIOFDSA ACGT'{red}AC GT'{white}TGCA'{green}xsdf'{white}FJK DSLA
%FDSAIOFDSA !
%\end{minipage}
%
%\noindent\begin{minipage}{200pt}
%\noindent\rule{\textwidth}{.5pt}
%\DNA!  ACGT'{red}A CGT'{white}TGCA'{green}x s df'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}TGCA'{green}x sdf '{white}FJKDSLAF
%DSAIOFDSA AC GT'{red}ACGT'{white}TG CA'{green}xsdf'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}T GCA'{green} xs df'{white}FJKDSLA
%FDSAIOFDSA ACGT'{red}AC GT'{white}TGCA'{green}xsdf'{white}FJK DSLA
%FDSAIOFDSA !
%\end{minipage}
%
%\noindent\begin{minipage}{\textwidth}
%\noindent\rule{\textwidth}{.5pt}
%\DNA!  ACGT'{red}A CGT'{white}TGCA'{green}x s df'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}TGCA'{green}x sdf '{white}FJKDSLAF
%DSAIOFDSA AC GT'{red}ACGT'{white}TG CA'{green}xsdf'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}T GCA'{green} xs df'{white}FJKDSLA
%FDSAIOFDSA ACGT'{red}AC GT'{white}TGCA'{green}xsdf'{white}FJK DSLA
%FDSAIOFDSA !
%\end{minipage}
%
%\renewcommand{\DNAblock}{5}
%\noindent\begin{minipage}{\textwidth}
%\noindent\rule{\textwidth}{.5pt}
%\DNA!  ACGT'{red}A CGT'{white}TGCA'{green}x s df'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}TGCA'{green}x sdf '{white}FJKDSLAF
%DSAIOFDSA AC GT'{red}ACGT'{white}TG CA'{green}xsdf'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}T GCA'{green} xs df'{white}FJKDSLA
%FDSAIOFDSA ACGT'{red}AC GT'{white}TGCA'{green}xsdf'{white}FJK DSLA
%FDSAIOFDSA !
%\end{minipage}
%\end{verbatim}
%\noindent\begin{minipage}{100pt}
%
%\noindent\rule{\textwidth}{.5pt}
%\DNA!  ACGT'{red}A CGT'{white}TGCA'{green}x s df'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}TGCA'{green}x sdf '{white}FJKDSLAF
%DSAIOFDSA AC GT'{red}ACGT'{white}TG CA'{green}xsdf'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}T GCA'{green} xs df'{white}FJKDSLA
%FDSAIOFDSA ACGT'{red}AC GT'{white}TGCA'{green}xsdf'{white}FJK DSLA
%FDSAIOFDSA !
%\end{minipage}
%
%\noindent\begin{minipage}{200pt}
%\noindent\rule{\textwidth}{.5pt}
%\DNA!  ACGT'{red}A CGT'{white}TGCA'{green}x s df'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}TGCA'{green}x sdf '{white}FJKDSLAF
%DSAIOFDSA AC GT'{red}ACGT'{white}TG CA'{green}xsdf'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}T GCA'{green} xs df'{white}FJKDSLA
%FDSAIOFDSA ACGT'{red}AC GT'{white}TGCA'{green}xsdf'{white}FJK DSLA
%FDSAIOFDSA !
%\end{minipage}
%
%\noindent\begin{minipage}{\textwidth}
%\noindent\rule{\textwidth}{.5pt}
%\DNA!  ACGT'{red}A CGT'{white}TGCA'{green}x s df'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}TGCA'{green}x sdf '{white}FJKDSLAF
%DSAIOFDSA AC GT'{red}ACGT'{white}TG CA'{green}xsdf'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}T GCA'{green} xs df'{white}FJKDSLA
%FDSAIOFDSA ACGT'{red}AC GT'{white}TGCA'{green}xsdf'{white}FJK DSLA
%FDSAIOFDSA !
%\end{minipage}
%
%\renewcommand{\DNAblock}{5}
%\noindent\begin{minipage}{\textwidth}
%\noindent\rule{\textwidth}{.5pt}
%\DNA!  ACGT'{red}A CGT'{white}TGCA'{green}x s df'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}TGCA'{green}x sdf '{white}FJKDSLAF
%DSAIOFDSA AC GT'{red}ACGT'{white}TG CA'{green}xsdf'{white}FJKD SLAF
%DSAIOFDSA ACGT'{red}ACGT'{white}T GCA'{green} xs df'{white}FJKDSLA
%FDSAIOFDSA ACGT'{red}AC GT'{white}TGCA'{green}xsdf'{white}FJK DSLA
%FDSAIOFDSA !
%\end{minipage}
%
%\StopEventually
%
%\section{The code}
%<*dnaseq>
%    \begin{macrocode}
\def\DNAblock{10}
\def\DNAreserve{0000}% für 4-stellige Zahlen
%%
%% registers /counters
%%
\newlength\bl@cklen
\newlength\l@neln
\newlength\t@mpln
\newlength\ch@rwd
\newcount{\blocks}
%%
%% calculate blocks per line
%% 
\def\DNAc@lcline{%
 \settowidth{\ch@rwd}{A}
 \setlength{\bl@cklen}{\DNAblock\ch@rwd}%
 \settowidth{\t@mpln}{\DNAreserve}
 \setlength{\l@neln}{\textwidth}
 \addtolength{\l@neln}{-\t@mpln}
 \loop%
    \setlength{\t@mpln}{\blocks\bl@cklen}
    \addtolength{\t@mpln}{\blocks\ch@rwd}
    \ifdim\l@neln>\t@mpln\advance\blocks by 1
 \repeat
 \advance\blocks by -1
 \ifnum\blocks<1\errmessage{line too short for 1 block^^J}%
 \else\expandafter\message\expandafter{Blocks per line: \the\blocks^^J}\fi%
}

%% main user macro
\def\DNA#1{%
   \def\@DNA@end{#1}\bgroup\ttfamily\DNAc@lcline
   \settoheight\dimen@{I}\advance\dimen@ by 1pt
   \edef\htst{\the\dimen@}%
   \def\struty{\rule[-.5pt]{\z@}{\htst}}%
   %% dnabase per line counter
   \count@=0
   %% block counter
   \@tempcnta=0
   %% total dnabase counter
   \@tempcntb=0
   \fboxrule=0pt \fboxsep=0pt
   \noindent\phantom{\DNAreserve}\llap 1\
   \@DNA
}

\def\@DNA@color{'}
\def\@DNA@thecolor{white}
\def\@DNA@setcolor#1{\def\@DNA@thecolor{#1}\@DNA}
%% do the blocking/line breaking
\def\@DNA#1{%
%% insert a space after \DNAblock bases
   \ifnum\count@=\DNAblock\count@=0\ %
   \advance\@tempcnta by 1\fi
   \def\@DNA@cmp{#1}%
%% check for end of sequence or color shift
   \ifx\@DNA@cmp\@DNA@end
     \let\next\egroup
   \else
     \ifx\@DNA@cmp\@DNA@color
       \let\next\@DNA@setcolor
     \else
       \advance\count@ by 1
       \advance\@tempcntb by 1
%% line break after calculated number of blocks
       \ifnum\@tempcnta=\blocks \\
         \hskip\z@\phantom{\DNAreserve}\llap {\the\@tempcntb}\ %
         \@tempcnta=0
       \fi
       \colorbox{\@DNA@thecolor}{\struty#1}%
       \penalty0\let\next\@DNA
     \fi
   \fi
   \next
}
%    \end{macrocode}
%</dnaseq>
% \Finale