# biotite.sequence.io.fasta.FastaFile¶

class biotite.sequence.io.fasta.FastaFile(chars_per_line=80)[source]

Bases: biotite.file.TextFile, collections.abc.MutableMapping

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.

Parameters
chars_per_lineint, 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.

Examples

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

read(self, file)[source]

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

Parameters
file_namefile-like object or str

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

clear(self)
copy(self)

Create a deep copy of this object.

Returns
copy

A copy of this object.

get(self, key, default=None)
items(self)
keys(self)
pop(self, key, default=<object object at 0x7fc2eac76050>)

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

popitem(self)

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

setdefault(self, key, default=None)
update(*args, **kwds)

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(self)
write(self, file)

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

Parameters
file_namefile-like object or str

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