This API uses ESM-2, a state-of-the-art transformer model trained on millions of protein sequences, to predict how much a mutation "changes" a protein's biological representation. It is designed to help researchers quickly screen the impact of amino acid substitutions.
When you send a protein sequence to this API, it doesn't just look at the letters; it understands the "context" of the amino acids.
- Embedding: The model converts the protein sequence into a high-dimensional numerical map (an embedding).
- Comparison: It compares the map of your Wild Type (original) protein to the map of your Mutant protein.
- Impact Score: It calculates the "distance" between these two maps. A higher score suggests a more significant structural or functional change.
You will need Python 3.9 or higher.
pip install fastapi uvicorn torch transformers numpy
Save the code as main.py and run:
uvicorn main:app --port 8000
The API has one main endpoint: /api/cosine-impact-batch. It is built to handle multiple mutants at once for faster processing.
You can test the API directly from your terminal using the following command:
curl -X POST "http://localhost:8000/api/cosine-impact-batch" \
-H "Content-Type: application/json" \
-d '{
"wild_seq": "MQIFVKTLTGKTITLEVE",
"mutant_seqs": [
"MQIFVKTLTGKTITLEVA",
"MQIFVKTLTGKTITLEVW"
]
}'
The API returns an array showing each mutant and its calculated "Impact" score:
[
{
"mutant": "MQIFVKTLTGKTITLEVA",
"impact": 0.1245
},
{
"mutant": "MQIFVKTLTGKTITLEVW",
"impact": 0.4892
}
]
- Low Impact (e.g., < 0.15): The mutation is likely "conservative." The new amino acid has similar properties to the old one.
- High Impact (e.g., > 0.40): The mutation is "radical." Replacing a small amino acid with a bulky or charged one often results in a higher score, indicating a potentially significant functional shift. The highest score is expected by changing the first amino acid, which is usually Methionine(M), to another amino acid.
- Model:
ESM-2 (8M parameters)— Light enough to run on a standard CPU. - Framework: FastAPI and PyTorch.
- CORS: Pre-configured for local development and Vercel deployments.