# Accessing L2G scores through API

**URL:** <https://community.opentargets.org/t/accessing-l2g-scores-through-api/218>\
**Category:** GraphQL API\
**Tags:** genetics-portal\
**Created:** [10 June 2021 15:01 UTC](https://community.opentargets.org/t/accessing-l2g-scores-through-api/218 "2021-06-10T15:01:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marynias](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@marynias](https://community.opentargets.org/u/marynias)\
**Post date:** [10 June 2021 15:01 UTC](https://community.opentargets.org/t/accessing-l2g-scores-through-api/218/1 "2021-06-10T15:01:57Z")

</div>

Hello, I am struggling to formulate a GraphQL query that would allow me to fetch L2G scores for a given SNP-study association, such as displayed here under **Gene prioritisation using locus-to-gene pipeline** : [Open Targets Genetics](https://genetics.opentargets.org/study-locus/GCST003044/1_67215986_T_G) . Or if not available, at least the highest scoring gene for a given SNP-study association. I can only find the _ManhattanAssociation_ type which should somehow be able to produce _bestLocus2Genes_ but I am unable to formulate a successful query for it.

---

<div class="post-metadata">

**Author:** ![ahercules](https://avatars.discourse-cdn.com/v4/letter/a/f4b2a3/32.png) [@ahercules](https://community.opentargets.org/u/ahercules)\
**Post date:** [11 June 2021 11:28 UTC](https://community.opentargets.org/t/accessing-l2g-scores-through-api/218/2 "2021-06-11T11:28:40Z")

</div>

Hello @marynias!

Welcome, and thank you for joining the Open Targets Community! 🙂

## How do I access Locus2Gene data for a specific study and locus?

To access the Locus2Gene data for a specific study and locus (represented by the lead variant ID) using the [Genetics Portal GraphQL API](http://genetics-api.opentargets.io/graphql), you will need to use the `studyLocus2GeneTable` endpoint and pass the `studyId` and `variantId` as parameters.

For example, to access the Locus2Gene data for [Crohn’s disease (GCST003044) and the locus around 1\_67215986\_T\_G](https://genetics.opentargets.org/study-locus/GCST003044/1_67215986_T_G), you would use the following query:

```auto
query getL2GScoresForAStudyVariantPair {
  studyLocus2GeneTable(studyId:"GCST003044", variantId:"1_67215986_T_G") {
    rows {
      gene {
        symbol
        id
      }
      yProbaModel
      yProbaDistance
      yProbaInteraction
      yProbaMolecularQTL
      yProbaPathogenicity
      hasColoc
      distanceToLocus
    }
  }
}

```

[Link to run GraphQL API query](http://genetics-api.opentargets.io/graphql/browser?query=query%20getL2GScoresForAStudyVariantPair%20%7B%0A%20%20studyLocus2GeneTable(studyId%3A%22GCST003044%22%2C%20variantId%3A%221_67215986_T_G%22)%20%7B%0A%20%20%20%20rows%20%7B%0A%20%20%20%20%20%20gene%20%7B%0A%20%20%20%20%20%20%20%20symbol%0A%20%20%20%20%20%20%20%20id%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20yProbaModel%0A%20%20%20%20%20%20yProbaDistance%0A%20%20%20%20%20%20yProbaInteraction%0A%20%20%20%20%20%20yProbaMolecularQTL%0A%20%20%20%20%20%20yProbaPathogenicity%0A%20%20%20%20%20%20hasColoc%0A%20%20%20%20%20%20distanceToLocus%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A&operationName=getL2GScoresForAStudyVariantPair)

Within the API response, the following fields map to the columns in the Locus2Gene data table seen in the screenshot below:

 ![Screenshot 2021-06-11 at 11.43.03](https://europe1.discourse-cdn.com/flex017/uploads/opentargets/original/1X/c5d868da7dde396616091905979565ca28a5a21a.png)

| Column label | API response field |
| --- | --- |
| Gene | `rows.gene.symbol` |
| Overall L2G score | `rows.yProbaModel` |
| Variant Pathogenicity | `rows.yProbaPathogenicity` |
| Distance | `rows.yProbaDistance` |
| QTL Coloc | `rows.yProbaMolecularQTL` |
| Chromatin interaction | `rows.yProbaInteraction` |
| Distance to locus (bp) | `rows.distanceToLocus` |
| Evidence of colocalisation | `rows.hasColoc` |

## Are there other ways to access Locus2Gene data for more systematic queries?

The GraphQL API approach is good way to find Locus2Gene data for a _single_ study-locus pair.

However, for more systemic analyses involving multiple studies or loci, I would recommend that you use our BigQuery instance - [open-targets-genetics](https://console.cloud.google.com/bigquery?project=open-targets-genetics).

For example, the same GraphQL API query for [Crohn’s disease (GCST003044) and the locus around 1\_67215986\_T\_G](https://genetics.opentargets.org/study-locus/GCST003044/1_67215986_T_G) in BigQuery would be:

```auto
SELECT 
    study_id,
    gene_id,
    y_proba_full_model,
    y_proba_logi_distance,
    y_proba_logi_interaction,
    y_proba_logi_molecularQTL,
    y_proba_logi_pathogenicity
FROM `open-targets-genetics.200201.locus2gene` 
WHERE 
    study_id='GCST003044' 
    AND pos=67215986 
    AND chrom='1'
    AND ref='T'
    AND alt='G' 
ORDER BY y_proba_full_model desc 
# LIMIT 100

```

[Link to run the BigQuery script](https://console.cloud.google.com/bigquery?sq=1022493902394:c7dbde6ae76c49b8954eaa99f05a7cfd)

Results of the query can be exported in CSV or JSON formats or can be imported into your own BigQuery instance of Google Sheets.

Alternatively, you can also download all of the Locus2Gene data in Parquet format using [our FTP service](http://ftp.ebi.ac.uk/pub/databases/opentargets/genetics/20022712/l2g/).

I hope this helps answer your question! Please feel free to comment below if you have further questions about accessing the data! 🙂

---

<div class="post-metadata">

**Author:** ![marynias](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@marynias](https://community.opentargets.org/u/marynias)\
**Post date:** [11 June 2021 14:13 UTC](https://community.opentargets.org/t/accessing-l2g-scores-through-api/218/3 "2021-06-11T14:13:59Z")

</div>

Thank you @ahercules for the clear and prompt recipe! I would have never figured that one out on my own :).

---

<div class="post-metadata">

**Author:** ![frahimov](https://avatars.discourse-cdn.com/v4/letter/f/b38774/32.png) [@frahimov](https://community.opentargets.org/u/frahimov)\
**Post date:** [26 May 2022 18:27 UTC](https://community.opentargets.org/t/accessing-l2g-scores-through-api/218/4 "2022-05-26T18:27:26Z")

</div>

Hello,

I would like to do the exact same thing, but access the “Overall V2G” scores instead. What table do you suggest? To be more specific, I want to access columns in this table through API

> **[Open Targets Genetics](https://genetics.opentargets.org/locus?chromosome=7&end=129943748&selectedGenes=ENSG00000128604&start=127943748)**
>
> Open Targets Genetics explores associations between traits, variants, and genes with a focus on multi-trait analysis and gene to variant scoring.

Thank you!

---

<div class="post-metadata">

**Author:** ![Xiangyu](https://avatars.discourse-cdn.com/v4/letter/x/90db22/32.png) [@Xiangyu](https://community.opentargets.org/u/Xiangyu)\
**Post date:** [17 June 2022 13:14 UTC](https://community.opentargets.org/t/accessing-l2g-scores-through-api/218/5 "2022-06-17T13:14:58Z")

</div>

Hi!

For the overall V2G score for a given variant (1\_67215986\_T\_G in this case), you can use the following query in the GraphAPI playground:

```auto
query getV2GScoresForAStudyVariantPair {
  genesForVariant(variantId: "1_67215986_T_G"){
      gene {
        symbol
        id
      }
      overallScore
    }
  }
`

Thanks,
Xiangyu
```
