What is the best way to load bgen files into python?
1
0
Entering edit mode
6 weeks ago
Diego • 0

I am new to the BGEN format, (I mainly work with PLINK formatted files or VCFs). I have been trying to load a series of BGEN files to python using bgen-reader; however, there has been some issues that the developers have not been able to solve. Is there an alternative to loading BGEN files into python? maybe change the BGEN to another format and then import them to python?

BGEN Python • 323 views
ADD COMMENT
1
Entering edit mode

Seen pybgen or this another bgen reader as alternative options?

ADD REPLY
1
Entering edit mode
6 weeks ago
carlk ▴ 20

bgen-reader is available via PyPi or Conda. It offers a NumPy-inspired API. Here is a sample:

>>> # Download a sample file
>>> from bgen_reader import example_filepath
>>> bgen_file = example_filepath("example.bgen")

>>> # Read from the file
>>> from bgen_reader import open_bgen
>>> bgen = open_bgen(bgen_file, verbose=False)
>>> probs0 = bgen.read(0)   # Read 1st variant
>>> print(probs0.shape)     # Shape of the NumPy array
(500, 1, 3)
>>> probs_all = bgen.read() # Read all variants
>>> print(probs_all.shape)  # Shape of the NumPy array
(500, 199, 3)

I'm one of the authors and happy to help users.

  • Carl
  • Carl Kadie, Ph.D.
  • FaST-LMM & PySnpTools Team (also Bgen-Reader!)
  • (Microsoft Research, retired)
ADD COMMENT

Login before adding your answer.

Traffic: 1630 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6