IntervalTrack¶
A Track backed by a sorted-list interval index. Stores Region objects and
supports fast overlap queries. signal_at() returns an overlap-weighted
average of region scores within the query window.
IntervalTrack
¶
A Track backed by a sorted-list interval index.
Stores a collection of Region objects and supports fast
overlap queries via IntervalIndex.
signal_at() returns an overlap-weighted average of region scores
within the query window. regions() yields all overlapping regions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Any
|
Named source with a |
required |
regions
|
Iterable[Region]
|
Iterable of |
required |
Examples:
>>> t = IntervalTrack(TrackLabel("peaks"), [Region("chr1", 100, 200, score=5.0)])
>>> list(t.regions("chr1", 150, 160))
[Region(chrom='chr1', start=100, end=200, strand='.', score=5.0, name='', tags={})]
Source code in src/seqchain/track.py
signal_at
¶
Overlap-weighted average score of regions in the query window.
For each overlapping region, computes the number of overlapping
base pairs with the query and weights by the region's score.
Returns the weighted average, or 0.0 if there are no overlaps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chrom
|
str
|
Chromosome name. |
required |
start
|
int
|
Window start (inclusive). |
required |
end
|
int
|
Window end (exclusive). |
required |
Returns:
| Type | Description |
|---|---|
float
|
Weighted average score, or |
Examples:
>>> t = IntervalTrack(TrackLabel("t"), [Region("chr1", 100, 200, score=10.0)])
>>> t.signal_at("chr1", 150, 250)
10.0
Source code in src/seqchain/track.py
regions
¶
Yield all regions overlapping the query window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chrom
|
str
|
Chromosome name. |
required |
start
|
int
|
Window start (inclusive). |
required |
end
|
int
|
Window end (exclusive). |
required |
Returns:
| Type | Description |
|---|---|
Iterator[Region]
|
Iterator of overlapping |
Examples:
>>> t = IntervalTrack(TrackLabel("t"), [Region("chr1", 10, 20)])
>>> len(list(t.regions("chr1", 15, 25)))
1
Source code in src/seqchain/track.py
__iter__
¶
Iterate over all regions in entry order.
Returns:
| Type | Description |
|---|---|
Iterator[Region]
|
Iterator of |
Examples:
Source code in src/seqchain/track.py
__getitem__
¶
Access regions by index or slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int | slice
|
Integer index or slice. |
required |
Returns:
| Type | Description |
|---|---|
Region | list[Region]
|
A single |
Region | list[Region]
|
Regions for a slice. |
Examples:
Source code in src/seqchain/track.py
__len__
¶
map_scores
¶
Return a new IntervalTrack with fn applied to every region score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[float], float]
|
A function that maps a float score to a new float score. |
required |
Returns:
| Type | Description |
|---|---|
'IntervalTrack'
|
A new IntervalTrack with transformed scores. |
Examples:
>>> t = IntervalTrack(TrackLabel("t"), [Region("chr1", 0, 10, score=2.0)])
>>> t2 = t.map_scores(lambda s: s * 3)
>>> t2[0].score
6.0
Source code in src/seqchain/track.py
filter_entries
¶
Return a new IntervalTrack keeping only regions where fn(score) is true.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[float], bool]
|
Predicate on the score. |
required |
Returns:
| Type | Description |
|---|---|
'IntervalTrack'
|
A new IntervalTrack with only matching regions. |
Examples:
>>> t = IntervalTrack(TrackLabel("t"), [Region("chr1", 0, 10, score=5.0)])
>>> t2 = t.filter_entries(lambda s: s > 3.0)
>>> len(t2)
1
Source code in src/seqchain/track.py
scores
¶
with_scores
¶
Rebuild the IntervalTrack with new scores in entry order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scores
|
Sequence[float]
|
New score values, one per region. |
required |
Returns:
| Type | Description |
|---|---|
'IntervalTrack'
|
A new IntervalTrack with replaced scores. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If length does not match. |
Examples:
>>> t = IntervalTrack(TrackLabel("t"), [Region("chr1", 0, 10, score=1.0)])
>>> t2 = t.with_scores([99.0])
>>> t2[0].score
99.0