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/train.py
CHANGED
|
@@ -1,48 +1,9 @@
|
|
|
1
|
-
from typing import Optional, List, Union
|
|
2
|
-
from openprotein.pydantic import BaseModel
|
|
3
|
-
|
|
4
|
-
import openprotein.pydantic as pydantic
|
|
5
1
|
from openprotein.base import APISession
|
|
6
|
-
from openprotein.
|
|
7
|
-
from openprotein.
|
|
8
|
-
|
|
9
|
-
from openprotein.errors import InvalidParameterError, APIError, InvalidJob
|
|
10
|
-
from openprotein.api.data import AssayDataset, AssayMetadata
|
|
11
|
-
from openprotein.jobs import JobType
|
|
12
|
-
from openprotein.api.predict import PredictService, PredictFuture
|
|
13
|
-
from datetime import datetime
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class CVItem(BaseModel):
|
|
17
|
-
row_index: int
|
|
18
|
-
sequence: str
|
|
19
|
-
measurement_name: str
|
|
20
|
-
y: float
|
|
21
|
-
y_mu: float
|
|
22
|
-
y_var: float
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
class CVResults(Job):
|
|
26
|
-
num_rows: int
|
|
27
|
-
page_size: int
|
|
28
|
-
page_offset: int
|
|
29
|
-
result: List[CVItem]
|
|
2
|
+
from openprotein.errors import InvalidJob
|
|
3
|
+
from openprotein.schemas import Job, WorkflowCVJob, WorkflowTrainJob
|
|
30
4
|
|
|
31
5
|
|
|
32
|
-
|
|
33
|
-
step: int
|
|
34
|
-
loss: float
|
|
35
|
-
tag: str
|
|
36
|
-
tags: dict
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class TrainGraph(BaseModel):
|
|
40
|
-
traingraph: List[TrainStep]
|
|
41
|
-
created_date: datetime
|
|
42
|
-
job_id: str
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
def list_models(session: APISession, job_id: str) -> List:
|
|
6
|
+
def list_models(session: APISession, job_id: str) -> list:
|
|
46
7
|
"""
|
|
47
8
|
List models assoicated with job
|
|
48
9
|
|
|
@@ -79,15 +40,15 @@ def crossvalidate(session: APISession, train_job_id: str, n_splits: int = 5) ->
|
|
|
79
40
|
response = session.post(
|
|
80
41
|
endpoint, json={"train_job_id": train_job_id, "n_splits": n_splits}
|
|
81
42
|
)
|
|
82
|
-
return
|
|
43
|
+
return Job.model_validate(response.json())
|
|
83
44
|
|
|
84
45
|
|
|
85
46
|
def get_crossvalidation(
|
|
86
47
|
session: APISession,
|
|
87
48
|
job_id: str,
|
|
88
|
-
page_size:
|
|
89
|
-
page_offset:
|
|
90
|
-
) ->
|
|
49
|
+
page_size: int | None = None,
|
|
50
|
+
page_offset: int | None = 0,
|
|
51
|
+
) -> WorkflowCVJob:
|
|
91
52
|
"""
|
|
92
53
|
Get CV results
|
|
93
54
|
|
|
@@ -103,16 +64,16 @@ def get_crossvalidation(
|
|
|
103
64
|
response = session.get(endpoint, params=params)
|
|
104
65
|
if response.status_code == 404:
|
|
105
66
|
raise InvalidJob("No CV job has been submitted for this job!")
|
|
106
|
-
return
|
|
67
|
+
return WorkflowCVJob.model_validate(response.json())
|
|
107
68
|
|
|
108
69
|
|
|
109
70
|
def _train_job(
|
|
110
71
|
session: APISession,
|
|
111
72
|
endpoint: str,
|
|
112
|
-
|
|
113
|
-
measurement_name:
|
|
73
|
+
assay_id: str,
|
|
74
|
+
measurement_name: str | list[str],
|
|
114
75
|
model_name: str = "",
|
|
115
|
-
force_preprocess:
|
|
76
|
+
force_preprocess: bool = False,
|
|
116
77
|
) -> Job:
|
|
117
78
|
"""
|
|
118
79
|
Create a training job.
|
|
@@ -150,37 +111,24 @@ def _train_job(
|
|
|
150
111
|
HTTPError
|
|
151
112
|
If the request to the server fails.
|
|
152
113
|
"""
|
|
153
|
-
if not isinstance(assaydataset, AssayDataset):
|
|
154
|
-
raise InvalidParameterError("assaydataset should be an assaydata Job result")
|
|
155
|
-
if isinstance(measurement_name, str):
|
|
156
|
-
measurement_name = [measurement_name]
|
|
157
|
-
|
|
158
|
-
for measurement in measurement_name:
|
|
159
|
-
if measurement not in assaydataset.measurement_names:
|
|
160
|
-
raise InvalidParameterError(f"No {measurement} in measurement names")
|
|
161
|
-
if assaydataset.shape[0] < 3:
|
|
162
|
-
raise InvalidParameterError("Assaydata must have >=3 data points for training!")
|
|
163
|
-
if model_name is None:
|
|
164
|
-
model_name = ""
|
|
165
114
|
|
|
166
115
|
data = {
|
|
167
|
-
"assay_id":
|
|
116
|
+
"assay_id": assay_id,
|
|
168
117
|
"measurement_name": measurement_name,
|
|
169
118
|
"model_name": model_name,
|
|
170
119
|
}
|
|
171
120
|
params = {"force_preprocess": str(force_preprocess).lower()}
|
|
172
121
|
|
|
173
122
|
response = session.post(endpoint, params=params, json=data)
|
|
174
|
-
response.
|
|
175
|
-
return FutureFactory.create_future(session=session, response=response)
|
|
123
|
+
return Job.model_validate(response.json())
|
|
176
124
|
|
|
177
125
|
|
|
178
126
|
def create_train_job(
|
|
179
127
|
session: APISession,
|
|
180
|
-
|
|
181
|
-
measurement_name:
|
|
128
|
+
assay_id: str,
|
|
129
|
+
measurement_name: str | list[str],
|
|
182
130
|
model_name: str = "",
|
|
183
|
-
force_preprocess:
|
|
131
|
+
force_preprocess: bool = False,
|
|
184
132
|
):
|
|
185
133
|
"""
|
|
186
134
|
Create a training job.
|
|
@@ -220,442 +168,55 @@ def create_train_job(
|
|
|
220
168
|
"""
|
|
221
169
|
endpoint = "v1/workflow/train"
|
|
222
170
|
return _train_job(
|
|
223
|
-
session,
|
|
171
|
+
session=session,
|
|
172
|
+
endpoint=endpoint,
|
|
173
|
+
assay_id=assay_id,
|
|
174
|
+
measurement_name=measurement_name,
|
|
175
|
+
model_name=model_name,
|
|
176
|
+
force_preprocess=force_preprocess,
|
|
224
177
|
)
|
|
225
178
|
|
|
226
179
|
|
|
227
180
|
def _create_train_job_br(
|
|
228
181
|
session: APISession,
|
|
229
|
-
|
|
230
|
-
measurement_name:
|
|
182
|
+
assay_id: str,
|
|
183
|
+
measurement_name: str | list[str],
|
|
231
184
|
model_name: str = "",
|
|
232
|
-
force_preprocess:
|
|
185
|
+
force_preprocess: bool = False,
|
|
233
186
|
):
|
|
234
187
|
"""Alias for create_train_job"""
|
|
235
188
|
endpoint = "v1/workflow/train/br"
|
|
236
189
|
return _train_job(
|
|
237
|
-
session,
|
|
190
|
+
session=session,
|
|
191
|
+
endpoint=endpoint,
|
|
192
|
+
assay_id=assay_id,
|
|
193
|
+
measurement_name=measurement_name,
|
|
194
|
+
model_name=model_name,
|
|
195
|
+
force_preprocess=force_preprocess,
|
|
238
196
|
)
|
|
239
197
|
|
|
240
198
|
|
|
241
199
|
def _create_train_job_gp(
|
|
242
200
|
session: APISession,
|
|
243
|
-
|
|
244
|
-
measurement_name:
|
|
201
|
+
assay_id: str,
|
|
202
|
+
measurement_name: str | list[str],
|
|
245
203
|
model_name: str = "",
|
|
246
|
-
force_preprocess:
|
|
204
|
+
force_preprocess: bool = False,
|
|
247
205
|
):
|
|
248
206
|
"""Alias for create_train_job"""
|
|
249
207
|
endpoint = "v1/workflow/train/gp"
|
|
250
208
|
return _train_job(
|
|
251
|
-
session,
|
|
209
|
+
session=session,
|
|
210
|
+
endpoint=endpoint,
|
|
211
|
+
assay_id=assay_id,
|
|
212
|
+
measurement_name=measurement_name,
|
|
213
|
+
model_name=model_name,
|
|
214
|
+
force_preprocess=force_preprocess,
|
|
252
215
|
)
|
|
253
216
|
|
|
254
217
|
|
|
255
|
-
def get_training_results(session: APISession, job_id: str) ->
|
|
218
|
+
def get_training_results(session: APISession, job_id: str) -> WorkflowTrainJob:
|
|
256
219
|
"""Get Training results (e.g. loss etc) of job."""
|
|
257
220
|
endpoint = f"v1/workflow/train/{job_id}"
|
|
258
221
|
response = session.get(endpoint)
|
|
259
|
-
return
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
class CVFutureMixin:
|
|
263
|
-
"""
|
|
264
|
-
A mixin class to provide cross-validation job submission and retrieval.
|
|
265
|
-
|
|
266
|
-
Attributes
|
|
267
|
-
----------
|
|
268
|
-
session : APISession
|
|
269
|
-
The session object to use for API communication.
|
|
270
|
-
train_job_id : str
|
|
271
|
-
The id of the training job associated with this cross-validation job.
|
|
272
|
-
job : Job
|
|
273
|
-
The Job object for this cross-validation job.
|
|
274
|
-
|
|
275
|
-
Methods
|
|
276
|
-
-------
|
|
277
|
-
crossvalidate():
|
|
278
|
-
Submits a cross-validation job to the server.
|
|
279
|
-
get_crossvalidation(page_size: Optional[int] = None, page_offset: Optional[int] = 0):
|
|
280
|
-
Retrieves the results of the cross-validation job.
|
|
281
|
-
"""
|
|
282
|
-
|
|
283
|
-
session: APISession
|
|
284
|
-
train_job_id: str
|
|
285
|
-
job: Job
|
|
286
|
-
|
|
287
|
-
def crossvalidate(self):
|
|
288
|
-
"""
|
|
289
|
-
Submit a cross-validation job to the server.
|
|
290
|
-
|
|
291
|
-
Returns
|
|
292
|
-
-------
|
|
293
|
-
Job
|
|
294
|
-
The Job object for this cross-validation job.
|
|
295
|
-
|
|
296
|
-
"""
|
|
297
|
-
self.job = crossvalidate(self.session, self.train_job_id)
|
|
298
|
-
return self.job
|
|
299
|
-
|
|
300
|
-
def get_crossvalidation(
|
|
301
|
-
self, page_size: Optional[int] = None, page_offset: Optional[int] = 0
|
|
302
|
-
):
|
|
303
|
-
"""
|
|
304
|
-
Retrieves the results of the cross-validation job.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
Parameters
|
|
308
|
-
----------
|
|
309
|
-
page_size : int, optional
|
|
310
|
-
The number of items to retrieve in a single request..
|
|
311
|
-
page_offset : int, optional
|
|
312
|
-
The offset to start retrieving items from. Default is 0.
|
|
313
|
-
|
|
314
|
-
Returns
|
|
315
|
-
-------
|
|
316
|
-
dict
|
|
317
|
-
The results of the cross-validation job.
|
|
318
|
-
|
|
319
|
-
"""
|
|
320
|
-
return get_crossvalidation(
|
|
321
|
-
self.session, self.job.job_id, page_size, page_offset
|
|
322
|
-
)
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
class CVFuture(CVFutureMixin, AsyncJobFuture, FutureBase):
|
|
326
|
-
"""
|
|
327
|
-
This class helps initiating, submitting, and retrieving the
|
|
328
|
-
results of a cross-validation job.
|
|
329
|
-
|
|
330
|
-
Attributes
|
|
331
|
-
----------
|
|
332
|
-
session : APISession
|
|
333
|
-
The session object to use for API communication.
|
|
334
|
-
train_job_id : str
|
|
335
|
-
The id of the training job associated with this cross-validation job.
|
|
336
|
-
job : Job
|
|
337
|
-
The Job object for this cross-validation job.
|
|
338
|
-
page_size : int
|
|
339
|
-
The number of items to retrieve in a single request.
|
|
340
|
-
|
|
341
|
-
"""
|
|
342
|
-
|
|
343
|
-
job_type = [JobType.workflow_crossvalidate]
|
|
344
|
-
|
|
345
|
-
def __init__(self, session: APISession, train_job_id: str, job: Job = None):
|
|
346
|
-
"""
|
|
347
|
-
Constructs a new CVFuture instance.
|
|
348
|
-
|
|
349
|
-
Parameters
|
|
350
|
-
----------
|
|
351
|
-
session : APISession
|
|
352
|
-
The session object to use for API communication.
|
|
353
|
-
train_job_id : str
|
|
354
|
-
The id of the training job associated with this cross-validation job.
|
|
355
|
-
job : Job, optional
|
|
356
|
-
The Job object for this cross-validation job.
|
|
357
|
-
"""
|
|
358
|
-
super().__init__(session, job)
|
|
359
|
-
self.train_job_id = train_job_id
|
|
360
|
-
self.page_size = 1000
|
|
361
|
-
|
|
362
|
-
def __str__(self) -> str:
|
|
363
|
-
return str(self.job)
|
|
364
|
-
|
|
365
|
-
def __repr__(self) -> str:
|
|
366
|
-
return repr(self.job)
|
|
367
|
-
|
|
368
|
-
@property
|
|
369
|
-
def id(self):
|
|
370
|
-
return self.job.job_id
|
|
371
|
-
|
|
372
|
-
def _fmt_results(self, results):
|
|
373
|
-
return [i.dict() for i in results]
|
|
374
|
-
|
|
375
|
-
def get(self, verbose: bool = False) -> List:
|
|
376
|
-
"""
|
|
377
|
-
Get all the results of the CV job.
|
|
378
|
-
|
|
379
|
-
Args:
|
|
380
|
-
verbose (bool, optional): If True, print verbose output. Defaults False.
|
|
381
|
-
|
|
382
|
-
Raises:
|
|
383
|
-
APIError: If there is an issue with the API request.
|
|
384
|
-
|
|
385
|
-
Returns:
|
|
386
|
-
PredictJob: A list of predict objects representing the results.
|
|
387
|
-
"""
|
|
388
|
-
step = self.page_size
|
|
389
|
-
|
|
390
|
-
results = []
|
|
391
|
-
num_returned = step
|
|
392
|
-
offset = 0
|
|
393
|
-
|
|
394
|
-
while num_returned >= step:
|
|
395
|
-
try:
|
|
396
|
-
response = self.get_crossvalidation(page_offset=offset, page_size=step)
|
|
397
|
-
results += response.result
|
|
398
|
-
num_returned = len(response.result)
|
|
399
|
-
offset += num_returned
|
|
400
|
-
except APIError as exc:
|
|
401
|
-
if verbose:
|
|
402
|
-
print(f"Failed to get results: {exc}")
|
|
403
|
-
return self._fmt_results(results)
|
|
404
|
-
return self._fmt_results(results)
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
class TrainFutureMixin:
|
|
408
|
-
"""
|
|
409
|
-
This class provides functionality for retrieving the
|
|
410
|
-
results of a training job and initiating cross-validation jobs.
|
|
411
|
-
|
|
412
|
-
Attributes
|
|
413
|
-
----------
|
|
414
|
-
session : APISession
|
|
415
|
-
The session object to use for API communication.
|
|
416
|
-
job : Job
|
|
417
|
-
The Job object for this training job.
|
|
418
|
-
|
|
419
|
-
Methods
|
|
420
|
-
-------
|
|
421
|
-
get_results() -> TrainGraph:
|
|
422
|
-
Returns the results of the training job.
|
|
423
|
-
crossvalidate():
|
|
424
|
-
Submits a cross-validation job and returns it.
|
|
425
|
-
"""
|
|
426
|
-
|
|
427
|
-
session: APISession
|
|
428
|
-
job: Job
|
|
429
|
-
|
|
430
|
-
def _fmt_results(self, results):
|
|
431
|
-
train_dict = {}
|
|
432
|
-
tags = set([i.tag for i in results.traingraph])
|
|
433
|
-
for tag in tags:
|
|
434
|
-
train_dict[tag] = [
|
|
435
|
-
i.loss for i in results.traingraph if i.dict()["tag"] == tag
|
|
436
|
-
]
|
|
437
|
-
return train_dict
|
|
438
|
-
|
|
439
|
-
def get_results(self) -> TrainGraph:
|
|
440
|
-
"""
|
|
441
|
-
Gets the results of the training job.
|
|
442
|
-
|
|
443
|
-
Returns
|
|
444
|
-
-------
|
|
445
|
-
TrainGraph
|
|
446
|
-
The results of the training job.
|
|
447
|
-
"""
|
|
448
|
-
results = get_training_results(self.session, self.job.job_id)
|
|
449
|
-
return self._fmt_results(results)
|
|
450
|
-
|
|
451
|
-
def crossvalidate(self):
|
|
452
|
-
"""
|
|
453
|
-
Submits a cross-validation job.
|
|
454
|
-
|
|
455
|
-
If a cross-validation job has already been created, it returns that job.
|
|
456
|
-
Otherwise, it creates a new cross-validation job and returns it.
|
|
457
|
-
|
|
458
|
-
Returns
|
|
459
|
-
-------
|
|
460
|
-
CVFuture
|
|
461
|
-
The cross-validation job associated with this training job.
|
|
462
|
-
"""
|
|
463
|
-
cv = CVFuture(self.session, train_job_id=self.job.job_id)
|
|
464
|
-
job = cv.crossvalidate() # noqa: F841
|
|
465
|
-
return cv
|
|
466
|
-
|
|
467
|
-
def list_models(self):
|
|
468
|
-
"""
|
|
469
|
-
List models assoicated with job
|
|
470
|
-
|
|
471
|
-
Parameters
|
|
472
|
-
----------
|
|
473
|
-
session : APISession
|
|
474
|
-
Session object for API communication.
|
|
475
|
-
job_id : str
|
|
476
|
-
job ID
|
|
477
|
-
|
|
478
|
-
Returns
|
|
479
|
-
-------
|
|
480
|
-
List
|
|
481
|
-
List of models
|
|
482
|
-
"""
|
|
483
|
-
return list_models(self.session, self.job.job_id)
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
class TrainFuture(TrainFutureMixin, AsyncJobFuture, FutureBase):
|
|
487
|
-
"""Future Job for manipulating results"""
|
|
488
|
-
|
|
489
|
-
job_type = [JobType.workflow_train]
|
|
490
|
-
|
|
491
|
-
def __init__(
|
|
492
|
-
self,
|
|
493
|
-
session: APISession,
|
|
494
|
-
job: Job,
|
|
495
|
-
assaymetadata: Optional[AssayMetadata] = None,
|
|
496
|
-
):
|
|
497
|
-
super().__init__(session, job)
|
|
498
|
-
self.assaymetadata = assaymetadata
|
|
499
|
-
self._predict = PredictService(session)
|
|
500
|
-
|
|
501
|
-
def predict(
|
|
502
|
-
self, sequences: List[str], model_ids: Optional[List[str]] = None
|
|
503
|
-
) -> PredictFuture:
|
|
504
|
-
"""
|
|
505
|
-
Creates a predict job based on the training job.
|
|
506
|
-
|
|
507
|
-
Parameters
|
|
508
|
-
----------
|
|
509
|
-
sequences : List[str]
|
|
510
|
-
The list of sequences to be used for the Predict job.
|
|
511
|
-
model_ids : List[str], optional
|
|
512
|
-
The list of model ids to be used for Predict. Default is None.
|
|
513
|
-
|
|
514
|
-
Returns
|
|
515
|
-
-------
|
|
516
|
-
PredictFuture
|
|
517
|
-
The job object representing the Predict job.
|
|
518
|
-
"""
|
|
519
|
-
return self._predict.create_predict_job(sequences, self, model_ids=model_ids)
|
|
520
|
-
|
|
521
|
-
def predict_single_site(
|
|
522
|
-
self,
|
|
523
|
-
sequence: str,
|
|
524
|
-
model_ids: Optional[List[str]] = None,
|
|
525
|
-
) -> PredictFuture:
|
|
526
|
-
"""
|
|
527
|
-
Creates a new Predict job for single site mutation analysis with a trained model.
|
|
528
|
-
|
|
529
|
-
Parameters
|
|
530
|
-
----------
|
|
531
|
-
sequence : str
|
|
532
|
-
The sequence for single site analysis.
|
|
533
|
-
train_job : Any
|
|
534
|
-
The train job object representing the trained model.
|
|
535
|
-
model_ids : List[str], optional
|
|
536
|
-
The list of model ids to be used for Predict. Default is None.
|
|
537
|
-
|
|
538
|
-
Returns
|
|
539
|
-
-------
|
|
540
|
-
PredictFuture
|
|
541
|
-
The job object representing the Predict job.
|
|
542
|
-
|
|
543
|
-
Creates a predict job based on the training job
|
|
544
|
-
"""
|
|
545
|
-
return self._predict.create_predict_single_site(
|
|
546
|
-
sequence, self, model_ids=model_ids
|
|
547
|
-
)
|
|
548
|
-
|
|
549
|
-
def __str__(self) -> str:
|
|
550
|
-
return str(self.job)
|
|
551
|
-
|
|
552
|
-
def __repr__(self) -> str:
|
|
553
|
-
return repr(self.job)
|
|
554
|
-
|
|
555
|
-
@property
|
|
556
|
-
def id(self):
|
|
557
|
-
return self.job.job_id
|
|
558
|
-
|
|
559
|
-
def get(self, verbose: bool = False) -> TrainGraph:
|
|
560
|
-
try:
|
|
561
|
-
results = self.get_results()
|
|
562
|
-
except APIError as exc:
|
|
563
|
-
if verbose:
|
|
564
|
-
print(f"Failed to get results: {exc}")
|
|
565
|
-
raise exc
|
|
566
|
-
return results
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
class TrainingAPI:
|
|
570
|
-
"""API interface for calling Train endpoints"""
|
|
571
|
-
|
|
572
|
-
def __init__(
|
|
573
|
-
self,
|
|
574
|
-
session: APISession,
|
|
575
|
-
):
|
|
576
|
-
self.session = session
|
|
577
|
-
self.assay = None
|
|
578
|
-
|
|
579
|
-
def create_training_job(
|
|
580
|
-
self,
|
|
581
|
-
assaydataset: AssayDataset,
|
|
582
|
-
measurement_name: Union[str, List[str]],
|
|
583
|
-
model_name: str = "",
|
|
584
|
-
force_preprocess: Optional[bool] = False,
|
|
585
|
-
) -> TrainFuture:
|
|
586
|
-
"""
|
|
587
|
-
Create a training job on your data.
|
|
588
|
-
|
|
589
|
-
This function validates the inputs, formats the data, and sends the job.
|
|
590
|
-
|
|
591
|
-
Parameters
|
|
592
|
-
----------
|
|
593
|
-
assaydataset : AssayDataset
|
|
594
|
-
An AssayDataset object from which the assay_id is extracted.
|
|
595
|
-
measurement_name : str or List[str]
|
|
596
|
-
The name(s) of the measurement(s) to be used in the training job.
|
|
597
|
-
model_name : str, optional
|
|
598
|
-
The name to give the model.
|
|
599
|
-
force_preprocess : bool, optional
|
|
600
|
-
If set to True, preprocessing is forced even if data already exists.
|
|
601
|
-
|
|
602
|
-
Returns
|
|
603
|
-
-------
|
|
604
|
-
TrainFuture
|
|
605
|
-
A TrainFuture Job
|
|
606
|
-
|
|
607
|
-
Raises
|
|
608
|
-
------
|
|
609
|
-
InvalidParameterError
|
|
610
|
-
If the `assaydataset` is not an AssayDataset object,
|
|
611
|
-
If any measurement name provided does not exist in the AssayDataset,
|
|
612
|
-
or if the AssayDataset has fewer than 3 data points.
|
|
613
|
-
HTTPError
|
|
614
|
-
If the request to the server fails.
|
|
615
|
-
"""
|
|
616
|
-
if isinstance(measurement_name, str):
|
|
617
|
-
measurement_name = [measurement_name]
|
|
618
|
-
return create_train_job(
|
|
619
|
-
self.session, assaydataset, measurement_name, model_name, force_preprocess
|
|
620
|
-
)
|
|
621
|
-
|
|
622
|
-
def _create_training_job_br(
|
|
623
|
-
self,
|
|
624
|
-
assaydataset: AssayDataset,
|
|
625
|
-
measurement_name: Union[str, List[str]],
|
|
626
|
-
model_name: str = "",
|
|
627
|
-
force_preprocess: Optional[bool] = False,
|
|
628
|
-
) -> TrainFuture:
|
|
629
|
-
"""Same as create_training_job."""
|
|
630
|
-
return _create_train_job_br(
|
|
631
|
-
self.session, assaydataset, measurement_name, model_name, force_preprocess
|
|
632
|
-
)
|
|
633
|
-
|
|
634
|
-
def _create_training_job_gp(
|
|
635
|
-
self,
|
|
636
|
-
assaydataset: AssayDataset,
|
|
637
|
-
measurement_name: Union[str, List[str]],
|
|
638
|
-
model_name: str = "",
|
|
639
|
-
force_preprocess: Optional[bool] = False,
|
|
640
|
-
) -> TrainFuture:
|
|
641
|
-
"""Same as create_training_job."""
|
|
642
|
-
return _create_train_job_gp(
|
|
643
|
-
self.session, assaydataset, measurement_name, model_name, force_preprocess
|
|
644
|
-
)
|
|
645
|
-
|
|
646
|
-
def get_training_results(self, job_id: str) -> TrainFuture:
|
|
647
|
-
"""
|
|
648
|
-
Get training results (e.g. loss etc).
|
|
649
|
-
|
|
650
|
-
Parameters
|
|
651
|
-
----------
|
|
652
|
-
job_id : str
|
|
653
|
-
job_id to get
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
Returns
|
|
657
|
-
-------
|
|
658
|
-
TrainFuture
|
|
659
|
-
A TrainFuture Job
|
|
660
|
-
"""
|
|
661
|
-
return get_training_results(self.session, job_id)
|
|
222
|
+
return WorkflowTrainJob.model_validate(response.json())
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""OpenProtein app-level models providing service-level functionality."""
|
|
2
|
+
|
|
3
|
+
from .align import MSAFuture, PromptFuture
|
|
4
|
+
from .assaydata import AssayDataPage, AssayDataset, AssayMetadata
|
|
5
|
+
from .deprecated.poet import PoetGenerateFuture, PoetScoreFuture, PoetSingleSiteFuture
|
|
6
|
+
from .design import DesignFuture
|
|
7
|
+
from .embeddings import (
|
|
8
|
+
EmbeddingModel,
|
|
9
|
+
EmbeddingResultFuture,
|
|
10
|
+
EmbeddingsScoreResultFuture,
|
|
11
|
+
ESMModel,
|
|
12
|
+
OpenProteinModel,
|
|
13
|
+
PoETModel,
|
|
14
|
+
)
|
|
15
|
+
from .fold import AlphaFold2Model, ESMFoldModel, FoldModel, FoldResultFuture
|
|
16
|
+
from .futures import Future, MappedFuture, StreamingFuture
|
|
17
|
+
from .predict import PredictFuture
|
|
18
|
+
from .predictor import PredictionResultFuture, PredictorModel
|
|
19
|
+
from .svd import SVDModel
|
|
20
|
+
from .train import CVFuture, TrainFuture
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from openprotein.api import align
|
|
2
|
+
from openprotein.base import APISession
|
|
3
|
+
from openprotein.schemas import Job, PoetInputType
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class AlignFuture:
|
|
7
|
+
session: APISession
|
|
8
|
+
job: Job
|
|
9
|
+
|
|
10
|
+
def get_input(self, input_type: PoetInputType):
|
|
11
|
+
"""See child function docs."""
|
|
12
|
+
return align.get_input(self.session, self.job, input_type)
|
|
13
|
+
|
|
14
|
+
def get_seed(self):
|
|
15
|
+
"""See child function docs."""
|
|
16
|
+
return align.get_seed(self.session, self.job)
|
|
17
|
+
|
|
18
|
+
@property
|
|
19
|
+
def id(self):
|
|
20
|
+
return self.job.job_id
|