Skip to content

Commit

Permalink
Change pred and simil endpoints input params to pass 2 list of subjec…
Browse files Browse the repository at this point in the history
…ts/objects to predict
  • Loading branch information
vemonet committed Oct 16, 2023
1 parent 3e719b7 commit af04eb7
Show file tree
Hide file tree
Showing 19 changed files with 298 additions and 207 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/data
trapi-predict-kit/

/models/*
!/models/*.mlem
Expand Down
43 changes: 1 addition & 42 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,48 +110,7 @@ If you make changes to the data in the `data` folder you will need to add and pu
## 📝 Integrate new prediction models

The `openpredict` library provides a decorator `@trapi_predict` to annotate your functions that generate predictions.

Predictions generated from functions decorated with `@trapi_predict` can easily be imported in the Translator OpenPredict API, exposed as an API endpoint to get predictions from the web, and queried through the Translator Reasoner API (TRAPI)

```python
from trapi_predict_kit import trapi_predict, PredictOptions, PredictOutput

@trapi_predict(path='/predict',
name="Get predicted targets for a given entity",
description="Return the predicted targets for a given entity: drug (DrugBank ID) or disease (OMIM ID), with confidence scores.",
relations=[
{
'subject': 'biolink:Drug',
'predicate': 'biolink:treats',
'object': 'biolink:Disease',
},
{
'subject': 'biolink:Disease',
'predicate': 'biolink:treated_by',
'object': 'biolink:Drug',
},
]
)
def get_predictions(
input_id: str, options: PredictOptions
) -> PredictOutput:
# Add the code the load the model and get predictions here
predictions = {
"hits": [
{
"id": "DB00001",
"type": "biolink:Drug",
"score": 0.12345,
"label": "Leipirudin",
}
],
"count": 1,
}
return predictions
```

You can use [our cookiecutter template](https://github.com/MaastrichtU-IDS/cookiecutter-openpredict-api/) to quickly bootstrap a repository with everything ready to start developing your prediction models, to then easily publish and integrate them in the Translator ecosystem
Checkout the [documentation of the `trapi-predict-kit` library](https://maastrichtu-ids.github.io/trapi-predict-kit/getting-started/expose-model) to add new predictions models.

## 📬 Pull Request process

Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ENV MODULE_NAME=trapi.main
ENV VARIABLE_NAME=app

RUN pip install -e ".[train,test]"
RUN pip install -e ./trapi-predict-kit

RUN dvc pull -f

Expand All @@ -55,8 +56,10 @@ EXPOSE 8808
# Build entrypoint script to pull latest dvc changes before startup
RUN echo "#!/bin/bash" > /entrypoint.sh && \
echo "dvc pull" >> /entrypoint.sh && \
# echo "pip install -e ." >> /entrypoint.sh && \
echo "/start.sh" >> /entrypoint.sh && \
chmod +x /entrypoint.sh


CMD [ "/entrypoint.sh" ]
# CMD [ "/entrypoint.sh" ]
CMD [ "uvicorn", "trapi.main:app", "--debug", "--reload"]
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ services:
environment:
PYTHONUNBUFFERED: '1'
LOG_LEVEL: 'INFO'
# entrypoint: pytest --cov=src tests/integration
entrypoint: pytest tests/integration/test_openpredict_api.py
entrypoint: pytest --cov=src tests/integration
# entrypoint: pytest tests/integration/test_train_model.py -s
# entrypoint: pytest tests/integration/test_openpredict_api.py::test_post_trapi -s
# entrypoint: pytest tests/package/test_decorator.py -s

Expand Down
14 changes: 7 additions & 7 deletions models/openpredict_baseline.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,27 @@

<https://w3id.org/openpredict/openpredict_baseline/accuracy> a mls:EvaluationMeasure ;
rdfs:label "accuracy" ;
mls:hasValue 8.66941e-01 .
mls:hasValue 8.704152e-01 .

<https://w3id.org/openpredict/openpredict_baseline/average_precision> a mls:EvaluationMeasure ;
rdfs:label "average_precision" ;
mls:hasValue 8.514183e-01 .
mls:hasValue 8.660077e-01 .

<https://w3id.org/openpredict/openpredict_baseline/f1> a mls:EvaluationMeasure ;
rdfs:label "f1" ;
mls:hasValue 7.813454e-01 .
mls:hasValue 7.87334e-01 .

<https://w3id.org/openpredict/openpredict_baseline/precision> a mls:EvaluationMeasure ;
rdfs:label "precision" ;
mls:hasValue 8.627594e-01 .
mls:hasValue 8.68504e-01 .

<https://w3id.org/openpredict/openpredict_baseline/recall> a mls:EvaluationMeasure ;
rdfs:label "recall" ;
mls:hasValue 7.144006e-01 .
mls:hasValue 7.201709e-01 .

<https://w3id.org/openpredict/openpredict_baseline/roc_auc> a mls:EvaluationMeasure ;
rdfs:label "roc_auc" ;
mls:hasValue 8.924977e-01 .
mls:hasValue 8.990311e-01 .

<https://w3id.org/openpredict/run/openpredict_baseline> a mls:Run ;
dc:identifier "openpredict_baseline" ;
Expand All @@ -95,7 +95,7 @@
mls:hasOutput <https://w3id.org/openpredict/openpredict_baseline/Model>,
<https://w3id.org/openpredict/run/openpredict_baseline/ModelEvaluation> ;
mls:realizes openpredict:LogisticRegression ;
prov:generatedAtTime "2022-12-14T13:05:44.989115"^^xsd:dateTime .
prov:generatedAtTime "2023-10-16T10:01:01.382159"^^xsd:dateTime .

<https://w3id.org/openpredict/run/openpredict_baseline/ModelEvaluation> a mls:ModelEvaluation,
prov:Entity ;
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dynamic = ["version"]
dependencies = [
"requests >=2.23.0",
"trapi-predict-kit @ git+https://github.com/MaastrichtU-IDS/trapi-predict-kit.git",
# "trapi-predict-kit @ {root:uri}/../trapi-predict-kit",
# "trapi-predict-kit @ {root:uri}/trapi-predict-kit",

"pydantic >=1.9",
"fastapi >=0.68.1",
Expand Down
Loading

0 comments on commit af04eb7

Please sign in to comment.