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

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