FASTA is the simplest common sequence format: a header line starting with > followed by sequence lines. Its simplicity is why it is used everywhere, and why small formatting mistakes break pipelines.
The basic rules
A FASTA record has a header and a sequence. The header starts with > and usually contains an identifier and a description. The sequence follows on one or more lines. Records are separated by the next >.
Most parsers accept uppercase and lowercase letters, N for unknown bases and gaps in aligned FASTA. They differ on blank lines, spaces inside sequence, digits, comment lines and duplicate identifiers.
The identifier trap
Many tools use the first word after > as the identifier and ignore the rest. Others use the whole line. If your header is >sample1 condition=control, one tool may call the sequence sample1 and another may call it sample1 condition=control.
This matters when joining a FASTA with a sample sheet or a tree. The identifiers must match exactly. A common failure is a tree tip named sample1 and a FASTA record named sample1_trimmed, which look similar to a person and different to a program.
Decide on an identifier convention and keep it across files. Avoid spaces, parentheses, commas and semicolons in identifiers unless the tool documents support.
Line length and wrapping
Sequence can be on one line or wrapped at a fixed width. Both are valid. A parser should not care. A person reading the file may care, and some older tools assume a particular width.
Do not mix wrapped and unwrapped records in a way that confuses a simple script. If you generate FASTA, choose one width and use it consistently. If you edit by hand, check that you did not introduce a line break inside a codon.
Case and ambiguity
Lowercase is often used to mark soft-masked repeats. Uppercase is used for primary sequence. A tool that converts everything to uppercase loses that information. A tool that treats lowercase as invalid rejects a valid file.
N means an unknown base. - is a gap in an alignment and is not a base. Mixing - into an unaligned sequence can break translation and alignment. U appears in RNA; many DNA tools do not accept it.
Duplicate identifiers
Duplicate headers are legal in the format but dangerous in practice. A dictionary keyed by identifier will keep one record and silently drop the other. A tree with duplicate tips is ambiguous. A variant annotation with duplicate transcripts is confusing.
Before analysis, check for duplicates and decide whether they are intentional isoforms, repeated regions or a merge accident.
Encoding and line endings
FASTA is text. Use UTF-8 or plain ASCII and Unix line endings. Windows line endings usually work, but a stray carriage return can end up in an identifier and cause a mismatch that is hard to see.
Avoid a byte-order mark at the start of the file. Some parsers treat it as part of the first header. If a file starts with a strange character before >, inspect the raw bytes.
Validation before use
A short validation step saves time:
- Every record starts with
>. - Every identifier is unique or intentionally repeated.
- The sequence contains only allowed characters.
- The length matches the expected value.
- The file ends with a newline.
- The checksum matches the source.
For a reference genome, also check chromosome names and lengths. For a protein file, check for stop codons and unexpected characters.
A minimal validation script
A short script can catch most problems without a dependency. Read the file line by line; require a header before any sequence; collect identifiers in a set; reject duplicate identifiers unless a flag allows them; check that every sequence character is in an allowed alphabet; and print the number of records, the minimum and maximum length and the first identifier.
Run the same script on the reference and on every query file. A mismatch in the first identifier is often the first sign of a naming problem that would otherwise appear much later as an empty result.
Identifiers and database lookups
A FASTA identifier is the key that links a sequence to a database entry. The first token after > is usually the identifier; the rest is a description. Some tools use the whole header, which breaks the lookup when the description changes.
If the file is used for a database search, check whether the identifiers match the expected format. An accession with a version suffix may or may not match the database. A description that contains a pipe or a space can confuse a parser. Keep a copy of the identifier mapping if you rename anything for a pipeline. A mapping table is also useful when a sequence is re-annotated and the accession version changes. If a database lookup returns an unexpected entry, compare the identifier carefully before assuming the sequence is wrong.
Key points
- The first word of the header is often the identifier.
- Keep identifiers identical across FASTA, sample sheets and trees.
- Case can carry meaning; do not normalise blindly.
Nis unknown,-is a gap,Uis RNA.- Validate before analysis.
Common mistakes
- Adding a description to a header and breaking an exact match.
- Using spaces in identifiers.
- Mixing DNA, RNA and protein alphabets.
- Duplicating identifiers and losing a record.
- Editing a file and leaving a stray character.
When to ask for help
If a tool rejects a FASTA file that looks correct, if an identifier does not match a sample sheet, or if a translated sequence has unexpected stops, ask before editing the file by hand. You can order an analysis or read the sequence alignment guide. The free FASTA validator checks common problems, and the Sequence Analysis studio handles translation and alignment.
Sources and further reading
Written by the Solagene team for research and education. Found an error? Tell us and we will correct it.