bgen_metafile
|
BGEN metafile file handler. |
Close file stream. |
|
File path. |
|
Number of partitions. |
|
Number of variants. |
|
Number of variants per partition. |
|
|
Read partition. |
- class cbgen.bgen_metafile(filepath)[source]
BGEN metafile file handler.
>>> import cbgen >>> >>> bgen = cbgen.bgen_file(cbgen.example.get("haplotypes.bgen")) >>> mf = cbgen.bgen_metafile(cbgen.example.get("haplotypes.bgen.metafile")) >>> print(mf.npartitions) 1 >>> print(mf.nvariants) 4 >>> print(mf.partition_size) 4 >>> 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_metafile(cbgen.example.get("haplotypes.bgen.metafile")) as mf: ... print(mf.npartitions) 1
- Parameters
- Raises
RuntimeError – If a file stream reading error occurs.
- property partition_size: int
Number of variants per partition.
The last partition might have less variants than the partition size. Every other partition is guaranteed to have
partition_size
variants.- Return type
- Returns
Partition size.
- read_partition(index)[source]
Read partition.
- Parameters
index (
int
) – Partition index.- Return type
- Returns
Partition.
- Raises
RuntimeError – If index is invalid or a file stream reading error occurs.