From 7950f8e3f922806269006e9f967a2b8bc2f65937 Mon Sep 17 00:00:00 2001 From: Jayaram Kancherla Date: Tue, 15 Oct 2024 11:01:46 -0700 Subject: [PATCH] fix issue with combine when accessing seqnames as factors --- src/genomicranges/GenomicRanges.py | 4 ++-- tests/test_gr_methods_basic.py | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/genomicranges/GenomicRanges.py b/src/genomicranges/GenomicRanges.py index 62f4e1f..d8b711a 100644 --- a/src/genomicranges/GenomicRanges.py +++ b/src/genomicranges/GenomicRanges.py @@ -3120,7 +3120,7 @@ def subtract( def _fast_combine_GenomicRanges(*x: GenomicRanges) -> GenomicRanges: return GenomicRanges( ranges=ut.combine_sequences(*[y._ranges for y in x]), - seqnames=ut.combine_sequences(*[y._seqnames for y in x]), + seqnames=ut.combine_sequences(*[y.get_seqnames() for y in x]), strand=ut.combine_sequences(*[y._strand for y in x]), names=None, mcols=None, @@ -3149,7 +3149,7 @@ def _combine_GenomicRanges(*x: GenomicRanges) -> GenomicRanges: return GenomicRanges( ranges=ut.combine_sequences(*[y._ranges for y in x]), - seqnames=ut.combine_sequences(*[y._seqnames for y in x]), + seqnames=ut.combine_sequences(*[y.get_seqnames() for y in x]), strand=ut.combine_sequences(*[y._strand for y in x]), names=all_names, mcols=ut.relaxed_combine_rows(*[y._mcols for y in x]), diff --git a/tests/test_gr_methods_basic.py b/tests/test_gr_methods_basic.py index 49cce59..044fa3d 100644 --- a/tests/test_gr_methods_basic.py +++ b/tests/test_gr_methods_basic.py @@ -150,8 +150,22 @@ def test_combine(): assert g_src is not None assert g_tgt is not None - out: GenomicRanges = ut.combine_sequences(g_src, g_tgt) + out = ut.combine_sequences(g_src, g_tgt) assert out is not None assert len(out) == 15 assert len(out.get_mcols().get_column_names()) == 2 + +def test_combine_diff(): + a = GenomicRanges(["A"], IRanges([0], [10])) + b = GenomicRanges(["B"], IRanges([5], [15])) + + assert a is not None + assert b is not None + + out = ut.combine_sequences(a, b) + + assert out is not None + assert len(out) == 2 + assert len(out.get_mcols().get_column_names()) == 0 + assert out.get_seqnames() == ["A", "B"]