Designing sequences#

This tutorial shows you how to design protein sequences based on your chosen objectives. Use our sequence-to-function learning to customize design criteria and design variant libraries based on your data.

What you need before getting started#

In order to design sequences, you need an uploaded dataset and a trained model. Please see Uploading data and Training models for more information.

Initializing your design#

Set up a design job using your trained model as a criteria. You also need to create a mutation map to define which positions and residues should be mutated.

Our helper functions can be used to initialize your design mutation dictionary:

[ ]:
from openprotein.api.design import DesignConstraint

parent_sequence = assay.get_first().loc[0,'sequence']
print(parent_sequence)
WRHGDISSSNDTVGVAVVNYKMPRLHTAAEVLDNARKIAEMIVGMKQGLPGMDLVVFPEYSLQGIMYDPAEMMETAVAIPGEETEIFSRACRKANVWGVFSLTGERHEEHPRKAPYNTLVLIDNNGEIVQKYRKIIPWCPIEGWYPGGQTYVSEGPKGMKISLIICDDGNYPEIWRDCAMKGAELIVRCQGYMYPAKDQQVMMAKAMAWANNCYVAVANAAGFDGVYSYFGHSAIIGFDGRTLGECGEEEMGIQYAQLSLSQIRDARANDQSQNHLFKILHRGYSGLQASGDGDRGLAECPFEFYRTWVTDAEKARENVERLTRSTTGVAQCPVGRLPYEGLEKEA

Initialize the design constraints:

[ ]:
design = DesignConstraint(parent_sequence)

Use the constraints to indicate which mutations are allowed at which positions.

For example, we can restrict positions 3 and 6 to G, L only, and position 9 to C only.

[ ]:
design.allow([3, 6], ["G", "L"])

design.allow(9, "C")

Request the mapping:

[ ]:
mutations = design.as_dict()
[ ]:
model_id = train.list_models()[0]['model_id']

Create the design parameters:

[ ]:
from openprotein.api.design import DesignJobCreate, ModelCriterion, NMutationCriterion, Criterion

design_data = DesignJobCreate(
    assay_id=assay.id,
    criteria=[
        [
            ModelCriterion(
                criterion_type='model',
                model_id=model_id,
                measurement_name="isobutyramide_normalized_fitness",
                criterion=Criterion(target=-0.5, weight=1.0, direction="<")
            ),
        ],
        [NMutationCriterion(criterion_type="n_mutations", )]
    ],
    num_steps=3,
    allowed_tokens=mutations
)

Create the design job:

[ ]:
design_job = session.design.create_design_job(design_data)

design_id = design_job.id
design_job
DesignJob(status=<JobStatus.PENDING: 'PENDING'>, job_id='724cfc7d-c7df-44b7-8103-504a1731cb1c', job_type=<JobType.workflow_design: '/workflow/design'>, created_date=datetime.datetime(2024, 5, 9, 6, 10, 7, 661298), start_date=None, end_date=None, prerequisite_job_id=None, progress_message=None, progress_counter=None, num_records=None, sequence_length=None)

View the design results:

[ ]:
results = design_job.wait()
[ ]:
results[-1]
{'step': 1,
 'sample_index': 35,
 'sequence': 'WRGGDGSSCNDTVGVAVVNYKMPRLHTAAEVLDNARKIAEMIVGMKQGLPGMDLVVFPEYSLQGIMYDPAEMMETAVAIPGEETEIFSRACRKANVWGVFSLTGERHEEHPRKAPYNTLVLIDNNGEIVQKYRKIIPWCPIEGWYPGGQTYVSEGPKGMKISLIICDDGNYPEIWRDCAMKGAELIVRCQGYMYPAKDQQVMMAKAMAWANNCYVAVANAAGFDGVYSYFGHSAIIGFDGRTLGECGEEEMGIQYAQLSLSQIRDARANDQSQNHLFKILHRGYSGLQASGDGDRGLAECPFEFYRTWVTDAEKARENVERLTRSTTGVAQCPVGRLPYEGLEKEA',
 'scores': [[{'score': -0.790411651134491,
    'metadata': {'y_mu': -0.4945774972438812,
     'y_var': 0.0021692514419555664}}],
  [{'score': 343.0, 'metadata': {'y_mu': None, 'y_var': None}}]]}

Next steps#

Our Design API reference contains more information about designing your sequences.

Explore your designed sequence’s structure with our Structure prediction models, or evaluate the single substitution variants of your sequence with our Property Regression models. Visit Using single site analysis for more information.