03 Working with UK Biobank summary statistics
Vincent J. Carey, stvjc at channing.harvard.edu
October 30, 2024
Source:vignettes/ukbb.Rmd
ukbb.Rmd
Overview
In this document we illustrate some approaches to working with UK Biobank summary statistics. Be sure that that the python module ukbb_pan_ancestry
has been installed where reticulate can find it. (We don’t use basilisk as of 12/24/2022 because of issues in the terra spark cluster.)
If the above command indicates that BiocHail is not available, see the Installation section near the end of this document.
Initialization and description
Standalone
We have produced a representation of summary statistics for a sample of 9888 loci. This 5GB resource can be retrieved and cached with the following code:
hl = hail_init()
ss = get_ukbb_sumstat_10kloci_mt(hl) # can take about a minute to unzip 5GB
ss$count() # but if a persistent MatrixTable is at the location given
# by env var HAIL_UKBB_SUMSTAT_10K_PATH it goes quickly
To get a description of available content, we need a python chunk:
r.ss.describe()
Terra
Here’s a basic description of the summary stats table, with code that works in terra.bio:
hl = bare_hail()
hl$init(idempotent=TRUE, spark_conf=list(
'spark.hadoop.fs.gs.requester.pays.mode'= 'CUSTOM',
'spark.hadoop.fs.gs.requester.pays.buckets'= 'ukb-diverse-pops-public',
'spark.hadoop.fs.gs.requester.pays.project.id'= Sys.getenv("GOOGLE_PROJECT")))
We need to use a python chunk to get the output, using gs:// storage references.
'gs://ukb-diverse-pops-public/sumstats_release/results_full.mt').describe() r.hl.read_matrix_table(
Exploring the subset
Metadata on study phenotypes
We’ll collect the column metadata to start to understand details of annotation of phenotypes.
sscol = ss$cols()$collect() # OK because we are just working over column metadata
ss1 = sscol[[1]]
names(ss1)
ss1$get("phenocode")
ss1$get("description")
We’ve introduced a function that extracts selected fields for a given phenotype, that accommodates availability of results for specific populations.
multipop_df(ss1)
This can be iterated over all the elements of sscol
to produce a comprehensive searchable table. Here’s a small illustration:
Metadata on loci
We’ll trim the material to be worked with by sampling both rows and columns. (2023.01.08: In future revisions we will be able to control the seed for random sampling.)
sss = ss$sample_rows(.01)$sample_cols(.01)
sss$count()
Row metadata are simple to collect:
Exercises
Infrastructure
- Define an interface to this subset of 10k loci that supports queries like
- has disease x been studied in UK Biobank?
- how many phenotypes have been studied in K populations, K=2, 3, …?
- how consistent is the annotation – are numbers of controls and cases always recorded?
- Do the UK Biobank portals produce information to resolve these questions?
- if so, what are the API calls to obtain answers?
- if not, what is missing from the portals to allow answers to be obtained?
Installing BiocHail
BiocHail
should be installed as follows:
if (!require("BiocManager"))
install.packages("BiocManager")
BiocManager::install("BiocHail")
SessionInfo
## R version 4.4.1 (2024-06-14)
## Platform: aarch64-apple-darwin20
## Running under: macOS Sonoma 14.7
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## time zone: America/New_York
## tzcode source: internal
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] BiocStyle_2.32.1
##
## loaded via a namespace (and not attached):
## [1] cli_3.6.3 knitr_1.48 rlang_1.1.4
## [4] xfun_0.48 png_0.1-8 textshaping_0.4.0
## [7] jsonlite_1.8.9 htmltools_0.5.8.1 ragg_1.3.3
## [10] sass_0.4.9 rmarkdown_2.28 grid_4.4.1
## [13] evaluate_1.0.1 jquerylib_0.1.4 fastmap_1.2.0
## [16] yaml_2.3.10 lifecycle_1.0.4 bookdown_0.40
## [19] BiocManager_1.30.25 compiler_4.4.1 fs_1.6.4
## [22] Rcpp_1.0.13 htmlwidgets_1.6.4 lattice_0.22-6
## [25] systemfonts_1.1.0 digest_0.6.37 R6_2.5.1
## [28] reticulate_1.39.0 bslib_0.8.0 Matrix_1.7-0
## [31] tools_4.4.1 pkgdown_2.1.1 cachem_1.1.0
## [34] desc_1.4.3