# GWAS lead variants via API

**URL:** <https://community.opentargets.org/t/gwas-lead-variants-via-api/429>\
**Category:** GraphQL API\
**Created:** [7 January 2022 17:43 UTC](https://community.opentargets.org/t/gwas-lead-variants-via-api/429 "2022-01-07T17:43:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pietznerm](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/pietznerm/32/148_2.png) [@pietznerm](https://community.opentargets.org/u/pietznerm)\
**Post date:** [7 January 2022 17:43 UTC](https://community.opentargets.org/t/gwas-lead-variants-via-api/429/1 "2022-01-07T17:43:42Z")

</div>

Hi OpenTargets Team,

I am a huge fan of your resource. I am currently working on a script to query GWAS variant associations for a set of genetic variants. I managed to do so for PheWAS associations. However, since most of those are likely due to LD-confounding I am most interest in the link between the queried variant and genuine lead signals at published GWAS loci. Basically the panel called " GWAS lead variants". Would be great to get some sample script using R.

Best,  
Maik

---

<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 January 2022 12:18 UTC](https://community.opentargets.org/t/gwas-lead-variants-via-api/429/2 "2022-01-11T12:18:32Z")

</div>

Hello @pietznerm! 👋

Welcome to the Open Targets Community! 🎉

If you want to recreate the “GWAS Lead Variants” table for a number of variants, I would recommend that you use our `v2d` dataset.

### What is the Open Targets Genetics `v2d` dataset?

The `v2d` dataset is a series of JSON lines files, where each individual JSON line entry includes data on the tag and lead variants for a given study.

`{"study_id":"GCST90012110","lead_chrom":"1","lead_pos":1574655,"lead_ref":"GGC","lead_alt":"G","direction":"+","beta":0.00657455,"beta_ci_lower":0.00476262212,"beta_ci_upper":0.00838647788,"pval_mantissa":4.3,"pval_exponent":-13,"pval":4.3E-13,"pmid":"PMID:32042192","pub_date":"2020-02-10","pub_journal":"Nat Med","pub_title":"Using human genetics to understand the disease impacts of testosterone in men and women.","pub_author":"Ruth KS","trait_reported":"Sex hormone-binding globulin levels adjusted for BMI","ancestry_initial":["European=368929"],"ancestry_replication":[],"n_initial":368929,"num_assoc_loci":815,"has_sumstats":true,"source":"GCST","trait_efos":["EFO_0004696"],"trait_category":"measurement","tag_chrom":"1","tag_pos":1537493,"tag_ref":"T","tag_alt":"A","overall_r2":0.868737707721,"AFR_1000G_prop":0.0,"AMR_1000G_prop":0.0,"EAS_1000G_prop":0.0,"EUR_1000G_prop":1.0,"SAS_1000G_prop":0.0,"log10_ABF":19.755002754225544,"posterior_prob":0.016564937297166}`

### How do I query the `v2d` dataset?

To query the dataset and find the GWAS lead variant information for a given variant, you will need to write an R script that queries the dataset for the following fields: `tag_chrom`, `tag_pos`, `tag_ref`, and `tag_alt`.

For example, using variant [1\_1313807\_G\_A](https://genetics.opentargets.org/variant/1_1313807_G_A), the R script would need to query for:

`tag_chrom` == `1`  
`tag_pos` == ` 1313807`  
`tag_ref` == `G`  
`tag_alt` == `A`

The script would return 6 JSON objects, including:

`{"study_id":"GCST007430","lead_chrom":"1","lead_pos":1384749,"lead_ref":"C","lead_alt":"G","direction":"-","beta":-0.0194,"beta_ci_lower":-0.025672,"beta_ci_upper":-0.013128,"pval_mantissa":1.98,"pval_exponent":-9,"pval":1.98E-9,"pmid":"PMID:30804560","pub_date":"2019-02-25","pub_journal":"Nat Genet","pub_title":"New genetic signals for lung function highlight pathways and chronic obstructive pulmonary disease associations across multiple ancestries.","pub_author":"Shrine N","trait_reported":"Peak expiratory flow","ancestry_initial":["European=321047"],"ancestry_replication":["European=24218"],"n_initial":321047,"n_replication":24218,"num_assoc_loci":265,"has_sumstats":true,"source":"GCST","trait_efos":["EFO_0009718"],"trait_category":"measurement","tag_chrom":"1","tag_pos":1313807,"tag_ref":"G","tag_alt":"A","overall_r2":0.757951324816,"AFR_1000G_prop":0.0,"AMR_1000G_prop":0.0,"EAS_1000G_prop":0.0,"EUR_1000G_prop":1.0,"SAS_1000G_prop":0.0}`

Within each of the 6 JSON objects, you will see the published lead variant information in the `lead_chrom`, `lead_pos`, `lead_ref`, and `lead_alt` fields along with relevant study fields (e.g. `study_id`).

For example, using the above JSON object, the lead variant is `1_1384749_C_G` and it was identified in the GWAS Catalog study [GCST007430](https://genetics.opentargets.org/study/GCST007430).

### How can I access the `v2d` dataset?

The Open Targets Genetics `v2d` dataset is available in JSON format from our FTP server:

[ftp.ebi.ac.uk/pub/databases/opentargets/genetics/latest/v2d/](http://ftp.ebi.ac.uk/pub/databases/opentargets/genetics/latest/v2d/)

Alternatively, you can also access the dataset in our BigQuery [open-targets-genetics](https://console.cloud.google.com/bigquery?p=open-targets-genetics&d=genetics&t=variant_disease&page=dataset) instance and use SQL to access the relevant fields:

[Find GWAS lead variant, study, and reported trait information for a given tag variant with BigQuery](https://console.cloud.google.com/bigquery?sq=352646847630:a00e77104bdd4be5910fc30f918c66c0)

I hope this helps – feel free to post any follow up questions below!

Cheers,

~ Andrew 🙂

---

<div class="post-metadata">

**Author:** ![pietznerm](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/pietznerm/32/148_2.png) [@pietznerm](https://community.opentargets.org/u/pietznerm)\
**Post date:** [12 January 2022 17:01 UTC](https://community.opentargets.org/t/gwas-lead-variants-via-api/429/3 "2022-01-12T17:01:31Z")

</div>

Thank you, Andrew!! This was really helpful and easy to implement. However, some overall\_r2 entries do contain missing values and I was wondering, how the connection between the lead signal and the tag variant has been made in those cases.

Best,  
Maik

---

<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:** [18 February 2022 17:00 UTC](https://community.opentargets.org/t/gwas-lead-variants-via-api/429/4 "2022-02-18T17:00:30Z")

</div>

Hello @pietznerm!

My sincere apologies for not responding to your follow up question earlier.

Our Variant2Disease pipeline relies on different methods of expanding lead variants to tag variants, including LD expansion and fine mapping expansion. The FinnGen data that we have integrated also has its own method of lead variant to tag variant expansion.

For more information, please see [our Variant2Disease pipeline documentation](https://genetics-docs.opentargets.org/our-approach/assigning-traits-to-loci#lead-variant-to-tag-variant-expansion), which details the different methods we use.

---

<div class="post-metadata">

**Author:** ![alessandro.testori](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@alessandro.testori](https://community.opentargets.org/u/alessandro.testori)\
**Post date:** [24 October 2024 07:59 UTC](https://community.opentargets.org/t/gwas-lead-variants-via-api/429/5 "2024-10-24T07:59:38Z")

</div>

Hello! I am trying to get lead variants and studies via API given a tag variant, but I am afraid I was only able to find the code to get tag variants given a lead variant, as in the example you provided at [Open Targets Genetics](https://genetics.opentargets.org/api):

query Variant {  
tagVariantsAndStudiesForIndexVariant(variantId: “1\_55058182\_G\_A”) {  
associations {  
tagVariant {  
id  
rsId  
\_\_typename  
}  
study {  
studyId  
traitReported  
pmid  
pubDate  
pubAuthor  
\_\_typename  
}  
pval  
nTotal  
overallR2  
posteriorProbability  
\_\_typename  
}  
\_\_typename  
}  
}

Could you please provide a sample query to get lead variants and studies/traits, given a tag variant?  
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:** [24 October 2024 10:07 UTC](https://community.opentargets.org/t/gwas-lead-variants-via-api/429/6 "2024-10-24T10:07:44Z")

</div>

Welcome to Open Targets Alessandro!

I’ve written below an example query for lead variants and studies/traits, given a tag variant of interest. Please let us know how it goes!

Best wishes,  
Xiangyu Jack

```auto
query LeadVariantsForTagVariant {
  indexVariantsAndStudiesForTagVariant(variantId: "1_55058182_G_A") {
    associations {
      indexVariant {
        id
        rsId
      }
      study {
        studyId
        traitReported
        pmid
        pubDate
        pubAuthor
      }
      pval
      nTotal
      overallR2
      posteriorProbability
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![alessandro.testori](https://avatars.discourse-cdn.com/v4/letter/a/e47774/32.png) [@alessandro.testori](https://community.opentargets.org/u/alessandro.testori)\
**Post date:** [24 October 2024 14:42 UTC](https://community.opentargets.org/t/gwas-lead-variants-via-api/429/7 "2024-10-24T14:42:31Z")

</div>

> [@Xiangyu](#):
>
> Xiangyu

Thank you Xiangyu, it works!
