Skip to content

Commit

Permalink
change sparse.bim
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlKCarlK committed Nov 4, 2023
1 parent 33fd324 commit ac522dd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 28 deletions.
24 changes: 17 additions & 7 deletions bed_reader/_open_bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,19 +1245,29 @@ def read_sparse(
Examples
--------
To read all data in a .bed file, set ``index`` to ``None``. This is the default.
cmk continue updating the docs here.
Read all data in a .bed file into a `scipy.sparse.csc_matrix`.
The file has 10 individuals (samples) by 20 SNPs (variants).
All but eight values are 0.
.. doctest::
>>> # pip install bed-reader[samples,sparse] # if needed
>>> from bed_reader import open_bed, sample_file
>>>
>>> file_name = sample_file("small.bed")
>>> file_name = sample_file("sparse.bed")
>>> with open_bed(file_name) as bed:
... print(bed.read())
[[ 1. 0. nan 0.]
[ 2. 0. nan 2.]
[ 0. 1. 2. 0.]]
... print(bed.shape())
... val_sparse = bed.read_sparse(dtype="int8")
... print(val_sparse)
(10, 20)
(8, 4) 1
(8, 5) 2
(0, 8) 2
(4, 9) 1
(7, 9) 1
(5, 11) 1
(2, 12) 1
(3, 12) 1
To read selected individuals (samples) and/or SNPs (variants), set each part of
a :class:`numpy.s_` to an `int`, a list of `int`, a slice expression, or
Expand Down
2 changes: 1 addition & 1 deletion bed_reader/_sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
path=pooch.os_cache("bed_reader"),
# The remote data is on Github
base_url="https://raw.githubusercontent.com/"
+ "fastlmm/bed-reader/rustybed/bed_reader/tests/data/",
+ "fastlmm/bed-reader/Oct2023/bed_reader/tests/data/",
# If this is a development version, get the data from the master branch
version_dev="master",
# The registry specifies the files that can be fetched
Expand Down
40 changes: 20 additions & 20 deletions bed_reader/tests/data/sparse.bim
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
1.0 sid_0 0.0 126131822 A1 A2
2.0 sid_1 0.0 70468033 A1 A2
2.0 sid_2 0.0 223618033 A1 A2
3.0 sid_3 0.0 67771248 A1 A2
4.0 sid_4 0.0 146322476 A1 A2
4.0 sid_5 0.0 299472476 A1 A2
5.0 sid_6 0.0 51277007 A1 A2
6.0 sid_7 0.0 89797274 A1 A2
7.0 sid_8 0.0 2175616 A1 A2
8.0 sid_9 0.0 128673782 A1 A2
9.0 sid_10 0.0 144360723 A1 A2
10.0 sid_11 0.0 113744049 A1 A2
11.0 sid_12 0.0 58449190 A1 A2
12.0 sid_13 0.0 85742409 A1 A2
13.0 sid_14 0.0 29012823 A1 A2
15.0 sid_15 0.0 16244046 A1 A2
16.0 sid_16 0.0 22451361 A1 A2
18.0 sid_17 0.0 109302574 A1 A2
20.0 sid_18 0.0 71272297 A1 A2
22.0 sid_19 0.0 92855895 A1 A2
1 sid_0 0.0 126131822 A1 A2
1 sid_1 0.0 70468033 A1 A2
1 sid_2 0.0 223618033 A1 A2
1 sid_3 0.0 67771248 A1 A2
5 sid_4 0.0 146322476 A1 A2
5 sid_5 0.0 299472476 A1 A2
5 sid_6 0.0 51277007 A1 A2
5 sid_7 0.0 89797274 A1 A2
5 sid_8 0.0 2175616 A1 A2
5 sid_9 0.0 128673782 A1 A2
5 sid_10 0.0 144360723 A1 A2
5 sid_11 0.0 113744049 A1 A2
5 sid_12 0.0 58449190 A1 A2
Y sid_13 0.0 85742409 A1 A2
Y sid_14 0.0 29012823 A1 A2
Y sid_15 0.0 16244046 A1 A2
Y sid_16 0.0 22451361 A1 A2
Y sid_17 0.0 109302574 A1 A2
Y sid_18 0.0 71272297 A1 A2
Y sid_19 0.0 92855895 A1 A2
3 changes: 3 additions & 0 deletions bed_reader/tests/registry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@ some_missing.val.npy 316ad46abcf30b15d3140a893b207b90ae63b00aa1d76443f6113a66c3e
toydata.5chrom.bed bc1cedaf4c296749dd49cc0dcb95d2a8f4c792433b37ebb9f847dba53c2fc4cf
toydata.5chrom.bim 131f4beba07b56a604fafb03a9f536dbdfbf6a67a094ddb7714db9609a3a89a3
toydata.5chrom.fam 9551c70290580c9b23cb83c98ccc7791f380169bdaddfbc2edb905ff78879cc4
sparse.bed 70f76a3920b4c8498ecfae9c8837c3ea841a874f88f60c082141905a24d63114
sparse.fam 729bb46dab41082c6b5937f7f9e3a68d0c0f27d2ad795f1fa1fd146354fb6aa7
sparse.bim 0d08176c438aa1aed8c4d9c64faffc4ba6560688f2c708cfbd0ca87d273c3754

0 comments on commit ac522dd

Please sign in to comment.