Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pairtools/lib/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,11 @@ def compute_scaling(
pairs_df = pairs

elif isinstance(pairs, str) or hasattr(pairs, "buffer") or hasattr(pairs, "peek"):
pairs_df, _, _ = pairsio.read_pairs(pairs, nproc=nproc_in, chunksize=chunksize)
pairs_df, _, header_chromsizes = pairsio.read_pairs(
pairs, nproc=nproc_in, chunksize=chunksize
)
if chromsizes is None and header_chromsizes is not None and len(header_chromsizes):
chromsizes = header_chromsizes
else:
raise ValueError(
"pairs must be either a path to a pairs file or a pd.DataFrame"
Expand Down
13 changes: 13 additions & 0 deletions tests/test_scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,16 @@ def test_scaling():
assert (
output["n_pairs"].sum() == 9
) # double unmapped pairs are currently ignored by lib.scaling


def test_scaling_uses_header_chromsizes():
# Without an explicit view, the implicit per-chromosome view must use the chromsizes
# from the .pairs header (chr* = 100 in mock.pairsam); otherwise region ends stay at
# -1 and n_bp2 is left empty.
from pairtools.lib.scaling import compute_scaling

mock_pairsam_path = os.path.join(testdir, "data", "mock.pairsam")
cis, _trans = compute_scaling(mock_pairsam_path, regions=None)

assert (cis["end1"] == 100).all()
assert (cis["n_bp2"] > 0).any()