Function to read the UK Biobank BGEN files into a bigSNP.
Character vector of paths to files with extension ".bgen". The corresponding ".bgen.bgi" index files must exist.
The path (without extension) for the backing files (".bk" and ".rds") that are created by this function for storing the bigSNP object.
List (same length as the number of BGEN files) of
character vector of SNP IDs to read. These should be in the form
If you have one BGEN file only, just wrap your vector of IDs with
This function assumes that these IDs are uniquely identifying variants.
An optional vector of the row indices (individuals) that
are used. If not specified, all rows are used.
Don't use negative indices.
Directory of index files. Default is the same as
How to read BGEN probabilities? Currently implemented:
as dosages (rounded to two decimal places), the default,
as hard calls, randomly sampled based on those probabilities
(similar to PLINK option '
Number of cores used. Default doesn't use parallelism.
You may use
The path to the RDS file
<backingfile>.rds that stores the
object created by this function.
Note that this function creates one other file which stores the values of
the Filebacked Big Matrix.
You shouldn't read from BGEN files more than once. Instead, use snp_attach to load the "bigSNP" object in any R session from backing files.
For more information on this format, please visit BGEN webpage.
This function is designed to read UK Biobank imputation files. This assumes
that variants have been compressed with zlib, that there are only 2 possible
alleles, and that each probability is stored on 8 bits. For example, if you
use qctool to generate your own BGEN files, please make sure you are using
-ofiletype bgen_v1.2 -bgen-bits 8'.
If the format is not the expected one, this will result in an error or even
a crash of your R session. Another common source of error is due to corrupted
files; e.g. if using UK Biobank files, compare the result of
with the ones at https://biobank.ndph.ox.ac.uk/ukb/refer.cgi?id=998.
You can look at some example code from my papers on how to use this function: