vignettes/basic-query.Rmd
basic-query.Rmd
In this example, we’re going to run a simple remote gor query using
the gorr
package.
First load the gorr
package, the tidyverse
package is recommended in general, but not required for this example
First we’ll need to establish a connection to our direct query API.
To do that we’ll need to call gor_connect
and provide it
with the relevant parameters pointing to the direct-query-service,
i.e. api_key
and project
:
api_key <- Sys.getenv("GOR_API_KEY")
conn <- gor_connect(api_key, project = Sys.getenv("GOR_API_PROJECT"))
#> Warning: 'gor_connect' is deprecated.
#> Use 'platform_connect' instead.
#> See help("Deprecated")
conn
#> ── GOR API service connection ──────────────────────────────────────────────────
#> • Service Root/s: https://platform.wuxinextcodedev.com/api/query, https://platform.wuxinextcodedev.com/api/phenotype-catalog, https://platform.wuxinextcodedev.com/queryserver, https://platform.wuxinextcodedev.com/workflow
#> • Project: ukbb_hg38
#> • API key issued at: 2022-05-18 10:18:54
#> • API key expires at: Never
#> • Access token issued at: 2022-06-16 15:55:00
#> • Access token expires at: 2022-06-17 15:55:00
If everything goes as planned, we’ll have a conn
object
to pass into the gor_query
function to finally run a
query:
result <- gor_query("gor #dbsnp# | top 100", conn)
The results come back as an R data.frame
:
print(result)
#> # A tibble: 100 × 5
#> chrom pos reference allele rsids
#> <chr> <int> <chr> <chr> <chr>
#> 1 chr1 10001 T A rs1570391677
#> 2 chr1 10001 T C rs1570391677
#> 3 chr1 10002 A C rs1570391692
#> 4 chr1 10003 A C rs1570391694
#> 5 chr1 10007 T C rs1639538116
#> 6 chr1 10007 T G rs1639538116
#> 7 chr1 10008 A C rs1570391698
#> 8 chr1 10008 A G rs1570391698
#> 9 chr1 10008 A T rs1570391698
#> 10 chr1 10009 A C rs1570391702
#> # … with 90 more rows
It should also be noted that larger gor queries can be constructed
inside a string block and piped directly into the gor_query
function:
chr21_results <- "
gor -p chr21 #dbsnp#
| where len(reference)=1 and len(allele)=1
| calc snptype reference+'/'+allele
| hide rsIDs
| top 100" %>%
gor_query(conn)
print(chr21_results)
#> # A tibble: 100 × 5
#> chrom pos reference allele snptype
#> <chr> <int> <chr> <chr> <chr>
#> 1 chr21 5025532 G C G/C
#> 2 chr21 5030088 C T C/T
#> 3 chr21 5030105 C A C/A
#> 4 chr21 5030151 T G T/G
#> 5 chr21 5030154 T C T/C
#> 6 chr21 5030160 T A T/A
#> 7 chr21 5030173 G C G/C
#> 8 chr21 5030192 A G A/G
#> 9 chr21 5030201 A C A/C
#> 10 chr21 5030208 A G A/G
#> # … with 90 more rows