Skip to content

Commit

Permalink
fix rest of the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jkanche committed May 20, 2024
1 parent 5427b3d commit df3d67e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ testing =
setuptools
pytest
pytest-cov
scipy

[options.entry_points]
# Add here console scripts like:
Expand Down
6 changes: 6 additions & 0 deletions src/scrnaseq/fetch_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def fetch_dataset(
old = alt_read_object_function(single_cell_load_object)

def reset_alt_read_func():
print("unregistering????")
alt_read_object_function(old)

atexit.register(reset_alt_read_func)
Expand Down Expand Up @@ -167,6 +168,9 @@ def single_cell_load_object(
Returns:
A `SummarizedExperiment` of the object.
"""

print(path, scrnaseq_realize_assays, scrnaseq_realize_reduced_dims)
print("SSSS")
obj = read_object(
path,
metadata=metadata,
Expand All @@ -175,6 +179,8 @@ def single_cell_load_object(
**kwargs,
)

print(obj)

if isinstance(obj, SummarizedExperiment):
if scrnaseq_realize_assays:
_assays = {}
Expand Down
47 changes: 43 additions & 4 deletions tests/test_fetch_dataset.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import numpy as np
import pytest
from scrnaseq import fetch_dataset
import scipy.sparse as sp
from delayedarray import is_sparse
from dolomite_matrix import ReloadedArray
from scrnaseq import fetch_dataset, fetch_metadata
from singlecellexperiment import SingleCellExperiment

__author__ = "Jayaram Kancherla"
Expand All @@ -8,7 +12,42 @@


def test_fetch_dataset():
sce = fetch_dataset("zeisel-brain-2015", "2023-12-14")
# sce = fetch_dataset("zeisel-brain-2015", "2023-12-14")
# assert isinstance(sce, SingleCellExperiment)

print(sce)
assert isinstance(sce, SingleCellExperiment)
# # Correctly creates ReloadedMatrix objects.
# ass = sce.get_assays()
# assert all(isinstance(a, ReloadedArray) for _, a in ass.items())
# assert all(is_sparse(a) for _, a in ass.items())

# ass_0 = ass["counts"]
# assert "zeisel-brain-2015" in ass_0.seed.path
# assert "2023-12-14" in ass_0.seed.path

# Works with realization options.
sce = fetch_dataset("zeisel-brain-2015", "2023-12-14", realize_assays=True)
ass = sce.get_assays()
assert all(isinstance(a, (sp.csc_matrix, sp.csr_matrix)) for _, a in ass.items())

alt_exps = sce.get_alternative_experiments()
for altname, alt in alt_exps.items():
print(altname, alt)
alt_exp_ass = alt.get_assays()
print(type(alt_exp_ass["counts"]))
assert all(isinstance(a, (np.ndarray)) for _, a in alt_exp_ass.items())


def test_fetch_dataset_realizes_reduced_dimensions():
sce = fetch_dataset("aztekin-tail-2019", "2023-12-14", realize_reduced_dims=False)
red_dim = sce.get_reduced_dims()
assert all(isinstance(a, ReloadedArray) for _, a in red_dim.items())

sce = fetch_dataset("aztekin-tail-2019", "2023-12-14", realize_reduced_dims=True)
red_dim = sce.get_reduced_dims()
assert all(isinstance(a, np.ndarray) for _, a in red_dim.items())


def test_fetch_metadata():
meta = fetch_metadata("zeisel-brain-2015", "2023-12-14")
assert "Brain structure" in meta["title"]
assert meta["taxonomy_id"][0] == "10090"

0 comments on commit df3d67e

Please sign in to comment.