Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict Boltz sequence length to 1000 #15

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions ginkgo_ai_client/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ class PromoterActivityQuery(QueryBase):
The name of the query. It will appear in the API response and can be used to
handle exceptions.
inference_framework: Literal["promoter-0"] = "promoter-0"
The inference framework to use for the inference. Currently only supports
The inference framework to use for the inference. Currently only supports
borzoi_model: Literal["human-fold0"] = "human-fold0"
The model to use for the inference. Currently only supports the trained
The model to use for the inference. Currently only supports the trained
model of "human-fold0".
Returns
-------
Expand Down Expand Up @@ -511,6 +511,11 @@ class _Protein(pydantic.BaseModel):

@pydantic.validator("sequence")
def validate_sequence(cls, sequence):
if len(sequence) > 1000:
raise ValueError(
f"We currently only accept sequences of length 1000 or less for Boltz "
f"structure prediction (length: {len(sequence)})"
)
sequence = sequence.upper()
invalid_chars = [c for c in sequence if c not in "LAGVSERTIDPKQNFYMHWCXBUZO"]
if len(invalid_chars) > 0:
Expand Down Expand Up @@ -579,10 +584,14 @@ def download_structure(self, path: str):
class BoltzStructurePredictionQuery(QueryBase):
"""A query to predict the structure of a protein using the Boltz model.

This type of query is better constructed using the `from_yaml_file` or
`from_protein_sequence` methods.

Parameters
----------
sequences: List[Dict[Literal["protein", "ligand"], Union[_Protein, _CCD, _Smiles]]]
The sequences to predict the structure for
The sequences to predict the structure for.
Only protein sequences of size <1000aa are supported for now.
model: Literal["boltz"] = "boltz"
The model to use for the inference (only Boltz(1) is supported for now).
query_name: Optional[str] = None
Expand Down
8 changes: 8 additions & 0 deletions test/test_query_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ def test_boltz_structure_prediction_query_from_protein_sequence():
query = BoltzStructurePredictionQuery.from_protein_sequence(sequence="MLLKP")
sequences = query.model_dump(exclude_none=True)["sequences"]
assert sequences == [{"protein": {"id": "A", "sequence": "MLLKP"}}]


def test_boltz_structure_prediction_query_fails_on_sequence_too_long():
expected_error_message = re.escape(
"We currently only accept sequences of length 1000 or less"
)
with pytest.raises(ValueError, match=expected_error_message):
BoltzStructurePredictionQuery.from_protein_sequence(sequence=1100 * "A")
Loading