bgen_metafile

bgen_metafile(filepath)

BGEN metafile file handler.

bgen_metafile.close()

Close file stream.

bgen_metafile.filepath

File path.

bgen_metafile.npartitions

Number of partitions.

bgen_metafile.nvariants

Number of variants.

bgen_metafile.partition_size

Number of variants per partition.

bgen_metafile.read_partition(index)

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

filepath (Union[str, Path]) – BGEN metafile file path.

Raises

RuntimeError – If a file stream reading error occurs.

close()[source]

Close file stream.

property filepath: pathlib.Path

File path.

Return type

Path

Returns

File path.

property npartitions: int

Number of partitions.

Return type

int

Returns

Number of partitions.

property nvariants: int

Number of variants.

Return type

int

Returns

Number of variants.

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

int

Returns

Partition size.

read_partition(index)[source]

Read partition.

Parameters

index (int) – Partition index.

Return type

Partition

Returns

Partition.

Raises

RuntimeError – If index is invalid or a file stream reading error occurs.