0

How might I approach to create this in Latex? I am relatively new to Latex and haven't had experience with creation of any diagrams.

The numbers and texts themselves are arbitrary as long as there is room for them. I am also looking for the shaded 'stripchart' to have proper scaling e.g. the start of the green section (point 313) should be 313/1139 of the total width of the bar from the left. Note that these numbers should be able to be replaced by any set of numbers. The same idea applies for the arrowed rows. Total width would be textwidth.

enter image description here

2

Welcome to TeX.SX!

You could use TikZ to draw your diagram. I highly recommend reading the documentation of this package to understand how to use it. For example, you could start like this:

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

\newcounter{rowstart}
\newcounter{rowend}

\newcounter{sequencestart}
\newcounter{sequenceend}

\newcounter{matchrevstart}
\newcounter{matchrevend}

\newcounter{matchfwdstart}
\newcounter{matchfwdend}

\newcommand{\drawsequence}{%
\begin{tikzpicture}[x=.25mm, y=5cm, 
        row/.append style={black},
        sequence/.append style={row, fill=green},
    ]

\coordinate (rstart) at (\therowstart,0);
\coordinate (sstart) at (\thesequencestart,0);
\coordinate (send) at (\thesequenceend,0);
\coordinate (rend) at (\therowend,0);

\draw[row] ([yshift=5mm]rstart) rectangle coordinate[pos=.5] (xrleft) ([yshift=-5mm]sstart);
\draw[sequence] ([yshift=5mm]sstart) rectangle coordinate[pos=.5] (xsequence) ([yshift=-5mm]send);
\draw[row] ([yshift=5mm]send) rectangle coordinate[pos=.5] (xrright) ([yshift=-5mm]rend);

\node at ([yshift=7.5mm]rstart) {\therowstart};
\node at ([yshift=7.5mm]sstart) {\thesequencestart};
\node at ([yshift=7.5mm]send) {\thesequenceend};
\node at ([yshift=7.5mm]rend) {\therowend};

\node at (xrleft) {5' UTR};
\node at (xrright) {3' UTR};
\node at (xsequence) {Protein Coding Sequence};

\draw[dashed] ([yshift=-5mm]\thematchrevstart,0) -- ++(0,-.8);
\draw[dashed] ([yshift=-5mm]\thematchfwdend,0) -- ++(0,-.8);

\draw[->] (\thematchrevstart,-.25) node[above right] {\thematchrevstart} -- node[above, pos=.5] {\footnotesize Region of exact match, Reverse strand sequencing} (\thematchrevend,-.25) node[above left] {\thematchrevend};

\draw[<-] (\thematchfwdstart,-.5) node[above right] {\thematchfwdstart} -- node[above, pos=.5] {\footnotesize Region of exact match, Forward strand sequencing} (\thematchfwdend,-.5) node[above left] {\thematchfwdend};

\draw[<->] (\thematchrevstart,-.75) -- node[above, pos=.5] {\footnotesize Extent of cloned cDNA, excluding the polyA tail} (\thematchfwdend,-.75);

\end{tikzpicture}%
}

\begin{document}

\setcounter{rowstart}{1}
\setcounter{rowend}{1139}

\setcounter{sequencestart}{313}
\setcounter{sequenceend}{765}

\setcounter{matchrevstart}{213}
\setcounter{matchrevend}{1001}

\setcounter{matchfwdstart}{429}
\setcounter{matchfwdend}{1039}

\drawsequence

\end{document}

Resulting in the following:

enter image description here


However, you said, the result should be exactly as wide as the text. So, I made a few adjustments to the above code, so that the result always scales to text width. I had to increase the space of the arrows a bit, because the text would not fit.

\documentclass{article}
\usepackage{tikz}

\newcounter{rowstart}
\newcounter{rowend}

\newcounter{sequencestart}
\newcounter{sequenceend}

\newcounter{matchrevstart}
\newcounter{matchrevend}

\newcounter{matchfwdstart}
\newcounter{matchfwdend}

\newcommand{\drawsequence}{%
\noindent\begin{tikzpicture}[
        row/.append style={black},
        sequence/.append style={row, fill=green},
    ]

\coordinate (rstart) at ({\therowstart/\therowend*\textwidth},0);
\coordinate (sstart) at ({\thesequencestart/\therowend*\textwidth},0);
\coordinate (send) at ({\thesequenceend/\therowend*\textwidth},0);
\coordinate (rend) at ({\therowend/\therowend*\textwidth},0);

\coordinate (mrstart) at ({\thematchrevstart/\therowend*\textwidth},0);
\coordinate (mfstart) at ({\thematchfwdstart/\therowend*\textwidth},0);
\coordinate (mrend) at ({\thematchrevend/\therowend*\textwidth},0);
\coordinate (mfend) at ({\thematchfwdend/\therowend*\textwidth},0);

\draw[row] ([yshift=2.5mm]rstart) rectangle coordinate[pos=.5] (xrleft) ([yshift=-2.5mm]sstart);
\draw[sequence] ([yshift=2.5mm]sstart) rectangle coordinate[pos=.5] (xsequence) ([yshift=-2.5mm]send);
\draw[row] ([yshift=2.5mm]send) rectangle coordinate[pos=.5] (xrright) ([yshift=-2.5mm]rend);

\node[anchor=west] at ([yshift=5mm]rstart) {\therowstart};
\node at ([yshift=5mm]sstart) {\thesequencestart};
\node at ([yshift=5mm]send) {\thesequenceend};
\node[anchor=east] at ([yshift=5mm]rend) {\therowend};

\node at (xrleft) {5' UTR};
\node at (xrright) {3' UTR};
\node at (xsequence) {Protein Coding Sequence};

\draw[dashed] ([yshift=-2.5mm]mrstart) -- ([yshift=-36mm]mrstart);
\draw[dashed] ([yshift=-2.5mm]mfend) -- ([yshift=-36mm]mfend);

\draw[->] ([yshift=-15mm]mrstart) node[above right] {\thematchrevstart} -- node[above, pos=.5, text width=50mm, align=center] {\footnotesize Region of exact match, Reverse strand sequencing} ([yshift=-15mm]mrend) node[above left] {\thematchrevend};

\draw[<-] ([yshift=-25mm]mfstart) node[above right] {\thematchfwdstart} -- node[above, pos=.5, text width=50mm, align=center] {\footnotesize Region of exact match, Forward strand sequencing} ([yshift=-25mm]mfend) node[above left] {\thematchfwdend};

\draw[<->] ([yshift=-35mm]mrstart) -- node[above, pos=.5, text width=50mm, align=center] {\footnotesize Extent of cloned cDNA, excluding the polyA tail} ([yshift=-35mm]mfend);

\end{tikzpicture}%
}

\begin{document}

\setcounter{rowstart}{1}
\setcounter{rowend}{1139}

\setcounter{sequencestart}{313}
\setcounter{sequenceend}{765}

\setcounter{matchrevstart}{213}
\setcounter{matchrevend}{1001}

\setcounter{matchfwdstart}{429}
\setcounter{matchfwdend}{1039}

\drawsequence

\end{document}

Result:

enter image description here

| improve this answer | |
  • Thanks that's amazing! While you were making the update I put the commands after the \begin{document} in a figure environment to fit to textwidth: \begin{figure}\resizebox{\textwidth}{!}{\input{HERE}}\end{figure}. Your version is more appropriate but any ideas on how to make the words single-line (e.g. smaller; largest size enough to fit in one line)? – humbadambadam Apr 25 at 10:03
  • You could replace \footnotesize by \tiny, which is the smallest font size of LaTeX. If this is still not small enough, you can use \fontsize{<size>}{<baselineskip>}\selectfont. You still need to shift the arrows back up, of course. – Jasper Habicht Apr 25 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.