Bases: biotite.file.TextFile,

This class represents a file in FASTA format.

A FASTA file contains so called header lines, beginning with >, that describe following sequence. The corresponding sequence starts at the line after the header line and ends at the next header line or at the end of file. The header along with its sequence forms an entry.

This class is used in a dictionary like manner, implementing the MutableMapping interface: Headers (without the leading >) are used as keys, and strings containing the sequences are the corresponding values. Entries can be accessed using indexing, del deletes the entry at the given index.

chars_per_line : int, optional

The number characters in a line containing sequence data after which a line break is inserted. Only relevant, when adding sequences to a file. Default is 80.


>>> import os.path
>>> file = FastaFile()
>>> file["seq1"] = "ATACT"
>>> print(file["seq1"])
>>> file["seq2"] = "AAAATT"
>>> print(file)
>>> print(dict(file.items()))
{'seq1': 'ATACT', 'seq2': 'AAAATT'}
>>> for header, seq in file.items():
...     print(header, seq)
seq1 ATACT
>>> del file["seq1"]
>>> print(dict(file.items()))
{'seq2': 'AAAATT'}
>>> file.write(os.path.join(path_to_directory, "test.fasta"))

Parse a file (or file-like object) and store the content in this object.

file_name : file-like object or str

The file to be read. Alternatively a file path cen be supplied.

clear() → None. Remove all items from D.

Create a deep copy of this object.


A copy of this object.

get(k[, d]) → D[k] if k in D, else d. d defaults to None.
items() → a set-like object providing a view on D's items
keys() → a set-like object providing a view on D's keys
pop(k[, d]) → v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

popitem() → (k, v), remove and return some (key, value) pair

as a 2-tuple; but raise KeyError if D is empty.

setdefault(k[, d]) → D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) → None. Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

values() → an object providing a view on D's values

Write the contents of this object into a file (or file-like object).

file_name : file-like object or str

The file to be written to. Alternatively a file path cen be supplied.