FASTA cleaner

Fixes sequences, headers and line width in a messy FASTA. Paste it or choose a file; nothing is uploaded.

Cleaned FASTA

What does a FASTA cleaner fix?

Sequences copied from GenBank, a paper, a spreadsheet or an email are rarely valid FASTA. They carry position numbers, spaces, mixed case, stray symbols, long descriptive headers and sometimes two records with the same name. Alignment programs, BLAST database builders and tree builders then stop with an error, or worse, read the file wrongly without saying so. This tool repairs the file in the browser and tells you exactly what it changed.

  • Sequence lines: digits, spaces and line breaks are removed. Characters that are not valid codes for the sequence type are removed or replaced with N (nucleotides) orX (protein). A question mark counts as an unknown position.
  • Headers: kept, cut to the ID, made safe for strict programs, or renamed in order. Repeated names get a suffix (_2, _3) so every record is unique.
  • Records: empty records, or records shorter than a length you set, are dropped. Old-style comment lines starting with a semicolon are dropped too.
  • Layout: every sequence is rewrapped to one line width, 60 by default, or written on a single line with 0.

Worked example

"Try an example" loads four records: a GenBank-numbered contig in lower case, a second record with the same name, a fragment with gaps, a stray @@ and two ?, and a failed read that is only question marks. With the default settings the numbers and spaces go, @@ and the question marks are removed, the second contig_1 becomes contig_1_2, and the failed read is dropped because nothing is left of it. The result is 3 records and213 nt (gap characters included). Switch "Invalid characters" to "Replace" and the question marks become N instead, so the failed read survives as eight N.

Valid FASTA characters

TypeAccepted lettersReplacement
DNA or RNAA C G T U R Y S W K M B D H V NN
ProteinA C D E F G H I K L M N P Q R S T V W Y B Z X J U O *X
Both- and . as gapskept unless removed

With "Detect", a file is read as DNA or RNA when at least 90% of its letters are A, C, G, T, U or N, and as protein otherwise. Set the type yourself for short or unusual sequences.

FASTA header rules that avoid errors

The header is the line that starts with >. Most programs take the text up to the first space as the sequence ID and ignore the rest, so two records that differ only after the space look identical to them. Characters with a meaning in other formats cause trouble as well: parentheses, commas, colons and semicolons in Newick trees, pipes in NCBI-style IDs, and anything beyond 10 characters in strict PHYLIP.

  • ID only keeps the first word: >NM_000518.5 Homo sapiens HBB becomes >NM_000518.5.
  • Spaces to _ keeps the whole description as one word.
  • Safe characters keeps letters, digits, dot, hyphen and underscore, and turns everything else into an underscore.
  • Rename in order writes seq_1, seq_2 and so on with a prefix you choose. A sequence pasted without a header gets one this way.

After cleaning

Identical sequences are reported but not removed; theFASTA deduplicator does that. To join records into one sequence use Combine FASTA, and for numbered or grouped output for a figure use the sequence formatter.

Frequently asked questions

How do I clean a FASTA file?

Paste the file or choose it from your device. Position numbers, spaces and line breaks inside the sequences are removed, characters that are not valid DNA, RNA or protein codes are removed or replaced with N or X, headers can be shortened or made safe, and the result is rewrapped to the line width you set. Copy it or download it as a .fasta file.

Which characters are valid in a FASTA sequence?

For DNA and RNA the IUPAC nucleotide codes: A, C, G, T, U and the ambiguity codes R, Y, S, W, K, M, B, D, H, V, N. For protein the 20 amino acid letters plus B, Z, X, J, U, O and * for a stop. A gap is written as - or a dot. Digits, spaces and other symbols are not part of the sequence.

Why do programs reject my FASTA headers?

Many tools read only the first word of the header as the sequence ID, and some fail on spaces, pipes, brackets, colons, commas or semicolons, which have a meaning in Newick trees and PHYLIP files. Two records with the same ID are another common cause. Use "ID only" or "Safe characters", and turn on "Make names unique".

Should invalid characters be removed or replaced with N?

Replace them when positions matter, for example in an alignment or when coordinates refer to the sequence, because removing a character shifts everything after it. Remove them when the character is clearly junk, such as a stray symbol from copy and paste.

How large a FASTA file can it clean?

Files up to 50 MB work. The file is read and cleaned by the browser on your device, so the limit is the memory of the tab rather than an upload quota. For larger files use a command-line tool such as seqkit.