Skip to content

Shift resized intervals to stay on chromosome - #199

Open
buyan-kh wants to merge 1 commit into
Genentech:mainfrom
buyan-kh:cursor/resize-genome-bounds-300d
Open

Shift resized intervals to stay on chromosome#199
buyan-kh wants to merge 1 commit into
Genentech:mainfrom
buyan-kh:cursor/resize-genome-bounds-300d

Conversation

@buyan-kh

@buyan-kh buyan-kh commented Sep 9, 2026

Copy link
Copy Markdown

Summary

grelu.sequence.utils.resize can produce start < 0 or end > chrom_size when applied to intervals (for example adata.var = resize(adata.var, seq_len)). That failure only shows up later, when a dataset calls check_chrom_ends.

This adds an optional genome= argument on the intervals path. When it is set, chrom sizes are loaded with grelu.io.genome.read_sizes and windows that leave the chromosome are shifted so they stay on-chromosome while keeping seq_len. Rows are never dropped, so AnnData X/var alignment is preserved. If seq_len is larger than a chromosome, resize raises. genome=None (the default) keeps the previous unconstrained behavior.

This is intended for #176. It does not change the open column-order work on #198.

Compare for an upstream PR: https://github.com/Genentech/gReLU/compare/main...buyan-kh:gReLU:cursor/resize-genome-bounds-300d?expand=1

Fixes #176

Test plan

Ran locally (this environment does not have the full gReLU stack / hg38):

PYTHONPATH=src python3 -m pytest tests/test_sequence.py::test_resize tests/test_sequence.py::test_resize_intervals_genome -o addopts=

2 passed in 1.39s

Also ran the rest of tests/test_sequence.py excluding hg38 / tangermeme tests:

PYTHONPATH=src python3 -m pytest tests/test_sequence.py -o addopts= -k "not test_seq_formatting and not test_gc_distribution and not test_dinuc_shuffle"

13 passed, 3 deselected in 1.24s

Coverage of the new tests (tests/files/test_genome.fa / .sizes, chr10/chr21 size 2000):

  • OOB-left: start < 0 is shifted to [0, seq_len)
  • OOB-right: end > chrom_size is shifted to [size - seq_len, size)
  • seq_len larger than the chromosome raises
  • genome=None still allows out-of-bounds coordinates
  • row count / index preserved (no drops)
Open in Web Open in Cursor 

Co-authored-by: Buyan Khurelbaatar <buyan-kh@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

As it turns out, you can resize your features right off the chromosome

2 participants