答案1
这是一个使用 DNA 序列的版本,将其分成碱基并进行补充,每个都存储在expl3
-\seq
变量中。
显示是通过TikZ
和构建节点完成的,稍后添加5'
和结束标记。3'
\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}
答案2
由于底部由顶部决定,因此指定其中一个即可。我选择了顶部。
\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}
这个想法很简单:映射序列,为每个项目建立一个表格。效率不高,但很有效。
允许在顶行使用前缀和后缀的版本:
\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}