Skip to content

Commit

Permalink
Modified scaling.bins_pairs_by_distance to fix error thrown by narrow…
Browse files Browse the repository at this point in the history
… distance ranges. (#152)

* Fix IndexError when dist_range maximum is less than the largest distance present in pairs
* upper limit set to np.iinfo(np.int64).max (not np.inf)
  • Loading branch information
itsameerkat authored Nov 8, 2022
1 parent 7c3d18e commit 63db477
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pairtools/lib/scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def bins_pairs_by_distance(
pairs_df, dist_bins, regions=None, chromsizes=None, ignore_trans=False
):

dist_bins = np.r_[dist_bins, np.iinfo(np.int64).max]
if regions is None:
if chromsizes is None:
chroms = sorted(
Expand Down Expand Up @@ -208,7 +209,7 @@ def bins_pairs_by_distance(
)

pairs_reduced_df["max_dist"] = np.where(
pairs_reduced_df["dist_bin_idx"] < len(dist_bins),
pairs_reduced_df["dist_bin_idx"] < len(dist_bins)-1,
dist_bins[pairs_reduced_df["dist_bin_idx"]],
np.iinfo(np.int64).max,
)
Expand All @@ -220,6 +221,8 @@ def bins_pairs_by_distance(
(pairs_reduced_df.chrom1 == pairs_reduced_df.chrom2)
& (pairs_reduced_df.start1 == pairs_reduced_df.start2)
& (pairs_reduced_df.end1 == pairs_reduced_df.end2)
& (pairs_reduced_df.min_dist > 0)
& (pairs_reduced_df.max_dist < np.iinfo(np.int64).max)
)

pairs_for_scaling_df = pairs_reduced_df.loc[pairs_for_scaling_mask]
Expand Down

0 comments on commit 63db477

Please sign in to comment.