Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Jan 13, 2025
1 parent 948c425 commit fab2aa0
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 7 deletions.
54 changes: 54 additions & 0 deletions test/integration/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,64 @@
# SPDX-License-Identifier: MIT


import pathlib
from typing import Sequence

from pandas.testing import assert_frame_equal

from stripepy.IO import 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

metadata1 = f1.metadata
metadata2 = f2.metadata

metadata1.pop("min-chromosome-size")
metadata2.pop("min-chromosome-size")

assert metadata1 == metadata2


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

assert_frame_equal(df1, df2, check_exact=False)


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:
_compare_attributes(f1, f2)
for chrom in chroms:
_compare_result(f1, f2, chrom, "LT")
_compare_result(f1, f2, chrom, "UT")
19 changes: 12 additions & 7 deletions test/integration/test_stripepy_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
import pathlib
import warnings

import h5py
import hictkpy
import pytest

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 @@ -22,6 +21,7 @@ class TestStripePyCall:
def setup_class():
test_files = [
testdir / "data" / "4DNFI9GMP2J8.mcool",
testdir / "data" / "results_4DNFI9GMP2J8_v2.hdf5",
]

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

chrom_sizes = hictkpy.MultiResFile(testfile).chromosomes()
Expand All @@ -43,7 +44,7 @@ def test_stripepy_call(tmpdir):
str(testfile),
str(resolution),
"--glob-pers-min",
"0.10",
"0.05",
"--loc-pers-min",
"0.33",
"--loc-trend-min",
Expand All @@ -58,21 +59,25 @@ 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.items() if size >= chrom_size_cutoff]
)

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

chrom_size_cutoff = max(hictkpy.MultiResFile(testfile).chromosomes().values()) - 1
chrom_sizes = hictkpy.MultiResFile(testfile).chromosomes()
chrom_size_cutoff = max(chrom_sizes.values()) - 1

args = [
"call",
str(testfile),
str(resolution),
"--glob-pers-min",
"0.10",
"0.05",
"--loc-pers-min",
"0.33",
"--loc-trend-min",
Expand All @@ -96,4 +101,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, [tuple(chrom_sizes.keys())[0]])

0 comments on commit fab2aa0

Please sign in to comment.