<p>NCBI's FASTA format description:</p>
<p><a href="https://www.ncbi.nlm.nih.gov/genbank/fastaformat/" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/genbank/fastaformat/</a></p>
<p>NCBI's BLAST page describing valid FASTA input:</p>
<p><a href="https://blast.ncbi.nlm.nih.gov/Blast.cgi?CMD=Web&amp;PAGE_TYPE=BlastDocs&amp;DOC_TYPE=BlastHelp" rel="nofollow noreferrer">https://blast.ncbi.nlm.nih.gov/Blast.cgi?CMD=Web&amp;PAGE_TYPE=BlastDocs&amp;DOC_TYPE=BlastHelp</a></p>
<p>NCBI's SNP page describing FASTA format:</p>
<p><a href="https://www.ncbi.nlm.nih.gov/projects/SNP/snp_legend.cgi?legend=fasta" rel="nofollow noreferrer">https://www.ncbi.nlm.nih.gov/projects/SNP/snp_legend.cgi?legend=fasta</a></p>
<p>UniProt's FASTA-header description:</p>
<p><a href="https://www.uniprot.org/help/fasta-headers" rel="nofollow noreferrer">https://www.uniprot.org/help/fasta-headers</a></p>
<p>Wikipedia reference (indicating format origin):</p>
<p><a href="https://en.wikipedia.org/wiki/FASTA_format" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/FASTA_format</a></p>
<p>FASTA program (origin of format, per Wikipedia):</p>
<p><a href="https://fasta.bioch.virginia.edu/wrp_fasta/fasta_guide.pdf" rel="nofollow noreferrer">https://fasta.bioch.virginia.edu/wrp_fasta/fasta_guide.pdf</a></p>
<p>Harvard <em>PolyPhen</em> page describing FASTA format:</p>
<p><a href="http://genetics.bwh.harvard.edu/pph/FASTA.html" rel="nofollow noreferrer">http://genetics.bwh.harvard.edu/pph/FASTA.html</a></p>
<p>FASTA file format (from Pacific Biosciences):</p>
<p><a href="https://pacbiofileformats.readthedocs.io/en/3.0/FASTA.html" rel="nofollow noreferrer">https://pacbiofileformats.readthedocs.io/en/3.0/FASTA.html</a></p>

CC BY-SA 4.0
2021-07-15T01:39:25.793Z
2021-07-15T01:57:47.940Z
2021-07-15T01:57:47.940Z
jubilatious1
<p>I am not aware of an official fasta format description. <strike>The only constraint that I know of is that there should not be any whitespace after <code>&gt;</code></strike>. Apart from that particular position, whitespaces are allowed in the header line.</p>
<p>So, regarding your particular example, both are valid fasta sequences. When in doubt, you can use <a href="https://biopython.org/wiki/SeqIO" rel="nofollow noreferrer"><code>SeqIO</code></a> from <code>Biopython</code>, if you can parse your file with the following code, it <strike> is</strike> should be a valid fasta file.</p>
<pre><code>from Bio import SeqIO

with open(&quot;example.fasta&quot;) as handle:
    for record in SeqIO.parse(handle, &quot;fasta&quot;):
        print(record.id)
</code></pre>
<p>Edit per @Chris_Rands' comment</p>
<p>The code below does the same as above, meaning that <code>SeqIO.parse()</code> takes care of opening and closing the file.</p>
<pre><code>from Bio import SeqIO

for record in SeqIO.parse(&quot;example.fasta&quot;, &quot;fasta&quot;):
    print(record.id)
</code></pre>

