openprotein-python 0.4.3__py3-none-any.whl → 0.5.0.dev0__py3-none-any.whl
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/__init__.py +40 -17
- openprotein/api/__init__.py +2 -7
- openprotein/api/align.py +68 -496
- openprotein/api/assaydata.py +216 -0
- openprotein/api/deprecated/__init__.py +0 -0
- openprotein/api/deprecated/poet.py +304 -0
- openprotein/api/design.py +7 -433
- openprotein/api/embedding.py +155 -999
- openprotein/api/fold.py +26 -319
- openprotein/api/job.py +91 -0
- openprotein/api/predict.py +25 -381
- openprotein/api/predictor.py +205 -0
- openprotein/api/svd.py +150 -0
- openprotein/api/train.py +42 -481
- openprotein/app/__init__.py +11 -0
- openprotein/app/models/__init__.py +20 -0
- openprotein/app/models/align/__init__.py +5 -0
- openprotein/app/models/align/base.py +20 -0
- openprotein/app/models/align/msa.py +140 -0
- openprotein/app/models/align/prompt.py +83 -0
- openprotein/app/models/assaydata.py +176 -0
- openprotein/app/models/deprecated/__init__.py +0 -0
- openprotein/app/models/deprecated/poet.py +183 -0
- openprotein/app/models/design.py +102 -0
- openprotein/app/models/embeddings/__init__.py +7 -0
- openprotein/app/models/embeddings/base.py +269 -0
- openprotein/app/models/embeddings/esm.py +32 -0
- openprotein/app/models/embeddings/future.py +98 -0
- openprotein/app/models/embeddings/openprotein.py +21 -0
- openprotein/app/models/embeddings/poet.py +393 -0
- openprotein/app/models/embeddings/test.py +38 -0
- openprotein/app/models/fold/__init__.py +6 -0
- openprotein/app/models/fold/alphafold2.py +50 -0
- openprotein/app/models/fold/base.py +81 -0
- openprotein/app/models/fold/esmfold.py +31 -0
- openprotein/app/models/fold/future.py +53 -0
- openprotein/app/models/futures.py +445 -0
- openprotein/app/models/predict.py +158 -0
- openprotein/app/models/predictor/__init__.py +4 -0
- openprotein/app/models/predictor/predict.py +78 -0
- openprotein/app/models/predictor/predictor.py +141 -0
- openprotein/app/models/svd.py +171 -0
- openprotein/app/models/train.py +300 -0
- openprotein/app/services/__init__.py +11 -0
- openprotein/app/services/align.py +147 -0
- openprotein/app/services/assaydata.py +127 -0
- openprotein/app/services/design.py +77 -0
- openprotein/app/services/embeddings.py +126 -0
- openprotein/app/services/fold.py +89 -0
- openprotein/app/services/job.py +48 -0
- openprotein/app/services/predict.py +139 -0
- openprotein/app/services/predictor.py +168 -0
- openprotein/app/services/svd.py +102 -0
- openprotein/app/services/train.py +135 -0
- openprotein/config.py +0 -3
- openprotein/errors.py +22 -5
- openprotein/schemas/__init__.py +59 -0
- openprotein/schemas/align.py +55 -0
- openprotein/schemas/assaydata.py +27 -0
- openprotein/schemas/deprecated/__init__.py +0 -0
- openprotein/schemas/deprecated/poet.py +70 -0
- openprotein/schemas/design.py +251 -0
- openprotein/schemas/embeddings.py +103 -0
- openprotein/schemas/fold.py +10 -0
- openprotein/schemas/job.py +110 -0
- openprotein/schemas/predict.py +83 -0
- openprotein/schemas/predictor.py +83 -0
- openprotein/schemas/svd.py +32 -0
- openprotein/schemas/train.py +34 -0
- {openprotein_python-0.4.3.dist-info → openprotein_python-0.5.0.dev0.dist-info}/METADATA +19 -14
- openprotein_python-0.5.0.dev0.dist-info/RECORD +76 -0
- {openprotein_python-0.4.3.dist-info → openprotein_python-0.5.0.dev0.dist-info}/WHEEL +1 -1
- openprotein/api/data.py +0 -532
- openprotein/api/jobs.py +0 -351
- openprotein/api/poet.py +0 -612
- openprotein/futures.py +0 -60
- openprotein/jobs.py +0 -186
- openprotein/pydantic.py +0 -20
- openprotein/schemas.py +0 -55
- openprotein_python-0.4.3.dist-info/RECORD +0 -24
- {openprotein_python-0.4.3.dist-info → openprotein_python-0.5.0.dev0.dist-info/licenses}/LICENSE.txt +0 -0
openprotein/api/align.py
CHANGED
|
@@ -1,87 +1,17 @@
|
|
|
1
|
-
from typing import Iterator, Optional, List, BinaryIO, Literal, Union
|
|
2
|
-
from openprotein.pydantic import BaseModel, Field, validator, root_validator
|
|
3
|
-
from enum import Enum
|
|
4
|
-
from io import BytesIO
|
|
5
|
-
import random
|
|
6
|
-
import csv
|
|
7
1
|
import codecs
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
from
|
|
12
|
-
AsyncJobFuture,
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
from openprotein.jobs import (
|
|
16
|
-
ResultsParser,
|
|
17
|
-
Job,
|
|
18
|
-
register_job_type,
|
|
19
|
-
JobType,
|
|
20
|
-
job_args_get,
|
|
21
|
-
)
|
|
2
|
+
import csv
|
|
3
|
+
import io
|
|
4
|
+
import random
|
|
5
|
+
from typing import BinaryIO, Iterator
|
|
22
6
|
|
|
23
7
|
import openprotein.config as config
|
|
24
|
-
|
|
25
|
-
from openprotein.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
APIError,
|
|
29
|
-
)
|
|
30
|
-
from openprotein.futures import FutureBase, FutureFactory
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class PoetInputType(str, Enum):
|
|
34
|
-
INPUT = "RAW"
|
|
35
|
-
MSA = "GENERATED"
|
|
36
|
-
PROMPT = "PROMPT"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class MSASamplingMethod(str, Enum):
|
|
40
|
-
RANDOM = "RANDOM"
|
|
41
|
-
NEIGHBORS = "NEIGHBORS"
|
|
42
|
-
NEIGHBORS_NO_LIMIT = "NEIGHBORS_NO_LIMIT"
|
|
43
|
-
NEIGHBORS_NONGAP_NORM_NO_LIMIT = "NEIGHBORS_NONGAP_NORM_NO_LIMIT"
|
|
44
|
-
TOP = "TOP"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
class PromptPostParams(BaseModel):
|
|
48
|
-
msa_id: str
|
|
49
|
-
num_sequences: Optional[int] = Field(None, ge=0, lt=100)
|
|
50
|
-
num_residues: Optional[int] = Field(None, ge=0, lt=24577)
|
|
51
|
-
method: MSASamplingMethod = MSASamplingMethod.NEIGHBORS_NONGAP_NORM_NO_LIMIT
|
|
52
|
-
homology_level: float = Field(0.8, ge=0, le=1)
|
|
53
|
-
max_similarity: float = Field(1.0, ge=0, le=1)
|
|
54
|
-
min_similarity: float = Field(0.0, ge=0, le=1)
|
|
55
|
-
always_include_seed_sequence: bool = False
|
|
56
|
-
num_ensemble_prompts: int = 1
|
|
57
|
-
random_seed: Optional[int] = None
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
@register_job_type(JobType.align_align)
|
|
61
|
-
class MSAJob(Job):
|
|
62
|
-
msa_id: Optional[str] = None
|
|
63
|
-
job_type: Literal[JobType.align_align] = JobType.align_align
|
|
64
|
-
|
|
65
|
-
@root_validator
|
|
66
|
-
def set_msa_id(cls, values):
|
|
67
|
-
if not values.get("msa_id"):
|
|
68
|
-
values["msa_id"] = values.get("job_id")
|
|
69
|
-
return values
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
@register_job_type(JobType.align_prompt)
|
|
73
|
-
class PromptJob(MSAJob):
|
|
74
|
-
prompt_id: Optional[str] = None
|
|
75
|
-
job_type: Literal[JobType.align_prompt] = JobType.align_prompt
|
|
76
|
-
|
|
77
|
-
@root_validator
|
|
78
|
-
def set_prompt_id(cls, values):
|
|
79
|
-
if not values.get("prompt_id"):
|
|
80
|
-
values["prompt_id"] = values.get("job_id")
|
|
81
|
-
return values
|
|
8
|
+
import requests
|
|
9
|
+
from openprotein.base import APISession
|
|
10
|
+
from openprotein.errors import APIError, InvalidParameterError, MissingParameterError
|
|
11
|
+
from openprotein.schemas import Job, MSASamplingMethod, PoetInputType
|
|
82
12
|
|
|
83
13
|
|
|
84
|
-
def csv_stream(response: requests.Response) ->
|
|
14
|
+
def csv_stream(response: requests.Response) -> Iterator[list[str]]:
|
|
85
15
|
"""
|
|
86
16
|
Returns a CSV reader from a requests.Response object.
|
|
87
17
|
|
|
@@ -104,9 +34,9 @@ def csv_stream(response: requests.Response) -> csv.reader:
|
|
|
104
34
|
|
|
105
35
|
def get_align_job_inputs(
|
|
106
36
|
session: APISession,
|
|
107
|
-
job_id,
|
|
37
|
+
job_id: str,
|
|
108
38
|
input_type: PoetInputType,
|
|
109
|
-
prompt_index:
|
|
39
|
+
prompt_index: int | None = None,
|
|
110
40
|
) -> requests.Response:
|
|
111
41
|
"""
|
|
112
42
|
Get MSA and related data for an align job.
|
|
@@ -142,17 +72,17 @@ def get_align_job_inputs(
|
|
|
142
72
|
|
|
143
73
|
|
|
144
74
|
def get_input(
|
|
145
|
-
|
|
75
|
+
session: APISession,
|
|
146
76
|
job: Job,
|
|
147
77
|
input_type: PoetInputType,
|
|
148
|
-
prompt_index:
|
|
149
|
-
) ->
|
|
78
|
+
prompt_index: int | None = None,
|
|
79
|
+
) -> Iterator[list[str]]:
|
|
150
80
|
"""
|
|
151
81
|
Get input data for a given job.
|
|
152
82
|
|
|
153
83
|
Parameters
|
|
154
84
|
----------
|
|
155
|
-
|
|
85
|
+
session : APISession
|
|
156
86
|
The API session.
|
|
157
87
|
job : Job
|
|
158
88
|
The job for which to retrieve data.
|
|
@@ -167,19 +97,21 @@ def get_input(
|
|
|
167
97
|
A CSV reader for the response data.
|
|
168
98
|
"""
|
|
169
99
|
job_id = job.job_id
|
|
170
|
-
response = get_align_job_inputs(
|
|
100
|
+
response = get_align_job_inputs(
|
|
101
|
+
session=session, job_id=job_id, input_type=input_type, prompt_index=prompt_index
|
|
102
|
+
)
|
|
171
103
|
return csv_stream(response)
|
|
172
104
|
|
|
173
105
|
|
|
174
106
|
def get_prompt(
|
|
175
|
-
|
|
176
|
-
) ->
|
|
107
|
+
session: APISession, job: Job, prompt_index: int | None = None
|
|
108
|
+
) -> Iterator[list[str]]:
|
|
177
109
|
"""
|
|
178
110
|
Get the prompt for a given job.
|
|
179
111
|
|
|
180
112
|
Parameters
|
|
181
113
|
----------
|
|
182
|
-
|
|
114
|
+
session : APISession
|
|
183
115
|
The API session.
|
|
184
116
|
job : Job
|
|
185
117
|
The job for which to retrieve the prompt.
|
|
@@ -188,51 +120,60 @@ def get_prompt(
|
|
|
188
120
|
|
|
189
121
|
Returns
|
|
190
122
|
-------
|
|
191
|
-
|
|
123
|
+
Iterator[list[str]]
|
|
192
124
|
A CSV reader for the prompt data.
|
|
193
125
|
"""
|
|
194
|
-
return get_input(
|
|
126
|
+
return get_input(
|
|
127
|
+
session=session,
|
|
128
|
+
job=job,
|
|
129
|
+
input_type=PoetInputType.PROMPT,
|
|
130
|
+
prompt_index=prompt_index,
|
|
131
|
+
)
|
|
195
132
|
|
|
196
133
|
|
|
197
|
-
def get_seed(
|
|
134
|
+
def get_seed(session: APISession, job: Job) -> Iterator[list[str]]:
|
|
198
135
|
"""
|
|
199
136
|
Get the seed for a given MSA job.
|
|
200
137
|
|
|
201
138
|
Parameters
|
|
202
139
|
----------
|
|
203
|
-
|
|
140
|
+
session : APISession
|
|
204
141
|
The API session.
|
|
205
142
|
job : Job
|
|
206
143
|
The job for which to retrieve the seed.
|
|
207
144
|
|
|
208
145
|
Returns
|
|
209
146
|
-------
|
|
210
|
-
|
|
147
|
+
Iterator[list[str]]
|
|
211
148
|
A CSV reader for the seed sequence.
|
|
212
149
|
"""
|
|
213
|
-
return get_input(
|
|
150
|
+
return get_input(session=session, job=job, input_type=PoetInputType.INPUT)
|
|
214
151
|
|
|
215
152
|
|
|
216
|
-
def get_msa(
|
|
153
|
+
def get_msa(session: APISession, job: Job) -> Iterator[list[str]]:
|
|
217
154
|
"""
|
|
218
155
|
Get the generated MSA (Multiple Sequence Alignment) for a given job.
|
|
219
156
|
|
|
220
157
|
Parameters
|
|
221
158
|
----------
|
|
222
|
-
|
|
159
|
+
session : APISession
|
|
223
160
|
The API session.
|
|
224
161
|
job : Job
|
|
225
162
|
The job for which to retrieve the MSA.
|
|
226
163
|
|
|
227
164
|
Returns
|
|
228
165
|
-------
|
|
229
|
-
|
|
166
|
+
Iterator[list[str]]
|
|
230
167
|
A CSV reader for the MSA data.
|
|
231
168
|
"""
|
|
232
|
-
return get_input(
|
|
169
|
+
return get_input(session=session, job=job, input_type=PoetInputType.MSA)
|
|
233
170
|
|
|
234
171
|
|
|
235
|
-
def msa_post(
|
|
172
|
+
def msa_post(
|
|
173
|
+
session: APISession,
|
|
174
|
+
msa_file: BinaryIO | None = None,
|
|
175
|
+
seed: str | bytes | None = None,
|
|
176
|
+
) -> Job:
|
|
236
177
|
"""
|
|
237
178
|
Create an MSA.
|
|
238
179
|
|
|
@@ -243,11 +184,11 @@ def msa_post(session: APISession, msa_file=None, seed=None):
|
|
|
243
184
|
Parameters
|
|
244
185
|
----------
|
|
245
186
|
session : APISession
|
|
246
|
-
|
|
247
|
-
msa_file :
|
|
248
|
-
Ready-made MSA. Defaults to None.
|
|
249
|
-
seed : str, optional
|
|
250
|
-
Seed to trigger MSA job. Defaults to None.
|
|
187
|
+
|
|
188
|
+
msa_file : BinaryIO, Optional
|
|
189
|
+
Ready-made MSA file. Defaults to None.
|
|
190
|
+
seed : str | bytes, optional
|
|
191
|
+
Seed sequence to trigger MSA job. Defaults to None.
|
|
251
192
|
|
|
252
193
|
Raises
|
|
253
194
|
------
|
|
@@ -256,7 +197,7 @@ def msa_post(session: APISession, msa_file=None, seed=None):
|
|
|
256
197
|
|
|
257
198
|
Returns
|
|
258
199
|
-------
|
|
259
|
-
|
|
200
|
+
Job
|
|
260
201
|
Job details.
|
|
261
202
|
"""
|
|
262
203
|
if (msa_file is None and seed is None) or (
|
|
@@ -267,29 +208,30 @@ def msa_post(session: APISession, msa_file=None, seed=None):
|
|
|
267
208
|
|
|
268
209
|
is_seed = False
|
|
269
210
|
if seed is not None:
|
|
270
|
-
|
|
211
|
+
seed = seed.encode() if isinstance(seed, str) else seed
|
|
212
|
+
msa_file = io.BytesIO(b"\n".join([b">seed", seed]))
|
|
271
213
|
is_seed = True
|
|
272
214
|
|
|
273
215
|
params = {"is_seed": is_seed}
|
|
274
216
|
files = {"msa_file": msa_file}
|
|
275
217
|
|
|
276
218
|
response = session.post(endpoint, files=files, params=params)
|
|
277
|
-
return
|
|
219
|
+
return Job.model_validate(response.json())
|
|
278
220
|
|
|
279
221
|
|
|
280
222
|
def prompt_post(
|
|
281
223
|
session: APISession,
|
|
282
224
|
msa_id: str,
|
|
283
|
-
num_sequences:
|
|
284
|
-
num_residues:
|
|
225
|
+
num_sequences: int | None = None,
|
|
226
|
+
num_residues: int | None = None,
|
|
285
227
|
method: MSASamplingMethod = MSASamplingMethod.NEIGHBORS_NONGAP_NORM_NO_LIMIT,
|
|
286
228
|
homology_level: float = 0.8,
|
|
287
229
|
max_similarity: float = 1.0,
|
|
288
230
|
min_similarity: float = 0.0,
|
|
289
231
|
always_include_seed_sequence: bool = False,
|
|
290
232
|
num_ensemble_prompts: int = 1,
|
|
291
|
-
random_seed:
|
|
292
|
-
) ->
|
|
233
|
+
random_seed: int | None = None,
|
|
234
|
+
) -> Job:
|
|
293
235
|
"""
|
|
294
236
|
Create a protein sequence prompt from a linked MSA (Multiple Sequence Alignment) for PoET Jobs.
|
|
295
237
|
|
|
@@ -329,7 +271,7 @@ def prompt_post(
|
|
|
329
271
|
|
|
330
272
|
Returns
|
|
331
273
|
-------
|
|
332
|
-
|
|
274
|
+
Job
|
|
333
275
|
"""
|
|
334
276
|
endpoint = "v1/align/prompt"
|
|
335
277
|
|
|
@@ -375,7 +317,7 @@ def prompt_post(
|
|
|
375
317
|
params["max_msa_tokens"] = num_residues
|
|
376
318
|
|
|
377
319
|
response = session.post(endpoint, params=params)
|
|
378
|
-
return
|
|
320
|
+
return Job.model_validate(response.json())
|
|
379
321
|
|
|
380
322
|
|
|
381
323
|
def upload_prompt_post(
|
|
@@ -402,7 +344,7 @@ def upload_prompt_post(
|
|
|
402
344
|
|
|
403
345
|
Returns
|
|
404
346
|
-------
|
|
405
|
-
|
|
347
|
+
Job
|
|
406
348
|
An object representing the status and results of the prompt job.
|
|
407
349
|
"""
|
|
408
350
|
|
|
@@ -410,12 +352,14 @@ def upload_prompt_post(
|
|
|
410
352
|
files = {"prompt_file": prompt_file}
|
|
411
353
|
try:
|
|
412
354
|
response = session.post(endpoint, files=files)
|
|
413
|
-
return
|
|
355
|
+
return Job.model_validate(response.json())
|
|
414
356
|
except Exception as exc:
|
|
415
357
|
raise APIError(f"Failed to upload prompt post: {exc}") from exc
|
|
416
358
|
|
|
417
359
|
|
|
418
|
-
def poet_score_post(
|
|
360
|
+
def poet_score_post(
|
|
361
|
+
session: APISession, prompt_id: str, queries: list[bytes | str]
|
|
362
|
+
) -> Job:
|
|
419
363
|
"""
|
|
420
364
|
Submits a job to score sequences based on the given prompt.
|
|
421
365
|
|
|
@@ -435,7 +379,7 @@ def poet_score_post(session: APISession, prompt_id: str, queries: List[bytes]):
|
|
|
435
379
|
|
|
436
380
|
Returns
|
|
437
381
|
-------
|
|
438
|
-
|
|
382
|
+
Job
|
|
439
383
|
An object representing the status and results of the scoring job.
|
|
440
384
|
"""
|
|
441
385
|
endpoint = "v1/poet/score"
|
|
@@ -445,22 +389,21 @@ def poet_score_post(session: APISession, prompt_id: str, queries: List[bytes]):
|
|
|
445
389
|
if not prompt_id:
|
|
446
390
|
raise MissingParameterError("Must include prompt_id in request!")
|
|
447
391
|
|
|
448
|
-
if isinstance(
|
|
449
|
-
queries = [i.encode() for i in queries]
|
|
392
|
+
queries_bytes = [i.encode() if isinstance(i, str) else i for i in queries]
|
|
450
393
|
try:
|
|
451
|
-
variant_file = BytesIO(b"\n".join(
|
|
394
|
+
variant_file = io.BytesIO(b"\n".join(queries_bytes))
|
|
452
395
|
params = {"prompt_id": prompt_id}
|
|
453
396
|
response = session.post(
|
|
454
397
|
endpoint, files={"variant_file": variant_file}, params=params
|
|
455
398
|
)
|
|
456
|
-
return
|
|
399
|
+
return Job.model_validate(response.json())
|
|
457
400
|
except Exception as exc:
|
|
458
401
|
raise APIError(f"Failed to post poet score: {exc}") from exc
|
|
459
402
|
|
|
460
403
|
|
|
461
404
|
def poet_score_get(
|
|
462
405
|
session: APISession, job_id, page_size=config.POET_PAGE_SIZE, page_offset=0
|
|
463
|
-
):
|
|
406
|
+
) -> Job:
|
|
464
407
|
"""
|
|
465
408
|
Fetch a page of results from a PoET score job.
|
|
466
409
|
|
|
@@ -482,7 +425,7 @@ def poet_score_get(
|
|
|
482
425
|
|
|
483
426
|
Returns
|
|
484
427
|
-------
|
|
485
|
-
|
|
428
|
+
Job
|
|
486
429
|
An object representing the PoET scoring job, including its current status and results (if any).
|
|
487
430
|
"""
|
|
488
431
|
endpoint = "v1/poet/score"
|
|
@@ -497,375 +440,4 @@ def poet_score_get(
|
|
|
497
440
|
params={"job_id": job_id, "page_size": page_size, "page_offset": page_offset},
|
|
498
441
|
)
|
|
499
442
|
|
|
500
|
-
return
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
class AlignFutureMixin:
|
|
504
|
-
session: APISession
|
|
505
|
-
job: Job
|
|
506
|
-
|
|
507
|
-
def get_input(self, input_type: PoetInputType):
|
|
508
|
-
"""See child function docs."""
|
|
509
|
-
return get_input(self.session, self.job, input_type)
|
|
510
|
-
|
|
511
|
-
def get_prompt(self, prompt_index: Optional[int] = None):
|
|
512
|
-
"""See child function docs."""
|
|
513
|
-
return get_prompt(self.session, self.job, prompt_index=prompt_index)
|
|
514
|
-
|
|
515
|
-
def get_seed(self):
|
|
516
|
-
"""See child function docs."""
|
|
517
|
-
return get_seed(self.session, self.job)
|
|
518
|
-
|
|
519
|
-
def get_msa(self):
|
|
520
|
-
"""See child function docs."""
|
|
521
|
-
return get_msa(self.session, self.job)
|
|
522
|
-
|
|
523
|
-
@property
|
|
524
|
-
def id(self):
|
|
525
|
-
return self.job.job_id
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
class MSAFuture(AlignFutureMixin, AsyncJobFuture, FutureBase):
|
|
529
|
-
"""
|
|
530
|
-
Represents a result of a MSA job.
|
|
531
|
-
|
|
532
|
-
Attributes
|
|
533
|
-
----------
|
|
534
|
-
session : APISession
|
|
535
|
-
An instance of APISession for API interactions.
|
|
536
|
-
job : Job
|
|
537
|
-
The PoET scoring job.
|
|
538
|
-
page_size : int
|
|
539
|
-
The number of results to fetch in a single page.
|
|
540
|
-
|
|
541
|
-
Methods
|
|
542
|
-
-------
|
|
543
|
-
get(verbose=False)
|
|
544
|
-
Get the final results of the PoET scoring job.
|
|
545
|
-
|
|
546
|
-
Returns
|
|
547
|
-
-------
|
|
548
|
-
List[PoetScoreResult]
|
|
549
|
-
The list of results from the PoET scoring job.
|
|
550
|
-
"""
|
|
551
|
-
|
|
552
|
-
job_type = "/align/align"
|
|
553
|
-
|
|
554
|
-
def __init__(self, session: APISession, job: Job, page_size=config.POET_PAGE_SIZE):
|
|
555
|
-
"""
|
|
556
|
-
init a PoetScoreFuture instance.
|
|
557
|
-
|
|
558
|
-
Parameters
|
|
559
|
-
----------
|
|
560
|
-
session : APISession
|
|
561
|
-
An instance of APISession for API interactions.
|
|
562
|
-
job : Job
|
|
563
|
-
The PoET scoring job.
|
|
564
|
-
page_size : int
|
|
565
|
-
The number of results to fetch in a single page.
|
|
566
|
-
|
|
567
|
-
"""
|
|
568
|
-
super().__init__(session, job)
|
|
569
|
-
self.page_size = page_size
|
|
570
|
-
self._msa_id = None
|
|
571
|
-
self._prompt_id = None
|
|
572
|
-
|
|
573
|
-
def __str__(self) -> str:
|
|
574
|
-
return str(self.job)
|
|
575
|
-
|
|
576
|
-
def __repr__(self) -> str:
|
|
577
|
-
return repr(self.job)
|
|
578
|
-
|
|
579
|
-
@property
|
|
580
|
-
def id(self):
|
|
581
|
-
return self.job.job_id
|
|
582
|
-
|
|
583
|
-
@property
|
|
584
|
-
def prompt_id(self):
|
|
585
|
-
if self.job.job_type == "/align/prompt" and self._prompt_id is None:
|
|
586
|
-
self._prompt_id = self.job.job_id
|
|
587
|
-
return self._prompt_id
|
|
588
|
-
|
|
589
|
-
@property
|
|
590
|
-
def msa_id(self):
|
|
591
|
-
if self.job.job_type == "/align/align" and self._msa_id is None:
|
|
592
|
-
self._msa_id = self.job.job_id
|
|
593
|
-
return self._msa_id
|
|
594
|
-
|
|
595
|
-
def wait(self, verbose: bool = False):
|
|
596
|
-
_ = self.job.wait(
|
|
597
|
-
self.session,
|
|
598
|
-
interval=config.POLLING_INTERVAL,
|
|
599
|
-
timeout=config.POLLING_TIMEOUT,
|
|
600
|
-
verbose=False,
|
|
601
|
-
) # no progress to track
|
|
602
|
-
return self.get()
|
|
603
|
-
|
|
604
|
-
def get(self, verbose: bool = False) -> csv.reader:
|
|
605
|
-
return self.get_msa()
|
|
606
|
-
|
|
607
|
-
def sample_prompt(
|
|
608
|
-
self,
|
|
609
|
-
num_sequences: Optional[int] = None,
|
|
610
|
-
num_residues: Optional[int] = None,
|
|
611
|
-
method: MSASamplingMethod = MSASamplingMethod.NEIGHBORS_NONGAP_NORM_NO_LIMIT,
|
|
612
|
-
homology_level: float = 0.8,
|
|
613
|
-
max_similarity: float = 1.0,
|
|
614
|
-
min_similarity: float = 0.0,
|
|
615
|
-
always_include_seed_sequence: bool = False,
|
|
616
|
-
num_ensemble_prompts: int = 1,
|
|
617
|
-
random_seed: Optional[int] = None,
|
|
618
|
-
) -> PromptJob:
|
|
619
|
-
"""
|
|
620
|
-
Create a protein sequence prompt from a linked MSA (Multiple Sequence Alignment) for PoET Jobs.
|
|
621
|
-
|
|
622
|
-
Parameters
|
|
623
|
-
----------
|
|
624
|
-
num_sequences : int, optional
|
|
625
|
-
Maximum number of sequences in the prompt. Must be <100.
|
|
626
|
-
num_residues : int, optional
|
|
627
|
-
Maximum number of residues (tokens) in the prompt. Must be less than 24577.
|
|
628
|
-
method : MSASamplingMethod, optional
|
|
629
|
-
Method to use for MSA sampling. Defaults to NEIGHBORS_NONGAP_NORM_NO_LIMIT.
|
|
630
|
-
homology_level : float, optional
|
|
631
|
-
Level of homology for sequences in the MSA (neighbors methods only). Must be between 0 and 1. Defaults to 0.8.
|
|
632
|
-
max_similarity : float, optional
|
|
633
|
-
Maximum similarity between sequences in the MSA and the seed. Must be between 0 and 1. Defaults to 1.0.
|
|
634
|
-
min_similarity : float, optional
|
|
635
|
-
Minimum similarity between sequences in the MSA and the seed. Must be between 0 and 1. Defaults to 0.0.
|
|
636
|
-
always_include_seed_sequence : bool, optional
|
|
637
|
-
Whether to always include the seed sequence in the MSA. Defaults to False.
|
|
638
|
-
num_ensemble_prompts : int, optional
|
|
639
|
-
Number of ensemble jobs to run. Defaults to 1.
|
|
640
|
-
random_seed : int, optional
|
|
641
|
-
Seed for random number generation. Defaults to a random number between 0 and 2**32-1.
|
|
642
|
-
|
|
643
|
-
Raises
|
|
644
|
-
------
|
|
645
|
-
InvalidParameterError
|
|
646
|
-
If provided parameter values are not in the allowed range.
|
|
647
|
-
MissingParameterError
|
|
648
|
-
If both or none of 'num_sequences', 'num_residues' is specified.
|
|
649
|
-
|
|
650
|
-
Returns
|
|
651
|
-
-------
|
|
652
|
-
PromptJob
|
|
653
|
-
"""
|
|
654
|
-
msa_id = self.msa_id
|
|
655
|
-
return prompt_post(
|
|
656
|
-
self.session,
|
|
657
|
-
msa_id,
|
|
658
|
-
num_sequences=num_sequences,
|
|
659
|
-
num_residues=num_residues,
|
|
660
|
-
method=method,
|
|
661
|
-
homology_level=homology_level,
|
|
662
|
-
max_similarity=max_similarity,
|
|
663
|
-
min_similarity=min_similarity,
|
|
664
|
-
always_include_seed_sequence=always_include_seed_sequence,
|
|
665
|
-
num_ensemble_prompts=num_ensemble_prompts,
|
|
666
|
-
random_seed=random_seed,
|
|
667
|
-
)
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
class PromptFuture(MSAFuture, FutureBase):
|
|
671
|
-
"""
|
|
672
|
-
Represents a result of a prompt job.
|
|
673
|
-
|
|
674
|
-
Attributes
|
|
675
|
-
----------
|
|
676
|
-
session : APISession
|
|
677
|
-
An instance of APISession for API interactions.
|
|
678
|
-
job : Job
|
|
679
|
-
The PoET scoring job.
|
|
680
|
-
page_size : int
|
|
681
|
-
The number of results to fetch in a single page.
|
|
682
|
-
|
|
683
|
-
Methods
|
|
684
|
-
-------
|
|
685
|
-
get(verbose=False)
|
|
686
|
-
Get the final results of the PoET scoring job.
|
|
687
|
-
|
|
688
|
-
Returns
|
|
689
|
-
-------
|
|
690
|
-
List[PoetScoreResult]
|
|
691
|
-
The list of results from the PoET scoring job.
|
|
692
|
-
"""
|
|
693
|
-
|
|
694
|
-
job_type = "/align/prompt"
|
|
695
|
-
|
|
696
|
-
def __init__(
|
|
697
|
-
self,
|
|
698
|
-
session: APISession,
|
|
699
|
-
job: Job,
|
|
700
|
-
page_size=config.POET_PAGE_SIZE,
|
|
701
|
-
msa_id: Optional[str] = None,
|
|
702
|
-
):
|
|
703
|
-
"""
|
|
704
|
-
init a PoetScoreFuture instance.
|
|
705
|
-
|
|
706
|
-
Parameters
|
|
707
|
-
----------
|
|
708
|
-
session (APISession): An instance of APISession for API interactions.
|
|
709
|
-
job (Job): The PoET scoring job.
|
|
710
|
-
page_size (int, optional): The number of results to fetch in a single page. Defaults to config.POET_PAGE_SIZE.
|
|
711
|
-
|
|
712
|
-
"""
|
|
713
|
-
super().__init__(session, job)
|
|
714
|
-
self.page_size = page_size
|
|
715
|
-
|
|
716
|
-
if msa_id is None:
|
|
717
|
-
msa_id = job_args_get(self.session, job.job_id).get("root_msa")
|
|
718
|
-
self._msa_id = msa_id
|
|
719
|
-
|
|
720
|
-
def get(self, verbose: bool = False) -> csv.reader:
|
|
721
|
-
return self.get_prompt()
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
Prompt = Union[PromptFuture, str]
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
def validate_prompt(prompt: Prompt):
|
|
728
|
-
"""helper function to validate prompt_id is prompt type"""
|
|
729
|
-
if not (isinstance(prompt, PromptFuture) or isinstance(prompt, str)):
|
|
730
|
-
raise ValueError(
|
|
731
|
-
f"Expect prompt to be either a PromptFuture or str, got {type(prompt)}"
|
|
732
|
-
)
|
|
733
|
-
if isinstance(prompt, str):
|
|
734
|
-
return prompt
|
|
735
|
-
return prompt.prompt_id
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
def validate_msa(msa: Union[MSAFuture, str]):
|
|
739
|
-
"""helper function to validate prompt_id is prompt type"""
|
|
740
|
-
if not (isinstance(msa, MSAFuture) or isinstance(msa, str)):
|
|
741
|
-
raise ValueError(
|
|
742
|
-
f"Expect prompt to be either a MSAFuture or str, got {type(msa)}"
|
|
743
|
-
)
|
|
744
|
-
if isinstance(msa, str):
|
|
745
|
-
return msa
|
|
746
|
-
return msa.msa_id
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
class AlignAPI:
|
|
750
|
-
"""API interface for calling Poet and Align endpoints"""
|
|
751
|
-
|
|
752
|
-
def __init__(self, session: APISession):
|
|
753
|
-
self.session = session
|
|
754
|
-
|
|
755
|
-
def upload_msa(self, msa_file) -> MSAFuture:
|
|
756
|
-
"""
|
|
757
|
-
Upload an MSA from file.
|
|
758
|
-
|
|
759
|
-
Parameters
|
|
760
|
-
----------
|
|
761
|
-
msa_file : str, optional
|
|
762
|
-
Ready-made MSA. If not provided, default value is None.
|
|
763
|
-
|
|
764
|
-
Raises
|
|
765
|
-
------
|
|
766
|
-
APIError
|
|
767
|
-
If there is an issue with the API request.
|
|
768
|
-
|
|
769
|
-
Returns
|
|
770
|
-
-------
|
|
771
|
-
MSAJob
|
|
772
|
-
Job object containing the details of the MSA upload.
|
|
773
|
-
"""
|
|
774
|
-
return msa_post(self.session, msa_file=msa_file)
|
|
775
|
-
|
|
776
|
-
def create_msa(self, seed: bytes) -> MSAFuture:
|
|
777
|
-
"""
|
|
778
|
-
Construct an MSA via homology search with the seed sequence.
|
|
779
|
-
|
|
780
|
-
Parameters
|
|
781
|
-
----------
|
|
782
|
-
seed : bytes
|
|
783
|
-
Seed sequence for the MSA construction.
|
|
784
|
-
|
|
785
|
-
Raises
|
|
786
|
-
------
|
|
787
|
-
APIError
|
|
788
|
-
If there is an issue with the API request.
|
|
789
|
-
|
|
790
|
-
Returns
|
|
791
|
-
-------
|
|
792
|
-
MSAJob
|
|
793
|
-
Job object containing the details of the MSA construction.
|
|
794
|
-
"""
|
|
795
|
-
return msa_post(self.session, seed=seed)
|
|
796
|
-
|
|
797
|
-
def upload_prompt(self, prompt_file: BinaryIO) -> Job:
|
|
798
|
-
"""
|
|
799
|
-
Directly upload a prompt.
|
|
800
|
-
|
|
801
|
-
Bypass post_msa and prompt_post steps entirely. In this case PoET will use the prompt as is.
|
|
802
|
-
You can specify multiple prompts (one per replicate) with an <END_PROMPT> and newline between CSVs.
|
|
803
|
-
|
|
804
|
-
Parameters
|
|
805
|
-
----------
|
|
806
|
-
prompt_file : BinaryIO
|
|
807
|
-
Binary I/O object representing the prompt file.
|
|
808
|
-
|
|
809
|
-
Raises
|
|
810
|
-
------
|
|
811
|
-
APIError
|
|
812
|
-
If there is an issue with the API request.
|
|
813
|
-
|
|
814
|
-
Returns
|
|
815
|
-
-------
|
|
816
|
-
PromptJob
|
|
817
|
-
An object representing the status and results of the prompt job.
|
|
818
|
-
"""
|
|
819
|
-
return upload_prompt_post(self.session, prompt_file)
|
|
820
|
-
|
|
821
|
-
def get_prompt(self, job: Job, prompt_index: Optional[int] = None) -> csv.reader:
|
|
822
|
-
"""
|
|
823
|
-
Get prompts for a given job.
|
|
824
|
-
|
|
825
|
-
Parameters
|
|
826
|
-
----------
|
|
827
|
-
job : Job
|
|
828
|
-
The job for which to retrieve data.
|
|
829
|
-
prompt_index : Optional[int]
|
|
830
|
-
The replicate number for the prompt (input_type=-PROMPT only)
|
|
831
|
-
|
|
832
|
-
Returns
|
|
833
|
-
-------
|
|
834
|
-
csv.reader
|
|
835
|
-
A CSV reader for the response data.
|
|
836
|
-
"""
|
|
837
|
-
return get_input(
|
|
838
|
-
self.session, job, PoetInputType.PROMPT, prompt_index=prompt_index
|
|
839
|
-
)
|
|
840
|
-
|
|
841
|
-
def get_seed(self, job: Job) -> csv.reader:
|
|
842
|
-
"""
|
|
843
|
-
Get input data for a given msa job.
|
|
844
|
-
|
|
845
|
-
Parameters
|
|
846
|
-
----------
|
|
847
|
-
job : Job
|
|
848
|
-
The job for which to retrieve data.
|
|
849
|
-
|
|
850
|
-
Returns
|
|
851
|
-
-------
|
|
852
|
-
csv.reader
|
|
853
|
-
A CSV reader for the response data.
|
|
854
|
-
"""
|
|
855
|
-
return get_input(self.session, job, PoetInputType.INPUT)
|
|
856
|
-
|
|
857
|
-
def get_msa(self, job: Job) -> csv.reader:
|
|
858
|
-
"""
|
|
859
|
-
Get generated MSA for a given job.
|
|
860
|
-
|
|
861
|
-
Parameters
|
|
862
|
-
----------
|
|
863
|
-
job : Job
|
|
864
|
-
The job for which to retrieve data.
|
|
865
|
-
|
|
866
|
-
Returns
|
|
867
|
-
-------
|
|
868
|
-
csv.reader
|
|
869
|
-
A CSV reader for the response data.
|
|
870
|
-
"""
|
|
871
|
-
return get_input(self.session, job, PoetInputType.MSA)
|
|
443
|
+
return Job.model_validate(response.json())
|