Batch download disease/association scores

I am trying to download association scores from a list of IDs using the api/v4/graphql but it feels cumbersome as i am iterating through the lists and making individual calls then concatenating into a dataframe (python code appended below). Probably there is a better way of doing this, any recommendations will be deeply appreciated :slight_smile:

import pandas as pd
import json
import requests
dfENSG=dfENSG.str.strip()#contains #gene_id like "ENSG00000169093"...
colS=pd.DataFrame(columns=["ID","name","disease", "datasourceScores"])
cntG=0;
for gene_id in dfENSG:
    cntG=cntG+1
    print(cntG,gene_id)
    query_string = """
      query target($ensemblId: String!){
        target(ensemblId: $ensemblId){
        id
        approvedSymbol
        associatedDiseases {
          count
          rows {
            disease {
              id
              name
            }
            datasourceScores {
              id
              score
            }
          }
        }
      }
    }
    """
    variables = {"ensemblId": gene_id}
    base_url = "https://api.platform.opentargets.org/api/v4/graphql"
    r = requests.post(base_url, json={"query": query_string, "variables": variables})
    print(r.status_code)
    if r.status_code==200:
        api_response = json.loads(r.text)
        iD=api_response['data']['target']['id']
        print(iD)
        iG=api_response['data']['target']['approvedSymbol']
        print(iG)
        aS=api_response['data']['target']['associatedDiseases']['rows']#[1]['datasourceScores'][0]['score']
        dataOIDP=pd.DataFrame(aS,columns=["disease", "datasourceScores"])
        dataOIDP["ID"]=iD
        dataOIDP["name"]=iG
        colS=pd.concat([colS,dataOIDP])
colS.to_csv("openTargetResults.csv")

Hi @animesh!

The API is optimised for queries about a single entity or association. For queries about multiple entities or associations, we recommend using one of our other data access points: Google BigQuery or our Data Downloads.

You can find out more information about these in our documentation: Data access - Open Targets Platform Documentation

You can also take a look at some other threads on the Community, for example:

Or maybe another user has found a solution?

Thanks @hcornu , will check it out :+1: