bed-reader 1.0.0b1__tar.gz → 1.0.0b4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/.github/workflows/ci.yml +4 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/CHANGELOG.md +5 -5
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/Cargo.lock +1 -1
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/Cargo.toml +1 -1
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/PKG-INFO +4 -4
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/README.md +3 -2
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/_open_bed.py +70 -22
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/_sample_data.py +8 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/test_open_bed.py +35 -3
- bed_reader-1.0.0b4/bed_reader/tests/test_opt_dep.py +29 -0
- bed_reader-1.0.0b4/ignore.py +5 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/pyproject.toml +1 -1
- bed_reader-1.0.0b4/requirements-min-dev.txt +3 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/requirements.txt +0 -1
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/useful.bat +4 -1
- bed_reader-1.0.0b1/requirements-minimal.txt +0 -1
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/.flake8 +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/.gitignore +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/.isort.cfg +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/AUTHORS.txt +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/LICENSE.md +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/README-rust.md +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/__init__.py +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/_to_bed.py +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/__init__.py +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/benchmark/benchmark.py +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/500x400_o640_array.memmap +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/badfile.bed +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/empty.bed +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/plink_sim_10s_100v_10pmiss.bed +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/plink_sim_10s_100v_10pmiss.bim +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/plink_sim_10s_100v_10pmiss.fam +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small.bad_bim +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small.bed +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small.bim +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small.bim_bad_positions.bim +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small.deb +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small.fam +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small.fam_bad +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small.maf +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small.mib +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small2_array.memmap +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small_array.memmap +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small_no_bim.bed +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small_no_bim.fam +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small_no_fam.bed +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small_no_fam.bim +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small_too_short.bed +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small_too_short.bim +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/small_too_short.fam +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/smallmode0.bed +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/smallmode0.bim +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/smallmode0.fam +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/smallmodebad.bed +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/some_missing.bed +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/some_missing.bim +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/some_missing.fam +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/some_missing.properties.npz +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/some_missing.val.npy +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/sparse.bed +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/sparse.bim +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/sparse.fam +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/toydata.5chrom.bed +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/toydata.5chrom.bim +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/toydata.5chrom.fam +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/registry.txt +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/test_file_dot.py +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/build.rs +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/pytest.ini +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/requirements-dev.txt +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/src/lib.rs +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/src/python_module.rs +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/src/tests.rs +0 -0
- {bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/tests/tests_api.rs +0 -0
|
@@ -170,6 +170,8 @@ jobs:
|
|
|
170
170
|
virtualenv vEnv; source vEnv/bin/activate
|
|
171
171
|
python -m pip install --upgrade pip maturin
|
|
172
172
|
maturin develop
|
|
173
|
+
pip install -r requirements-min-dev.txt
|
|
174
|
+
pytest bed_reader/tests/test_opt_dep.py
|
|
173
175
|
echo "requirements"
|
|
174
176
|
pip install -r requirements.txt
|
|
175
177
|
echo "requirements-dev"
|
|
@@ -183,6 +185,8 @@ jobs:
|
|
|
183
185
|
echo "pwd"
|
|
184
186
|
pwd
|
|
185
187
|
python -m pip install --upgrade pip maturin
|
|
188
|
+
pip install -r requirements-min-dev.txt
|
|
189
|
+
pytest bed_reader/tests/test_opt_dep.py
|
|
186
190
|
echo "requirements"
|
|
187
191
|
pip install -r requirements.txt
|
|
188
192
|
echo "requirements-dev"
|
|
@@ -5,17 +5,17 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [1.0.0] - 2023-11-
|
|
8
|
+
## [1.0.0] - 2023-11-5
|
|
9
9
|
|
|
10
10
|
### Changed
|
|
11
11
|
|
|
12
|
-
- (Python)
|
|
13
|
-
If you want
|
|
14
|
-
`pip install bed-reader`.
|
|
12
|
+
- (Python) Core project now depends only on `numpy`.
|
|
13
|
+
If you want to download samples files or create
|
|
14
|
+
sparse matrices, say `pip install bed-reader[samples,sparse]`.
|
|
15
15
|
|
|
16
16
|
- (Python) Added new `read_sparse()` method for creating
|
|
17
17
|
`sympy.sparse.csc_matrix` and `sympy.sparse.csr_matrix`. This
|
|
18
|
-
method can save memory when a *.bed file contains mostly
|
|
18
|
+
method can save memory when a *.bed file contains mostly zeros.
|
|
19
19
|
|
|
20
20
|
- (Rust) Rust methods that returned `Result` now return
|
|
21
21
|
`Result<_,Box<BedErrorPlus>>`. Before, they returned
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
2
2
|
|
|
3
3
|
[package]
|
|
4
|
-
version = "1.0.0-beta.
|
|
4
|
+
version = "1.0.0-beta.4"
|
|
5
5
|
name = "bed-reader"
|
|
6
6
|
description = "Read and write the PLINK BED format, simply and efficiently."
|
|
7
7
|
repository = "https://github.com/fastlmm/bed-reader"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: bed-reader
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.0b4
|
|
4
4
|
Classifier: Programming Language :: Python :: 3.8
|
|
5
5
|
Classifier: Programming Language :: Python :: 3.9
|
|
6
6
|
Classifier: Programming Language :: Python :: 3.10
|
|
@@ -9,7 +9,6 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
9
9
|
Classifier: Programming Language :: Python :: 3
|
|
10
10
|
Classifier: Programming Language :: Python
|
|
11
11
|
Requires-Dist: numpy >=1.13.3
|
|
12
|
-
Requires-Dist: pandas >=0.25.1
|
|
13
12
|
Requires-Dist: pooch >=1.5.0 ; extra == 'samples'
|
|
14
13
|
Requires-Dist: scipy >=1.4 ; extra == 'sparse'
|
|
15
14
|
Provides-Extra: samples
|
|
@@ -28,11 +27,12 @@ Project-URL: Source Code, https://github.com/fastlmm/bed-reader
|
|
|
28
27
|
Project-URL: Bug Tracker, https://github.com/fastlmm/bed-reader/issues
|
|
29
28
|
Project-URL: Documentation, http://fastlmm.github.io/bed-reader
|
|
30
29
|
|
|
31
|
-
<!-- This must be keep in sync with doc/source/index.rst manually -->
|
|
30
|
+
<!-- This README.md must be keep in sync with doc/source/index.rst manually -->
|
|
32
31
|
|
|
33
32
|
<!-- markdownlint-disable MD046 -->
|
|
33
|
+
<!-- MD046 is about 'code block style' -->
|
|
34
34
|
<!-- markdownlint-disable MD041 -->
|
|
35
|
-
|
|
35
|
+
<!-- MD041 is about 'first line in a file should be a top-level heading'. -->
|
|
36
36
|
[](https://badge.fury.io/py/bed-reader)
|
|
37
37
|
[](https://github.com/fastlmm/bed-reader/actions/workflows/ci.yml)
|
|
38
38
|

|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
<!-- This must be keep in sync with doc/source/index.rst manually -->
|
|
1
|
+
<!-- This README.md must be keep in sync with doc/source/index.rst manually -->
|
|
2
2
|
|
|
3
3
|
<!-- markdownlint-disable MD046 -->
|
|
4
|
+
<!-- MD046 is about 'code block style' -->
|
|
4
5
|
<!-- markdownlint-disable MD041 -->
|
|
5
|
-
|
|
6
|
+
<!-- MD041 is about 'first line in a file should be a top-level heading'. -->
|
|
6
7
|
[](https://badge.fury.io/py/bed-reader)
|
|
7
8
|
[](https://github.com/fastlmm/bed-reader/actions/workflows/ci.yml)
|
|
8
9
|

|
|
@@ -13,9 +13,6 @@ try:
|
|
|
13
13
|
except ImportError:
|
|
14
14
|
sparse = None
|
|
15
15
|
|
|
16
|
-
# cmk remove pandas
|
|
17
|
-
import pandas as pd
|
|
18
|
-
|
|
19
16
|
from .bed_reader import read_f32, read_f64, read_i8 # type: ignore
|
|
20
17
|
|
|
21
18
|
|
|
@@ -1146,9 +1143,6 @@ class open_bed:
|
|
|
1146
1143
|
delimiter = _delimiters[suffix]
|
|
1147
1144
|
if delimiter in {r"\s+"}:
|
|
1148
1145
|
delimiter = None
|
|
1149
|
-
delim_whitespace = True
|
|
1150
|
-
else:
|
|
1151
|
-
delim_whitespace = False
|
|
1152
1146
|
|
|
1153
1147
|
usecolsdict = {}
|
|
1154
1148
|
dtype_dict = {}
|
|
@@ -1160,34 +1154,30 @@ class open_bed:
|
|
|
1160
1154
|
assert len(usecolsdict) > 0 # real assert
|
|
1161
1155
|
|
|
1162
1156
|
if os.path.getsize(property_filepath) == 0:
|
|
1163
|
-
|
|
1157
|
+
columns, row_count = [], 0
|
|
1164
1158
|
else:
|
|
1165
|
-
|
|
1159
|
+
columns, row_count = _read_csv(
|
|
1166
1160
|
property_filepath,
|
|
1167
1161
|
delimiter=delimiter,
|
|
1168
|
-
delim_whitespace=delim_whitespace,
|
|
1169
|
-
header=None,
|
|
1170
|
-
index_col=False,
|
|
1171
|
-
comment=None,
|
|
1172
1162
|
dtype=dtype_dict,
|
|
1173
1163
|
usecols=usecolsdict.values(),
|
|
1174
1164
|
)
|
|
1175
1165
|
|
|
1176
1166
|
if count is None:
|
|
1177
|
-
self._counts[suffix] =
|
|
1167
|
+
self._counts[suffix] = row_count
|
|
1178
1168
|
else:
|
|
1179
|
-
if count !=
|
|
1169
|
+
if count != row_count:
|
|
1180
1170
|
raise ValueError(
|
|
1181
|
-
f"The number of lines in the *.{suffix} file, {
|
|
1171
|
+
f"The number of lines in the *.{suffix} file, {row_count}, "
|
|
1182
1172
|
+ "should not be different from the current "
|
|
1183
1173
|
+ "f{_count_name[suffix]}, {count}"
|
|
1184
1174
|
)
|
|
1185
|
-
for key in usecolsdict.keys():
|
|
1175
|
+
for i, key in enumerate(usecolsdict.keys()):
|
|
1186
1176
|
mm = _meta_meta[key]
|
|
1187
|
-
if
|
|
1177
|
+
if row_count == 0:
|
|
1188
1178
|
output = np.array([], dtype=mm.dtype)
|
|
1189
1179
|
else:
|
|
1190
|
-
output =
|
|
1180
|
+
output = columns[i]
|
|
1191
1181
|
if not np.issubdtype(output.dtype, mm.dtype):
|
|
1192
1182
|
output = np.array(output, dtype=mm.dtype)
|
|
1193
1183
|
self.properties_dict[key] = output
|
|
@@ -1202,7 +1192,14 @@ class open_bed:
|
|
|
1202
1192
|
) -> (Union[sparse.csc_matrix, sparse.csr_matrix]) if sparse is not None else None:
|
|
1203
1193
|
"""
|
|
1204
1194
|
Read genotype information into a :mod:`scipy.sparse` matrix. Sparse matrices
|
|
1205
|
-
may be useful when the data is mostly
|
|
1195
|
+
may be useful when the data is mostly zeros.
|
|
1196
|
+
|
|
1197
|
+
.. note::
|
|
1198
|
+
This method requires :mod:`scipy`. Install `scipy` with:
|
|
1199
|
+
|
|
1200
|
+
.. code-block:: bash
|
|
1201
|
+
|
|
1202
|
+
pip install --upgrade bed-reader[sparse]
|
|
1206
1203
|
|
|
1207
1204
|
Parameters
|
|
1208
1205
|
----------
|
|
@@ -1367,7 +1364,7 @@ class open_bed:
|
|
|
1367
1364
|
or len(sid_index) > np.iinfo(np.int32).max
|
|
1368
1365
|
):
|
|
1369
1366
|
raise ValueError(
|
|
1370
|
-
"Too many Individuals or SNPs (variants) requested. Maximum is {np.iinfo(np.int32).max}."
|
|
1367
|
+
"Too (many Individuals or SNPs (variants) requested. Maximum is {np.iinfo(np.int32).max}."
|
|
1371
1368
|
)
|
|
1372
1369
|
|
|
1373
1370
|
if batch_size is None:
|
|
@@ -1493,9 +1490,60 @@ class open_bed:
|
|
|
1493
1490
|
indptr[1:][batch_slice] = np.cumsum(counts_with_initial)[1:]
|
|
1494
1491
|
|
|
1495
1492
|
|
|
1496
|
-
|
|
1497
|
-
|
|
1493
|
+
def _read_csv(filepath, delimiter=None, dtype=None, usecols=None):
|
|
1494
|
+
# Prepare the usecols by ensuring it is a list of indices
|
|
1495
|
+
usecols_indices = list(usecols)
|
|
1496
|
+
transposed = np.loadtxt(
|
|
1497
|
+
filepath,
|
|
1498
|
+
dtype=np.str_,
|
|
1499
|
+
delimiter=delimiter,
|
|
1500
|
+
usecols=usecols_indices,
|
|
1501
|
+
unpack=True,
|
|
1502
|
+
)
|
|
1503
|
+
if transposed.ndim == 1:
|
|
1504
|
+
transposed = transposed.reshape(-1, 1)
|
|
1505
|
+
row_count = transposed.shape[1] # because unpack=True
|
|
1506
|
+
|
|
1507
|
+
# Convert column lists to numpy arrays with the specified dtype
|
|
1508
|
+
columns = []
|
|
1509
|
+
for output_index, input_index in enumerate(usecols_indices):
|
|
1510
|
+
col = transposed[output_index]
|
|
1511
|
+
# Find the dtype for this column
|
|
1512
|
+
col_dtype = dtype.get(input_index, np.str_)
|
|
1513
|
+
# Convert the column list to a numpy array with the specified dtype
|
|
1514
|
+
columns.append(_convert_to_dtype(col, col_dtype))
|
|
1515
|
+
|
|
1516
|
+
return columns, row_count
|
|
1517
|
+
|
|
1518
|
+
|
|
1519
|
+
def _convert_to_dtype(str_arr, dtype):
|
|
1520
|
+
assert dtype in [np.str_, np.float32, np.int32] # real assert
|
|
1521
|
+
|
|
1522
|
+
if dtype == np.str_:
|
|
1523
|
+
return str_arr
|
|
1524
|
+
|
|
1525
|
+
try:
|
|
1526
|
+
new_arr = str_arr.astype(dtype)
|
|
1527
|
+
except ValueError as e:
|
|
1528
|
+
if dtype == np.float32:
|
|
1529
|
+
raise e
|
|
1530
|
+
# for backwards compatibility, see if intermediate float helps int conversion
|
|
1531
|
+
try:
|
|
1532
|
+
assert dtype == np.int32 # real assert
|
|
1533
|
+
float_arr = str_arr.astype(np.float32)
|
|
1534
|
+
except ValueError:
|
|
1535
|
+
raise e
|
|
1536
|
+
new_arr = float_arr.astype(np.int32)
|
|
1537
|
+
if not np.array_equal(new_arr, float_arr):
|
|
1538
|
+
raise ValueError(
|
|
1539
|
+
f"invalid literal for int: '{str_arr[np.where(new_arr != float_arr)][:1]}')"
|
|
1540
|
+
)
|
|
1541
|
+
return new_arr
|
|
1542
|
+
|
|
1498
1543
|
|
|
1544
|
+
if __name__ == "__main__":
|
|
1499
1545
|
import pytest
|
|
1500
1546
|
|
|
1547
|
+
logging.basicConfig(level=logging.INFO)
|
|
1548
|
+
|
|
1501
1549
|
pytest.main(["--doctest-modules", __file__])
|
|
@@ -44,6 +44,14 @@ def sample_file(filepath: Union[str, Path]) -> str:
|
|
|
44
44
|
Local name of sample .bed file.
|
|
45
45
|
|
|
46
46
|
|
|
47
|
+
.. note::
|
|
48
|
+
This function requires the :mod:`pooch` package. Install `pooch` with:
|
|
49
|
+
|
|
50
|
+
.. code-block:: bash
|
|
51
|
+
|
|
52
|
+
pip install --upgrade bed-reader[samples]
|
|
53
|
+
|
|
54
|
+
|
|
47
55
|
By default this function puts files under the user's cache directory.
|
|
48
56
|
Override this by setting
|
|
49
57
|
the `BED_READER_DATA_DIR` environment variable.
|
|
@@ -5,12 +5,9 @@ from pathlib import Path
|
|
|
5
5
|
|
|
6
6
|
import numpy as np
|
|
7
7
|
import pytest
|
|
8
|
-
import scipy.sparse as sparse
|
|
9
8
|
|
|
10
9
|
from bed_reader import open_bed, subset_f64_f64, to_bed
|
|
11
10
|
|
|
12
|
-
# cmk somehow add test that get nice message for no pooch or scipy.
|
|
13
|
-
|
|
14
11
|
|
|
15
12
|
def test_read1(shared_datadir):
|
|
16
13
|
import math
|
|
@@ -413,6 +410,8 @@ def test_write1_x_x_cpp(tmp_path, shared_datadir):
|
|
|
413
410
|
|
|
414
411
|
|
|
415
412
|
def test_respect_read_inputs(shared_datadir):
|
|
413
|
+
import scipy.sparse as sparse
|
|
414
|
+
|
|
416
415
|
ref_val_float = reference_val(shared_datadir)
|
|
417
416
|
ref_val_float2 = ref_val_float.copy()
|
|
418
417
|
ref_val_float2[ref_val_float != ref_val_float] = -127
|
|
@@ -899,6 +898,39 @@ def test_sparse():
|
|
|
899
898
|
print(val_sparse.shape)
|
|
900
899
|
|
|
901
900
|
|
|
901
|
+
def test_convert_to_dtype():
|
|
902
|
+
from bed_reader._open_bed import _convert_to_dtype
|
|
903
|
+
|
|
904
|
+
input = [
|
|
905
|
+
[["a", "b", "c"], ["a", "b", "c"], None, None],
|
|
906
|
+
[["1.0", "2.0", "3.0"], ["1.0", "2.0", "3.0"], [1, 2, 3], [1.0, 2.0, 3.0]],
|
|
907
|
+
[["1.0", "2.0", "3.5"], ["1.0", "2.0", "3.5"], None, [1.0, 2.0, 3.5]],
|
|
908
|
+
[["1", "2", "3"], ["1", "2", "3"], [1, 2, 3], [1.0, 2.0, 3.0]],
|
|
909
|
+
[["1", "A", "3"], ["1", "A", "3"], None, None],
|
|
910
|
+
]
|
|
911
|
+
# convert all to np.array
|
|
912
|
+
input = [
|
|
913
|
+
[np.array(inner) if inner is not None else None for inner in outer]
|
|
914
|
+
for outer in input
|
|
915
|
+
]
|
|
916
|
+
|
|
917
|
+
for ori, exp_str, exp_int, exp_float in input:
|
|
918
|
+
for dtype, exp in (
|
|
919
|
+
[np.str_, exp_str],
|
|
920
|
+
[np.int32, exp_int],
|
|
921
|
+
[
|
|
922
|
+
np.float32,
|
|
923
|
+
exp_float,
|
|
924
|
+
],
|
|
925
|
+
):
|
|
926
|
+
try:
|
|
927
|
+
actual = _convert_to_dtype(ori, dtype)
|
|
928
|
+
assert np.array_equal(actual, exp)
|
|
929
|
+
except ValueError as e:
|
|
930
|
+
print(e)
|
|
931
|
+
assert exp is None
|
|
932
|
+
|
|
933
|
+
|
|
902
934
|
if __name__ == "__main__":
|
|
903
935
|
logging.basicConfig(level=logging.INFO)
|
|
904
936
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
|
|
3
|
+
from bed_reader import open_bed, sample_file
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_optional_dependencies(shared_datadir):
|
|
7
|
+
try:
|
|
8
|
+
import scipy.sparse as sprase
|
|
9
|
+
except ImportError:
|
|
10
|
+
sprase = None
|
|
11
|
+
|
|
12
|
+
file = shared_datadir / "plink_sim_10s_100v_10pmiss.bed"
|
|
13
|
+
with open_bed(file) as bed:
|
|
14
|
+
if sprase is None:
|
|
15
|
+
with pytest.raises(ImportError):
|
|
16
|
+
_ = bed.read_sparse(dtype="int8")
|
|
17
|
+
else:
|
|
18
|
+
_ = bed.read_sparse(dtype="int8")
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
import pooch
|
|
22
|
+
except ImportError:
|
|
23
|
+
pooch = None
|
|
24
|
+
|
|
25
|
+
if pooch is None:
|
|
26
|
+
with pytest.raises(ImportError):
|
|
27
|
+
_ = sample_file("small.bed")
|
|
28
|
+
else:
|
|
29
|
+
_ = sample_file("small.bed")
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
numpy>=1.13.3
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/plink_sim_10s_100v_10pmiss.bed
RENAMED
|
File without changes
|
{bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/plink_sim_10s_100v_10pmiss.bim
RENAMED
|
File without changes
|
{bed_reader-1.0.0b1 → bed_reader-1.0.0b4}/bed_reader/tests/data/plink_sim_10s_100v_10pmiss.fam
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|