dnaio
raw JSON → 1.2.4 verified Fri May 01 auth: no python
A Python library for reading and writing FASTA and FASTQ files efficiently. Current version 1.2.4, released periodically with active development. It provides a simple iterator-based API and supports compression.
pip install dnaio Common errors
error AttributeError: module 'dnaio' has no attribute 'read' ↓
cause The legacy dnaio.read() and dnaio.write() functions were removed in version 1.0.0.
fix
Use dnaio.open() instead: with dnaio.open('file.fasta') as f: for record in f: ...
error TypeError: '_io.TextIOWrapper' object is not iterable ↓
cause Calling dnaio.open() on a file object without specifying format or mode correctly.
fix
Pass the filename as a string, not a file object. Ensure mode is 'r' (default) for reading.
Warnings
gotcha dnaio.open() returns an iterator, not a list. If you need random access or indexing, load records into a list first. ↓
fix records = list(dnaio.open('file.fastq'))
deprecated The old dnaio.read() and dnaio.write() functions are deprecated since version 1.0. Use dnaio.open() instead. ↓
fix Replace dnaio.read('file') with dnaio.open('file') and dnaio.write('file', records) with dnaio.open('file', mode='w') as f: for r in records: f.write(r)
gotcha FASTQ quality scores are automatically converted to Phred+33; if your file uses Phred+64, you must specify quality_scale=64. ↓
fix with dnaio.open('file.fastq', quality_scale=64) as f: ...
Imports
- open
import dnaio - SequenceRecord
from dnaio import SequenceRecord
Quickstart
import dnaio
with dnaio.open('example.fasta') as f:
for record in f:
print(record.name, record.sequence)
# Writing
with dnaio.open('output.fasta', mode='w') as f:
f.write(dnaio.SequenceRecord('seq1', 'ACGT'))