# What is the best way to query pheWAS traits for multiple variants?

**URL:** <https://community.opentargets.org/t/what-is-the-best-way-to-query-phewas-traits-for-multiple-variants/466>\
**Category:** Open Targets Genetics FAQs\
**Tags:** genetics-portal\
**Created:** [17 February 2022 02:03 UTC](https://community.opentargets.org/t/what-is-the-best-way-to-query-phewas-traits-for-multiple-variants/466 "2022-02-17T02:03:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![slifong08](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/slifong08/32/163_2.png) [@slifong08](https://community.opentargets.org/u/slifong08)\
**Post date:** [17 February 2022 02:03 UTC](https://community.opentargets.org/t/what-is-the-best-way-to-query-phewas-traits-for-multiple-variants/466/1 "2022-02-17T02:03:07Z")

</div>

Hi Open Target Team,

I’d like to query multiple genetic variants (100s) for pheWAS trait associations using UKBB, FinnGen, and GWAS catalog. Is it best to use an API approach or download the entire dataset from the Open Targets Genetics portal? If the former, is the GraphiQL only linked to the PheWAS catalog or all pheWAS datasets? If the latter, what is the data table I would want to download?

Thank you,

Sarah

---

<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:** [17 February 2022 16:12 UTC](https://community.opentargets.org/t/what-is-the-best-way-to-query-phewas-traits-for-multiple-variants/466/2 "2022-02-17T16:12:59Z")

</div>

Hello @slifong08! 👋

Welcome to the Open Targets Community! 🎉

Unfortunately, due to the size and scope of our PheWAS plot data, we are unable to provide the raw data in downloadable datasets.

You can access the data through our GraphQL API, using the `pheWAS` endpoint and passing the variant in [our variant format](https://genetics-docs.opentargets.org/how-to-use-open-targets-genetics-starting-with/variant) of `chromosome` + `_` + `position` + `_` + `reference allele` + `_` + `alternative/effect allele` format (e.g. `12_130461363_C_A`).

For example, to get the PheWAS data for [12\_130461363\_C\_A](https://genetics.opentargets.org/variant/12_130461363_C_A), you would construct the following GraphQL query:

```auto
query PheWASQuery{
  pheWAS(variantId: "1_154453788_C_T") {
    associations {
      study {
        studyId
        traitReported
        traitCategory
        pmid
        pubDate
        pubAuthor
        source
      }
      pval
      beta
      oddsRatio
      nTotal
      nCases
      eaf
      se
    }
  }
}

```

[Run this query in our GraphQL API playground](https://api.genetics.opentargets.org/graphql/browser?operationName=PheWASQuery&query=query%20PheWASQuery%7B%0A%20%20pheWAS(variantId%3A%20%221_154453788_C_T%22)%20%7B%0A%20%20%20%20associations%20%7B%0A%20%20%20%20%20%20study%20%7B%0A%20%20%20%20%20%20%20%20studyId%0A%20%20%20%20%20%20%20%20traitReported%0A%20%20%20%20%20%20%20%20traitCategory%0A%20%20%20%20%20%20%20%20pmid%0A%20%20%20%20%20%20%20%20pubDate%0A%20%20%20%20%20%20%20%20pubAuthor%0A%20%20%20%20%20%20%20%20source%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20pval%0A%20%20%20%20%20%20beta%0A%20%20%20%20%20%20oddsRatio%0A%20%20%20%20%20%20nTotal%0A%20%20%20%20%20%20nCases%0A%20%20%20%20%20%20eaf%0A%20%20%20%20%20%20se%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D)

It is important to note that our GraphQL API only returns trait associations from UK Biobank, FinnGen, and GWAS Catalog where the p-value is \< 0.005 and this threshold cannot be adjusted.

---

<div class="post-metadata">

**Author:** ![slifong08](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/slifong08/32/163_2.png) [@slifong08](https://community.opentargets.org/u/slifong08)\
**Post date:** [18 February 2022 18:36 UTC](https://community.opentargets.org/t/what-is-the-best-way-to-query-phewas-traits-for-multiple-variants/466/3 "2022-02-18T18:36:01Z")

</div>

Thank you! This is very helpful!

---

<div class="post-metadata">

**Author:** ![Shicheng\_Guo](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/shicheng_guo/32/217_2.png) [@Shicheng\_Guo](https://community.opentargets.org/u/Shicheng_Guo)\
**Post date:** [2 May 2022 22:57 UTC](https://community.opentargets.org/t/what-is-the-best-way-to-query-phewas-traits-for-multiple-variants/466/4 "2022-05-02T22:57:50Z")

</div>

Hi, any further script to clear the format to data.frame? Thanks.

---

<div class="post-metadata">

**Author:** ![CS\_G](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/cs_g/32/462_2.png) [@CS\_G](https://community.opentargets.org/u/CS_G)\
**Post date:** [9 August 2023 21:43 UTC](https://community.opentargets.org/t/what-is-the-best-way-to-query-phewas-traits-for-multiple-variants/466/5 "2023-08-09T21:43:48Z")

</div>

Hi. In my attempts to implement the solution in R, I’m encountering errors with the pheWAS API query. If someone please help me get it up and running, I would be very grateful.

query\_url = ‘[https://api.platform.opentargets.org/api/v4/graphql](https://api.platform.opentargets.org/api/v4/graphql)’

# Building query

request\_body = list(operationName= ‘PheWASQuery’,  
variables = list(  
variantId = “1\_154453788\_C\_T”  
),  
query = ’  
query PheWASQuery($variantId: String!){  
pheWAS(variantId: $variantId) {  
associations {  
study {  
studyId  
traitReported  
traitCategory  
pmid  
pubDate  
pubAuthor  
source  
}  
pval  
beta  
oddsRatio  
nTotal  
nCases  
eaf  
se  
}  
}  
}’  
)  
response = POST(query\_url, body=request\_body, encode=‘json’)

char = rawToChar(response$content)  
data = jsonlite::fromJSON(char)

# OUTPUT

> data  
> $data  
> NULL  
> $errors  
> message  
> 1 Cannot query field ‘pheWAS’ on type ‘Query’. (line 3, column 7):\n pheWAS(variantId: $variantId) {\n ^  
> locations  
> 1 3, 7

---

<div class="post-metadata">

**Author:** ![dsuveges](https://dub1.discourse-cdn.com/flex017/user_avatar/community.opentargets.org/dsuveges/32/30_2.png) [@dsuveges](https://community.opentargets.org/u/dsuveges)\
**Post date:** [10 August 2023 07:42 UTC](https://community.opentargets.org/t/what-is-the-best-way-to-query-phewas-traits-for-multiple-variants/466/6 "2023-08-10T07:42:51Z")

</div>

Hi, the only problem with your query is that the API of the Genetics Portal has a different address: `https://api.genetics.opentargets.org/graphql/` your query looks like [this](https://api.genetics.opentargets.org/graphql/browser?query=query%20PheWASQuery(%24variantId%3A%20String!)%20%7B%0A%20%20pheWAS(variantId%3A%20%24variantId)%20%7B%0A%20%20%20%20associations%20%7B%0A%20%20%20%20%20%20study%20%7B%0A%20%20%20%20%20%20%20%20studyId%0A%20%20%20%20%20%20%20%20traitReported%0A%20%20%20%20%20%20%20%20traitCategory%0A%20%20%20%20%20%20%20%20pmid%0A%20%20%20%20%20%20%20%20pubDate%0A%20%20%20%20%20%20%20%20pubAuthor%0A%20%20%20%20%20%20%20%20source%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20pval%0A%20%20%20%20%20%20beta%0A%20%20%20%20%20%20oddsRatio%0A%20%20%20%20%20%20nTotal%0A%20%20%20%20%20%20nCases%0A%20%20%20%20%20%20eaf%0A%20%20%20%20%20%20se%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D%0A&operationName=PheWASQuery&variables=%7B%0A%20%20%22variantId%22%3A%20%221_154453788_C_T%22%0A%7D). Please let us know if my answer was not fully resolving the issue.
