Skip to content

Commit

Permalink
some of "test_cloud_read1" passes
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlKCarlK committed Dec 23, 2023
1 parent fbebe68 commit 22dcff3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
11 changes: 7 additions & 4 deletions bed_reader/_open_bed_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ def __init__(

@classmethod
async def create(
cls,
filepath: Union[str, Path],
iid_count: Optional[int] = None,
sid_count: Optional[int] = None,
Expand All @@ -251,6 +252,7 @@ async def create(
fam_filepath: Union[str, Path] = None,
bim_filepath: Union[str, Path] = None,
):
print(type(filepath), filepath)
self = open_bed_cloud(
filepath,
iid_count=iid_count,
Expand All @@ -265,6 +267,7 @@ async def create(
if not self.skip_format_check:
with open(self.filepath, "rb") as filepointer:
self._check_file(filepointer)
return self

async def __aenter__(self):
# Setup or additional operations when entering the context
Expand Down Expand Up @@ -934,8 +937,8 @@ def allele_2(self) -> np.ndarray:
"""
return self.property_item("allele_2")

@property
def iid_count(self) -> np.ndarray:
# @property # remove
async def iid_count(self) -> np.ndarray:
"""
Number of individuals (samples).
Expand All @@ -960,7 +963,7 @@ def iid_count(self) -> np.ndarray:
3
"""
return self._count("fam")
return await self._count("fam")

@property
def sid_count(self) -> np.ndarray:
Expand Down Expand Up @@ -997,7 +1000,7 @@ def _property_filepath(self, suffix):
assert suffix == "bim" # real assert
return self._bim_filepath

def _count(self, suffix):
async def _count(self, suffix):
count = self._counts[suffix]
if count is None:
count = _rawincount(self._property_filepath(suffix))
Expand Down
27 changes: 14 additions & 13 deletions bed_reader/tests/test_open_bed_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@ async def test_cloud_read1(shared_datadir):
import math

file = shared_datadir / "plink_sim_10s_100v_10pmiss.bed"
with open_bed_cloud(file) as bed_cloud:
assert bed_cloud.iid_count == 10
assert bed_cloud.fid[-1] == "0"
assert bed_cloud.iid[-1] == "9"
assert bed_cloud.shape == (10, 100)

val = bed_cloud.read(dtype="int8")
# really shouldn't do mean on data where -127 represents missing
assert val.mean() == -13.142
val_sparse = bed_cloud.read_sparse(dtype="int8")
assert math.isclose(val_sparse.mean(), -13.142, rel_tol=1e-9)
assert bed_cloud.chromosome[-1] == "1"
assert bed_cloud.bp_position[-1] == 100
print(type(file), file)
async with await open_bed_cloud.create(file) as bed_cloud:
assert await bed_cloud.iid_count() == 10
# assert bed_cloud.fid[-1] == "0"
# assert bed_cloud.iid[-1] == "9"
# assert bed_cloud.shape == (10, 100)

# val = bed_cloud.read(dtype="int8")
# # really shouldn't do mean on data where -127 represents missing
# assert val.mean() == -13.142
# val_sparse = bed_cloud.read_sparse(dtype="int8")
# assert math.isclose(val_sparse.mean(), -13.142, rel_tol=1e-9)
# assert bed_cloud.chromosome[-1] == "1"
# assert bed_cloud.bp_position[-1] == 100


# def test_cloud_write(tmp_path, shared_datadir):
Expand Down

0 comments on commit 22dcff3

Please sign in to comment.