Skip to main content

🧬 Codeine

Codeine is a Python library for constrained reverse translation of protein sequences.

Installation & documentation

Codeine is available on PyPI:

pip install codeine

Full documentation: https://codeine.readthedocs.io/.

Quick start

from codeine import CodingSpace

space = CodingSpace('MKTIIALSYIFCLVF')

print(space.n_valid_sequences)
print(space.sample())

Overview

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 exactly represents the complete set of coding sequences for a given protein under specified constraints. It enables efficient counting, sampling, enumeration and mutation library design without the need for sequence filtering or repair.

Examples

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 ForbiddenMotifs, MaxHomopolymer

space = CodingSpace(
    'MKTLEFQNGSCPRYKKL',
    fixed_codons={
        2: 'AAG',
        16: 'AAG',
    },
    constraints=[
        ForbiddenMotifs([
            RestrictionSite.EcoRI,
            RestrictionSite.BamHI,
            'CTGCAG',
        ]),
        MaxHomopolymer(max_length=4),
    ],
)

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())

Metadata

Release files for codeine 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for codeine 0.5.2
File Size Uploaded
codeine-0.5.2.tar.gz 48.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for codeine 0.5.2
File Interpreter ABI Platform
codeine-0.5.2-py3-none-any.whl Python 3 none any Details

Total release size: 107.3 kB

Release files / codeine-0.5.2.tar.gz

Download URL codeine-0.5.2.tar.gz
Size 48.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8dc0bf91c4176aa80d7cae89efb6882718f70add2fd10bf331bca37b49ecb0a7
BLAKE2b-256 checksum
How to use checksums
1e06e29f9503f1d9ffa4f3808e45f8b5da39fd88cac524d98e7647b32128989e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / codeine-0.5.2-py3-none-any.whl

Download URL codeine-0.5.2-py3-none-any.whl
Size 58.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f7daf04a923077738a926a51c0f82d03568d5799d89335a8a4ae58c248395d6
BLAKE2b-256 checksum
How to use checksums
eb6e314818014b63af576614d1dcc09cc67ba881722e6f82d8cd3cd65e42cb89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

This release

0.5.2 This release

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page