genome_entropy.io.fasta
FASTA file reading and writing utilities.
Functions
|
Read a FASTA file and return a dictionary of sequence_id -> sequence. |
|
Read a FASTA file and yield (sequence_id, sequence) tuples. |
|
Write sequences to a FASTA file. |
- genome_entropy.io.fasta.read_fasta(fasta_path)[source]
Read a FASTA file and return a dictionary of sequence_id -> sequence.
Automatically detects and handles gzipped files (ending in .gz).
- Parameters:
fasta_path (str | Path) – Path to FASTA file (plain text or gzipped)
- Returns:
Dictionary mapping sequence IDs to sequences
- Raises:
FileNotFoundError – If the FASTA file doesn’t exist
ValueError – If the FASTA file is malformed
- Return type:
- genome_entropy.io.fasta.read_fasta_iter(fasta_path)[source]
Read a FASTA file and yield (sequence_id, sequence) tuples.
Memory-efficient iterator for large FASTA files. Automatically detects and handles gzipped files (ending in .gz).
- Parameters:
fasta_path (str | Path) – Path to FASTA file (plain text or gzipped)
- Yields:
Tuples of (sequence_id, sequence)
- Raises:
FileNotFoundError – If the FASTA file doesn’t exist
ValueError – If the FASTA file is malformed
- Return type: