在马尔可夫链节点内绘制配对的 DNA 序列

在马尔可夫链节点内绘制配对的 DNA 序列

我又一次陷入困境,我到处寻找,但我很难画出如下所示的东西在此处输入图片描述

我为我糟糕的“绘画”技巧道歉。所有圆圈应该大小相同。我有以下代码

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,chains}
\usetikzlibrary{shapes.gates.logic.US,trees,positioning,arrows}
\begin{document}      
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,node distance=4cm]
\node[state]         [ inner sep = 0.7 cm ]        (0) {};
\node[state]     [label={[label distance=.2cm]75:Recombination},left of= 0, inner sep = 0.7 cm ]            (1) {};
\node[state]   [label={[label distance=.2cm]75:Coalescense},left of= 1, inner sep = 0.7 cm ]              (2) {};
\node[state] (b) [label={[label distance=.2cm]270:\textit{Left tree taller}},below of = 0, left of = 1  , node distance=4 cm ]  {$x_t > x_{t-1}$};
\node[state] (c) [label={[label distance=.2cm]90:\textit{Right tree taller}},above of = 0, left of = 1 , node distance= 4 cm ] {$x_t < x_{t-1}$};
\node[state] (a) [label={[label distance=.2cm]270:\textit{Same tree height}},right  of = 2, right of = 1, node distance= 4  cm ]{$x_t = x_{t-1}$};
  \node (s0) [below=0 em of 0] {\textbf{State 0}};
  \node (s1) [below=0 em of 1] {\textbf{State 1}};
  \node (s2) [below=0 em of 2] {\textbf{State 2}};
\draw  
    (1)   edge             node[above = .02 cm] {$\eta$}   (2)
    (0)     edge           node[above = .02 cm] {$\rho$}   (1)
    (2) edge[dashed]  (b)
    (2) edge[dashed] (c)
    (0) edge[dashed] (a);
\end{tikzpicture}
\end{document}

答案1

可能,带有链接的节点可以用来完成pics,但是这里你有一个强力解决方案。

\documentclass[tikz,border=2mm]{standalone}

\usetikzlibrary{positioning, arrows, automata, fit, shapes}

\begin{document}

\begin{tikzpicture}[->,>=stealth', shorten >=1pt, node distance=1.8cm, ball/.style={draw, circle, minimum size=3mm, inner sep=0pt, fill=#1}, ball/.default={black},
mystate/.style={state, minimum size=2cm}]

\node[mystate, label=below:\textbf{State 0}] (0) {};
\node[mystate, label={[label distance=.2cm]75:Recombination}, label=below:\textbf{State 1}, left = of 0] (1) {};
\node[mystate, label={[label distance=.2cm]75:Coalescense}, label=below:\textbf{State 2}, left =  of 1] (2) {};
\node[mystate, label={[label distance=.2cm]270:\textit{Left tree taller}}, below = of 2] (b) {$x_t > x_{t-1}$};
\node[mystate, label={[label distance=.2cm]90:\textit{Right tree taller}}, above = of 2, ] (c)  {$x_t < x_{t-1}$};
\node[mystate] [label={[label distance=.2cm]270:\textit{Same tree height}}, right = of 0] (a) {$x_t = x_{t-1}$};
\draw  
    (1)   edge             node[above = .02 cm] {$\eta$}   (2)
    (0)     edge           node[above = .02 cm] {$\rho$}   (1)
    (2) edge[dashed]  (b)
    (2) edge[dashed] (c)
    (0) edge[dashed] (a);

\foreach \i in {45,135,225,315}
\path (2.center) --++(\i:5mm) node[ball] (2-\i) {};

\foreach \i in {45,135,225,315}
\path (0.center) --++(\i:5mm) node[ball] (0-\i) {};

\foreach \i in {135,225,315}
\path (1.center) --++(\i:5mm) node[ball] (1-\i) {};
\path (1.center) --++(45:5mm) node[ball=white] (1-45) {};

