3

I need to modify how to draw DNA sequences. There is a function \DNASequence which does the job. It uses nodes of constant size. However, I need to put arbitrary text instead of only one letter in a cell. How to do it? I tried to modify original code but I don't know how to get the actual width of a node.

\documentclass[10pt]{beamer}
\usepackage[utf8]{inputenc} % Language = Spanish
\usepackage{color}
\usepackage{tikz}
\usetheme{Warsaw} 
\usecolortheme{whale}
\usepackage{xstring}
\usetikzlibrary{calc, arrows}

\newcommand*{\NodeSize}{0.5cm}%
\newcommand*{\YShiftBetweenRows}{-1cm}% Subsequent rows are shited down so they don't overlap
\tikzset{DNA Style/.style={minimum size=0.5cm, draw=gray, line width=1pt}}{}

\newlength{\YShift}% 
\newcounter{ColumnCounter}% Prefix for node labels

\setlength{\YShift}{0cm}% 
\setcounter{ColumnCounter}{0}
\newcounter{angle}
\setcounter{angle}{0}
%
\begin{document}
\newcommand*{\DNASequence}[2][Mark]{%
% https://tex.stackexchange.com/questions/12091/tikz-foreach-loop-with-macro-defined-list
\def\Sequence{#2}
\foreach [count=\xi] \Label/\Color in \Sequence {%
    \pgfmathsetmacro{\XShift}{\NodeSize*\xi}%
    \IfStrEq{\Color}{}{\def\Color{white}}{}
    \edef\NodeName{#1-\arabic{ColumnCounter}}
    \node [DNA Style, fill=\Color, xshift=\XShift] (\NodeName) {\Label};
    \stepcounter{ColumnCounter}
} 
}%


\begin{frame}{bla}
\begin{tikzpicture}
\DNASequence{AAAA/cyan,, Big/orange,,,Small/blue,,G/red!25,,C/yellow};
\end{tikzpicture}
\end{frame}
\end{document}

EDIT: I need \DNASequence function which draws arbitrary text in the nodes.

ashim
  • 1,783
  • 1
    Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – jub0bs May 06 '13 at 07:30

1 Answers1

3

The following is adapted from my earlier answer at Display issues drawing DNA sequences with TikZ:

enter image description here

Code:

\documentclass[border=3pt]{article}
\usepackage{tikz}
\usepackage{xstring,calc}
\usetikzlibrary{calc}

\newlength{\NodeSize}

\tikzset{DNA Style/.style={minimum size=0.5cm, draw=gray, line width=1pt, inner sep = 2pt}}{}

\newcounter{ColumnCounter}% Prefix for node labels

\newlength{\CurrentXPos} \newcommand{\PreviousNode}{}% \newcommand{\DNASequence}[2][Mark]{% % https://tex.stackexchange.com/questions/12091/tikz-foreach-loop-with-macro-defined-list \def\Sequence{#2}% \def\PreviousNode{}% \foreach [count=\xi] \Label/\Color in \Sequence {% \IfStrEq{\Color}{}{\def\Color{white}}{} \edef\NodeName{#1-\arabic{ColumnCounter}} \IfStrEq{\PreviousNode}{}{% \node [DNA Style, fill=\Color, anchor=west] (\NodeName) {\Label}; \xdef\PreviousNode{\NodeName}% }{ \node [DNA Style, fill=\Color, anchor=west, xshift=-\pgflinewidth] at (\PreviousNode.east)(\NodeName) {\Label}; \xdef\PreviousNode{\NodeName}% } \stepcounter{ColumnCounter} } }%

\begin{document} \begin{tikzpicture} \begin{scope} \DNASequence{ABCC/magenta!20,,, XYZ/violet!30,,ABC/green, G/blue!20,, G/cyan!30,, C/olive}; \end{scope} \begin{scope}[yshift=-1cm] \DNASequence{ABCDEFGHS/brown!20,, XYS/cyan!30,,, G/blue!20,, G/orange!30,, C/blue!30, X/red!20, Y/yellow!75}; \end{scope} \end{tikzpicture} \end{document}

Peter Grill
  • 223,288