FastaParser
A Python FASTA file Parser and Writer.
The FASTA file format is a standard text-based format for representing nucleotide and aminoacid sequences (usual file extensions include: .fasta, .fna, .ffn, .faa and .frn). FastaParser is able to parse such files and extract the biological sequences within into Python objects. It can also handle and manipulate such sequences as well as write sequences to new or existing FASTA files.
Installation
With pip:
$ pip install fastaparser
Usage
Read FASTA files
Generate python objects from FASTA files:
>>> import fastaparser
>>> with open("fasta_file.fasta") as fasta_file:
parser = fastaparser.Reader(fasta_file)
for seq in parser:
# seq is a FastaSequence object
print('ID:', seq.id)
print('Description:', seq.description)
print('Sequence:', seq.sequence_as_string())
print()
output:
ID: sp|P04439|HLAA_HUMAN
Description: HLA class I histocompatibility antigen, A alpha chain OS=Homo sapi...
Sequence: MAVMAPRTLLLLLSGALALTQTWAGSHSMRYFFTSVSRPGRGEPRFIAVGYVDDTQFVRFDSDAASQRM...
ID: sp|P15822|ZEP1_HUMAN
Description: Zinc finger protein 40 OS=Homo sapiens OX=9606 GN=HIVEP1 PE=1 SV=3...
Sequence: MPRTKQIHPRNLRDKIEEAQKELNGAEVSKKEILQAGVKGTSESLKGVKRKKIVAENHLKKIPKSPLRN...
or just parse FASTA headers and sequences, which is much faster but less feature rich:
>>> import fastaparser
>>> with open("fasta_file.fasta") as fasta_file:
parser = fastaparser.Reader(fasta_file, parse_method='quick')
for seq in parser:
# seq is a namedtuple('Fasta', ['header', 'sequence'])
print('Header:', seq.header)
print('Sequence:', seq.sequence)
print()
output:
Header: >sp|P04439|HLAA_HUMAN HLA class I histocompatibility antigen, A alpha c...
Sequence: MAVMAPRTLLLLLSGALALTQTWAGSHSMRYFFTSVSRPGRGEPRFIAVGYVDDTQFVRFDSDAASQRM...
Header: >sp|P15822|ZEP1_HUMAN Zinc finger protein 40 OS=Homo sapiens OX=9606 GN...
Sequence: MPRTKQIHPRNLRDKIEEAQKELNGAEVSKKEILQAGVKGTSESLKGVKRKKIVAENHLKKIPKSPLRN...
Write FASTA files
Create FASTA files from FastaSequence objects:
>>> import fastaparser
>>> with open("fasta_file.fasta", 'w') as fasta_file:
writer = fastaparser.Writer(fasta_file)
fasta_sequence = fastaparser.FastaSequence(
sequence='ACTGCTGCTAGCTAGC',
id='id123',
description='test sequence'
)
writer.writefasta(fasta_sequence)
or single header and sequence strings:
>>> import fastaparser
>>> with open("fasta_file.fasta", 'w') as fasta_file:
writer = fastaparser.Writer(fasta_file)
writer.writefasta(('id123 test sequence', 'ACTGCTGCTAGCTAGC'))
Documentation
Documentation for FastaParser is available here: https://fastaparser.readthedocs.io/en/latest
History
1.1.1 (04-09-2022)
- Added support for Python 3.9 and 3.10
1.1 (13-02-2020)
- Added property setters for:
- FastaSequence.id
- FastaSequence.description
- Added property deleters for:
- FastaSequence.id
- FastaSequence.description
- FastaSequence.sequence_type
- LetterCode.letter_type
1.0 (27-01-2020)
- First release on PyPI and Anaconda Cloud
- Reader, Writer, FastaSequence and LetterCode classes
Metadata
Release files for fastaparser 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastaparser-1.1.1.tar.gz | 27.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastaparser-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 57.6 kB
Release files / fastaparser-1.1.1.tar.gz
| Download URL | fastaparser-1.1.1.tar.gz |
|---|---|
| Size | 27.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
55adcc43285cac07a39844de2bbc5a0b9a40eb35fa99a44b62abe19917cd778e
|
|
BLAKE2b-256 checksum How to use checksums |
5bbb5a567fe0c0ae5ef34a1d547666ff712ef5d16ac6d3f5fae1dad315dda652
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / fastaparser-1.1.1-py3-none-any.whl
| Download URL | fastaparser-1.1.1-py3-none-any.whl |
|---|---|
| Size | 29.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c929f712bd4ea3e6f3569761c6c4fbe798e9a1c4b04d322deb05c8922e731cd4
|
|
BLAKE2b-256 checksum How to use checksums |
09f2b29911ca428036cbb78095dd5a1506f85b1868bd37bd49102046e0ab571b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|