Skip to content

Track protocol

Runtime-checkable protocol that all track containers satisfy. Every Track has a name and supports signal_at(), regions(), map_scores(), filter_entries(), scores(), and with_scores().

Track

Bases: Protocol

Protocol that all track containers satisfy.

Every Track has a name and supports two query methods: signal_at() for numeric values over a genomic window, and regions() for region-based overlap queries.

Examples:

>>> isinstance(IntervalTrack(TrackLabel("t"), []), Track)
True

signal_at

signal_at(chrom: str, start: int, end: int) -> float

Return a numeric signal over a genomic 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
float

A float signal value.

Source code in src/seqchain/track.py
def signal_at(self, chrom: str, start: int, end: int) -> float:
    """Return a numeric signal over a genomic window.

    Args:
        chrom: Chromosome name.
        start: Window start (inclusive).
        end: Window end (exclusive).

    Returns:
        A float signal value.
    """
    ...

regions

regions(chrom: str, start: int, end: int) -> Iterator[Region]

Yield regions overlapping a genomic 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 Region objects.

Source code in src/seqchain/track.py
def regions(self, chrom: str, start: int, end: int) -> Iterator[Region]:
    """Yield regions overlapping a genomic window.

    Args:
        chrom: Chromosome name.
        start: Window start (inclusive).
        end: Window end (exclusive).

    Returns:
        Iterator of overlapping `Region` objects.
    """
    ...

map_scores

map_scores(fn: Callable[[float], float]) -> 'Track'

Return a new Track with fn applied to every 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
'Track'

A new Track of the same type with transformed scores.

Source code in src/seqchain/track.py
def map_scores(self, fn: Callable[[float], float]) -> "Track":
    """Return a new Track with *fn* applied to every score.

    Args:
        fn: A function that maps a float score to a new float score.

    Returns:
        A new Track of the same type with transformed scores.
    """
    ...

filter_entries

filter_entries(fn: Callable[[float], bool]) -> 'Track'

Return a new Track keeping only entries where fn(score) is true.

Parameters:

Name Type Description Default
fn Callable[[float], bool]

Predicate on the score.

required

Returns:

Type Description
'Track'

A new Track of the same type with only matching entries.

Source code in src/seqchain/track.py
def filter_entries(self, fn: Callable[[float], bool]) -> "Track":
    """Return a new Track keeping only entries where *fn(score)* is true.

    Args:
        fn: Predicate on the score.

    Returns:
        A new Track of the same type with only matching entries.
    """
    ...

scores

scores() -> Iterator[float]

Iterate over all scores in entry order.

Returns:

Type Description
Iterator[float]

Iterator of float scores.

Source code in src/seqchain/track.py
def scores(self) -> Iterator[float]:
    """Iterate over all scores in entry order.

    Returns:
        Iterator of float scores.
    """
    ...

with_scores

with_scores(scores: Sequence[float]) -> 'Track'

Rebuild the Track with new scores in entry order.

Length of scores must match the number of entries.

Parameters:

Name Type Description Default
scores Sequence[float]

New score values, one per entry.

required

Returns:

Type Description
'Track'

A new Track of the same type with replaced scores.

Raises:

Type Description
ValueError

If length does not match.

Source code in src/seqchain/track.py
def with_scores(self, scores: Sequence[float]) -> "Track":
    """Rebuild the Track with new scores in entry order.

    Length of *scores* must match the number of entries.

    Args:
        scores: New score values, one per entry.

    Returns:
        A new Track of the same type with replaced scores.

    Raises:
        ValueError: If length does not match.
    """
    ...