1

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 (read) [rectangle,draw,fill=color1] {TTTCAGATTT};
  \node (refread) at (1,3) [rectangle,draw,fill=color1] {TTTCAGATTT};
  \node at (refread.west) [rectangle,draw,fill=color2,anchor=east] {ACCAGG};
  \node at (refread.east) [rectangle,draw,fill=color2,anchor=west] {AAA};
  \draw[->]{(read) -- (refread)};
\end{tikzpicture}
\end{center}

enter image description here

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

enter image description here

  • 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
3

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

\begin{tikzpicture}
  \node (read) [rectangle,draw,fill=color1] {TTTCAGATTT};

  \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);

  \draw[->]{(read) -- (refread)};
\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).

enter image description here

  • 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
1

In addition to Michael's answer:

the box heights were still uneven; I fixed this with \vphantom like this:

\node at (refread.east) [...] {\vphantom{ACTG}AAA\,};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.