16

I have to include relatively small genomic sequences in a Latex document (still, they are words of around 600-900 As Ts Gs and Cs) but I cannot find a way to force line wrapping after a certain number of characters.

I saw a massive amount of similar topics on the matter, most of them citing listings and discretionaries, but all of the suggested solutions rely on either the small size of the long words to manually add "invisible breakpoints", or the fact that within the words, some special characters (dots, underscores) or patterns, can be defined as breakable areas.

Unfortunately, the sequences I work on are too long to edit manually, and there's no special pattern that can be used within a discretionary, and none of these solutions would help if I want to stick to the standard 50 bases per line.

I'm really at loss of ideas, so if you would have any lead, please share!

Here is an example of sequence that I need to include:

CTCCTTGGGCTGTTATTCCGTAAAAGTATTTGTGGAAGATACGGCTGTCATACATGATATGTTTTTTGTTTATAACAATAGTTCTTTCTTTGATTTCACCATAGGTTGCCTCAAATTGCTCTTTTGTTGCTTGTCCAGCTGTTAAGACTAAATGTTTTGACCCCTCATTTATAAGACCGATTGCGTTGAATGGTAAGACATTCTGTTGTGCTGATTGTAATTCTGAATAGCTACGGATTTTTATGAAGATATAGTTTTTTAATATTGGTATTTCATTCCAGACATACTTCTGTATAAAGGATTTATTAAACGGTGTTGTTTTGATTGCTCTATAATACTTATCTTGTTGTCCTCTTAATTTTACCCAAGGTCTTTCAAACTCTTGGGAGTTAATGATTATAAGCATATTGTAAAGCTGTCCAGCTAATCCGAAGAATACTGGAAGCCAGTGGGTAAAGCTTGTCTGTTTTGGTAAAGCTGTTTGAACGTCTGACAAGAACAAGTCCAGACCTTCATATTTGTGGATTTTTTGAAACTTCATATTTTGATATGAACCGTCTACAATATCACTATATTTTACTGGTTGCCCAGTTTTTTGATTAATGTATCCAGGTCTTTAATATCTACTACTAAAACCACCGTAACCATAGTCCACGTTAGAGATATAGAGAGGTTTCGCATAAATGTGAACCCAGATTGCTTGTTGTTGTCTTTCATAACTCATTTGAAGACCAGTTTTAATGCGTTCTTTAATTGCTTGATACGTT

migrated from stackoverflow.com May 28 '13 at 0:01

This question came from our site for professional and enthusiast programmers.

  • I don't see this as a duplicate. The questioner explicitly asking for breaking after a specific number of characters, not after a specific length, which is the issue in the linked question. – Andrew Swann May 28 '13 at 8:49
13

The seqsplit package will break up such expressions, by adding suitable break points. It is designed exactly for these types of DNA sequences, and copes in a sophisticated way with various forms of input. However, you wish to break your material after a specific number of characters instead. This can be achieved with the commands provided by the xstring package, via its splitting command \StrSplit:

Sample output

\documentclass{article}

\usepackage{xstring,etoolbox}

