Skip to content

Use chromsizes from the pairs header in scaling (fixes empty n_bp2)#286

Closed
OfficialBishal wants to merge 1 commit into
open2c:masterfrom
OfficialBishal:fix-scaling-header-chromsizes
Closed

Use chromsizes from the pairs header in scaling (fixes empty n_bp2)#286
OfficialBishal wants to merge 1 commit into
open2c:masterfrom
OfficialBishal:fix-scaling-header-chromsizes

Conversation

@OfficialBishal

Copy link
Copy Markdown

Closes #282.

Running pairtools scaling without --view left the n_bp2 column empty: compute_scaling reads the chromsizes from the .pairs header (via read_pairs) but discarded them (pairs_df, _, _ = ...), so bins_pairs_by_distance fell back to region ends of -1 and n_bp2 could not be computed.

This uses the header chromsizes when the caller doesn't pass an explicit chromsizes, matching the existing intent — the CLI passes the stream "so that it can parse the header automatically". An explicit chromsizes argument and the DataFrame input path are unaffected (the change is gated on chromsizes is None).

On tests/data/mock.pairsam (header chr* = 100):

  • before: end1 == -1 for every bin, cis n_bp2 all 0, trans n_bp2 garbage.
  • after: end1 is the chromosome length from the header, and n_bp2 is populated.

Added test_scaling_uses_header_chromsizes covering the no-view case.

compute_scaling() read the .pairs header chromsizes via read_pairs() but discarded them, so running scaling without --view left region ends at -1 and produced an empty n_bp2 column. Use the header chromsizes when the caller does not pass any, and add a test.

Closes open2c#282
@Phlya

Phlya commented Jun 25, 2026

Copy link
Copy Markdown
Member

I think I already fixed it here: #283

@OfficialBishal

Copy link
Copy Markdown
Author

Ah, thanks @Phlya#283 already fixes this (and handles the unmapped pairs too). Closing in favor of yours. If the small regression test I added here is useful, happy to send it over to #283. Sorry for the duplicate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

scaling without specified view is broken

2 participants