Python exampleΒΆ

import requests
import json
import sys

### Setting up the connection to the api ###
# The valid APIKEY is read as the first argument from the command line
session  = requests.Session()
base_url = 'https://apimlqv2.tenwiseservice.nl/api/mlquery/'
session.headers['referer'] = 'https://apimlqv2.tenwiseservice.nl/'
session.get(base_url + "start/")
payload = {'apikey': sys.argv[1],
           'csrfmiddlewaretoken': session.cookies.get_dict()['csrftoken']}


### Get the relations for 2 concepts ###
# In this case we look at relations with
# CXCR3 (HGNC:4540) and Parkinsons Disease (TWDIS_06685)
# These are referred to as the subjects.

payload['concept_ids_subject'] = "HGNC:4540,TWDIS_06685"
results = session.post(base_url + "conceptset/relations/",
                       payload)

js = results.json()
relations = js['result']['relations']

### Get all ids and names for which a relation is found ###
# These are referred to as the "object"
# This is done by the annotation method

object_ids = {x['object']:1 for x in relations}
ids = ["HGNC:4540","TWDIS_06685"] + list(object_ids.keys())
payload['concept_ids'] = ",".join(ids)
results = session.post(base_url + "conceptset/annotation/",
                       payload)
js = results.json()
annotation = js['result']['annotation']

### Print out some details for each relation ###
print("\t".join(['Subject','Object','Score','Overlap']))

for relation in relations:
    if relation['score'] >100:
        if relation['overlap'] > 10:
            print("\t".join([
                annotation[relation['subject']]['name'][0],
                annotation[relation['object']]['name'][0],
                str(relation['score']),
                str(relation['overlap'])
              ]
            )
)

Example output

Subject Object  Score   Overlap
CXCR3   CXCR5   2782    53
CXCR3   CCL11   182     19
CXCR3   CCL17   300     16
CXCR3   CCL19   283     16
CXCR3   CCL20   170     15
CXCR3   CCL21   259     16
CXCR3   CCL22   231     12
CXCR3   CCL3    273     34
CXCR3   CCL5    262     89
CXCR3   CXCL10  2368    470
CXCR3   CXCL11  6604    183
CXCR3   CXCL13  640     19
CXCR3   CX3CL1  489     11
CXCR3   CXCL12  245     39
parkinson's disease     FGF20   103     40
parkinson's disease     PRKN    161     515
parkinson's disease     PITX3   117     23
parkinson's disease     L-dopa metabolism       101     12
parkinson's disease     nigrostriatal pathway   139     741
parkinson's disease     KW6002  115     45
parkinson's disease     LY127809        104     419
parkinson's disease     ACP103  160     117
parkinson's disease     CEP1347 101     38
parkinson's disease     RO407592        133     204