CC BY-SA 4.0
2021-07-09T17:17:35.977Z
For such a simple format, that's actually quite a few odd edge cases with FASTA (e.g. see https://bioinformatics.stackexchange.com/questions/388/are-there-any-databases-of-templates-for-common-bioinformatic-file-formats). There's nothing official about Biopython's definition of FASTA (and it's subject to change, e.g. https://github.com/biopython/biopython/issues/1814 ) but I agree it's a practical solution
Chris_Rands
CC BY-SA 4.0
2021-07-10T14:09:55.800Z
Just a note: anything following a space or tab on a `>` line is considered comments. Those texts are not part of sequence names.
user172818
CC BY-SA 4.0
2021-07-12T18:04:28.810Z
@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?
terdon
CC BY-SA 4.0
2021-07-12T18:20:48.467Z
@terdon, here is the link about the "no space after >" constraint: http://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
CC BY-SA 4.0
2021-07-12T18:25:06.487Z
@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: https://blast.ncbi.nlm.nih.gov/Blast.cgi?CMD=Web&PAGE_TYPE=BlastDocs&DOC_TYPE=BlastHelp. 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.
terdon
CC BY-SA 4.0
2021-07-12T21:30:47.867Z
@terdon This convention has been widely accepted by almost every mainstream tool for decades. Actually, section 2.2 in the fasta user guide gives an example of fasta: `>sequence_name1 and description`. I don't know if this example was in the earliest version of fasta, but anyway the original authors have accepted this convention, too. You can download sequences in fasta from NCBI or Ensembl and you will see they clearly put all sorts of auxiliary information after a space. Fastq has a paper which follows the same convention.
user172818
CC BY-SA 4.0
2021-07-12T21:38:21.893Z
@user172818 when you say "fasta user guide", do you mean the [original `fasta` tool](https://pubmed.ncbi.nlm.nih.gov/2983426/)? If that already had that convention, then that's a pretty strong argument indeed. As for being an accepted convention, absolutely, no question about that. I just know that I've seen all sorts of stuff in various fasta headers in the wild so I'm wary of saying that anything is standardized in the format.
terdon
CC BY-SA 4.0
2021-07-12T21:50:43.470Z
@terdon Yes, I was referring to this PDF from the fasta software website (section 2.2): https://fasta.bioch.virginia.edu/wrp_fasta/fasta_guide.pdf
user172818
CC BY-SA 4.0
2021-07-09T10:10:51.397Z
2021-07-12T18:32:49.510Z
2021-07-12T18:32:49.510Z
haci
<p>The following is a valid .fasta file content:</p>
<p><code>&gt;HSBGPG Human gene for bone gla protein (BGP) GGCAGATTCCCCCTAGACCCGCCCGCACCATGGTCAGGCATGCCCCTCCTCATCGCTGGGCACAGCCCAGAGGGT ATAAACAGTGCTGGAGGCTGGCGGGGCAGGCCAGCTGAGTCCTGAGCAGCAGCCCAGCGCAGCCACCGAGACACC ATGAG.</code></p>
<p>Is this also?</p>
<p><code>&gt;Arbirary_Name_iJustCameUP_with_and_other_local_identifiers GGCAGATTCCCCCTAGACCCGCCCGCACCATGGTCAGGCATGCCCCTCCTCATCGCTGGGCACAGCCCAGAGGGT ATAAACAGTGCTGGAGGCTGGCGGGGCAGGCCAGCTGAGTCCTGAGCAGCAGCCCAGCGCAGCCACCGAGACACC ATGAG.</code></p>

<fasta>
Can the header line contain arbitrary text in FASTA format?
# Can the header line contain arbitrary text in FASTA format?

(Asked by: username_0 on 2021-07-09)

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.`

**Tags:** fasta

---

## 2 answers

### Answer by username_1 on 2021-07-15. Score: 2 | Accepted answer

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>

UniProt's FASTA-header description:

<https://www.uniprot.org/help/fasta-headers>

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):

<https://pacbiofileformats.readthedocs.io/en/3.0/FASTA.html>


---

### Answer by username_2 on 2021-07-09. Score: 4

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)

> **Comments:**
> **username_3**: For such a simple format, that's actually quite a few odd edge cases with FASTA (e.g. see https://bioinformatics.stackexchange.com/questions/388/are-there-any-databases-of-templates-for-common-bioinformatic-file-formats). There's nothing official about Biopython's definition of FASTA (and it's subject to change, e.g. https://github.com/biopython/biopython/issues/1814 ) but I agree it's a practical solution  
> **username_4**: Just a note: anything following a space or tab on a `>` line is considered comments. Those texts are not part of sequence names.  
> **username_5**: @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?  
> **username_2**: @terdon, here is the link about the "no space after >" constraint: http://genetics.bwh.harvard.edu/pph/FASTA.html . To be honest I did not try if common fasta parsers work with a space or not.  
> **username_5**: @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: https://blast.ncbi.nlm.nih.gov/Blast.cgi?CMD=Web&PAGE_TYPE=BlastDocs&DOC_TYPE=BlastHelp. 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.  
> **username_4**: @terdon This convention has been widely accepted by almost every mainstream tool for decades. Actually, section 2.2 in the fasta user guide gives an example of fasta: `>sequence_name1 and description`. I don't know if this example was in the earliest version of fasta, but anyway the original authors have accepted this convention, too. You can download sequences in fasta from NCBI or Ensembl and you will see they clearly put all sorts of auxiliary information after a space. Fastq has a paper which follows the same convention.  
> **username_5**: @user172818 when you say "fasta user guide", do you mean the [original `fasta` tool](https://pubmed.ncbi.nlm.nih.gov/2983426/)? If that already had that convention, then that's a pretty strong argument indeed. As for being an accepted convention, absolutely, no question about that. I just know that I've seen all sorts of stuff in various fasta headers in the wild so I'm wary of saying that anything is standardized in the format.  
> **username_4**: @terdon Yes, I was referring to this PDF from the fasta software website (section 2.2): https://fasta.bioch.virginia.edu/wrp_fasta/fasta_guide.pdf  

---

