The following TikZ code shows a representation of DNA code segments.
I have two different versions of this code. Version 1 uses multipart rectangles, and is my preferred version. Version 2 models the DNA sequences as individual squares stuck together. The issue with that is that these squares tend to come unstuck on changing scale, which is annoying.
Partly for that reason, I prefer version 1, but it has some problems. If these can't be fixed, then I will use version 2.
Here is the problems.
1) The block on the left, call this block A, has the colors bleeding outside the boxes in some places. Particularly on the right side. See for example the bottom right corner, where the square flanked by $X_{9}$ and $X^{(6)}$. Here this bleeding of the color out of the square is quite noticeable. It can be seen in other places as well. This effect becomes much less if
\tikzstyle{every path}=[very thick]
is removed. However, I want the thick paths. This might be the result of user error, or a bug. I think it might be the cumulative result of rounding errors as TikZ moves along calculating the dimensions of the parts of the rectangle, since it gets worse as one moves to the right. The question is whether there is a way around it.
2) The arrows from block A to the right should have an arrow head only at the termination point, but has arrows on both ends.
3) The boxes on the left and the right should be aligned. They are aligned on the top, but not the bottom.
Finally, a few questions which are not strictly problems.
4) Any suggestions to stop the arrows from obscuring the labels? Maybe make the labels a different color? Is there an easy way to superimpose the labels on top of the arrows?
5) Is there any way to make the division lines within the multipart rectangles a different thickness from the other lines?
6) How can I make the block of code which begins with
\node [below] at (leftrow6.one south) {$\mathsmaller{\mathbf{X_{0}}}$};
into a loop? An attempt is below, namely
\foreach \i in {one, two, three, four, five, six, seven, eight, nine, ten}
{
\foreach \j in {0,...,9}
{
\node [below] at (leftrow6.\i south) {$\mathsmaller{\mathbf{X_{\j}}}$};
}
}
but this does not work.
The code for the two versions follow. Suggestions for improvement, including reducing lines of code appreciated. The image for version 1 is at the bottom.
Version 1
\documentclass[a4paper, 12pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows, positioning, calc, patterns, shadows, external}
%%%<
\usepackage{verbatim}
\usepackage{lmodern}
\usepackage{scrextend}
\usepackage{relsize}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>
\usetikzlibrary{chains,fit,shapes, shapes.multipart}
\begin{document}
\changefontsizes{20pt}
\begin{tikzpicture}
\tikzstyle{every path}=[very thick]
\tikzstyle{line} = [draw, -latex', thick]
\tikzstyle{seq}=[rectangle split, rectangle split horizontal, rectangle split parts=#1, minimum height=1cm, draw, anchor=center]
\matrix[row sep=0.5cm] at (0cm, 4cm)
{
\node [seq=10, rectangle split part fill={blue!20, none, cyan!30, none, blue!20, none, none, cyan!30, none, cyan!30}] (leftrow1)
{C \nodepart{two} \phantom{X} \nodepart{three} A \nodepart{four} \phantom{X} \nodepart{five} G \nodepart{six} \phantom{X} \nodepart{seven} \phantom{X} \nodepart{eight} G \nodepart{nine} \phantom{X} \nodepart{ten} C}; \\
\node [seq=10, rectangle split part fill={green!20, none, orange!50, none, green!20, none, none, orange!50, none, orange!50}] (leftrow2)
{A \nodepart{two} \phantom{X} \nodepart{three} C \nodepart{four} \phantom{X} \nodepart{five} C \nodepart{six} \phantom{X} \nodepart{seven} \phantom{X} \nodepart{eight} A \nodepart{nine} \phantom{X} \nodepart{ten} A}; \\
\node [seq=10, rectangle split part fill={green!20, none, yellow!50, none, green!20, none, none, yellow!50, none, yellow!50}] (leftrow3)
{A \nodepart{two} \phantom{X} \nodepart{three} T \nodepart{four} \phantom{X} \nodepart{five} C \nodepart{six} \phantom{X} \nodepart{seven} \phantom{X} \nodepart{eight} T \nodepart{nine} \phantom{X} \nodepart{ten} T}; \\
\node [seq=10, rectangle split part fill={blue!20, none, cyan!30, none, blue!20, none, none, cyan!30, none, cyan!30}] (leftrow4)
{C \nodepart{two} \phantom{X} \nodepart{three} A \nodepart{four} \phantom{X} \nodepart{five} G \nodepart{six} \phantom{X} \nodepart{seven} \phantom{X} \nodepart{eight} G \nodepart{nine} \phantom{X} \nodepart{ten} C}; \\
\node [seq=10, rectangle split part fill={blue!20, none, cyan!30, none, blue!20, none, none, cyan!30, none, cyan!30}] (leftrow5)
{C \nodepart{two} \phantom{X} \nodepart{three} A \nodepart{four} \phantom{X} \nodepart{five} G \nodepart{six} \phantom{X} \nodepart{seven} \phantom{X} \nodepart{eight} G \nodepart{nine} \phantom{X} \nodepart{ten} C}; \\
\node [seq=10, rectangle split part fill={red!50, none, orange!50, none, red!50, none, none, orange!50, none, orange!50}] (leftrow6)
{A \nodepart{two} \phantom{X} \nodepart{three} C \nodepart{four} \phantom{X} \nodepart{five} A \nodepart{six} \phantom{X} \nodepart{seven} \phantom{X} \nodepart{eight} A \nodepart{nine} \phantom{X} \nodepart{ten} A}; \\
};
\node [below] at (leftrow6.one south) {$\mathsmaller{\mathbf{X_{0}}}$};
\node [below] at (leftrow6.two south) {$\mathsmaller{\mathbf{X_{1}}}$};
\node [below] at (leftrow6.three south) {$\mathsmaller{\mathbf{X_{2}}}$};
\node [below] at (leftrow6.four south) {$\mathsmaller{\mathbf{X_{3}}}$};
\node [below] at (leftrow6.five south) {$\mathsmaller{\mathbf{X_{4}}}$};
\node [below] at (leftrow6.six south) {$\mathsmaller{\mathbf{X_{5}}}$};
\node [below] at (leftrow6.seven south) {$\mathsmaller{\mathbf{X_{6}}}$};
\node [below] at (leftrow6.eight south) {$\mathsmaller{\mathbf{X_{7}}}$};
\node [below] at (leftrow6.nine south) {$\mathsmaller{\mathbf{X_{8}}}$};
\node [below] at (leftrow6.ten south) {$\mathsmaller{\mathbf{X_{9}}}$};
%loop version does not work
%\foreach \i in {{one}, {two}, {three}, {four}, {five}, {six}, {seven}, {eight},
%{nine}, {ten}}
%{
% \foreach \j in {0,...,9}
% {
% \node [below] at (leftrow6.\i south) {$\mathsmaller{\mathbf{X_{\j}}}$};
% }
%}
% loop version does not work
\foreach \i in {1,...,6}
{
\node [right] at (leftrow\i.ten east) {$\mathsmaller{\mathbf{X^{(\i)}}}$};
}
\matrix[row sep=0.5cm] at (10cm, 4cm)
{
\node [seq=2, rectangle split part fill={blue!20, blue!20}] (tupletoprow)
{C \nodepart{two} G}; \\
\node [seq=2, rectangle split part fill={green!20, green!20}]
{A \nodepart{two} C}; \\
\node [seq=2, rectangle split part fill={green!20, green!20}]
{A \nodepart{two} C}; \\
\node [seq=2, rectangle split part fill={blue!20, blue!20}]
{C \nodepart{two} G}; \\
\node [seq=2, rectangle split part fill={blue!20, blue!20}]
{C \nodepart{two} G}; \\
\node [seq=2, rectangle split part fill={red!50, red!50}] (tuplebottomrow)
{A \nodepart{two} A}; \\
};
\matrix[row sep=0.5cm] at (13cm, 4cm)
{
\node [seq=3, rectangle split part fill={cyan!30, cyan!30}] (tripletoprow)
{A \nodepart{two} G \nodepart{three} C}; \\
\node [seq=3, rectangle split part fill={orange!50, orange!50}]
{C \nodepart{two} A \nodepart{three} A}; \\
\node [seq=3, rectangle split part fill={yellow!50, yellow!50}]
{T \nodepart{two} T \nodepart{three} T}; \\
\node [seq=3, rectangle split part fill={cyan!30, cyan!30}]
{A \nodepart{two} G \nodepart{three} C}; \\
\node [seq=3, rectangle split part fill={cyan!30, cyan!30}]
{A \nodepart{two} G \nodepart{three} C}; \\
\node [seq=3, rectangle split part fill={orange!50, orange!50}] (triplebottomrow)
{C \nodepart{two} A \nodepart{three} A}; \\
};
\node [below] at (tuplebottomrow.south) {$(\mathsmaller{\mathbf{X_{0}}}, \mathsmaller{\mathbf{X_{4}}})$};
\node [below] at (triplebottomrow.south) {$(\mathsmaller{\mathbf{X_{3}}}, \mathsmaller{\mathbf{X_{7}}}, , \mathsmaller{\mathbf{X_{9}}})$};
\node [above] at (tupletoprow.north) {(0, 4)};
\node [above] at (tripletoprow.north) {(3, 7, 9)};
\path [line] (leftrow6.one south) edge[out=270, in=270] node {}(tuplebottomrow);
\path [line] (leftrow6.five south) edge[out=270, in=270] node {}(tuplebottomrow);
\path [line] (leftrow1.three north) edge[out=90, in=90] node {}(tripletoprow);
\path [line] (leftrow1.eight north) edge[out=90, in=90] node {}(tripletoprow);
\path [line] (leftrow1.ten north) edge[out=90, in=90] node {}(tripletoprow);
\end{tikzpicture}
\changefontsizes{12pt}
\end{document}
Version 2
\documentclass[a4paper, 12pt]{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows, positioning, calc, patterns, shadows, external}
\usepackage{verbatim}
\usepackage{lmodern}
\usepackage{scrextend}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
\usetikzlibrary{chains,fit,shapes}
\begin{document}
\changefontsizes{15pt}
\begin{tikzpicture}
\tikzstyle{every path}=[very thick]
\tikzstyle{line} = [draw, -latex', thick]
\edef\sizeseqbox{1.3cm}
\tikzstyle{seq}=[draw,minimum size=\sizeseqbox]
\matrix [row sep=3mm] at (-7, 0)
{
\node []{}; & \node []{}; & \node [] {}; & \node []{}; & \node []{}; & \node []{}; & \node []{}; & \node []{}; & \node []{}; & \node [] {}; \\
\node [seq, fill=blue!20]{C}; & \node [seq]{}; & \node [seq, fill=cyan!30] (triplecol1left) {A}; & \node [seq]{}; & \node [seq, fill=blue!20]{G}; & \node [seq]{}; & \node [seq]{}; & \node [seq, fill=cyan!30] (triplecol2left) {G}; & \node [seq]{}; & \node [seq, fill=cyan!30] (triplecol3left) {C}; & \node [] {$\mathbf{X^{(1)}}$};\\
\node [seq, fill=green!20]{A}; & \node [seq]{}; & \node [seq, fill=orange!50]{C}; & \node [seq]{}; & \node [seq, fill=green!20]{C}; & \node [seq]{}; & \node [seq]{}; & \node [seq, fill=orange!50]{A}; & \node [seq]{}; & \node [seq, fill=orange!50]{A}; & \node [] {$\mathbf{X^{(2)}}$};\\
\node [seq, fill=green!20]{A}; & \node [seq]{}; & \node [seq, fill=yellow!50]{T}; & \node [seq]{}; & \node [seq, fill=green!20]{C}; & \node [seq]{}; & \node [seq]{}; & \node [seq, fill=yellow!50]{T}; & \node [seq]{}; & \node [seq, fill=yellow!50]{T}; & \node [] {$\mathbf{X^{(3)}}$};\\
\node [seq, fill=blue!20]{C}; & \node [seq]{}; & \node [seq, fill=cyan!30]{A}; & \node [seq]{}; & \node [seq, fill=blue!20]{G}; & \node [seq]{}; & \node [seq]{}; & \node [seq, fill=cyan!30]{G}; & \node [seq]{}; & \node [seq, fill=cyan!30]{C}; & \node [] {$\mathbf{X^{(4)}}$};\\
\node [seq, fill=blue!20]{C}; & \node [seq]{}; & \node [seq, fill=cyan!30]{A}; & \node [seq]{}; & \node [seq, fill=blue!20]{G}; & \node [seq]{}; & \node [seq]{}; & \node [seq, fill=cyan!30]{G}; & \node [seq]{}; & \node [seq, fill=cyan!30]{C}; & \node [] {$\mathbf{X^{(5)}}$};\\
\node [seq, fill=red!50] (tuplecol1left) {A}; & \node [seq]{}; & \node [seq, fill=orange!50] {C}; & \node [seq]{}; & \node [seq, fill=red!50] (tuplecol2left) {A}; & \node [seq]{}; & \node [seq]{}; & \node [seq, fill=orange!50] {A}; & \node [seq]{}; & \node [seq, fill=orange!50] {A}; & \node [] {$\mathbf{X^{(6)}}$};\\
\node []{$\mathbf{X_{0}}$}; & \node []{$\mathbf{X_{1}}$}; & \node [] {$\mathbf{X_{2}}$}; & \node []{$\mathbf{X_{3}}$}; & \node []{$\mathbf{X_{4}}$}; & \node []{$\mathbf{X_{5}}$}; & \node []{$\mathbf{X_{6}}$}; & \node []{$\mathbf{X_{7}}$}; & \node []{$\mathbf{X_{8}}$}; & \node [] {$\mathbf{X_{9}}$}; \\
};
\matrix [row sep=3mm] at (5, 0)
{
\node [] {(0,}; & \node [] {4)}; \\
\node [seq, fill=blue!20]{C}; & \node [seq, fill=blue!20]{G}; \\
\node [seq, fill=green!20]{A}; & \node [seq, fill=green!20]{C}; \\
\node [seq, fill=green!20]{A}; & \node [seq, fill=green!20]{C}; \\
\node [seq, fill=blue!20]{C}; & \node [seq, fill=blue!20]{G}; \\
\node [seq, fill=blue!20]{C}; & \node [seq, fill=blue!20]{G}; \\
\node [seq, fill=red!50] (tuplecol1right) {A}; & \node [seq, fill=red!50] (tuplecol2right) {A}; \\
\node [] {$(\mathbf{X_0},$}; & \node [] {$\mathbf{X_4})$}; \\
};
\matrix [row sep=3mm] at (9, 0)
{
\node [] {(2,}; & \node [] {7,}; & \node [] {9)}; \\
\node [seq, fill=cyan!30] (triplecol1right) {A}; & \node [seq, fill=cyan!30] (triplecol2right) {G}; & \node [seq, fill=cyan!30] (triplecol3right) {C}; \\
\node [seq, fill=orange!50]{C}; & \node [seq, fill=orange!50]{A}; & \node [seq, fill=orange!50]{A}; \\
\node [seq, fill=yellow!50]{T}; & \node [seq, fill=yellow!50]{T}; & \node [seq, fill=yellow!50]{T}; \\
\node [seq, fill=cyan!30]{A}; & \node [seq, fill=cyan!30]{G}; & \node [seq, fill=cyan!30]{C}; \\
\node [seq, fill=cyan!30]{A}; & \node [seq, fill=cyan!30]{G}; & \node [seq, fill=cyan!30]{C}; \\
\node [seq, fill=orange!50] {C};& \node [seq, fill=orange!50] {A};& \node [seq, fill=orange!50] {A};\\
\node [] {($\mathbf{X_2},$}; & \node [] {$\mathbf{X_7},$}; & \node [] {$\mathbf{X_9})$}; \\
};
\path [line] (tuplecol1left) edge[out=270, in=270] node {}(tuplecol1right.south east);
\path [line] (tuplecol2left) edge[out=270, in=270] node {}(tuplecol2right.south west);
\path [line] (triplecol1left) edge[out=90, in=90] node {}(triplecol2right);
\path [line] (triplecol2left) edge[out=90, in=90] node {}(triplecol2right);
\path [line] (triplecol3left) edge[out=90, in=90] node {}(triplecol2right);
\end{tikzpicture}
\changefontsizes{12pt}
\end{document}
listings
for typesetting different characters with different colors in a DNA sequence and, or similar processing intikz
to add coloring and boxes, with automatic insertion of\tikzmark
at each node. Then do the arrow drawgins based on the\tikzmark
s.