Skip to contents

Pure, and it reads both response shapes on purpose: the search query returns a hits array, the direct disease lookup returns a single record. A caller resolving a term does not know in advance which query ran, so one parser reads either and the difference stops mattering downstream.

Usage

opentargets_parse_matches(body)

Arguments

body

A parsed Open Targets GraphQL response body.

Value

A tibble of id, name, score, description, and source_url, best match first, or NULL when nothing matched. score is NA for a direct lookup, which has no relevance score to report.

Examples

hits <- list(data = list(search = list(hits = list(
  list(id = "MONDO_0018975", name = "neurofibromatosis type 1", score = 24.9)
))))
opentargets_parse_matches(hits)
#> # A tibble: 1 × 5
#>   id            name                     score description source_url           
#>   <chr>         <chr>                    <dbl> <chr>       <chr>                
#> 1 MONDO_0018975 neurofibromatosis type 1  24.9 NA          https://platform.ope…

single <- list(data = list(disease = list(id = "EFO_0000508", name = "neurofibroma")))
opentargets_parse_matches(single)
#> # A tibble: 1 × 5
#>   id          name         score description source_url                         
#>   <chr>       <chr>        <dbl> <chr>       <chr>                              
#> 1 EFO_0000508 neurofibroma    NA NA          https://platform.opentargets.org/d…