From 22ffd22170aaf6e23e2217c2704e496b2b3d24a4 Mon Sep 17 00:00:00 2001 From: Jayaram Kancherla Date: Mon, 13 Nov 2023 08:33:06 -0800 Subject: [PATCH] fix tests for trim method --- setup.cfg | 4 ++-- src/genomicranges/GenomicRanges.py | 20 +++++++------------- src/genomicranges/SeqInfo.py | 8 ++++---- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/setup.cfg b/setup.cfg index b04881b..48889b0 100644 --- a/setup.cfg +++ b/setup.cfg @@ -50,10 +50,10 @@ package_dir = install_requires = importlib-metadata; python_version<"3.8" pandas - biocframe>=0.3.16 + biocframe==0.3.16 numpy biocgenerics - biocutils + biocutils>=0.1.1 [options.packages.find] where = src diff --git a/src/genomicranges/GenomicRanges.py b/src/genomicranges/GenomicRanges.py index 9bb672c..46a6879 100644 --- a/src/genomicranges/GenomicRanges.py +++ b/src/genomicranges/GenomicRanges.py @@ -1,19 +1,10 @@ import math import random from collections import OrderedDict -from typing import ( - Any, - Callable, - Dict, - List, - Literal, - Optional, - Union, -) +from typing import Any, Callable, Dict, List, Literal, Optional, Sequence, Union from warnings import warn from biocframe import BiocFrame -from biocframe.types import SlicerArgTypes from biocgenerics.colnames import colnames, set_colnames from biocgenerics.combine import combine from biocgenerics.combine_cols import combine_cols @@ -477,7 +468,9 @@ def __repr__(self) -> str: return capture.get() # for documentation, otherwise serves no real use. - def __getitem__(self, args: SlicerArgTypes) -> Union["GenomicRanges", dict, list]: + def __getitem__( + self, args: Union[int, str, Sequence, tuple] + ) -> Union["GenomicRanges", dict, list]: """Subset the object. This operation returns a new object with the same type as the caller. @@ -904,10 +897,11 @@ def trim(self) -> "GenomicRanges": for idx in range(len(all_chrs)): keep = True t_chr = all_chrs[idx] + s_idx = seqinfos.seqnames.index(t_chr) if ( is_circular is not None - and is_circular[t_chr] is False - and all_ends[idx] > seqlengths[t_chr] + and is_circular[s_idx] is False + and all_ends[idx] > seqlengths[s_idx] ): keep = False diff --git a/src/genomicranges/SeqInfo.py b/src/genomicranges/SeqInfo.py index 7e151fc..ac169bd 100644 --- a/src/genomicranges/SeqInfo.py +++ b/src/genomicranges/SeqInfo.py @@ -1,7 +1,7 @@ -from typing import Dict, List, Optional, Union, Sequence -import biocutils as bu +from typing import Dict, List, Optional, Sequence, Union from warnings import warn +import biocutils as bu __author__ = "jkanche" __copyright__ = "jkanche" @@ -112,8 +112,8 @@ def _validate_seqlengths(self): raise ValueError("'seqlengths' should be a list of integers") if n != len(self._seqlengths): raise ValueError("'seqnames' and 'seqlengths' should have the same length") - for l in self._seqlengths: - if l is not None and l < 0: + for sl in self._seqlengths: + if sl is not None and sl < 0: raise ValueError("all entries of 'seqlengths' should be non-negative") def _validate_is_circular(self):