diff --git a/coolpuppy/coolpup.py b/coolpuppy/coolpup.py index 234e49d..b7c7ef1 100644 --- a/coolpuppy/coolpup.py +++ b/coolpuppy/coolpup.py @@ -575,7 +575,6 @@ def get_combinations( groupby=[], modify_2Dintervals_func=None, ): - if intervals is None: intervals = self.intervals if not len(intervals) >= 1: @@ -734,7 +733,6 @@ def get_intervals_stream( groupby=[], modify_2Dintervals_func=None, ): - if intervals is None: intervals = self.intervals intervals = filter_func1(intervals) @@ -927,8 +925,10 @@ def __init__( except Exception as e: raise ValueError("provided expected is not valid") from e self.ExpSnipper = snipping.ExpectedSnipper( - self.clr, self.expected, view_df=self.view_df, - expected_value_col=self.expected_value_col + self.clr, + self.expected, + view_df=self.view_df, + expected_value_col=self.expected_value_col, ) self.expected_selections = { region_name: self.ExpSnipper.select(region_name, region_name) @@ -2006,12 +2006,17 @@ def pileup( pileup_df - pandas DataFrame containing the pileups and their grouping information, if any, all possible annotations from the arguments of this function. """ - if by_distance: + if by_distance is not False: if by_distance is True or by_distance == "default": distance_edges = "default" by_distance = True elif len(by_distance) > 0: - distance_edges = by_distance + try: + distance_edges = [int(i) for i in by_distance] + except Exception as e: + raise ValueError( + "Distance bin edges have to be an iterable of integers or convertable to integers" + ) from e by_distance = True else: raise ValueError( @@ -2021,8 +2026,6 @@ def pileup( raise ValueError( "Can't do local pileups by distance, please specify only one of those arguments" ) - else: - by_distance = False if not rescale: rescale_flank = None diff --git a/tests/test_coolpup.py b/tests/test_coolpup.py index 8468400..993d6f4 100644 --- a/tests/test_coolpup.py +++ b/tests/test_coolpup.py @@ -7,7 +7,7 @@ """ from matplotlib.pyplot import ioff -from coolpuppy.coolpup import PileUpper, CoordCreator +from coolpuppy.coolpup import PileUpper, CoordCreator, pileup from cooltools.lib import io, common import pandas as pd import numpy as np @@ -101,16 +101,34 @@ def test_bystrand_bydistance_pileups_with_controls(request): features = bf.read_table( op.join(request.fspath.dirname, "data/toy_features.bed"), schema="bed" ) - cc = CoordCreator( - features, - 1_000_000, + + pup = pileup( + clr=clr, + features=features, features_format="bed", - local=False, + view_df=regions, + mindist=0, flank=2_000_000, + nshifts=1, + by_strand=True, + by_distance=True, + ) + assert np.all( + pup.sort_values(["orientation", "distance_band"])["n"] == [1, 2, 1, 1, 1, 6] + ) + + distance_bins = np.append([0], 50000 * 2 ** np.arange(30)) + pup = pileup( + clr=clr, + features=features, + features_format="bed", + view_df=regions, mindist=0, + flank=2_000_000, + nshifts=1, + by_strand=True, + by_distance=distance_bins, ) - pu = PileUpper(clr, cc, expected=False, view_df=regions, control=True) - pup = pu.pileupsByStrandByDistanceWithControl() assert np.all( pup.sort_values(["orientation", "distance_band"])["n"] == [1, 2, 1, 1, 1, 6] )