Can the header line contain arbitrary text in FASTA format?

The following is a valid .fasta file content:

>HSBGPG Human gene for bone gla protein (BGP) GGCAGATTCCCCCTAGACCCGCCCGCACCATGGTCAGGCATGCCCCTCCTCATCGCTGGGCACAGCCCAGAGGGT ATAAACAGTGCTGGAGGCTGGCGGGGCAGGCCAGCTGAGTCCTGAGCAGCAGCCCAGCGCAGCCACCGAGACACC ATGAG.

Is this also?

>Arbirary_Name_iJustCameUP_with_and_other_local_identifiers GGCAGATTCCCCCTAGACCCGCCCGCACCATGGTCAGGCATGCCCCTCCTCATCGCTGGGCACAGCCCAGAGGGT ATAAACAGTGCTGGAGGCTGGCGGGGCAGGCCAGCTGAGTCCTGAGCAGCAGCCCAGCGCAGCCACCGAGACACC ATGAG.

NCBI's FASTA format description:

https://www.ncbi.nlm.nih.gov/genbank/fastaformat/

NCBI's BLAST page describing valid FASTA input:

https://blast.ncbi.nlm.nih.gov/Blast.cgi?CMD=Web&PAGE_TYPE=BlastDocs&DOC_TYPE=BlastHelp

NCBI's SNP page describing FASTA format:

https://www.ncbi.nlm.nih.gov/projects/SNP/snp_legend.cgi?legend=fasta

Wikipedia reference (indicating format origin):

https://en.wikipedia.org/wiki/FASTA_format

FASTA program (origin of format, per Wikipedia):

https://fasta.bioch.virginia.edu/wrp_fasta/fasta_guide.pdf

Harvard PolyPhen page describing FASTA format:

http://genetics.bwh.harvard.edu/pph/FASTA.html

FASTA file format (from Pacific Biosciences):

I am not aware of an official fasta format description. The only constraint that I know of is that there should not be any whitespace after >. Apart from that particular position, whitespaces are allowed in the header line.

So, regarding your particular example, both are valid fasta sequences. When in doubt, you can use SeqIO from Biopython, if you can parse your file with the following code, it is should be a valid fasta file.

from Bio import SeqIO

with open("example.fasta") as handle:
for record in SeqIO.parse(handle, "fasta"):
print(record.id)


Edit per @Chris_Rands' comment

The code below does the same as above, meaning that SeqIO.parse() takes care of opening and closing the file.

from Bio import SeqIO

for record in SeqIO.parse("example.fasta", "fasta"):
print(record.id)

• For such a simple format, that's actually quite a few odd edge cases with FASTA (e.g. see bioinformatics.stackexchange.com/questions/388/…). There's nothing official about Biopython's definition of FASTA (and it's subject to change, e.g. github.com/biopython/biopython/issues/1814 ) but I agree it's a practical solution Jul 9 at 17:17
• Just a note: anything following a space or tab on a > line is considered comments. Those texts are not part of sequence names. Jul 10 at 14:09
• @user172818 why are you saying that? Yes, some tools parse sequence names that way but not all, that's just a relatively common convention, but as far as I know there is no fasta standard. So what is considered a comment is down to the author of whatever tool you're using to parse the file. Is there some standard I don't know about? Jul 12 at 18:04
• @terdon, here is the link about the "no space after >" constraint: genetics.bwh.harvard.edu/pph/FASTA.html . To be honest I did not try if common fasta parsers work with a space or not.
– haci
Jul 12 at 18:20
• @haci yeah, that's just the format that PolyPhen requires, not a general characteristic of fasta which, since it isn't defined by any standard, doesn't really have any limitations at all. Here's another reputable source giving their own definition: blast.ncbi.nlm.nih.gov/…. I am racking my brain but I can't remember where I used to see sequences like > foo (with a space). Either it was many years ago or I imagined it, or both. I'm still convinced I remember it but the brain does play tricks so I won't press the point. Jul 12 at 18:25