\newcommand{\fixsplit}[2]{\StrLen{#2}[\mynum]\ifnumcomp{\mynum}{<}{\numexpr(#1)+1\relax}%
  {#2}%
  {\StrSplit{#2}{#1}{\myfirststr}{\mysecondstr}\myfirststr\linebreak
  \fixsplit{#1}{\mysecondstr}}}

\begin{document}


\begin{quote}
  \ttfamily
  \fixsplit{30}{CTCCTTGGGCTGTTATTCCGTAAAAGTATTTGTGGAAGATACGGCTGTCATACATGATATGTTTTTTGTTTATAACAATAGTTCTTTCTTTGATTTCACCATAGGTTGCCTCAAATTGCTCTTTTGTTGCTTGTCCAGCTGTTAAGACTAAATGTTTTGACCCCTCATTTATAAGACCGATTGCGTTGAATGGTAAGACATTCTGTTGTGCTGATTGTAATTCTGAATAGCTACGGATTTTTATGAAGATATAGTTTTTTAATATTGGTATTTCATTCCAGACATACTTCTGTATAAAGGATTTATTAAACGGTGTTGTTTTGATTGCTCTATAATACTTATCTTGTTGTCCTCTTAATTTTACCCAAGGTCTTTCAAACTCTTGGGAGTTAATGATTATAAGCATATTGTAAAGCTGTCCAGCTAATCCGAAGAATACTGGAAGCCAGTGGGTAAAGCTTGTCTGTTTTGGTAAAGCTGTTTGAACGTCTGACAAGAACAAGTCCAGACCTTCATATTTGTGGATTTTTTGAAACTTCATATTTTGATATGAACCGTCTACAATATCACTATATTTTACTGGTTGCCCAGTTTTTTGATTAATGTATCCAGGTCTTTAATATCTACTACTAAAACCACCGTAACCATAGTCCACGTTAGAGATATAGAGAGGTTTCGCATAAATGTGAACCCAGATTGCTTGTTGTTGTCTTTCATAACTCATTTGAAGACCAGTTTTAATGCGTTCTTTAATTGCTTGATACGTT}
\end{quote}

\end{document}

Note that I have chosen to print the result with a fixed width font, otherwise you get a rather strange effect. Also note that the way xstring works, results of operations usually have to be stored in a macro, rather than being used directly.

  • This is exactly what I was looking for, thanks a lot! How I managed to miss that is beyond me. I should have guessed formatting biological sequences (not just general text) was already implemented somewhere. The cool thing is, the package is in the Fedora repositories, and most likely in for other linux distros as well. I also found the dnaseq package which sounds pretty cool, with more features than splitseq. – Nisaea May 28 '13 at 9:02
3

Can you please try this one:

\documentclass{article}
\begin{document}
\parindent=0pt
\ttfamily

\makeatletter
\def\xfoo#1#2{\@tempcnta=0%
  \@tfor\xx:=#2\do{\advance\@tempcnta 1%
    \xx\ifnum\the\@tempcnta=#1\newline\@tempcnta=0\fi%
  }%
}

\xfoo{10}{CTCCTTGGGCTGTTATTCCGTAAAAGTATTTGTGGAAGATACGGCTGTCATACATGATATGTTTTTTGTTTATAACAATAGTTCTTTCTTTGATTTCACCATAGGTTGCCTCAAATTGCTCTTTTGTTGCTTGTCCAGCTGTTAAGACTAAATGTTTTGACCCCTCATTTATAAGACCGATTGCGTTGAATGGTAAGACATTCTGTTGTGCTGATTGTAATTCTGAATAGCTACGGATTTTTATGAAGATATAGTTTTTTAATATTGGTATTTCATTCCAGACATACTTCTGTATAAAGGATTTATTAAACGGTGTTGTTTTGATTGCTCTATAATACTTATCTTGTTGTCCTCTTAATTTTACCCAAGGTCTTTCAAACTCTTGGGAGTTAATGATTATAAGCATATTGTAAAGCTGTCCAGCTAATCCGAAGAATACTGGAAGCCAGTGGGTAAAGCTTGTCTGTTTTGGTAAAGCTGTTTGAACGTCTGACAAGAACAAGTCCAGACCTTCATATTTGTGGATTTTTTGAAACTTCATATTTTGATATGAACCGTCTACAATATCACTATATTTTACTGGTTGCCCAGTTTTTTGATTAATGTATCCAGGTCTTTAATATCTACTACTAAAACCACCGTAACCATAGTCCACGTTAGAGATATAGAGAGGTTTCGCATAAATGTGAACCCAGATTGCTTGTTGTTGTCTTTCATAACTCATTTGAAGACCAGTTTTAATGCGTTCTTTAATTGCTTGATACGTT}
\end{document}
2

If you can change and replace selected text with your editor, then replace C by C\brk{}, G by G\brk{}, A by A\brk{} and T by T\brk{}in your long strings. If you don't want to have text disappearing out of view, use a % at linebreaks

\documentclass{article}

\newcommand*{\brk}{\discretionary{}{}{}\hfil}
\begin{document}

\noindent C\brk{}T\brk{}C\brk{}C\brk{}T\brk{}T\brk{}G\brk{}G\brk{}G\brk{}C\brk{}T\brk{}G\brk{}T\brk{}T\brk{}A\brk{}T\brk{}T\brk{}C\brk{}C\brk{}G\brk{}T\brk{}A\brk{}A\brk{}A\brk{}A\brk{}G\brk{}T\brk{}A\brk{}T\brk{}T\brk{}T\brk{}G\brk{}T\brk{}G\brk{}G\brk{}A\brk{}A\brk{}G\brk{}A\brk{}T\brk{}A\brk{}C\brk{}G\brk{}G\brk{}C\brk{}T\brk{}G\brk{}T\brk{}C\brk{}A\brk{}T\brk{}A\brk{}C\brk{}A\brk{}T\brk{}G\brk{}A\brk{}T\brk{}A\brk{}T\brk{}G\brk{}T\brk{}T\brk{}T\brk{}T\brk{}T\brk{}T\brk{}G\brk{}T\brk{}T\brk{}T\brk{}A\brk{}T\brk{}A\brk{}A\brk{}C\brk{}A\brk{}A\brk{}T\brk{}A\brk{}G\brk{}T\brk{}T\brk{}C\brk{}T\brk{}T\brk{}T\brk{}C\brk{}T\brk{}T\brk{}T\brk{}G\brk{}A\brk{}T\brk{}
\hfill\mbox{}

\medskip

\noindent 
C\brk{}T\brk{}C\brk{}C\brk{}T\brk{}T\brk{}G\brk{}G\brk{}G\brk{}C\brk{}%
T\brk{}G\brk{}T\brk{}T\brk{}A\brk{}T\brk{}T\brk{}C\brk{}C\brk{}G\brk{}%
T\brk{}A\brk{}A\brk{}A\brk{}A\brk{}G\brk{}T\brk{}A\brk{}T\brk{}T\brk{}%
T\brk{}G\brk{}T\brk{}G\brk{}G\brk{}A\brk{}A\brk{}G\brk{}A\brk{}T\brk{}%
A\brk{}C\brk{}G\brk{}G\brk{}C\brk{}T\brk{}G\brk{}T\brk{}C\brk{}A\brk{}%
T\brk{}A\brk{}C\brk{}A\brk{}T\brk{}G\brk{}A\brk{}T\brk{}A\brk{}T\brk{}%
G\brk{}T\brk{}T\brk{}T\brk{}T\brk{}T\brk{}T\brk{}G\brk{}T\brk{}T\brk{}%
T\brk{}A\brk{}T\brk{}A\brk{}A\brk{}C\brk{}A\brk{}A\brk{}T\brk{}A\brk{}%
G\brk{}T\brk{}T\brk{}C\brk{}T\brk{}T\brk{}T\brk{}C\brk{}T\brk{}T\brk{}%
T\brk{}G\brk{}A\brk{}T\brk{}
\hfill\mbox{}

\end{document}
  • That's not a bad idea in itself, but with a contig of 1kb, I would end up with a 7kchar string, which is, well... huge. I also wanted to avoid editing my sequences as much as possible, and find a "latexish" way of doing the job. But this is still a good solution for small isolated chunks if you don't have much to include. :) – Nisaea May 28 '13 at 9:07

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.