Get genetic variants associated with a disease with the Python client

This is an example on how you can get the genetic variants (evidence) associated with a disease of interest using the Open Targets Python client. This example highlights the filtering capabilities included in the client.

Check the Open Targets Platform REST API documentation for more details.

Firstly, create a virtual environment:

virtualenv venv
source venv/bin/activate

Then, install our Python client:

pip install opentargets

Now, choose your favourite editor and create a file that contains the code below:

from opentargets import OpenTargetsClient
import argparse
import pandas as pd
parser = argparse.ArgumentParser(description='Retrieve SNPs and other genetic associations which are linked to a given disease')
help='the disease of interest')
args = parser.parse_args()
ot = OpenTargetsClient()
e_for_disease = ot.get_evidence_for_disease(args.disease)
outfilepath = 'genetic_evidence_associated_with_' + args.disease + '.csv'
pd.DataFrame([x['unique_association_fields'] for x in e_for_disease]).to_csv(outfilepath)

You can now run it by typing the following on the command line (notice the quotes around the disease name):

(venv)$ python "neuropathic pain"

Your folder will now contain a CSV file with the genetic evidence connected to neuropathic pain: