What is the best way to load bgen files into python?
1
0
Entering edit mode
2.4 years ago
Diego ▴ 30

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 • 1.4k views
ADD COMMENT
1
Entering edit mode

Seen pybgen or this another bgen reader as alternative options?

ADD REPLY
2
Entering edit mode
2.4 years ago
carlk ▴ 40

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: 2665 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