Skip to main content

Read and write the PLINK BED format, simply and efficiently.

Project description

PyPI version Build Status PyPI

Read and write the PLINK BED format, simply and efficiently.

This is the Python README. For Rust, see README-rust.md.

Highlights

  • Fast multi-threaded Rust engine.
  • Supports all Python indexing methods. Slice data by individuals (samples) and/or SNPs (variants).
  • Used by PySnpTools, FaST-LMM, and PyStatGen.
  • Supports PLINK 1.9.
  • Read data locally or from the cloud, efficiently and directly.

Install

Full version: With all optional dependencies:

pip install bed-reader[samples,sparse]

Minimal version: Depends only on numpy:

pip install bed-reader

Usage

Read genomic data from a .bed file.

>>> import numpy as np
>>> from bed_reader import open_bed, sample_file
>>>
>>> file_name = sample_file("small.bed")
>>> bed = open_bed(file_name)
>>> val = bed.read()
>>> print(val)
[[ 1.  0. nan  0.]
 [ 2.  0. nan  2.]
 [ 0.  1.  2.  0.]]
>>> del bed

Read every second individual and SNPs (variants) from 20 to 30.

>>> file_name2 = sample_file("some_missing.bed")
>>> bed2 = open_bed(file_name2)
>>> val2 = bed2.read(index=np.s_[::2,20:30])
>>> print(val2.shape)
(50, 10)
>>> del bed2

List the first 5 individual (sample) ids, the first 5 SNP (variant) ids, and every unique chromosome. Then, read every genomic value in chromosome 5.

>>> with open_bed(file_name2) as bed3:
...     print(bed3.iid[:5])
...     print(bed3.sid[:5])
...     print(np.unique(bed3.chromosome))
...     val3 = bed3.read(index=np.s_[:,bed3.chromosome=='5'])
...     print(val3.shape)
['iid_0' 'iid_1' 'iid_2' 'iid_3' 'iid_4']
['sid_0' 'sid_1' 'sid_2' 'sid_3' 'sid_4']
['1' '10' '11' '12' '13' '14' '15' '16' '17' '18' '19' '2' '20' '21' '22'
 '3' '4' '5' '6' '7' '8' '9']
(100, 6)

From the cloud: open a file and read data for one SNP (variant) at index position 2.

>>> with open_bed("https://raw.githubusercontent.com/fastlmm/bed-sample-files/main/small.bed") as bed:
...     val = bed.read(index=np.s_[:,2], dtype="float64")
...     print(val)
[[nan]
 [nan]
 [ 2.]]

Project Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bed_reader-1.0.6a1.tar.gz (2.8 MB view hashes)

Uploaded Source

Built Distributions

bed_reader-1.0.6a1-cp313-none-win_amd64.whl (5.6 MB view hashes)

Uploaded CPython 3.13 Windows x86-64

bed_reader-1.0.6a1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ x86-64

bed_reader-1.0.6a1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.2 MB view hashes)

Uploaded CPython 3.13 manylinux: glibc 2.17+ ARM64

bed_reader-1.0.6a1-cp312-none-win_amd64.whl (5.6 MB view hashes)

Uploaded CPython 3.12 Windows x86-64

bed_reader-1.0.6a1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

bed_reader-1.0.6a1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.2 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

bed_reader-1.0.6a1-cp312-cp312-macosx_11_0_arm64.whl (5.8 MB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

bed_reader-1.0.6a1-cp312-cp312-macosx_10_12_x86_64.whl (6.0 MB view hashes)

Uploaded CPython 3.12 macOS 10.12+ x86-64

bed_reader-1.0.6a1-cp311-none-win_amd64.whl (5.6 MB view hashes)

Uploaded CPython 3.11 Windows x86-64

bed_reader-1.0.6a1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

bed_reader-1.0.6a1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.2 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

bed_reader-1.0.6a1-cp311-cp311-macosx_11_0_arm64.whl (5.8 MB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

bed_reader-1.0.6a1-cp311-cp311-macosx_10_12_x86_64.whl (5.9 MB view hashes)

Uploaded CPython 3.11 macOS 10.12+ x86-64

bed_reader-1.0.6a1-cp310-none-win_amd64.whl (5.6 MB view hashes)

Uploaded CPython 3.10 Windows x86-64

bed_reader-1.0.6a1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.3 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

bed_reader-1.0.6a1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.2 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

bed_reader-1.0.6a1-cp310-cp310-macosx_11_0_arm64.whl (5.8 MB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

bed_reader-1.0.6a1-cp310-cp310-macosx_10_12_x86_64.whl (5.9 MB view hashes)

Uploaded CPython 3.10 macOS 10.12+ x86-64

bed_reader-1.0.6a1-cp39-none-win_amd64.whl (5.6 MB view hashes)

Uploaded CPython 3.9 Windows x86-64

bed_reader-1.0.6a1-cp38-none-win_amd64.whl (5.6 MB view hashes)

Uploaded CPython 3.8 Windows x86-64

bed_reader-1.0.6a1-cp37-none-win_amd64.whl (5.6 MB view hashes)

Uploaded CPython 3.7 Windows x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page