# How to find targets associated with a disease using the new GraphQL API or Google BigQuery

**URL:** <https://community.opentargets.org/t/how-to-find-targets-associated-with-a-disease-using-the-new-graphql-api-or-google-bigquery/122>\
**Category:** Data Access\
**Tags:** ot-platform\
**Created:** [1 June 2021 12:51 UTC](https://community.opentargets.org/t/how-to-find-targets-associated-with-a-disease-using-the-new-graphql-api-or-google-bigquery/122 "2021-06-01T12:51:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hcornu](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/hcornu/32/716_2.png) [@hcornu](https://community.opentargets.org/u/hcornu)\
**Post date:** [1 June 2021 12:51 UTC](https://community.opentargets.org/t/how-to-find-targets-associated-with-a-disease-using-the-new-graphql-api-or-google-bigquery/122/1 "2021-06-01T12:51:28Z")

</div>

## Problem

The Open Targets helpdesk recently received the following question:

> I have used the older version of the Open Targets Platform (21.02), and the previous API technique, to get targets associated with disease and their overall scores.
> 
> But now after updating (to version 21.04) I can’t do it with the new GraphQL API technique. Could you help me with this? **How can I get associated targets with disease and their overall scores using the new GraphQL API?**
> 
> To make it easier, I need to get the first two columns of the table on, for example, [targets associated with COVID](https://platform.opentargets.org/disease/MONDO_0100096/associations), but without downloading it, just getting info from API inside Python script.

## Using the GraphQL API

In order to get targets associated with a specific disease, you will need to start your query with the disease ID and then use the `associatedTargets` field to access the relevant target data. For example, to get the first 10 targets associated with COVID (MONDO\_0100096), you would run the following query:

```auto
query targetsAssociatedWithCOVID {
  disease(efoId: "MONDO_0100096") {
    id
    name
    associatedTargets(page: { index: 0, size: 10 }) {
      count
      rows {
        target {
          id
          approvedSymbol
        }
        score
      }
    }
  }
}

```

You can [try this query in our GraphQL API playground](https://api.platform.opentargets.org/api/v4/graphql/browser?query=query%20targetsAssociatedWithCOVID%20%7B%0A%20%20disease(efoId:%20%22MONDO_0100096%22)%20%7B%0A%20%20%20%20id%0A%20%20%20%20name%0A%20%20%20%20associatedTargets(page:%20%7B%20index:%200,%20size:%2010%20%7D)%20%7B%0A%20%20%20%20%20%20count%0A%20%20%20%20%20%20rows%20%7B%0A%20%20%20%20%20%20%20%20target%20%7B%0A%20%20%20%20%20%20%20%20%20%20id%0A%20%20%20%20%20%20%20%20%20%20approvedSymbol%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20score%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D) by pressing the triangle play button.

Please note that when using the GraphQL API, you will need to construct your code and adjust the `index` and `size` parameters in order to access all of the data. The GraphQL API defaults to returning only 25 entries and so `index:0, size:25` will return the first 25 entries, `index:1, size:25` will return the next 25 entries, etc.

## Using BigQuery

To support more complex and systematic queries, we recommend that you use our BigQuery instance — [open-targets-prod](https://console.cloud.google.com/bigquery?project=open-targets-prod). To access the associations data using BigQuery, you can use the following SQL query with the [associationByOverallDirect dataset](https://console.cloud.google.com/bigquery?p=open-targets-prod&d=platform&t=associationByOverallDirect&page=table).

```auto
SELECT
  associations.diseaseId AS disease_id,
  diseases.name AS disease_name,
  associations.targetId AS target_id,
  targets.approvedSymbol AS target_approved_symbol,
  associations.score AS overall_association_score,
  evidenceCount AS number_of_evidence_strings
FROM
  `open-targets-prod.platform.associationByOverallDirect` AS associations
JOIN
  `open-targets-prod.platform.diseases` AS diseases
ON
  associations.diseaseId = diseases.id
JOIN
  `open-targets-prod.platform.targets` AS targets
ON
  associations.targetId = targets.id
WHERE
  associations.diseaseId='MONDO_0100096'
ORDER BY
  associations.score DESC

```

You can access the query [here](https://console.cloud.google.com/bigquery?sq=352646847630:83ac4bbb356a4e4987bdbc07ced43aa8) and download the data as JSON or CSV format.

Please note that the association scores returned by the GraphQL API and those available in BigQuery (or via[our data downloads](https://platform.opentargets.org/downloads)) are known to be different due to a modified algorithm and harmonic sum strategy. This will be fixed in our upcoming release, scheduled for the end of June — see our GitHub issue tracker [#1508](https://github.com/opentargets/platform/issues/1508) for more information.

## Other examples

For further information and sample scripts, take a look at [the Platform documentation](https://platform-docs.opentargets.org/data-access/google-bigquery). We also have a few other example scripts from @irene and @ahercules:

- [How to access drug warning and pharmacovigilance data](https://community.opentargets.org/t/how-to-guide-accessing-drug-warning-and-pharmacovigilance-data/65) using the API
- [How to find known drugs for a given disease](https://community.opentargets.org/t/how-to-find-known-drugs-for-a-given-disease/121/2) using BigQuery or data downloads
- [How to get marketed drugs for a set of targets](https://community.opentargets.org/t/get-marketed-drugs-for-a-set-of-targets-with-bigquery/101) using BigQuery
