# Display FASTA File in LaTeX

Is there a proper way to show a FASTA file in LaTeX?

So far I tried \$'s or listings and TeXshade but this does not seems to work.

-
What exactly is your issue with TeXshade? This is the standard solution for typesetting nucleotide sequences and alignments. “does not seem to work” isn’t a good error description; please be more specific. –  Konrad Rudolph Oct 6 '11 at 12:23
Its gives alignments as far as I can tell. I just want to show an example of a FASTA file. Thus a proper.. >header ATGCAGCAG and sequence. This I could not find with TeXsha –  Jasper Oct 6 '11 at 12:58
Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. Also, please add information to your question by editing it instead of posting additional information as an answer. –  N.N. Oct 6 '11 at 13:34
Please register your accounts here and on stackoverflow.com, so that they can be connected and you receive ownership of the question again. Then you will be able to update it to provide more information as well as accept the best answer. Thanks. –  Martin Scharrer Oct 6 '11 at 22:38

## migrated from stackoverflow.comOct 6 '11 at 12:41

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

Proper alignment using listings is possible by setting the font to typewriter (basicstyle=\ttfamily as optional parameter, or by using \lstset):

\documentclass{article}
\usepackage{filecontents}% http://ctan.org/pkg/filecontents
\usepackage{listings}% http://ctan.org/pkg/listings
​\begin{document}

% Taken from http://en.wikipedia.org/wiki/FASTA_format#Format
\begin{filecontents*}{fasta.txt}
>gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus]
LCLYTHIGRNIYYGSYLYSETWNTGIMLLLITMATAFMGYVLPWGQMSFWGATVITNLFSAIPYIGTNLV
EWIWGGFSVDKATLNRFFAFHFILPFTMVALAGVHLTFLHETGSNNPLGLTSDSDKIPFHPYYTIKDFLG
GLMPFLHTSKHRSMMLRPLSQALFWTLTMDLLTLTWIGSQPVEYPYTIIGQMASILYFSIILAFLPIAGX
IENY
\end{filecontents*}

\lstinputlisting[basicstyle=\ttfamily]{fasta.txt}
\end{document}


If you want to remove the header from the file, specify firstline=2 or however many lines your header takes up. If you only want to include certain parts of the file, use linerange={<first>-<last>}, where <first> and <last> are also included in the output.

In the above example, the filecontents package supplies the means to write contents to an external file directly, at compile time, for inclusion in the listing. This keeps the document self-contained and portable, much like the .dtx package distribution.

-