An R script to use API for fetching "Associated studies: locus-to-gene pipeline" section for a gene

Hello, I want to write a query in R that fetch all information regarding the “Associated studies: locus-to-gene pipeline” section (especially L2G pipeline scores) based on an “Ensemble ID” of a gene as input. Could you please help me to know how should I have such a query in the R script?

Hi Yazdan, Welcome to the OpenTargets community! The table on the gene page with the l2g scores are provided by the GraphQL API, via a single request. This request is easy to script in R to automate data retrieval (for examples, please see this or other threads on the community).

The API request to get L2G predictions for genes looks like this:

query GenePageL2GPipelineQuery($geneId: String!) {
  studiesAndLeadVariantsForGeneByL2G(geneId: $geneId) {
    pval
    yProbaModel
    study {
      studyId
      traitReported
      pubAuthor
      pubDate
      pmid
      nInitial
      nReplication
      hasSumstats
      nCases
    }
    variant {
      rsId
      id
    }
    odds {
      oddsCI
      oddsCILower
      oddsCIUpper
    }
    beta {
      betaCI
      betaCILower
      betaCIUpper
      direction
    }
  }
}

You can play around and optimize the query here. Please let us know if you have further questions.

2 Likes

Dear Team,

I am trying to repeat the R graphql-api code, however, I received the following error:

Response [https://api.platform.opentargets.org/api/v4/graphql]
Date: 2023-08-11 06:05
Status: 400
Content-Type: application/json
Size: 167 B

Could you please give some comments? Thanks.

This has been solved here Sample R script to query GraphQL API - #5 by irene

1 Like