{"id":23356,"library":"bgen","title":"Bgen","description":"Python package for loading and manipulating data from BGEN files, a binary file format for storing genotype data. Current version is 1.9.9, compatible with Python >=3.8. It is actively maintained with periodic releases.","status":"active","version":"1.9.9","language":"python","source_language":"en","source_url":"https://github.com/limix/bgen","tags":["genetics","bioinformatics","bgen","genotype","file-format","data-loading"],"install":[{"cmd":"pip install bgen","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required for array operations.","package":"numpy","optional":false},{"reason":"Required for building from source if wheel not available.","package":"cython","optional":true}],"imports":[{"note":"Main class for reading BGEN files.","wrong":"","symbol":"BGENFile","correct":"from bgen import BGENFile"},{"note":"Class for indexing BGEN files.","wrong":"","symbol":"BGENX","correct":"from bgen import BGENX"}],"quickstart":{"code":"from bgen import BGENFile\n\n# Replace with your actual BGEN file path\nbgen = BGENFile('example.bgen')\n\n# Get number of samples\nprint('Number of samples:', bgen.nsamples)\n\n# Get number of variants\nprint('Number of variants:', bgen.nvariants)\n\n# Iterate over first 5 variants\nfor i, variant in enumerate(bgen):\n    if i >= 5:\n        break\n    print('Variant:', variant.rsid, variant.chromosome, variant.position)\n    # Access genotype probabilities (3D array: samples x alleles x ploidy)\n    probs = variant.genotype()\n    print('Genotype probs shape:', probs.shape)","lang":"python","description":"Open a BGEN file and read basic information and variant genotypes."},"warnings":[{"fix":"Always check documentation or use .rsid for identifiers.","message":"BGENFile indexing is 0-based, not 1-based. Often users expect variant positions to be 1-indexed.","severity":"gotcha","affected_versions":"all"},{"fix":"Use 'from bgen import BGENFile; bgen = BGENFile(filename)' instead.","message":"Functions like 'bgen_open' are deprecated in favor of direct class instantiation.","severity":"deprecated","affected_versions":">=1.7"},{"fix":"Use the 'subsample' or 'probs' arguments to subset or use iterator for large files.","message":"Memory usage can be high when calling .genotype() on a large variant because it loads all sample data into memory.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'pip install bgen' and ensure you're using the correct Python interpreter.","cause":"Package not installed or installed in a different environment.","error":"ImportError: No module named 'bgen'"},{"fix":"Use iteration: for variant in bgen: ... or bgen[0] to access first variant.","cause":"Using an old API; BGENFile no longer has a read method; data is accessed via iteration or properties.","error":"bgen.BGENFile' object has no attribute 'read'"},{"fix":"Use dot notation: variant.rsid, variant.chromosome, etc.","cause":"Trying to access variant metadata using key-based access on a variant object, but variant is not a dict.","error":"KeyError: 'rsid'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}