diff --git a/src/stripepy/cli/view.py b/src/stripepy/cli/view.py index 8ce75e5..5a8f68b 100644 --- a/src/stripepy/cli/view.py +++ b/src/stripepy/cli/view.py @@ -38,7 +38,7 @@ def _read_stripes(f: ResultFile, chrom: str) -> pd.DataFrame: df1 = pd.concat([geo_lt, bio_lt], axis="columns") df2 = pd.concat([geo_ut, bio_ut], axis="columns") - return pd.concat([df1, df2]).set_index("seed").sort_index() + return pd.concat([df1, df2]).set_index("seed").sort_index(kind="stable") except Exception as e: raise RuntimeError(f'failed to read stripes for chromosome "{chrom}": {e}') diff --git a/src/stripepy/plot.py b/src/stripepy/plot.py index 0cb3382..f94d6ea 100644 --- a/src/stripepy/plot.py +++ b/src/stripepy/plot.py @@ -521,10 +521,10 @@ def fetch(v: npt.NDArray[int], left_bound: int, right_bound: int) -> Tuple[npt.N min_persistence = result.min_persistence lt_idx, lt_seeds = fetch( - np.sort(TDA(pd_lt, min_persistence=min_persistence)[2]), start // resolution, end // resolution + np.sort(TDA(pd_lt, min_persistence=min_persistence)[2], stable=True), start // resolution, end // resolution ) ut_idx, ut_seeds = fetch( - np.sort(TDA(pd_ut, min_persistence=min_persistence)[2]), start // resolution, end // resolution + np.sort(TDA(pd_ut, min_persistence=min_persistence)[2], stable=True), start // resolution, end // resolution ) return { diff --git a/src/stripepy/utils/TDA.py b/src/stripepy/utils/TDA.py index 8b198d5..62639fe 100644 --- a/src/stripepy/utils/TDA.py +++ b/src/stripepy/utils/TDA.py @@ -27,7 +27,7 @@ def TDA(marginal_pd, min_persistence=0): ) # Sorting maximum points (and, as a consequence, the corresponding minimum points) w.r.t. persistence: - argsorting = np.argsort(list(zip(*filtered_max_points_and_persistence))[1]).tolist() + argsorting = np.argsort(list(zip(*filtered_max_points_and_persistence))[1], stable=True).tolist() if len(filtered_min_points_and_persistence) == 0: filtered_min_points = [] diff --git a/src/stripepy/utils/common.py b/src/stripepy/utils/common.py index 8fd16f5..8293de8 100644 --- a/src/stripepy/utils/common.py +++ b/src/stripepy/utils/common.py @@ -31,7 +31,7 @@ def sort_based_on_arg0(*vectors: Sequence) -> Tuple[NDArray]: if len(vectors[0]) == 0: return tuple((np.array(v) for v in vectors)) # noqa - permutation = np.argsort(vectors[0]) + permutation = np.argsort(vectors[0], stable=True) return tuple((np.array(v)[permutation] for v in vectors)) # noqa diff --git a/src/stripepy/utils/persistence1d.py b/src/stripepy/utils/persistence1d.py index 3e38fab..81e0294 100644 --- a/src/stripepy/utils/persistence1d.py +++ b/src/stripepy/utils/persistence1d.py @@ -41,7 +41,7 @@ def run_persistence(data, level_sets="lower"): # Number of data to break ties (leftmost index comes first): num_elements = len(data) - sorted_idx = np.argsort(data, kind="stable")[::-1] if level_sets == "upper" else np.argsort(data, kind="stable") + sorted_idx = np.argsort(data, stable=True)[::-1] if level_sets == "upper" else np.argsort(data, stable=True) # Get a union find data structure: uf = UnionFind(num_elements)