1
$\begingroup$

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.

$\endgroup$
0

2 Answers 2

2
$\begingroup$

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

$\endgroup$
4
$\begingroup$

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)
$\endgroup$
8
  • 1
    $\begingroup$ 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 $\endgroup$ Commented Jul 9, 2021 at 17:17
  • 3
    $\begingroup$ Just a note: anything following a space or tab on a > line is considered comments. Those texts are not part of sequence names. $\endgroup$
    – user172818
    Commented Jul 10, 2021 at 14:09
  • $\begingroup$ @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? $\endgroup$
    – terdon
    Commented Jul 12, 2021 at 18:04
  • $\begingroup$ @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. $\endgroup$
    – haci
    Commented Jul 12, 2021 at 18:20
  • 1
    $\begingroup$ @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. $\endgroup$
    – terdon
    Commented Jul 12, 2021 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.