Skip to content

TableTrack

A Track for key-value numeric data (counts, expression, scores). Not coordinate-based — signal_at() always returns 0.0 and regions() always yields nothing. Data is accessed via get() and keys().

TableTrack

TableTrack(source: Any, data: dict[str, float])

A Track for key-value numeric data (counts, expression, scores).

Not coordinate-based — signal_at() always returns 0.0 and regions() always yields nothing. Data is accessed via get() and keys().

Parameters:

Name Type Description Default
source Any

Named source with a .name attribute (preset, config, TrackLabel).

required
data dict[str, float]

Dict mapping string keys to float values.

required

Examples:

>>> t = TableTrack(TrackLabel("counts"), {"geneA": 42.0, "geneB": 7.0})
>>> t.get("geneA")
42.0
Source code in src/seqchain/track.py
def __init__(self, source: Any, data: dict[str, float]) -> None:
    if isinstance(source, str):
        raise TypeError(
            f"TableTrack requires a named source (preset, config, "
            f"TrackLabel), not a bare string. Use TrackLabel({source!r}) "
            f"for engine-internal names."
        )
    try:
        self.name: str = source.name
    except AttributeError:
        raise TypeError(
            f"TableTrack source must have a .name attribute, "
            f"got {type(source).__name__}"
        )
    self._data = dict(data)

signal_at

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

Always returns 0.0 — TableTrack has no coordinate data.

Parameters:

Name Type Description Default
chrom str

Chromosome name (unused).

required
start int

Window start (unused).

required
end int

Window end (unused).

required

Returns:

Type Description
float

0.0.

Source code in src/seqchain/track.py
def signal_at(self, chrom: str, start: int, end: int) -> float:
    """Always returns ``0.0`` — TableTrack has no coordinate data.

    Args:
        chrom: Chromosome name (unused).
        start: Window start (unused).
        end: Window end (unused).

    Returns:
        ``0.0``.
    """
    return 0.0

regions

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

Always yields nothing — TableTrack has no coordinate data.

Parameters:

Name Type Description Default
chrom str

Chromosome name (unused).

required
start int

Window start (unused).

required
end int

Window end (unused).

required

Returns:

Type Description
Iterator[Region]

Empty iterator.

Source code in src/seqchain/track.py
def regions(self, chrom: str, start: int, end: int) -> Iterator[Region]:
    """Always yields nothing — TableTrack has no coordinate data.

    Args:
        chrom: Chromosome name (unused).
        start: Window start (unused).
        end: Window end (unused).

    Returns:
        Empty iterator.
    """
    return iter([])

get

get(key: str, default: float = 0.0) -> float

Look up a value by key.

Parameters:

Name Type Description Default
key str

The key to look up.

required
default float

Value to return if key is missing. Defaults to 0.0.

0.0

Returns:

Type Description
float

The stored float value, or default.

Examples:

>>> t = TableTrack(TrackLabel("t"), {"a": 1.0})
>>> t.get("a")
1.0
>>> t.get("missing")
0.0
Source code in src/seqchain/track.py
def get(self, key: str, default: float = 0.0) -> float:
    """Look up a value by key.

    Args:
        key: The key to look up.
        default: Value to return if key is missing. Defaults to ``0.0``.

    Returns:
        The stored float value, or *default*.

    Examples:
        >>> t = TableTrack(TrackLabel("t"), {"a": 1.0})
        >>> t.get("a")
        1.0
        >>> t.get("missing")
        0.0
    """
    return self._data.get(key, default)

keys

keys() -> list[str]

Return all keys in the table.

Returns:

Type Description
list[str]

List of key strings.

Examples:

>>> t = TableTrack(TrackLabel("t"), {"a": 1.0, "b": 2.0})
>>> sorted(t.keys())
['a', 'b']
Source code in src/seqchain/track.py
def keys(self) -> list[str]:
    """Return all keys in the table.

    Returns:
        List of key strings.

    Examples:
        >>> t = TableTrack(TrackLabel("t"), {"a": 1.0, "b": 2.0})
        >>> sorted(t.keys())
        ['a', 'b']
    """
    return list(self._data.keys())

__len__

__len__() -> int

Number of entries in the table.

Returns:

Type Description
int

Entry count.

Source code in src/seqchain/track.py
def __len__(self) -> int:
    """Number of entries in the table.

    Returns:
        Entry count.
    """
    return len(self._data)

map_scores

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

Return a new TableTrack with fn applied to every value.

Parameters:

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

A function that maps a float value to a new float value.

required

Returns:

Type Description
'TableTrack'

A new TableTrack with transformed values.

Examples:

