Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cooltools/api/rearrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ def rearrange_cooler(
bins_old, view_df, new_chrom_col=new_chrom_col, orientation_col=orientation_col
)
logging.info("Creating a new cooler")
# fetching pixel dtypes to avoid implicit casts of count column
dtypes = clr.pixels().dtypes.to_dict()
cooler.create_cooler(
out_cooler,
bins_new,
Expand All @@ -210,6 +212,7 @@ def rearrange_cooler(
bin_mapping,
chunksize=chunksize,
),
dtypes = dtypes,
assembly=assembly,
mode=mode,
mergebuf=int(2e7),
Expand Down
Binary file added tests/data/float_counts.cool
Binary file not shown.
14 changes: 13 additions & 1 deletion tests/test_rearrange_cooler.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_rearrange_cooler(request):

# III.
# Check that when taking two chromosomes in a different order and inverting one,
# all is ax espected
# all is as espected

reorder_invert_view = (
orig_view.iloc[1::-1].assign(strand=["+", "-"]).reset_index(drop=True)
Expand Down Expand Up @@ -136,3 +136,15 @@ def test_rearrange_cooler(request):
::-1, :
]
assert np.array_equal(old_trans_m, reordered_inverted_trans_m, equal_nan=True)

# IV.
# Check that pixel datatypes are propagted to output cooler
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

propagAted

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for pointing this out. already fixed it

float_clr = cooler.Cooler(op.join(request.fspath.dirname, "data/float_counts.cool"))
new_view = bioframe.make_viewframe(float_clr.chromsizes)
rearrange_cooler(float_clr, new_view, "test_propagated_datatypes.cool")

propagate_clr = cooler.Cooler("test_propagated_datatypes.cool")
assert_frame_equal(
float_clr.pixels()[:],
propagate_clr.pixels()[:]
)