Skip to content

Commit a3058c2

Browse files
committed
Add test that compares to PyBigWig with NaN as default value.
1 parent 662c04f commit a3058c2

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

example_data/some_positions.tsv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
chr center
2+
chr1 45298878
23
chr18 61036865
34
chr17 12174372
45
chr3 65857025

tests/test_against_pybigwig.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def get_batch(self, chromosomes, starts, ends):
2626

2727

2828
def test_same_output(bigwig_path):
29-
pybigwig_collection = PyBigWigCollection(bigwig_path, first_n_files=2)
30-
collection = BigWigCollection(bigwig_path, first_n_files=2)
29+
pybigwig_collection = PyBigWigCollection(bigwig_path, first_n_files=3)
30+
collection = BigWigCollection(bigwig_path, first_n_files=3)
3131

3232
df = pd.read_csv(config.example_positions, sep="\t")
3333
df = df[df["chr"].isin(collection.get_chromosomes_present_in_all_files())]
@@ -49,3 +49,31 @@ def test_same_output(bigwig_path):
4949
print(this_batch[pybigwig_batch != this_batch])
5050
print(pybigwig_batch[pybigwig_batch != this_batch])
5151
assert (pybigwig_batch == this_batch).all()
52+
53+
54+
def test_same_output_with_nans(bigwig_path):
55+
pybigwig_collection = PyBigWigCollection(bigwig_path, first_n_files=3)
56+
collection = BigWigCollection(bigwig_path, first_n_files=3)
57+
58+
df = pd.read_csv(config.example_positions, sep="\t")
59+
df = df[df["chr"].isin(collection.get_chromosomes_present_in_all_files())]
60+
chromosomes, starts, ends = (
61+
list(df["chr"]),
62+
list(df["center"] - 1000),
63+
list(df["center"] + 1000),
64+
)
65+
66+
pybigwig_batch = pybigwig_collection.get_batch(chromosomes, starts, ends)
67+
68+
this_batch = collection.get_batch(
69+
chromosomes, starts, ends, default_value=np.nan
70+
).get()
71+
print("PyBigWig:")
72+
print(pybigwig_batch)
73+
print(type(this_batch), "shape:", pybigwig_batch.shape)
74+
print("This Library:")
75+
print(this_batch)
76+
print(type(this_batch), "shape:", this_batch.shape)
77+
print(this_batch[pybigwig_batch != this_batch])
78+
print(pybigwig_batch[pybigwig_batch != this_batch])
79+
assert np.allclose(pybigwig_batch, this_batch, equal_nan=True)

0 commit comments

Comments
 (0)