openprotein-python 0.5.1__tar.gz → 0.5.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/.gitignore +2 -1
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/PKG-INFO +4 -3
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/__init__.py +53 -23
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/api/__init__.py +0 -1
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/api/align.py +1 -23
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/api/deprecated/poet.py +5 -1
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/api/design.py +12 -8
- openprotein_python-0.5.2/openprotein/api/designer.py +262 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/api/embedding.py +15 -5
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/api/job.py +3 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/api/predict.py +43 -9
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/api/predictor.py +36 -1
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/api/svd.py +3 -3
- openprotein_python-0.5.2/openprotein/api/umap.py +247 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/__init__.py +13 -4
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/__init__.py +19 -7
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/deprecated/poet.py +4 -3
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/design.py +8 -11
- openprotein_python-0.5.2/openprotein/app/models/designer.py +121 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/embeddings/base.py +54 -1
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/embeddings/future.py +11 -3
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/embeddings/poet.py +46 -6
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/predict.py +47 -2
- openprotein_python-0.5.2/openprotein/app/models/predictor/predictor.py +304 -0
- openprotein_python-0.5.2/openprotein/app/models/predictor/validate.py +37 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/svd.py +54 -5
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/train.py +3 -3
- openprotein_python-0.5.2/openprotein/app/models/umap.py +156 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/services/__init__.py +10 -4
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/services/design.py +9 -7
- openprotein_python-0.5.2/openprotein/app/services/designer.py +73 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/services/job.py +16 -3
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/services/predict.py +11 -5
- openprotein_python-0.5.2/openprotein/app/services/umap.py +97 -0
- openprotein_python-0.5.2/openprotein/auth.py +21 -0
- openprotein_python-0.5.2/openprotein/csv.py +26 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/schemas/__init__.py +20 -14
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/schemas/design.py +149 -39
- openprotein_python-0.5.2/openprotein/schemas/designer.py +38 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/schemas/embeddings.py +3 -4
- openprotein_python-0.5.2/openprotein/schemas/features.py +7 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/schemas/job.py +6 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/schemas/predict.py +2 -3
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/schemas/predictor.py +4 -12
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/schemas/svd.py +2 -3
- openprotein_python-0.5.2/openprotein/schemas/umap.py +35 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/pyproject.toml +22 -7
- openprotein_python-0.5.1/openprotein/app/models/predictor/predictor.py +0 -196
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/LICENSE.txt +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/README.md +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/_version.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/api/assaydata.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/api/deprecated/__init__.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/api/fold.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/api/train.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/align/__init__.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/align/base.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/align/msa.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/align/prompt.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/assaydata.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/deprecated/__init__.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/embeddings/__init__.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/embeddings/esm.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/embeddings/openprotein.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/embeddings/test.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/fold/__init__.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/fold/alphafold2.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/fold/base.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/fold/esmfold.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/fold/future.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/futures.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/predictor/__init__.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/models/predictor/predict.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/services/align.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/services/assaydata.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/services/embeddings.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/services/fold.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/services/predictor.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/services/svd.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/app/services/train.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/base.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/config.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/errors.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/fasta.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/schemas/align.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/schemas/assaydata.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/schemas/deprecated/__init__.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/schemas/deprecated/poet.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/schemas/fold.py +0 -0
- {openprotein_python-0.5.1 → openprotein_python-0.5.2}/openprotein/schemas/train.py +0 -0
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: openprotein_python
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.2
|
|
4
4
|
Summary: OpenProtein Python interface.
|
|
5
5
|
Author-email: Mark Gee <markgee@ne47.bio>
|
|
6
6
|
License: MIT
|
|
7
7
|
Classifier: Development Status :: 4 - Beta
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
9
|
Requires-Python: >=3.10
|
|
10
|
-
Requires-Dist: numpy<3,>=
|
|
11
|
-
Requires-Dist: pandas<3,>=2.
|
|
10
|
+
Requires-Dist: numpy<3,>=1.9
|
|
11
|
+
Requires-Dist: pandas<3,>=2.2.2
|
|
12
12
|
Requires-Dist: pydantic<3,>=2.5
|
|
13
13
|
Requires-Dist: requests<3,>=2.32.3
|
|
14
14
|
Requires-Dist: tqdm<5,>=4.66.5
|
|
15
15
|
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: hatchling>=1.26.1; extra == 'dev'
|
|
16
17
|
Requires-Dist: ipykernel<7,>=6.29.5; extra == 'dev'
|
|
17
18
|
Requires-Dist: matplotlib<4,>=3.9.2; extra == 'dev'
|
|
18
19
|
Requires-Dist: pandas-stubs<3,>=2.1.4.240909; extra == 'dev'
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
OpenProtein Python client.
|
|
3
|
+
|
|
4
|
+
A pythonic interface for interacting with our cutting-edge protein engineering platform.
|
|
5
|
+
|
|
6
|
+
isort:skip_file
|
|
7
|
+
"""
|
|
8
|
+
|
|
1
9
|
from openprotein._version import __version__
|
|
2
10
|
from openprotein.app import (
|
|
3
|
-
SVDAPI,
|
|
4
|
-
AlignAPI,
|
|
5
11
|
AssayDataAPI,
|
|
12
|
+
JobsAPI,
|
|
13
|
+
TrainingAPI,
|
|
6
14
|
DesignAPI,
|
|
15
|
+
AlignAPI,
|
|
7
16
|
EmbeddingsAPI,
|
|
8
17
|
FoldAPI,
|
|
9
|
-
|
|
18
|
+
SVDAPI,
|
|
19
|
+
UMAPAPI,
|
|
10
20
|
PredictorAPI,
|
|
11
|
-
|
|
21
|
+
DesignerAPI,
|
|
12
22
|
)
|
|
13
23
|
from openprotein.app.models import Future
|
|
14
24
|
from openprotein.base import APISession
|
|
@@ -19,15 +29,17 @@ class OpenProtein(APISession):
|
|
|
19
29
|
The base class for accessing OpenProtein API functionality.
|
|
20
30
|
"""
|
|
21
31
|
|
|
22
|
-
_embedding = None
|
|
23
|
-
_svd = None
|
|
24
|
-
_fold = None
|
|
25
|
-
_align = None
|
|
26
|
-
_jobs = None
|
|
27
32
|
_data = None
|
|
33
|
+
_jobs = None
|
|
28
34
|
_train = None
|
|
29
35
|
_design = None
|
|
36
|
+
_align = None
|
|
37
|
+
_embedding = None
|
|
38
|
+
_svd = None
|
|
39
|
+
_umap = None
|
|
40
|
+
_fold = None
|
|
30
41
|
_predictor = None
|
|
42
|
+
_designer = None
|
|
31
43
|
|
|
32
44
|
def wait(self, future: Future, *args, **kwargs):
|
|
33
45
|
return future.wait(*args, **kwargs)
|
|
@@ -37,15 +49,6 @@ class OpenProtein(APISession):
|
|
|
37
49
|
def load_job(self, job_id):
|
|
38
50
|
return self.jobs.__load(job_id=job_id)
|
|
39
51
|
|
|
40
|
-
@property
|
|
41
|
-
def jobs(self) -> JobsAPI:
|
|
42
|
-
"""
|
|
43
|
-
The jobs submodule gives access to functionality for listing jobs and checking their status.
|
|
44
|
-
"""
|
|
45
|
-
if self._jobs is None:
|
|
46
|
-
self._jobs = JobsAPI(self)
|
|
47
|
-
return self._jobs
|
|
48
|
-
|
|
49
52
|
@property
|
|
50
53
|
def data(self) -> AssayDataAPI:
|
|
51
54
|
"""
|
|
@@ -55,6 +58,15 @@ class OpenProtein(APISession):
|
|
|
55
58
|
self._data = AssayDataAPI(self)
|
|
56
59
|
return self._data
|
|
57
60
|
|
|
61
|
+
@property
|
|
62
|
+
def jobs(self) -> JobsAPI:
|
|
63
|
+
"""
|
|
64
|
+
The jobs submodule gives access to functionality for listing jobs and checking their status.
|
|
65
|
+
"""
|
|
66
|
+
if self._jobs is None:
|
|
67
|
+
self._jobs = JobsAPI(self)
|
|
68
|
+
return self._jobs
|
|
69
|
+
|
|
58
70
|
@property
|
|
59
71
|
def train(self) -> TrainingAPI:
|
|
60
72
|
"""
|
|
@@ -64,6 +76,15 @@ class OpenProtein(APISession):
|
|
|
64
76
|
self._train = TrainingAPI(self)
|
|
65
77
|
return self._train
|
|
66
78
|
|
|
79
|
+
@property
|
|
80
|
+
def design(self) -> DesignAPI:
|
|
81
|
+
"""
|
|
82
|
+
The design submodule gives access to functionality for designing new sequences using models from train.
|
|
83
|
+
"""
|
|
84
|
+
if self._design is None:
|
|
85
|
+
self._design = DesignAPI(self)
|
|
86
|
+
return self._design
|
|
87
|
+
|
|
67
88
|
@property
|
|
68
89
|
def align(self) -> AlignAPI:
|
|
69
90
|
"""
|
|
@@ -91,6 +112,15 @@ class OpenProtein(APISession):
|
|
|
91
112
|
self._svd = SVDAPI(self, self.embedding)
|
|
92
113
|
return self._svd
|
|
93
114
|
|
|
115
|
+
@property
|
|
116
|
+
def umap(self) -> UMAPAPI:
|
|
117
|
+
"""
|
|
118
|
+
The embedding submodule gives access to protein embedding models and their inference endpoints.
|
|
119
|
+
"""
|
|
120
|
+
if self._umap is None:
|
|
121
|
+
self._umap = UMAPAPI(self)
|
|
122
|
+
return self._umap
|
|
123
|
+
|
|
94
124
|
@property
|
|
95
125
|
def predictor(self) -> PredictorAPI:
|
|
96
126
|
"""
|
|
@@ -101,13 +131,13 @@ class OpenProtein(APISession):
|
|
|
101
131
|
return self._predictor
|
|
102
132
|
|
|
103
133
|
@property
|
|
104
|
-
def
|
|
134
|
+
def designer(self) -> DesignerAPI:
|
|
105
135
|
"""
|
|
106
|
-
The
|
|
136
|
+
The designer submodule gives access to functionality for designing new sequences using models from predictor train.
|
|
107
137
|
"""
|
|
108
|
-
if self.
|
|
109
|
-
self.
|
|
110
|
-
return self.
|
|
138
|
+
if self._designer is None:
|
|
139
|
+
self._designer = DesignerAPI(self)
|
|
140
|
+
return self._designer
|
|
111
141
|
|
|
112
142
|
@property
|
|
113
143
|
def fold(self) -> FoldAPI:
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import codecs
|
|
2
|
-
import csv
|
|
3
1
|
import io
|
|
4
2
|
import random
|
|
5
3
|
from typing import BinaryIO, Iterator
|
|
@@ -7,31 +5,11 @@ from typing import BinaryIO, Iterator
|
|
|
7
5
|
import openprotein.config as config
|
|
8
6
|
import requests
|
|
9
7
|
from openprotein.base import APISession
|
|
8
|
+
from openprotein.csv import csv_stream
|
|
10
9
|
from openprotein.errors import APIError, InvalidParameterError, MissingParameterError
|
|
11
10
|
from openprotein.schemas import Job, MSASamplingMethod, PoetInputType
|
|
12
11
|
|
|
13
12
|
|
|
14
|
-
def csv_stream(response: requests.Response) -> Iterator[list[str]]:
|
|
15
|
-
"""
|
|
16
|
-
Returns a CSV reader from a requests.Response object.
|
|
17
|
-
|
|
18
|
-
Parameters
|
|
19
|
-
----------
|
|
20
|
-
response : requests.Response
|
|
21
|
-
The response object to parse.
|
|
22
|
-
|
|
23
|
-
Returns
|
|
24
|
-
-------
|
|
25
|
-
csv.reader
|
|
26
|
-
A csv reader object for the response.
|
|
27
|
-
"""
|
|
28
|
-
raw_content = response.raw # the raw bytes stream
|
|
29
|
-
content = codecs.getreader("utf-8")(
|
|
30
|
-
raw_content
|
|
31
|
-
) # force the response to be encoded as utf-8
|
|
32
|
-
return csv.reader(content)
|
|
33
|
-
|
|
34
|
-
|
|
35
13
|
def get_align_job_inputs(
|
|
36
14
|
session: APISession,
|
|
37
15
|
job_id: str,
|
|
@@ -5,7 +5,11 @@ import requests
|
|
|
5
5
|
from openprotein import config
|
|
6
6
|
from openprotein.base import APISession
|
|
7
7
|
from openprotein.errors import APIError, InvalidParameterError, MissingParameterError
|
|
8
|
-
from openprotein.schemas import
|
|
8
|
+
from openprotein.schemas.deprecated.poet import (
|
|
9
|
+
PoetGenerateJob,
|
|
10
|
+
PoetScoreJob,
|
|
11
|
+
PoetSSPJob,
|
|
12
|
+
)
|
|
9
13
|
|
|
10
14
|
|
|
11
15
|
def poet_score_post(
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
from openprotein.base import APISession
|
|
2
|
-
from openprotein.schemas import
|
|
2
|
+
from openprotein.schemas import (
|
|
3
|
+
WorkflowDesign,
|
|
4
|
+
WorkflowDesignJob,
|
|
5
|
+
WorkflowDesignJobCreate,
|
|
6
|
+
)
|
|
3
7
|
|
|
4
8
|
|
|
5
|
-
def create_design_job(session: APISession, design_job:
|
|
9
|
+
def create_design_job(session: APISession, design_job: WorkflowDesignJobCreate):
|
|
6
10
|
"""
|
|
7
11
|
Send a POST request for protein design job.
|
|
8
12
|
|
|
@@ -13,7 +17,7 @@ def create_design_job(session: APISession, design_job: DesignJobCreate):
|
|
|
13
17
|
design_job : DesignJobCreate
|
|
14
18
|
The details of the design job to be created, with the following parameters:
|
|
15
19
|
- assay_id: The ID for the assay.
|
|
16
|
-
- criteria:
|
|
20
|
+
- criteria: Criteria for evaluating the design.
|
|
17
21
|
- num_steps: The number of steps in the genetic algo. Default is 8.
|
|
18
22
|
- pop_size: The population size for the genetic algo. Default is None.
|
|
19
23
|
- n_offsprings: The number of offspring for the genetic algo. Default is None.
|
|
@@ -24,13 +28,13 @@ def create_design_job(session: APISession, design_job: DesignJobCreate):
|
|
|
24
28
|
|
|
25
29
|
Returns
|
|
26
30
|
-------
|
|
27
|
-
|
|
31
|
+
WorkflowDesignJob
|
|
28
32
|
The created job as a Job instance.
|
|
29
33
|
"""
|
|
30
34
|
params = design_job.model_dump(exclude_none=True)
|
|
31
35
|
# print(f"sending design: {params}")
|
|
32
36
|
response = session.post("v1/workflow/design/genetic-algorithm", json=params)
|
|
33
|
-
return
|
|
37
|
+
return WorkflowDesignJob.model_validate(response.json())
|
|
34
38
|
|
|
35
39
|
|
|
36
40
|
def get_design_results(
|
|
@@ -39,7 +43,7 @@ def get_design_results(
|
|
|
39
43
|
step: int | None = None,
|
|
40
44
|
page_size: int | None = None,
|
|
41
45
|
page_offset: int | None = None,
|
|
42
|
-
) ->
|
|
46
|
+
) -> WorkflowDesign:
|
|
43
47
|
"""
|
|
44
48
|
Retrieves the results of a Design job.
|
|
45
49
|
|
|
@@ -60,7 +64,7 @@ def get_design_results(
|
|
|
60
64
|
|
|
61
65
|
Returns
|
|
62
66
|
-------
|
|
63
|
-
|
|
67
|
+
WorkflowDesignJob
|
|
64
68
|
The job object representing the Design job.
|
|
65
69
|
|
|
66
70
|
Raises
|
|
@@ -79,4 +83,4 @@ def get_design_results(
|
|
|
79
83
|
|
|
80
84
|
response = session.get(endpoint, params=params)
|
|
81
85
|
|
|
82
|
-
return
|
|
86
|
+
return WorkflowDesign.model_validate(response.json())
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"""API for interacting with the designer service."""
|
|
2
|
+
|
|
3
|
+
from typing import Generator, Iterator, NamedTuple
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
import pandas as pd
|
|
7
|
+
from openprotein.base import APISession
|
|
8
|
+
from openprotein.csv import csv_stream
|
|
9
|
+
from openprotein.schemas import (
|
|
10
|
+
Criteria,
|
|
11
|
+
Criterion,
|
|
12
|
+
Design,
|
|
13
|
+
DesignConstraint,
|
|
14
|
+
DesignJob,
|
|
15
|
+
Job,
|
|
16
|
+
Subcriterion,
|
|
17
|
+
)
|
|
18
|
+
from pydantic import TypeAdapter
|
|
19
|
+
|
|
20
|
+
PATH_PREFIX = "v1/designer/design"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def designs_list(session: APISession) -> list[Design]:
|
|
24
|
+
"""
|
|
25
|
+
List designs.
|
|
26
|
+
|
|
27
|
+
Parameters
|
|
28
|
+
----------
|
|
29
|
+
session : APISession
|
|
30
|
+
Session object for API communication.
|
|
31
|
+
|
|
32
|
+
Returns
|
|
33
|
+
-------
|
|
34
|
+
list[Design]
|
|
35
|
+
List of designs.
|
|
36
|
+
"""
|
|
37
|
+
endpoint = PATH_PREFIX
|
|
38
|
+
response = session.get(endpoint)
|
|
39
|
+
return TypeAdapter(list[Design]).validate_python(response.json())
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def design_get(session: APISession, design_id: str) -> Design:
|
|
43
|
+
"""
|
|
44
|
+
Get design.
|
|
45
|
+
|
|
46
|
+
Parameters
|
|
47
|
+
----------
|
|
48
|
+
session : APISession
|
|
49
|
+
Session object for API communication.
|
|
50
|
+
design_id: str
|
|
51
|
+
ID of design to get.
|
|
52
|
+
|
|
53
|
+
Returns
|
|
54
|
+
-------
|
|
55
|
+
Design
|
|
56
|
+
Design metadata.
|
|
57
|
+
"""
|
|
58
|
+
endpoint = PATH_PREFIX + f"/{design_id}"
|
|
59
|
+
response = session.get(endpoint)
|
|
60
|
+
return TypeAdapter(Design).validate_python(response.json())
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def designer_create_genetic_algorithm(
|
|
64
|
+
session: APISession,
|
|
65
|
+
assay_id: str,
|
|
66
|
+
criteria: Criteria | Subcriterion | Criterion,
|
|
67
|
+
num_steps: int = 25,
|
|
68
|
+
pop_size: int = 1024, # TODO - rename to library_size
|
|
69
|
+
n_offsprings: int = 5120,
|
|
70
|
+
crossover_prob: float = 1.0,
|
|
71
|
+
crossover_prob_pointwise: float = 0.2,
|
|
72
|
+
mutation_average_mutations_per_seq: int = 1,
|
|
73
|
+
allowed_tokens: DesignConstraint | dict[int, list[str]] = {},
|
|
74
|
+
) -> Job:
|
|
75
|
+
"""
|
|
76
|
+
Create design using genetic algorithm.
|
|
77
|
+
|
|
78
|
+
Parameters
|
|
79
|
+
----------
|
|
80
|
+
session : APISession
|
|
81
|
+
Session object for API communication.
|
|
82
|
+
assay_id : str
|
|
83
|
+
Assay ID to fit GP on.
|
|
84
|
+
criteria: list[list[DesignCriterion]]
|
|
85
|
+
List of list of design criteria, logically grouping by OR then AND.
|
|
86
|
+
num_steps: int, optional
|
|
87
|
+
The number of steps in the genetic algorithm. Default is 8.
|
|
88
|
+
pop_size: int, optional
|
|
89
|
+
The population size for the genetic algorithm. Default is 256.
|
|
90
|
+
n_offsprings: int, optional
|
|
91
|
+
The number of offspring for the genetic algorithm. Default is 5120.
|
|
92
|
+
crossover_prob: float, optional
|
|
93
|
+
The crossover probability for the genetic algorithm. Default is 1.
|
|
94
|
+
crossover_prob_pointwise: float, optional
|
|
95
|
+
The pointwise crossover probability for the genetic algorithm. Default is 0.2.
|
|
96
|
+
mutation_average_mutations_per_seq: int, optional
|
|
97
|
+
The average number of mutations per sequence. Default is 1.
|
|
98
|
+
allowed_tokens: DesignConstraint | dict[int, list[str]]
|
|
99
|
+
A dict of positions and allows tokens (e.g. *{1:['G','L']})* ) designating how mutations may occur. Defaults to empty dict.
|
|
100
|
+
|
|
101
|
+
Returns
|
|
102
|
+
-------
|
|
103
|
+
DesignJob
|
|
104
|
+
"""
|
|
105
|
+
if isinstance(criteria, Subcriterion):
|
|
106
|
+
criteria = Criteria([Criterion([criteria])])
|
|
107
|
+
elif isinstance(criteria, Criterion):
|
|
108
|
+
criteria = Criteria([criteria])
|
|
109
|
+
|
|
110
|
+
endpoint = PATH_PREFIX + "/genetic-algorithm"
|
|
111
|
+
|
|
112
|
+
body = {
|
|
113
|
+
"assay_id": assay_id,
|
|
114
|
+
"criteria": criteria.model_dump(),
|
|
115
|
+
"num_steps": num_steps,
|
|
116
|
+
"pop_size": pop_size,
|
|
117
|
+
"n_offsprings": n_offsprings,
|
|
118
|
+
"crossover_prob": crossover_prob,
|
|
119
|
+
"crossover_prob_pointwise": crossover_prob_pointwise,
|
|
120
|
+
"mutation_average_mutations_per_seq": mutation_average_mutations_per_seq,
|
|
121
|
+
"allowed_tokens": allowed_tokens,
|
|
122
|
+
}
|
|
123
|
+
response = session.post(endpoint, json=body)
|
|
124
|
+
return DesignJob.model_validate(response.json())
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def design_delete(session: APISession, design_id: str):
|
|
128
|
+
raise NotImplementedError()
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def designer_get_design_results(
|
|
132
|
+
session: APISession,
|
|
133
|
+
design_id: str,
|
|
134
|
+
step: int | None = -1,
|
|
135
|
+
) -> Iterator[list[str]]:
|
|
136
|
+
"""
|
|
137
|
+
Get csv encoded results for a design ID.
|
|
138
|
+
|
|
139
|
+
Parameters
|
|
140
|
+
----------
|
|
141
|
+
session : APISession
|
|
142
|
+
Session object for API communication.
|
|
143
|
+
design_id : str
|
|
144
|
+
Design ID to retrieve results from.
|
|
145
|
+
step: int | None, optional
|
|
146
|
+
Step of the design whose results to fetch. Defaults to -1, which refers to the last step.
|
|
147
|
+
|
|
148
|
+
Returns
|
|
149
|
+
-------
|
|
150
|
+
bytes
|
|
151
|
+
"""
|
|
152
|
+
params = {}
|
|
153
|
+
if step is not None:
|
|
154
|
+
params["step"] = step
|
|
155
|
+
endpoint = PATH_PREFIX + f"/{design_id}/results"
|
|
156
|
+
response = session.get(endpoint, params=params, stream=True)
|
|
157
|
+
return csv_stream(response)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
class DesignResult(NamedTuple):
|
|
161
|
+
step: int
|
|
162
|
+
sample_index: int
|
|
163
|
+
sequence: str
|
|
164
|
+
scores: np.ndarray
|
|
165
|
+
subscores: np.ndarray
|
|
166
|
+
means: np.ndarray
|
|
167
|
+
vars: np.ndarray
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def decode_design_result(
|
|
171
|
+
row: list[str],
|
|
172
|
+
score_start_index: int,
|
|
173
|
+
subscore_start_index: int,
|
|
174
|
+
pred_start_index: int,
|
|
175
|
+
) -> DesignResult:
|
|
176
|
+
"""
|
|
177
|
+
Decode prediction scores.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
data (bytes): raw bytes encoding the array received over the API
|
|
181
|
+
batched (bool): whether or not the result was batched. affects the retrieved csv format whether they contain additional columns and header rows.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
mus (np.ndarray): decoded array of means
|
|
185
|
+
vars (np.ndarray): decoded array of variances
|
|
186
|
+
"""
|
|
187
|
+
scores = np.array(
|
|
188
|
+
[float(score) for score in row[score_start_index:subscore_start_index]]
|
|
189
|
+
)
|
|
190
|
+
subscores = np.array(
|
|
191
|
+
[float(subscore) for subscore in row[subscore_start_index:pred_start_index]]
|
|
192
|
+
)
|
|
193
|
+
preds = np.array([float(pred) for pred in row[pred_start_index:]])
|
|
194
|
+
result = DesignResult(
|
|
195
|
+
step=int(row[0]),
|
|
196
|
+
sample_index=int(row[1]),
|
|
197
|
+
sequence=row[2],
|
|
198
|
+
scores=scores,
|
|
199
|
+
subscores=subscores,
|
|
200
|
+
means=preds[::2],
|
|
201
|
+
vars=preds[1::2],
|
|
202
|
+
)
|
|
203
|
+
return result
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def decode_design_results_stream(
|
|
207
|
+
data: Iterator[list[str]], header: list[str] | None = None
|
|
208
|
+
) -> Generator[DesignResult, None, None]:
|
|
209
|
+
"""
|
|
210
|
+
Decode design results.
|
|
211
|
+
|
|
212
|
+
Args:
|
|
213
|
+
data: Iterator[list[str]]
|
|
214
|
+
Data in the form of an iterator of list of string-encoded values
|
|
215
|
+
header: list[str] | None, optional
|
|
216
|
+
Headers describing the data. Should be same length as each row returned from the data iterator.
|
|
217
|
+
Defaults to None, which means the first row in the iterator should be header.
|
|
218
|
+
|
|
219
|
+
Returns:
|
|
220
|
+
step: int
|
|
221
|
+
Step index of the design.
|
|
222
|
+
sample_index: int
|
|
223
|
+
Index of the sample in the overall design.
|
|
224
|
+
sequence: str
|
|
225
|
+
Output designed sequence.
|
|
226
|
+
scores: np.ndarray[float]
|
|
227
|
+
M array of scores based on provided criteria (M groups of subcriteria).
|
|
228
|
+
subscores: np.ndarray[float]
|
|
229
|
+
N array of subscores based on provided criteria (flattened N subcriteria).
|
|
230
|
+
means: np.ndarray[float]
|
|
231
|
+
K array of means for each model subscriterion.
|
|
232
|
+
vars: np.ndarray[float]
|
|
233
|
+
K array of variances for each model subscriterion.
|
|
234
|
+
vars (np.ndarray): decoded array of variances
|
|
235
|
+
"""
|
|
236
|
+
if header is None:
|
|
237
|
+
header = next(data)
|
|
238
|
+
if header[0].isnumeric():
|
|
239
|
+
raise ValueError(
|
|
240
|
+
"Expected first row in data to be header of 'step','sample_index',..."
|
|
241
|
+
)
|
|
242
|
+
score_start_index = subscore_start_index = pred_start_index = len(header)
|
|
243
|
+
# first start indices
|
|
244
|
+
for i, col_name in enumerate(header):
|
|
245
|
+
if col_name.startswith("score"):
|
|
246
|
+
score_start_index = i
|
|
247
|
+
break
|
|
248
|
+
for i, col_name in enumerate(header[score_start_index:]):
|
|
249
|
+
if col_name.endswith("score"):
|
|
250
|
+
subscore_start_index = score_start_index + i
|
|
251
|
+
break
|
|
252
|
+
for i, col_name in enumerate(header[subscore_start_index:]):
|
|
253
|
+
if col_name.endswith("y_mu"):
|
|
254
|
+
pred_start_index = subscore_start_index + i
|
|
255
|
+
break
|
|
256
|
+
for row in data:
|
|
257
|
+
yield decode_design_result(
|
|
258
|
+
row=row,
|
|
259
|
+
score_start_index=score_start_index,
|
|
260
|
+
subscore_start_index=subscore_start_index,
|
|
261
|
+
pred_start_index=pred_start_index,
|
|
262
|
+
)
|
|
@@ -3,13 +3,14 @@ import random
|
|
|
3
3
|
from typing import Iterator
|
|
4
4
|
|
|
5
5
|
import numpy as np
|
|
6
|
-
from openprotein.api.align import csv_stream
|
|
7
6
|
from openprotein.base import APISession
|
|
7
|
+
from openprotein.csv import csv_stream
|
|
8
8
|
from openprotein.errors import InvalidParameterError
|
|
9
9
|
from openprotein.schemas import (
|
|
10
10
|
AttnJob,
|
|
11
11
|
EmbeddingsJob,
|
|
12
12
|
GenerateJob,
|
|
13
|
+
JobType,
|
|
13
14
|
LogitsJob,
|
|
14
15
|
ModelMetadata,
|
|
15
16
|
ScoreJob,
|
|
@@ -44,7 +45,9 @@ def get_model(session: APISession, model_id: str) -> ModelMetadata:
|
|
|
44
45
|
return ModelMetadata(**result)
|
|
45
46
|
|
|
46
47
|
|
|
47
|
-
def get_request_sequences(
|
|
48
|
+
def get_request_sequences(
|
|
49
|
+
session: APISession, job_id: str, job_type: JobType = JobType.embeddings_embed
|
|
50
|
+
) -> list[bytes]:
|
|
48
51
|
"""
|
|
49
52
|
Get results associated with the given request ID.
|
|
50
53
|
|
|
@@ -59,13 +62,18 @@ def get_request_sequences(session: APISession, job_id: str) -> list[bytes]:
|
|
|
59
62
|
-------
|
|
60
63
|
sequences : List[bytes]
|
|
61
64
|
"""
|
|
62
|
-
|
|
65
|
+
# NOTE - allow to handle svd/embed and umap/embed directly too instead of redirect
|
|
66
|
+
path = "v1" + job_type.value
|
|
67
|
+
endpoint = path + f"/{job_id}/sequences"
|
|
63
68
|
response = session.get(endpoint)
|
|
64
69
|
return TypeAdapter(list[bytes]).validate_python(response.json())
|
|
65
70
|
|
|
66
71
|
|
|
67
72
|
def request_get_sequence_result(
|
|
68
|
-
session: APISession,
|
|
73
|
+
session: APISession,
|
|
74
|
+
job_id: str,
|
|
75
|
+
sequence: str | bytes,
|
|
76
|
+
job_type: JobType = JobType.embeddings_embed,
|
|
69
77
|
) -> bytes:
|
|
70
78
|
"""
|
|
71
79
|
Get encoded result for a sequence from the request ID.
|
|
@@ -83,9 +91,11 @@ def request_get_sequence_result(
|
|
|
83
91
|
-------
|
|
84
92
|
result : bytes
|
|
85
93
|
"""
|
|
94
|
+
# NOTE - allow to handle svd/embed and umap/embed directly too instead of redirect
|
|
95
|
+
path = "v1" + job_type.value
|
|
86
96
|
if isinstance(sequence, bytes):
|
|
87
97
|
sequence = sequence.decode()
|
|
88
|
-
endpoint =
|
|
98
|
+
endpoint = path + f"/{job_id}/{sequence}"
|
|
89
99
|
response = session.get(endpoint)
|
|
90
100
|
return response.content
|
|
91
101
|
|
|
@@ -52,6 +52,7 @@ def jobs_list(
|
|
|
52
52
|
job_type: str | None = None,
|
|
53
53
|
assay_id: str | None = None,
|
|
54
54
|
more_recent_than: str | None = None,
|
|
55
|
+
limit: int | None = None,
|
|
55
56
|
) -> List[Job]:
|
|
56
57
|
"""
|
|
57
58
|
Retrieve a list of jobs filtered by specific criteria.
|
|
@@ -85,6 +86,8 @@ def jobs_list(
|
|
|
85
86
|
params["assay_id"] = assay_id
|
|
86
87
|
if more_recent_than is not None:
|
|
87
88
|
params["more_recent_than"] = more_recent_than
|
|
89
|
+
if limit is not None:
|
|
90
|
+
params["limit"] = limit
|
|
88
91
|
|
|
89
92
|
response = session.get(endpoint, params=params)
|
|
90
93
|
# return jobs, not futures
|