Skip to content

Commit

Permalink
Merge pull request #230 from open2c/fix-dtype-sort
Browse files Browse the repository at this point in the history
Fixing sorting of numerical columns
  • Loading branch information
Phlya authored Mar 27, 2024
2 parents f3b1973 + ad0c87e commit 8b9b04e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pairtools/cli/sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ def sort_py(
for col in columns:
colindex = int(col) if col.isnumeric() else column_names.index(col) + 1
cols.append(
f"-k {colindex},{colindex}{'n' if isinstance(pairsam_format.DTYPES_PAIRSAM.get(column_names[colindex-1], str), int) else ''}"
f"-k {colindex},{colindex}{'n' if issubclass(pairsam_format.DTYPES_PAIRSAM.get(column_names[colindex-1], str), int) else ''}"
)
cols = " ".join(cols)
command = rf"""
Expand Down
2 changes: 2 additions & 0 deletions tests/data/mock.pairsam
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ readid05 chr2 1 chr3 2 + + UU readid05129chr2160101Mchr320CGFFXS:i:0
readid06 ! 0 chr1 3 - + NU readid06129chr1160101Mchr130CGFFXS:i:0Yt:Z:NU readid0665chr1360101Mchr110ATIIXS:i:0Yt:Z:NU
readid07 ! 0 chr1 3 - + MU readid07129chr1160101Mchr130CGFFXS:i:0Yt:Z:NU readid0765chr1360101Mchr110ATIIXS:i:0Yt:Z:NU
readid08 ! 0 ! 0 - - WW readid08129chr1160101Mchr130CGFFXS:i:0Yt:Z:WW readid0865chr1360101Mchr110ATIIXS:i:0Yt:Z:WW
readid09 chr1 120 chr1 121 + + UU readid09129chr112060101Mchr11210CGFFXS:i:0Yt:Z:UU readid0965chr112160101Mchr11200ATIIXS:i:0Yt:Z:UU
readid10 chr1 13 chr1 14 + + UU readid10129chr11360101Mchr1140CGFFXS:i:0Yt:Z:UU readid1065chr11460101Mchr1130ATIIXS:i:0Yt:Z:UU
10 changes: 5 additions & 5 deletions tests/test_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ def test_mock_pairsam(setup_sort_two):
if prev_pair is not None:
assert cur_pair[0] >= prev_pair[0]
if cur_pair[0] == prev_pair[0]:
assert cur_pair[1] >= prev_pair[1]
if cur_pair[1] == prev_pair[1]:
assert cur_pair[2] >= prev_pair[2]
if cur_pair[2] == prev_pair[2]:
assert cur_pair[3] >= prev_pair[3]
assert cur_pair[2] >= prev_pair[2]
if cur_pair[2] == prev_pair[2]:
assert int(cur_pair[1]) >= int(prev_pair[1])
if int(cur_pair[1]) == int(prev_pair[1]):
assert int(cur_pair[3]) >= int(prev_pair[3])

prev_pair = cur_pair

Expand Down
4 changes: 3 additions & 1 deletion tests/test_scaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ def test_scaling():

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

assert output["n_pairs"].sum() == 7 # double unmapped pairs are currently ignored by lib.scaling
assert (
output["n_pairs"].sum() == 9
) # double unmapped pairs are currently ignored by lib.scaling
6 changes: 3 additions & 3 deletions tests/test_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def test_mock_pairsam():
if cur_pair[0] == prev_pair[0]:
assert cur_pair[2] >= prev_pair[2]
if cur_pair[2] == prev_pair[2]:
assert cur_pair[1] >= prev_pair[1]
if cur_pair[1] == prev_pair[1]:
assert cur_pair[3] >= prev_pair[3]
assert int(cur_pair[1]) >= int(prev_pair[1])
if int(cur_pair[1]) == int(prev_pair[1]):
assert int(cur_pair[3]) >= int(prev_pair[3])

prev_pair = cur_pair

0 comments on commit 8b9b04e

Please sign in to comment.