bgen_file
|
BGEN file handler. |
Close file stream. |
|
Check if it contains samples. |
|
|
Create metafile file. |
File path. |
|
Number of samples. |
|
Number of variants. |
|
|
Read genotype. |
|
Read genotype probability. |
Read samples. |
- class cbgen.bgen_file(filepath)[source]
BGEN file handler.
>>> import cbgen >>> >>> bgen = cbgen.bgen_file(cbgen.example.get("haplotypes.bgen")) >>> print(bgen.nvariants) 4 >>> print(bgen.nsamples) 4 >>> print(bgen.contain_samples) True >>> print(bgen.read_samples()) [b'sample_0' b'sample_1' b'sample_2' b'sample_3'] >>> mf = cbgen.bgen_metafile(cbgen.example.get("haplotypes.bgen.metafile")) >>> part = mf.read_partition(0) >>> gt = bgen.read_genotype(part.variants.offset[0]) >>> print(gt.probability) [[1. 0. 1. 0.] [0. 1. 1. 0.] [1. 0. 0. 1.] [0. 1. 0. 1.]] >>> mf.close() >>> bgen.close()
Use with-statement context to guarantee file closing at the end.
>>> with cbgen.bgen_file(cbgen.example.get("haplotypes.bgen")) as bgen: ... print(bgen.nvariants) 4
- property contain_samples: bool
Check if it contains samples.
- Return type
- Returns
True
if it does contain samples;False
otherwise.
- read_genotype(offset, precision=64)[source]
Read genotype.
- Parameters
- Return type
- Returns
Genotype.
- Raises
RuntimeError – If invalid offset of or a file stream reading error occurs.
- read_probability(offset, precision=64)[source]
Read genotype probability.
- Parameters
- Return type
- Returns
Probabilities.
- Raises
RuntimeError – If invalid offset of or a file stream reading error occurs.
- read_samples()[source]
Read samples.
- Return type
- Returns
Samples.
- Raises
RuntimeError – If samples are not stored or a file stream reading error occurs.