> ## Documentation Index
> Fetch the complete documentation index at: https://proto.evodesign.org/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Codon Adaptation Index

> Drive a coding sequence toward high (or low) codon adaptation index (CAI).

![Codon Adaptation Index](https://proto-bio.github.io/proto-assets/images/constraint/codon-adaptation-index/hero.png)

This constraint is open source. Any third-party models, product names, or trademarks referenced are the property of their respective owners, and Proto is not affiliated with them.

***

&#x20;Source

![Proto](https://mintcdn.com/bio-pro/cMLt8hAqaP9M3LKy/assets/logo/logo-light.svg?fit=max\&auto=format\&n=cMLt8hAqaP9M3LKy\&q=85\&s=f5e5dfd1b8f9b9db3a0be0e2eb01f678)

evo-design/proto-language

&#x20;View source

[Open](https://github.com/evo-design/proto-language/blob/0824a53b9c4ed4c3ed45d82d06d250a40b1c9e7a/proto_language/constraint/sequence_composition/codon_adaptation_index_constraint.py#L194)

Constraint contributors[![](https://avatars.githubusercontent.com/u/21143637?v=4\&s=64)bviggiano](https://github.com/bviggiano)
Score coding-sequence proposals by Codon Adaptation Index.

## API Reference

ConfigCodonAdaptationIndexConfig[ Source](https://github.com/evo-design/proto-language/blob/0824a53b9c4ed4c3ed45d82d06d250a40b1c9e7a/proto_language/constraint/sequence_composition/codon_adaptation_index_constraint.py#L100)

Configuration for the Codon Adaptation Index (CAI) constraint.

Exactly one reference source must be given: an explicit `reference_weights` table, or a
`reference_sequences` set from which relative adaptiveness is derived.

**reference\_weights** `object`

Codon -> relative adaptiveness in (0,1]; provide this or reference\_sequences.

**reference\_sequences** `array`

Reference coding sequences to derive relative adaptiveness from.

**direction** `enum` (default: max)

Whether to maximize ('max') or minimize ('min') the codon adaptation index.

Options: `max`, `min`

**sigmoid\_center** `number` (default: 0.7)

CAI value mapped to energy 0.5 (tunable; CAI is in (0, 1]).

**sigmoid\_scale** `number` (default: 0.15)

Positive float32-safe width of the sigmoid transform; larger is gentler.

ReturnsConstraintOutput

One result per sequence. `score` is in `[0.0, 1.0]` (lower is
better in the requested direction); `metadata` carries the raw `cai`.

## Usage

```python python icon="python" theme={null}
from proto_language.core import Constraint
from proto_language.constraint import codon_adaptation_index_constraint, CodonAdaptationIndexConfig

constraint = Constraint(
    inputs=[segment],
    function=codon_adaptation_index_constraint,
    function_config=CodonAdaptationIndexConfig(
        # Configure parameters here
    ),
)

scores = constraint.evaluate()
```

## Metadata

| Property | Value |
| - | - |
| Key | `codon-adaptation-index` |
| Function | `codon_adaptation_index_constraint` |
| Category | `sequence_composition` |
| Mode | `discrete` |
| Uses GPU | `False` |
| Supported Types | `dna`, `rna` |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.