Sequence Utilities
Labrat provides focused Python utilities for nucleotide composition, DNA complements, and FASTA translation. They fit quick checks in scripts, notebooks, and teaching examples.
Count canonical nucleotides
from labrat.genetics import atgc_content
counts = atgc_content("ATGCGAT")
print(counts)The result is:
{'A': 2, 'T': 2, 'G': 2, 'C': 1}
Input is case-insensitive. Counts include A, T, G, and C only, so the total can be smaller than the submitted sequence length.
Create a complementary strand
from labrat.genetics import complementary_dna
complement = complementary_dna("ATGN")
print(complement)The result is TACX. Non-canonical characters become X. The function returns the direct complement in the submitted order. Reverse this sequence when you need the reverse complement.
Translate a FASTA sequence
Create a small FASTA file whose nucleotide count is divisible by three:
>example
ATGAAATGG
Translate it with:
from labrat.genetics import dna2aminoacid
protein = dna2aminoacid("example.fasta")
print(protein)The result is MKW. Labrat removes whitespace, accepts lowercase sequence characters, and skips every line beginning with >. Stop codons are returned as _, and translation continues with the next codon.
Translation raises an error for an empty sequence, a length that leaves a remainder after division by three, or a codon containing a character outside A, T, G, and C.
Laboratory calculations
Labrat also provides laboratory calculations through its Python API. These functions accept plain numeric values, so confirm the intended units before using a result in experimental work.