\foreach \i in {0,1,2}{
    \draw[-, shorten >=0pt] (\i-135)--(\i-45) (\i-225)--(\i-315);
    \node[inner sep=2pt, ellipse, draw, fit=(\i-135) (\i-45)]{};
    \node[inner sep=2pt, ellipse, draw, fit=(\i-315) (\i-225)]{};
}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

您可以定义一个pic绘制链接对的函数。该函数有三个参数:左点的颜色、右点的颜色以及链接它们的线条的样式:

\tikzset{
pics/adn/.style args={#1 and #2 style #3}{
    code={
      \node[draw, fill=#1, inner sep=0pt, circle, minimum size=2mm] at (-.3,0) (A) {};
      \node[draw, fill=#2, inner sep=0pt, circle, minimum size=2mm] at ( .3,0) (B) {};
      \draw[#3, -, shorten >=0pt, shorten <=0pt] (A) -- (B);
      \node[ellipse,draw, fit=(A) (B), inner sep=1mm] {};
    }
}}

现在您可以在图片末尾添加以下几行:

\path (0) +(0, .4) pic { adn={black and black style solid} };
\path (0) +(0,-.4) pic { adn={black and black style solid} };

\path (1) +(0, .4) pic { adn={black and white style dashed} };
\path (1) +(0,-.4) pic { adn={black and black style solid} };

\path (2) +(0, .4) pic { adn={black and black style solid} };
\path (2) +(0,-.4) pic { adn={black and black style solid} };
\end{tikzpicture}

要得到:

结果

仅供参考,以下是完整的可编译代码:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,chains}
\usetikzlibrary{shapes.gates.logic.US,trees,positioning,arrows,shapes.geometric,fit}

\tikzset{
pics/adn/.style args={#1 and #2 style #3}{
    code={
      \node[draw, fill=#1, inner sep=0pt, circle, minimum size=2mm] at (-.3,0) (A) {};
      \node[draw, fill=#2, inner sep=0pt, circle, minimum size=2mm] at ( .3,0) (B) {};
      \draw[#3, -, shorten >=0pt, shorten <=0pt] (A) -- (B);
      \node[ellipse,draw, fit=(A) (B), inner sep=1mm] {};
    }
}}

\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,node distance=4cm]
\node[state]  [ inner sep = 0.7 cm ]        (0) {};
\node[state]  [label={[label distance=.2cm]75:Recombination},left of= 0, inner sep = 0.7 cm ]            (1) {};
\node[state]  [label={[label distance=.2cm]75:Coalescense},left of= 1, inner sep = 0.7 cm ]              (2) {};
\node[state] (b) [label={[label distance=.2cm]270:\textit{Left tree taller}},below of = 0, left of = 1  , node distance=4 cm ]  {$x_t > x_{t-1}$};
\node[state] (c) [label={[label distance=.2cm]90:\textit{Right tree taller}},above of = 0, left of = 1 , node distance= 4 cm ] {$x_t < x_{t-1}$};
\node[state] (a) [label={[label distance=.2cm]270:\textit{Same tree height}},right  of = 2, right of = 1, node distance= 4  cm ]{$x_t = x_{t-1}$};
  \node (s0) [below=0 em of 0] {\textbf{State 0}};
  \node (s1) [below=0 em of 1] {\textbf{State 1}};
  \node (s2) [below=0 em of 2] {\textbf{State 2}};
\draw  
    (1) edge    node[above = .02 cm] {$\eta$}   (2)
    (0) edge    node[above = .02 cm] {$\rho$}   (1)
    (2) edge[dashed]  (b)
    (2) edge[dashed] (c)
    (0) edge[dashed] (a);

\path (0) +(0, .4) pic { adn={black and black style solid} };
\path (0) +(0,-.4) pic { adn={black and black style solid} };

\path (1) +(0, .4) pic { adn={black and white style dotted} };
\path (1) +(0,-.4) pic { adn={black and black style solid} };

\path (2) +(0, .4) pic { adn={black and black style solid} };
\path (2) +(0,-.4) pic { adn={black and black style solid} };
\end{tikzpicture}

\end{document}

相关内容