Hinzufügen einer vertikalen Linie zwischen Buchstaben in verschiedenen Reihen. DNA-Sequenzbasen

Hinzufügen einer vertikalen Linie zwischen Buchstaben in verschiedenen Reihen. DNA-Sequenzbasen

Weiß jemand, wie man die folgende DNA-Duplexsequenz in LaTeX setzt?

Ich möchte eine vertikale Linie zwischen den Basen (Buchstaben) hinzufügen, wie in diesem Bild.

Danke

DNA-Duplex

Hier ist das andere Beispiel:

DNA-Duplex mit Modifikatoren

Antwort1

Hier ist eine Version, die die DNA-Sequenz verwendet, sie in die Basen aufspaltet und ebenfalls die Ergänzung durchführt, jeweils gespeichert in einer expl3-Variable \seq.

Die Anzeige erfolgt über TikZdie Aufbauknoten 5'und die 3'Endmarkierungen, die später hinzugefügt werden.

\documentclass{article}

\usepackage{xparse}
\usepackage{tikz}
\usetikzlibrary{calc}

\ExplSyntaxOn
\cs_generate_variant:Nn \tl_item:Nn {Nx}

\seq_new:N \l_jpaul_dna_seq
\seq_new:N \l_jpaul_complement_seq

\cs_new:Npn \splitdnaseq #1 {%
  \seq_set_split:Nnn \l_jpaul_dna_seq {} {#1}
  \tl_set:Nn \l_tmpa_tl {#1}
  % Building DNA complement strand
  \tl_replace_all:Nnn \l_tmpa_tl {A} {Q}
  \tl_replace_all:Nnn \l_tmpa_tl {T} {A}
  \tl_replace_all:Nnn \l_tmpa_tl {Q} {T}
  \tl_replace_all:Nnn \l_tmpa_tl {C} {Q}
  \tl_replace_all:Nnn \l_tmpa_tl {G} {C}
  \tl_replace_all:Nnn \l_tmpa_tl {Q} {G}
  % Splitting again and storing to the complement seq
  \seq_set_split:NnV \l_jpaul_complement_seq {} {\l_tmpa_tl}
}

\cs_new:Npn \lengthdna {
  \seq_count:N \l_jpaul_dna_seq
}

\cs_new:Npn \dnaitem #1 {%
  \seq_item:Nn \l_jpaul_dna_seq {#1}
}

\cs_new:Npn \complementitem #1 {%
  \seq_item:Nn \l_jpaul_complement_seq {#1}
}
\ExplSyntaxOff

\NewDocumentCommand{\displaydnaseq}{O{0.2}+m}{%
  \begingroup
  \def\factor{#1}
  \splitdnaseq{#2}
  \begin{tikzpicture}
    \node[red] (5primeleft) at (-\factor,0) {$5'$};
    \foreach \x in {1,...,\lengthdna} {%
      \node[font=\ttfamily,red] (base\x) at (\factor*\x,0)       {\dnaitem{\x}};
      \node[font=\ttfamily,blue] (compbase\x) at (\factor*\x,-1) {\complementitem{\x}};
      \draw[line width=0.7pt] (base\x) -- (compbase\x);
    }
    \node[font=\bfseries,outer sep=0pt,inner sep=0pt,red,right] (3primeright) at ($(base\lengthdna) + (\factor,0)$) {$3'$};
    \node[blue] (3primeleft) at (-\factor,-1) {$3'$};
    \node[font=\bfseries,outer sep=0pt,inner sep=0pt,blue,right] (5primeright) at ($(compbase\lengthdna) + (\factor,0)$) {$5'$};
  \end{tikzpicture}
  \endgroup
}


\begin{document}
\displaydnaseq{TGAATCATTAGCATAG}
\end{document}

Bildbeschreibung hier eingeben

Antwort2

Da die Unterseite durch die Oberseite bestimmt wird, reicht es aus, einen davon anzugeben. Ich habe die Oberseite gewählt.

\documentclass{article}

\usepackage{xparse}
\usepackage{xcolor,booktabs}

\ExplSyntaxOn
\NewDocumentCommand{\duplexsequence}{mmm}
 {
  \mbox
   {
    \renewcommand{\arraystretch}{0}
    \jpaul_ds_duplexsequence:nnn { #1 } { #2 } { #3 }
   }
 }

\cs_new_protected:Nn \jpaul_ds_duplexsequence:nnn
 {
  \jpaul_ds_lr:nn { #1 } { #2 }
  \hspace{1em}
  \tl_map_function:nN { #3 } \jpaul_ds_pair:n
  \hspace{1em}
  \jpaul_ds_lr:nn { #2 } { #1 }
 }

\cs_new_protected:Nn \jpaul_ds_pair:n
 {
  \begin{tabular}{@{}c@{}}
  \jpaul_ds_top:n { #1 } \\\addlinespace[.6ex]
  $|$ \\\addlinespace[.6ex]
  \jpaul_ds_bottom:n { #1 }
  \end{tabular}
 }

\cs_new_protected:Nn \jpaul_ds_top:n
 {
  \textcolor{top}{#1}
 }
\cs_new_protected:Nn \jpaul_ds_bottom:n
 {
  \textcolor{bottom}
   {
    \str_case:nn { #1 }
     {
      {T}{A}
      {A}{T}
      {C}{G}
      {G}{C}
     }
   }
 }

\cs_new_protected:Nn \jpaul_ds_lr:nn
 {
  \begin{tabular}{@{}c@{}}
  \smash{\textcolor{top}{#1}}\vphantom{T}\\\addlinespace[.6ex]
  \phantom{$|$}\\\addlinespace[.6ex]
  \smash{\textcolor{bottom}{#2}}\vphantom{T}
  \end{tabular}
 }
\ExplSyntaxOff

\definecolor{top}{RGB}{199,17,34}
\definecolor{bottom}{RGB}{0,39,160}

\begin{document}

\duplexsequence{5$'$}{3$'$}{TGAATCATTAGCATAG}

\end{document}

Die Idee ist einfach: Bilden Sie die Reihenfolge ab und erstellen Sie für jedes Element eine Tabelle. Nicht sehr effizient, aber effektiv.

Bildbeschreibung hier eingeben

Eine Version, die Präfix und Postfix in der obersten Zeile zulässt:

\documentclass{article}

\usepackage{xparse}
\usepackage{xcolor,booktabs}

\ExplSyntaxOn
\NewDocumentCommand{\duplexsequence}{mO{}mO{}m}
 {
  \mbox
   {
    \renewcommand{\arraystretch}{0}
    \jpaul_ds_duplexsequence:nnnnn { #1 } { #2 } { #3 } { #4 } { #5 }
   }
 }

\cs_new_protected:Nn \jpaul_ds_duplexsequence:nnnnn
 {% #1 is the number on the left
  % #2 is the optional prefix
  % #3 is the number on the right
  % #4 is the optional postfix
  % #5 is the top sequence
  \jpaul_ds_left:nnn { #1 } { #2 } { #3 }
  \tl_map_function:nN { #5 } \jpaul_ds_pair:n
  \jpaul_ds_right:nnn { #3 } { #4 } { #1 }
 }

\cs_new_protected:Nn \jpaul_ds_pair:n
 {
  \begin{tabular}{@{}c@{}}
  \jpaul_ds_top:n { #1 } \\\addlinespace[.6ex]
  $|$ \\\addlinespace[.6ex]
  \jpaul_ds_bottom:n { #1 }
  \end{tabular}
 }

\cs_new_protected:Nn \jpaul_ds_top:n
 {
  \textcolor{top}{#1}
 }
\cs_new_protected:Nn \jpaul_ds_bottom:n
 {
  \textcolor{bottom}
   {
    \str_case:nn { #1 }
     {
      {T}{A}
      {A}{T}
      {C}{G}
      {G}{C}
     }
   }
 }

\cs_new_protected:Nn \jpaul_ds_left:nnn
 {
  \begin{tabular}{@{}r@{}}
  \smash{\textcolor{top}{#1\quad#2}}\vphantom{T}\\\addlinespace[.6ex]
  \phantom{$|$}\\\addlinespace[.6ex]
  \smash{\textcolor{bottom}{#3\quad}}\vphantom{T}
  \end{tabular}
 }
\cs_new_protected:Nn \jpaul_ds_right:nnn
 {
  \begin{tabular}{@{}l@{}}
  \smash{\textcolor{top}{#2\quad#1}}\vphantom{T}\\\addlinespace[.6ex]
  \phantom{$|$}\\\addlinespace[.6ex]
  \smash{\textcolor{bottom}{\quad#3}}\vphantom{T}
  \end{tabular}
 }
\ExplSyntaxOff

\definecolor{top}{RGB}{199,17,34}
\definecolor{bottom}{RGB}{0,39,160}

\begin{document}

\duplexsequence{5$'$}{3$'$}{TGAATCATTAGCATAG}

\bigskip

\duplexsequence{5$'$}[SH-(sp18)-]{3$'$}{TGAATCATTAGCATAG}

\bigskip

\duplexsequence{5$'$}{3$'$}[-(sp18)-SH]{TGAATCATTAGCATAG}

\bigskip

\duplexsequence{5$'$}[SH-(sp18)-]{3$'$}[-(sp18)-SH]{TGAATCATTAGCATAG}

\end{document}

Bildbeschreibung hier eingeben

verwandte Informationen