Skip to content

Use IntegerList and BooleanList for seqinfo's attributes #149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions src/genomicranges/SeqInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def _validate_seqnames(seqnames):


def _validate_seqlengths(seqlengths, num_seqs):
if not ut.is_list_of_type(seqlengths, int, ignore_none=True):
if not (isinstance(seqlengths, ut.IntegerList) or ut.is_list_of_type(seqlengths, int, ignore_none=True)):
raise ValueError("'seqlengths' should be a list of integers.")

if num_seqs != len(seqlengths):
Expand All @@ -32,7 +32,7 @@ def _validate_seqlengths(seqlengths, num_seqs):


def _validate_is_circular(is_circular, num_seqs):
if not ut.is_list_of_type(is_circular, bool, ignore_none=True):
if not (isinstance(is_circular, ut.BooleanList) or ut.is_list_of_type(is_circular, bool, ignore_none=True)):
raise ValueError("'is_circular' should be a list of booleans.")

if num_seqs != len(is_circular):
Expand Down Expand Up @@ -141,8 +141,8 @@ def __init__(
"""
self._seqnames = list(seqnames)
self._reverse_seqnames = None
self._seqlengths = self._flatten_incoming(seqlengths, int)
self._is_circular = self._flatten_incoming(is_circular, bool)
self._seqlengths = list(ut.IntegerList(self._flatten_incoming(seqlengths, int)))
self._is_circular = list(ut.BooleanList(self._flatten_incoming(is_circular, bool)))
self._genome = self._flatten_incoming(genome, str)

if validate:
Expand Down
12 changes: 11 additions & 1 deletion tests/test_SeqInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_subset_seqinfo():

assert isinstance(subset, SeqInfo)
assert subset.seqnames == ["chr2", "chr3"]
assert subset.seqlengths == [101, 102]
assert list(subset.seqlengths) == [101, 102]


def test_merge_SeqInfo():
Expand Down Expand Up @@ -160,3 +160,13 @@ def test_copy_SeqInfo():

deepcopy_seq = deepcopy(seq)
assert seq.seqnames == deepcopy_seq.seqnames


def test_seqlength_types():
s = SeqInfo(["A"], seqlengths=[np.uint64(100)])

assert isinstance(s, SeqInfo)
assert list(s._seqlengths) == [100]

s = SeqInfo(seqnames=["A"], seqlengths=[100], is_circular=[None], genome=[None])
assert isinstance(s, SeqInfo)