Codeine is a Python library for exploring synonymous protein-coding sequence spaces under biological constraints.
Codeine is available on PyPI:
pip install codeineFull documentation: https://codeine.readthedocs.io/.
from codeine import CodingSpace
space = CodingSpace('MKTIIALSYIFCLVF')
print(space.n_valid_sequences)
print(space.sample())A protein sequence can typically be encoded by an enormous number of synonymous DNA/RNA coding sequences.
For many biotechnological applications, such as recombinant expression, we must choose a coding sequence while respecting practical constraints, for example:
- avoiding restriction enzyme sites,
- avoiding nucleotide homopolymers,
- avoiding repetitive sequences,
- fixing specific codons,
- mutating relative to a reference sequence.
Identifying valid coding sequences under such constraints quickly becomes challenging, especially for longer proteins.
Codeine represents the complete valid coding sequence space exactly for a given protein and experimental setup. It enables efficient counting, sampling, enumeration and mutation library design while guaranteeing that every generated sequence satisfies the specified constraints.
Count valid sequences:
from codeine import CodingSpace
space = CodingSpace('MKTLEFQNGSCPRYKKL')
print(space.n_valid_sequences)Sample a single valid sequence:
from codeine import CodingSpace
space = CodingSpace('MKTLEFQNGSCPRYKKL')
seq = space.sample()
print(seq)Sample many:
from codeine import CodingSpace
space = CodingSpace('MKTLEFQNGSCPRYKKL')
for seq in space.sample(n=5):
print(seq)Apply constraints:
from codeine import CodingSpace, RestrictionSite
from codeine.constraints import TandemRepeatConstraint
space = CodingSpace(
'MKTLEFQNGSCPRYKKL',
forbidden_motifs=[
RestrictionSite.EcoRI,
RestrictionSite.BamHI,
'CTGCAG',
],
codon_restrictions={
2: 'AAG',
16: 'AAG',
},
max_homopolymer=4,
constraints=[
TandemRepeatConstraint(repeat_length=3, min_copies=3),
],
)
print(space.n_valid_sequences)
print(space.sample())Use custom codon weights to change the sampling distribution:
from codeine import CodingSpace, CodonWeights
weights = CodonWeights.ecoli()
space = CodingSpace('MKTLEFQNGSCPRYKKL', codon_weights=weights)
print(space.sample())Use alternative genetic codes and RNA:
from codeine import CodingSpace, TranslationTable
table = TranslationTable(table_id=2, rna=True)
space = CodingSpace('MKTLEFQNGSCPRYKKL', translation_table=table)
print(space.sample())Enumerate all sequences (recommended only for small spaces):
from codeine import CodingSpace
space = CodingSpace('CYIQNCPLG')
for sequence in space:
print(sequence)Explore mutants of a chosen reference sequence:
from codeine import CodingSpace
space = CodingSpace('MKTLEFQNGSCPRYKKL')
reference = space.sample()
mutants = space.mutants(
reference,
free_positions=range(5, 14),
min_nts=2,
max_nts=5,
)
print(mutants.sample())