Read¶
- bgen_reader.read_bgen(filepath: Union[str, pathlib.Path], metafile_filepath: Optional[Union[str, pathlib.Path]] = None, samples_filepath: Optional[Union[str, pathlib.Path]] = None, verbose: bool = True)[source]
Read a given BGEN file.
- Parameters
filepath – Bgen file path.
metafile_filepath – File path to the corresponding metafile. A metafile can be created by calling
bgen_reader.create_metafile()
. IfNone
, a metafile will be automatically created. Defaults toNone
.samples_filepath – Path to a sample format file or
None
to read samples from the bgen file itself. Defaults toNone
.verbose –
True
to show progress;False
otherwise. Defaults toTrue
.
- Returns
variants (
dask.dataFrame.DataFrame
) – Variant position, chromosomes, rsids, etc.samples (
pandas.Series
) – Sample identifications.genotype (list) – List of genotypes.
Examples
>>> from bgen_reader import example_filepath, read_bgen >>> >>> bgen = read_bgen(example_filepath("haplotypes.bgen"), verbose=False) >>> variants = bgen["variants"] >>> samples = bgen["samples"] >>> >>> v = variants.loc[0].compute() >>> g = bgen["genotype"][0].compute() >>> print(v) id rsid chrom pos nalleles allele_ids vaddr 0 SNP1 RS1 1 1 2 A,G 102 >>> print(samples) 0 sample_0 1 sample_1 2 sample_2 3 sample_3 Name: id, dtype: object >>> print(g["probs"][0]) [1. 0. 1. 0.]