# Sequence alignment diagram with tikz

I am trying to create a DNA alignment diagram. Here is what I have:

\definecolor{color1}{RGB}{255,183,236}
\definecolor{color2}{RGB}{255,249,158}

\begin{center}
\begin{tikzpicture}
\node (refread) at (1,3) [rectangle,draw,fill=color1] {TTTCAGATTT};
\end{tikzpicture}
\end{center}


How can I make the thing at the top look like a single sequence with its parts highlighted, i.e. more like

• Not a direct response, but have you looked at the texshade package? It is a special-purpose package for highlighting nucleotide and peptide sequence alignments. – Michael Palmer Nov 20 '16 at 20:43
• Thanks, I didn't know about that package and I'll keep it in mind. But in this case, I need a different kind of diagram than that package provides. – Roman Cheplyaka Nov 20 '16 at 20:47

Draw the boxes at the top without frames first, and then a box around them all:

\begin{tikzpicture}

\node (refread) at (1,3) [rectangle,fill=color1,inner xsep=0pt,line width=0] {TTTCAGATTT};
\node (first) at (refread.west) [rectangle,fill=color2,anchor=east,inner xsep=0pt,,line width=0] {\,ACCAGG};
\node (last) at (refread.east) [rectangle,fill=color2,anchor=west,inner xsep=0pt,line width=0] {AAA\,};
\draw (first.south west) rectangle (last.north east);

\end{tikzpicture}


Edit: modified to address the white border issue. Box heights didn't change; that was probably just an artifact created by my pdf viewer (from which I took the screen capture).

• Thanks, but this still leaves gaps between the parts, which I'd like to avoid (I tried to show it in my "desired" example). I want it to look as if it were a single ACCAGGTTTCAGATTTAAA string typeset by TeX. Also, the AAA box height is a bit smaller than the rest, so there's a white horizontal gap at the bottom. It becomes more visible if you make the fill color dark. – Roman Cheplyaka Nov 20 '16 at 20:59
• imgur.com/a/DEGG9 – Roman Cheplyaka Nov 20 '16 at 21:02

the box heights were still uneven; I fixed this with \vphantom like this:
\node at (refread.east) [...] {\vphantom{ACTG}AAA\,};