>>> t = TableTrack(TrackLabel("t"), {"a": 2.0})
>>> t2 = t.map_scores(lambda s: s + 1)
>>> t2.get("a")
3.0
Source code in src/seqchain/track.py
def map_scores(self, fn: Callable[[float], float]) -> "TableTrack":
    """Return a new TableTrack with *fn* applied to every value.

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

    Returns:
        A new TableTrack with transformed values.

    Examples:
        >>> t = TableTrack(TrackLabel("t"), {"a": 2.0})
        >>> t2 = t.map_scores(lambda s: s + 1)
        >>> t2.get("a")
        3.0
    """
    return TableTrack(self, {k: fn(v) for k, v in self._data.items()})

filter_entries

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

Return a new TableTrack keeping only entries where fn(value) is true.

Parameters:

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

Predicate on the value.

required

Returns:

Type Description
'TableTrack'

A new TableTrack with only matching entries.

Examples:

>>> t = TableTrack(TrackLabel("t"), {"a": 5.0, "b": 1.0})
>>> t2 = t.filter_entries(lambda s: s > 3.0)
>>> t2.keys()
['a']
Source code in src/seqchain/track.py
def filter_entries(self, fn: Callable[[float], bool]) -> "TableTrack":
    """Return a new TableTrack keeping only entries where *fn(value)* is true.

    Args:
        fn: Predicate on the value.

    Returns:
        A new TableTrack with only matching entries.

    Examples:
        >>> t = TableTrack(TrackLabel("t"), {"a": 5.0, "b": 1.0})
        >>> t2 = t.filter_entries(lambda s: s > 3.0)
        >>> t2.keys()
        ['a']
    """
    return TableTrack(
        self,
        {k: v for k, v in self._data.items() if fn(v)},
    )

shared_keys

shared_keys(other: 'TableTrack') -> list[str]

Return keys present in both tables, sorted.

Parameters:

Name Type Description Default
other 'TableTrack'

Another TableTrack to intersect with.

required

Returns:

Type Description
list[str]

Sorted list of shared keys.

Examples:

>>> a = TableTrack(TrackLabel("a"), {"x": 1.0, "y": 2.0, "z": 3.0})
>>> b = TableTrack(TrackLabel("b"), {"y": 10.0, "z": 20.0, "w": 30.0})
>>> a.shared_keys(b)
['y', 'z']
Source code in src/seqchain/track.py
def shared_keys(self, other: "TableTrack") -> list[str]:
    """Return keys present in both tables, sorted.

    Args:
        other: Another TableTrack to intersect with.

    Returns:
        Sorted list of shared keys.

    Examples:
        >>> a = TableTrack(TrackLabel("a"), {"x": 1.0, "y": 2.0, "z": 3.0})
        >>> b = TableTrack(TrackLabel("b"), {"y": 10.0, "z": 20.0, "w": 30.0})
        >>> a.shared_keys(b)
        ['y', 'z']
    """
    return sorted(set(self._data) & set(other.keys()))

scores

scores() -> Iterator[float]

Iterate over all values in entry order.

Returns:

Type Description
Iterator[float]

Iterator of float values.

Examples:

>>> t = TableTrack(TrackLabel("t"), {"a": 1.0, "b": 2.0})
>>> list(t.scores())
[1.0, 2.0]
Source code in src/seqchain/track.py
def scores(self) -> Iterator[float]:
    """Iterate over all values in entry order.

    Returns:
        Iterator of float values.

    Examples:
        >>> t = TableTrack(TrackLabel("t"), {"a": 1.0, "b": 2.0})
        >>> list(t.scores())
        [1.0, 2.0]
    """
    return iter(self._data.values())

with_scores

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

Rebuild the TableTrack with new values in entry order.

Parameters:

Name Type Description Default
scores Sequence[float]

New values, one per key.

required

Returns:

Type Description
'TableTrack'

A new TableTrack with replaced values.

Raises:

Type Description
ValueError

If length does not match.

Examples:

>>> t = TableTrack(TrackLabel("t"), {"a": 1.0, "b": 2.0})
>>> t2 = t.with_scores([10.0, 20.0])
>>> t2.get("a")
10.0
Source code in src/seqchain/track.py
def with_scores(self, scores: Sequence[float]) -> "TableTrack":
    """Rebuild the TableTrack with new values in entry order.

    Args:
        scores: New values, one per key.

    Returns:
        A new TableTrack with replaced values.

    Raises:
        ValueError: If length does not match.

    Examples:
        >>> t = TableTrack(TrackLabel("t"), {"a": 1.0, "b": 2.0})
        >>> t2 = t.with_scores([10.0, 20.0])
        >>> t2.get("a")
        10.0
    """
    scores = list(scores)
    keys = list(self._data.keys())
    if len(scores) != len(keys):
        raise ValueError(
            f"Expected {len(keys)} scores, got {len(scores)}"
        )
    return TableTrack(self, dict(zip(keys, scores)))