Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Jan 10, 2025
1 parent 7848764 commit ba424f5
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/stripepy/utils/finders.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ def find_HIoIs(
if logger is None:
logger = structlog.get_logger()

iterable_input = (
params = (
(seed_site, seed_site_bounds[num_MP], seed_site_bounds[num_MP + 1])
for num_MP, seed_site in enumerate(seed_sites)
)

tasks = map_(partial(find_horizontal_domain, pseudodistribution, max_width=max_width), iterable_input)
tasks = map_(partial(find_horizontal_domain, pseudodistribution, max_width=max_width), params)
# This efficiently constructs a 2D numpy with shape (N, 2) from a list of 2-element tuples, where N is the number of seed sites.
# The first and second columns contains the left and right boundaries of the horizontal domains, respectively.
HIoIs = np.fromiter(itertools.chain.from_iterable(tasks), count=2 * len(seed_sites), dtype=int).reshape(-1, 2)
Expand Down
45 changes: 45 additions & 0 deletions test/integration/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,55 @@
# SPDX-License-Identifier: MIT


import pathlib
from typing import Sequence

from stripepy.IO import Result, ResultFile


def matplotlib_avail() -> bool:
try:
import matplotlib
except ImportError:
return False

return True


def _compare_attributes(f1: ResultFile, f2: ResultFile):
assert f1.assembly == f2.assembly
assert f1.resolution == f2.resolution
assert f1.format == f2.format
assert f1.normalization == f2.normalization
assert f1.chromosomes == f2.chromosomes


def _compare_field(f1: ResultFile, f2: ResultFile, chrom: str, field: str, location: str):
df1 = f1.get(chrom, field, location)
df2 = f2.get(chrom, field, location)

assert df1.columns == df2.columns
assert df1.equals(df2)


def _compare_result(f1: ResultFile, f2: ResultFile, chrom: str, location: str):
fields = (
"pseudodistribution",
"all_minimum_points",
"persistence_of_all_minimum_points",
"all_maximum_points",
"persistence_of_all_maximum_points",
"stripes",
)

for field in fields:
_compare_field(f1, f2, chrom, field, location)


def compare_result_files(reference: pathlib.Path, found: pathlib.Path, chroms: Sequence[str]):
with ResultFile(reference) as f1, ResultFile(found) as f2:
assert chroms in f1.chroms
_compare_attributes(f1, f2)
for chrom in chroms:
_compare_result(f1, f2, chrom, "LT")
_compare_result(f1, f2, chrom, "UT")
8 changes: 5 additions & 3 deletions test/integration/test_stripepy_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from stripepy import main

from .common import matplotlib_avail
from .common import compare_result_files, matplotlib_avail

testdir = pathlib.Path(__file__).resolve().parent.parent

Expand All @@ -33,6 +33,7 @@ def setup_class():
@staticmethod
def test_stripepy_call(tmpdir):
testfile = testdir / "data" / "4DNFI9GMP2J8.mcool"
result_file = testdir / "data" / "result_4DNFI9GMP2J8_v2.hdf5"
resolution = 10_000

chrom_sizes = hictkpy.MultiResFile(testfile).chromosomes()
Expand All @@ -58,11 +59,12 @@ def test_stripepy_call(tmpdir):
outfile = pathlib.Path(tmpdir) / testfile.stem / str(resolution) / "results.hdf5"

assert outfile.is_file()
assert h5py.File(outfile).attrs.get("format", "unknown") == "HDF5::StripePy"
compare_result_files(result_file, outfile, [chrom for chrom, size in chrom_sizes if size >= chrom_size_cutoff])

@staticmethod
def test_stripepy_call_with_roi(tmpdir):
testfile = testdir / "data" / "4DNFI9GMP2J8.mcool"
result_file = testdir / "data" / "result_4DNFI9GMP2J8_v2.hdf5"
resolution = 10_000

chrom_size_cutoff = max(hictkpy.MultiResFile(testfile).chromosomes().values()) - 1
Expand Down Expand Up @@ -96,4 +98,4 @@ def test_stripepy_call_with_roi(tmpdir):
outfile = pathlib.Path(tmpdir) / testfile.stem / str(resolution) / "results.hdf5"

assert outfile.is_file()
assert h5py.File(outfile).attrs.get("format", "unknown") == "HDF5::StripePy"
compare_result_files(result_file, outfile, [chrom for chrom, size in chrom_sizes if size >= chrom_size_cutoff])

0 comments on commit ba424f5

Please sign in to comment.