Skip to content

Commit 8b9b04e

Browse files
authored
Merge pull request #230 from open2c/fix-dtype-sort
Fixing sorting of numerical columns
2 parents f3b1973 + ad0c87e commit 8b9b04e

File tree

5 files changed

+14
-10
lines changed

5 files changed

+14
-10
lines changed

pairtools/cli/sort.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def sort_py(
198198
for col in columns:
199199
colindex = int(col) if col.isnumeric() else column_names.index(col) + 1
200200
cols.append(
201-
f"-k {colindex},{colindex}{'n' if isinstance(pairsam_format.DTYPES_PAIRSAM.get(column_names[colindex-1], str), int) else ''}"
201+
f"-k {colindex},{colindex}{'n' if issubclass(pairsam_format.DTYPES_PAIRSAM.get(column_names[colindex-1], str), int) else ''}"
202202
)
203203
cols = " ".join(cols)
204204
command = rf"""

tests/data/mock.pairsam

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ readid05 chr2 1 chr3 2 + + UU readid05129chr2160101Mchr320CGFFXS:i:0
1818
readid06 ! 0 chr1 3 - + NU readid06129chr1160101Mchr130CGFFXS:i:0Yt:Z:NU readid0665chr1360101Mchr110ATIIXS:i:0Yt:Z:NU
1919
readid07 ! 0 chr1 3 - + MU readid07129chr1160101Mchr130CGFFXS:i:0Yt:Z:NU readid0765chr1360101Mchr110ATIIXS:i:0Yt:Z:NU
2020
readid08 ! 0 ! 0 - - WW readid08129chr1160101Mchr130CGFFXS:i:0Yt:Z:WW readid0865chr1360101Mchr110ATIIXS:i:0Yt:Z:WW
21+
readid09 chr1 120 chr1 121 + + UU readid09129chr112060101Mchr11210CGFFXS:i:0Yt:Z:UU readid0965chr112160101Mchr11200ATIIXS:i:0Yt:Z:UU
22+
readid10 chr1 13 chr1 14 + + UU readid10129chr11360101Mchr1140CGFFXS:i:0Yt:Z:UU readid1065chr11460101Mchr1130ATIIXS:i:0Yt:Z:UU

tests/test_merge.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ def test_mock_pairsam(setup_sort_two):
9090
if prev_pair is not None:
9191
assert cur_pair[0] >= prev_pair[0]
9292
if cur_pair[0] == prev_pair[0]:
93-
assert cur_pair[1] >= prev_pair[1]
94-
if cur_pair[1] == prev_pair[1]:
95-
assert cur_pair[2] >= prev_pair[2]
96-
if cur_pair[2] == prev_pair[2]:
97-
assert cur_pair[3] >= prev_pair[3]
93+
assert cur_pair[2] >= prev_pair[2]
94+
if cur_pair[2] == prev_pair[2]:
95+
assert int(cur_pair[1]) >= int(prev_pair[1])
96+
if int(cur_pair[1]) == int(prev_pair[1]):
97+
assert int(cur_pair[3]) >= int(prev_pair[3])
9898

9999
prev_pair = cur_pair
100100

tests/test_scaling.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@ def test_scaling():
2222

2323
output = pd.read_csv(io.StringIO(result), sep="\t", header=0)
2424

25-
assert output["n_pairs"].sum() == 7 # double unmapped pairs are currently ignored by lib.scaling
25+
assert (
26+
output["n_pairs"].sum() == 9
27+
) # double unmapped pairs are currently ignored by lib.scaling

tests/test_sort.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def test_mock_pairsam():
5656
if cur_pair[0] == prev_pair[0]:
5757
assert cur_pair[2] >= prev_pair[2]
5858
if cur_pair[2] == prev_pair[2]:
59-
assert cur_pair[1] >= prev_pair[1]
60-
if cur_pair[1] == prev_pair[1]:
61-
assert cur_pair[3] >= prev_pair[3]
59+
assert int(cur_pair[1]) >= int(prev_pair[1])
60+
if int(cur_pair[1]) == int(prev_pair[1]):
61+
assert int(cur_pair[3]) >= int(prev_pair[3])
6262

6363
prev_pair = cur_pair

0 commit comments

Comments
 (0)