Skip to content

Commit

Permalink
rename functions, e.g. build-models to train-model
Browse files Browse the repository at this point in the history
  • Loading branch information
vemonet committed Sep 8, 2020
1 parent 5b82381 commit 4e8208e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ Run the pipeline to train the model used by the OpenPredict API.
From a Python script:

```python
from openpredict.openpredict_omim_drugbank import build_drug_disease_classifier
from openpredict.openpredict_omim_drugbank import train_drug_disease_classifier

build_drug_disease_classifier()
train_drug_disease_classifier()
```

Or using the command line:

```bash
openpredict build-models
openpredict train-model
```

> Work in progress
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
# Outdated image: docker.pkg.github.com/maastrichtu-ids/translator-openpredict/openpredict-api:latest
# Outdated image: umids/openpredict-api:latest
restart: unless-stopped
# command: build-models
# command: train-model
command: start-api --server-url https://openpredict.137.120.31.102.nip.io
ports:
- 8808:8808
Expand Down
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* [trainModel](#.openpredict.openpredict_omim_drugbank.trainModel)
* [multimetric\_score](#.openpredict.openpredict_omim_drugbank.multimetric_score)
* [evaluate](#.openpredict.openpredict_omim_drugbank.evaluate)
* [get\_drug\_disease\_classifier](#.openpredict.openpredict_omim_drugbank.build_drug_disease_classifier)
* [get\_drug\_disease\_classifier](#.openpredict.openpredict_omim_drugbank.train_drug_disease_classifier)
* [query\_omim\_drugbank\_classifier](#.openpredict.openpredict_omim_drugbank.query_omim_drugbank_classifier)
* [openpredict.openpredict\_api](#.openpredict.openpredict_api)
* [start\_spark](#.openpredict.openpredict_api.start_spark)
Expand Down Expand Up @@ -267,11 +267,11 @@ Evaluate the trained classifier

Scores

<a name=".openpredict.openpredict_omim_drugbank.build_drug_disease_classifier"></a>
<a name=".openpredict.openpredict_omim_drugbank.train_drug_disease_classifier"></a>
#### get\_drug\_disease\_classifier

```python
build_drug_disease_classifier()
train_drug_disease_classifier()
```

The main function to run the drug-disease similarities pipeline,
Expand Down
8 changes: 4 additions & 4 deletions openpredict/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys

from openpredict.openpredict_api import start_api as start_openpredict_api
from openpredict.openpredict_omim_drugbank import build_drug_disease_classifier
from openpredict.openpredict_omim_drugbank import train_drug_disease_classifier

@click.command()
@click.option(
Expand All @@ -19,8 +19,8 @@ def start_api(port, server_url, debug, start_spark):


@click.command()
def build_models():
build_drug_disease_classifier()
def train_model():
train_drug_disease_classifier()


@click.group()
Expand All @@ -29,7 +29,7 @@ def main(args=None):
logging.basicConfig(stream=sys.stderr, level=logging.INFO)

main.add_command(start_api)
main.add_command(build_models)
main.add_command(train_model)

if __name__ == "__main__":
sys.exit(main())
4 changes: 2 additions & 2 deletions openpredict/openpredict_omim_drugbank.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from sklearn.model_selection import GroupKFold, StratifiedKFold
from joblib import dump, load
import pkg_resources
from openpredict.build_utils import generate_classifier_metadata
from openpredict.train_utils import generate_classifier_metadata

def adjcencydict2matrix(df, name1, name2):
"""Convert dict to matrix
Expand Down Expand Up @@ -325,7 +325,7 @@ def evaluate(test_df, clf):
return scores


def build_drug_disease_classifier():
def train_drug_disease_classifier():
"""The main function to run the drug-disease similarities pipeline,
and build the drug-disease classifier.
It returns, and stores the generated classifier as a `.joblib` file
Expand Down
2 changes: 1 addition & 1 deletion openpredict/build_utils.py → openpredict/train_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def generate_classifier_metadata(classifier_id, scores, label="OpenPredict class
clf_prop_prefix = OPENPREDICT_NAMESPACE + classifier_id + "/"

if not (clf_uri, None, None) in g:
print('Generating RDF metadata for the classifier build at ' + TTL_METADATA_FILE)
print('Generating RDF metadata for the trained classifier at ' + TTL_METADATA_FILE)
g.add((clf_uri, RDF.type, URIRef(MLS_NAMESPACE + 'ModelEvaluation')))
g.add((clf_uri, RDFS.label, Literal(label)))
g.add((clf_uri, URIRef('http://www.w3.org/ns/prov#generatedAtTime'), Literal(datetime.now(), datatype=XSD.dateTime)))
Expand Down
4 changes: 2 additions & 2 deletions tests/run_function.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from joblib import load
from openpredict.openpredict_api import get_predict
from openpredict.openpredict_omim_drugbank import build_drug_disease_classifier
from openpredict.openpredict_omim_drugbank import train_drug_disease_classifier
from openpredict.build_utils import generate_classifier_metadata
from datetime import datetime

## Run it:
# python3 tests/run_function.py

# time_start = datetime.now()
# clf, scores = build_drug_disease_classifier()
# clf, scores = train_drug_disease_classifier()

# time_build = datetime.now()

Expand Down
6 changes: 3 additions & 3 deletions tests/test_build_models.py → tests/test_train_model.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest
from openpredict.openpredict_omim_drugbank import build_drug_disease_classifier
from openpredict.openpredict_omim_drugbank import train_drug_disease_classifier

def test_build_drug_disease_classifier():
def test_train_drug_disease_classifier():
"""Test the model to get drug-disease similarities (drugbank-omim)"""
clf, scores = build_drug_disease_classifier()
clf, scores = train_drug_disease_classifier()

assert 0.80 < scores['precision'] < 0.95
assert 0.60 < scores['recall'] < 0.80
Expand Down

0 comments on commit 4e8208e

Please sign in to comment.