genetics.dna2aminoacid()
Convert a DNA sequence from a FASTA file to an amino acid sequence.
Usage
genetics.dna2aminoacid(
fasta_file,
codons=None,
)This function reads a FASTA-formatted file, extracts the DNA sequence (skipping the header line that starts with ‘>’), and translates it into an amino acid sequence using the genetic code. The sequence is processed in groups of three nucleotides (codons), and each codon is looked up in the codon dictionary to determine the corresponding amino acid.
Parameters
fasta_file: str-
Path to the FASTA file containing the DNA sequence.
codons: dict = None- Dictionary mapping 3-letter DNA codons to single-letter amino acid codes. Defaults to the standard genetic code.
Returns
str: str- The translated amino acid sequence as a single-letter code string.
Raises
FileNotFoundError-
If the FASTA file cannot be found.
KeyError-
If an invalid codon (not in the dictionary) is encountered.
ValueError- If the DNA sequence length is not a multiple of 3.
Examples
>>> sequence = dna2aminoacid("sequence.fasta")
>>> print(sequence)MKTAYIAKQR...