Read PLINK files into Pandas data frames
Project description
pandas-plink
Pandas-plink is a Python package for reading PLINK binary file format and (since version 2.0.0) PLINK and GCTA realized relationship matrices. The file reading is taken place via lazy loading, meaning that it saves up memory by actually reading only the genotypes that are actually accessed by the user.
Notable changes can be found at the CHANGELOG.md.
Install
It be installed using pip:
pip install pandas-plink
Alternatively it can be intalled via conda:
conda install -c conda-forge pandas-plink
Usage
It is as simple as
>>> from pandas_plink import read_plink1_bin
>>> G = read_plink1_bin("chr11.bed", "chr11.bim", "chr11.fam", verbose=False)
>>> print(G)
<xarray.DataArray 'genotype' (sample: 14, variant: 779)>
dask.array<shape=(14, 779), dtype=float64, chunksize=(14, 779)>
Coordinates:
* sample (sample) object 'B001' 'B002' 'B003' ... 'B012' 'B013' 'B014'
* variant (variant) object '11_316849996' '11_316874359' ... '11_345698259'
father (sample) <U1 '0' '0' '0' '0' '0' '0' ... '0' '0' '0' '0' '0' '0'
fid (sample) <U4 'B001' 'B002' 'B003' 'B004' ... 'B012' 'B013' 'B014'
gender (sample) <U1 '0' '0' '0' '0' '0' '0' ... '0' '0' '0' '0' '0' '0'
i (sample) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13
iid (sample) <U4 'B001' 'B002' 'B003' 'B004' ... 'B012' 'B013' 'B014'
mother (sample) <U1 '0' '0' '0' '0' '0' '0' ... '0' '0' '0' '0' '0' '0'
trait (sample) <U2 '-9' '-9' '-9' '-9' '-9' ... '-9' '-9' '-9' '-9' '-9'
a0 (variant) <U1 'C' 'G' 'G' 'C' 'C' 'T' ... 'T' 'A' 'C' 'A' 'A' 'T'
a1 (variant) <U1 'T' 'C' 'C' 'T' 'T' 'A' ... 'C' 'G' 'T' 'G' 'C' 'C'
chrom (variant) <U2 '11' '11' '11' '11' '11' ... '11' '11' '11' '11' '11'
cm (variant) float64 0.0 0.0 0.0 0.0 0.0 0.0 ... 0.0 0.0 0.0 0.0 0.0
pos (variant) int64 157439 181802 248969 ... 28937375 28961091 29005702
snp (variant) <U9 '316849996' '316874359' ... '345653648' '345698259'
>>> print(G.sel(sample="B003", variant="11_316874359").values)
0.0
>>> print(G.a0.sel(variant="11_316874359").values)
G
>>> print(G.sel(sample="B003", variant="11_316941526").values)
2.0
>>> print(G.a1.sel(variant="11_316941526").values)
C
Portions of the genotype will be read as the user access them.
Covariance matrices can also be read very easily. Example:
>>> from pandas_plink import read_rel
>>> K = read_rel("plink2.rel.bin")
>>> print(K)
<xarray.DataArray (sample_0: 10, sample_1: 10)>
array([[ 0.885782, 0.233846, -0.186339, -0.009789, -0.138897, 0.287779,
0.269977, -0.231279, -0.095472, -0.213979],
[ 0.233846, 1.077493, -0.452858, 0.192877, -0.186027, 0.171027,
0.406056, -0.013149, -0.131477, -0.134314],
[-0.186339, -0.452858, 1.183312, -0.040948, -0.146034, -0.204510,
-0.314808, -0.042503, 0.296828, -0.011661],
[-0.009789, 0.192877, -0.040948, 0.895360, -0.068605, 0.012023,
0.057827, -0.192152, -0.089094, 0.174269],
[-0.138897, -0.186027, -0.146034, -0.068605, 1.183237, 0.085104,
-0.032974, 0.103608, 0.215769, 0.166648],
[ 0.287779, 0.171027, -0.204510, 0.012023, 0.085104, 0.956921,
0.065427, -0.043752, -0.091492, -0.227673],
[ 0.269977, 0.406056, -0.314808, 0.057827, -0.032974, 0.065427,
0.714746, -0.101254, -0.088171, -0.063964],
[-0.231279, -0.013149, -0.042503, -0.192152, 0.103608, -0.043752,
-0.101254, 1.423033, -0.298255, -0.074334],
[-0.095472, -0.131477, 0.296828, -0.089094, 0.215769, -0.091492,
-0.088171, -0.298255, 0.910274, -0.024663],
[-0.213979, -0.134314, -0.011661, 0.174269, 0.166648, -0.227673,
-0.063964, -0.074334, -0.024663, 0.914586]])
Coordinates:
* sample_0 (sample_0) object 'HG00419' 'HG00650' ... 'NA20508' 'NA20753'
* sample_1 (sample_1) object 'HG00419' 'HG00650' ... 'NA20508' 'NA20753'
fid (sample_1) object 'HG00419' 'HG00650' ... 'NA20508' 'NA20753'
iid (sample_1) object 'HG00419' 'HG00650' ... 'NA20508' 'NA20753'
>>> print(K.values)
[[ 0.89 0.23 -0.19 -0.01 -0.14 0.29 0.27 -0.23 -0.10 -0.21]
[ 0.23 1.08 -0.45 0.19 -0.19 0.17 0.41 -0.01 -0.13 -0.13]
[-0.19 -0.45 1.18 -0.04 -0.15 -0.20 -0.31 -0.04 0.30 -0.01]
[-0.01 0.19 -0.04 0.90 -0.07 0.01 0.06 -0.19 -0.09 0.17]
[-0.14 -0.19 -0.15 -0.07 1.18 0.09 -0.03 0.10 0.22 0.17]
[ 0.29 0.17 -0.20 0.01 0.09 0.96 0.07 -0.04 -0.09 -0.23]
[ 0.27 0.41 -0.31 0.06 -0.03 0.07 0.71 -0.10 -0.09 -0.06]
[-0.23 -0.01 -0.04 -0.19 0.10 -0.04 -0.10 1.42 -0.30 -0.07]
[-0.10 -0.13 0.30 -0.09 0.22 -0.09 -0.09 -0.30 0.91 -0.02]
[-0.21 -0.13 -0.01 0.17 0.17 -0.23 -0.06 -0.07 -0.02 0.91]]
Please, refer to the pandas-plink documentation for more information.
Authors
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file pandas_plink-2.0.1.tar.gz
.
File metadata
- Download URL: pandas_plink-2.0.1.tar.gz
- Upload date:
- Size: 72.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c44c0834b1869efeb66166209fb9cefcc99eda3471fd43a238447e49f91dfef0 |
|
MD5 | 8ffb949a1511e399ce01aa6b8c2db2b1 |
|
BLAKE2b-256 | 3c46673c7b01f35a806ace5cbba9e11ed8188fff4b5b8a67f4162883be90b147 |
File details
Details for the file pandas_plink-2.0.1-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: pandas_plink-2.0.1-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 80.5 kB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b369f7ff9d8b6b02af65ee4bc1cf4fcf21f4bc0280829e9d637c01221df8724 |
|
MD5 | 986ff4d655d9f23f67cc1a1d8280b62a |
|
BLAKE2b-256 | 48ef32ac4eb1efe6b80754154cd88f480df5a25c25ae1134fbc70258c4229a4b |
File details
Details for the file pandas_plink-2.0.1-cp37-cp37m-win32.whl
.
File metadata
- Download URL: pandas_plink-2.0.1-cp37-cp37m-win32.whl
- Upload date:
- Size: 79.7 kB
- Tags: CPython 3.7m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c262dffba3d42d60968eea28e8c9b8ff257bec3dd29eee29c39f39e1f479a0c5 |
|
MD5 | 403be47a0d7ec7464ebe81cd4d70b02e |
|
BLAKE2b-256 | 6a32eda3898478db5d9a885b6a6036eaaf4fe9cb7346852e818e407686a485b5 |
File details
Details for the file pandas_plink-2.0.1-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: pandas_plink-2.0.1-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 83.6 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 083435c1c6e37457e0a8510e71954928977c73e1fab1e6148a297adda67edf5d |
|
MD5 | 2bb5a4da61eafc5926f3af664df72917 |
|
BLAKE2b-256 | a63975661089c4ddaabda3bf2c9a1b5929ce0bcbd3b936f55030c09567f93b41 |
File details
Details for the file pandas_plink-2.0.1-cp37-cp37m-manylinux1_i686.whl
.
File metadata
- Download URL: pandas_plink-2.0.1-cp37-cp37m-manylinux1_i686.whl
- Upload date:
- Size: 83.3 kB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07d13cd6a7d4b0cc9b4a6fe3d8e6458d35fc715f63cc8f54b9f59f805f7b1a30 |
|
MD5 | 8cae48859b23419bac9d689567358003 |
|
BLAKE2b-256 | c8c380a8c13fb1392ae3bedfb26aa12e2e67b2794c2279be865e45730b7e9d2d |
File details
Details for the file pandas_plink-2.0.1-cp37-cp37m-macosx_10_6_intel.whl
.
File metadata
- Download URL: pandas_plink-2.0.1-cp37-cp37m-macosx_10_6_intel.whl
- Upload date:
- Size: 79.9 kB
- Tags: CPython 3.7m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27d6b5278b42ae8acbb6c22a0eebe0fd4f6dded043ab19b809ecda8e7e32b768 |
|
MD5 | 99a62679a16b22e62dd41c335c77bb1c |
|
BLAKE2b-256 | 13bd7ae1723988b10e262dd1c1686d73d9d465b016827e969d22674cc792d9d6 |
File details
Details for the file pandas_plink-2.0.1-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: pandas_plink-2.0.1-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 80.5 kB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcdaf256d1db08a665b230c4596761f12c9bfd05f423a34079c314f2e28909a8 |
|
MD5 | 7b8dd7c5b7233d3a3557191bd5165774 |
|
BLAKE2b-256 | 0ee53e2dc76fe6495394d460b6b457ad771c22cbdfef422da24ae6191ca120e9 |
File details
Details for the file pandas_plink-2.0.1-cp36-cp36m-win32.whl
.
File metadata
- Download URL: pandas_plink-2.0.1-cp36-cp36m-win32.whl
- Upload date:
- Size: 79.7 kB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a59b952c32fc0f200b4e35b6b559fea903c8fbd1d280a6072e82412229c5964 |
|
MD5 | c97ccde88016e23a518be7aeecd74319 |
|
BLAKE2b-256 | 62bc400ba86ebb5cd0d10024b9c093b81bf809b7e662e2d10925280f0547ea3e |
File details
Details for the file pandas_plink-2.0.1-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: pandas_plink-2.0.1-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 83.6 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91aebd07d09d1ca2f7ad969699f5ccf5b987919d06e8dff3b5238f3b46f13535 |
|
MD5 | 6bb37f612f48265dbe5fde95d6906a4b |
|
BLAKE2b-256 | d0eb8dba22c64e80dd41ea8290f063066024d4020533e04b096d4781cb2176ac |
File details
Details for the file pandas_plink-2.0.1-cp36-cp36m-manylinux1_i686.whl
.
File metadata
- Download URL: pandas_plink-2.0.1-cp36-cp36m-manylinux1_i686.whl
- Upload date:
- Size: 83.3 kB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc1edc44290b3b65f43d6f3db8f7c026070ae95de9e2cec7f837aa3de4ff3934 |
|
MD5 | a0ea1f6870f8517458b0feaf796ee819 |
|
BLAKE2b-256 | 9a891895459d0ff13ebe74672223c521316772fb85924d0838021f9eff92e9dd |
File details
Details for the file pandas_plink-2.0.1-cp36-cp36m-macosx_10_6_intel.whl
.
File metadata
- Download URL: pandas_plink-2.0.1-cp36-cp36m-macosx_10_6_intel.whl
- Upload date:
- Size: 79.9 kB
- Tags: CPython 3.6m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3989906038dfd2861efd6c02d0f32b18c98b31fdadaf87e2bbfde5bca5d92f8c |
|
MD5 | f9fa26d7b115dbd02f9e93ac37090bdb |
|
BLAKE2b-256 | 758ba2ddafdad1b303891d5648846653362570f7876ad271ff96082745421732 |