Retrieving >25 associated drugs

Hi all!

When querying ‘knownDrugs’ associated to a target, I am able to find at most 25 drugs. Would it be possible to retrieve more associated drugs without using Google Big Query?
I tried suggestions like (page: { size: x, index:y }) mentioned here and here, but they did not work for me.

Many thanks in advance,
Myrthe

query search{
  target(ensemblId:"ENSG00000047936"){
      knownDrugs{
      rows{
        drugId
        drug{
          name
        }
      }
      }
  }
}

Have you tried this?

query q{
  target(ensemblId: "ENSG00000047936"){
    id
    knownDrugs(size: 2){
      count
      rows{
        drug{
          name
        }
      }
    }
  }
}
1 Like

Dear Ochoa,

No, I had not tried that. It works wonderfully, thank you so much!

2 Likes

Could you please provide an updated version of this solution? I am still encountering an error.



# Load relevant library for HTTP requests
library(httr)

# Set base URL of Genetics Portal GraphQL API endpoint
base_url <- "https://api.genetics.opentargets.org/graphql"


# Additional query to get known drugs for a target
query_drugs <- "
  query q{
    target(ensemblId: \"ENSG00000047936\"){
      id
      knownDrugs(size: 2){
        count
        rows{
          drug{
            name
          }
        }
      }
    }
  }
"

# Construct POST request body object for the drugs query
post_body_drugs <- list(query = query_drugs)

# Perform POST request for drugs query
r_drugs <- POST(url=base_url, body=post_body_drugs, encode='json')

# Check for errors
if (status_code(r_drugs) == 200) {
  # Print known drugs data to RStudio console
  known_drugs <- content(r_drugs, "parsed")$data$target$knownDrugs$rows
  print(known_drugs)
} else {
  print(paste("Error:", status_code(r_drugs)))
}

Hi @Shicheng_Guo ,

I think in your R code, the base_url is incorrectly pointing to the genetics API whereas the query is on the Platform. It should be changed to

base_url <- "https://api.platform.opentargets.org/api/v4/graphql"

Is there something else that I might be missing? Hope that helps.

Best,
Prashant

1 Like