genomeblocks.locus

Core interval dataclasses.

Table of contents

  1. Locus
    1. Properties
    2. Methods
    3. Ordering
  2. Exon(Locus)
  3. CDS(Exon)
  4. UTR(Exon)

Locus

@dataclass
class Locus:
    chrom: str
    start: int
    end: int
    strand: str = "."

Properties

Name Type Description
uid str Canonical "chrom:start-end(strand)" identifier.
length int end - start.
center int (start + end) // 2.

Methods

Locus.overlaps(other)       # bool — both on same chrom AND ranges intersect
Locus.distance_to(other)    # int  — |center - other.center|, NotImplemented if cross-chrom
Locus.sequence(genome, r=None)
    # Extract sequence from a {chrom: str} genome dict.
    # If r is None, returns genome[chrom][start:end].
    # Otherwise, returns a ±r bp window around center.
Locus.copy()                # new Locus with same fields

Ordering

Locus defines __lt__, __le__, __gt__, __ge__ so lists of Locus objects sort by (chrom, start).


Exon(Locus)

@dataclass
class Exon(Locus):
    exon_number: int = 0

CDS(Exon)

Alias; same fields as Exon, used as a type marker.

UTR(Exon)

@dataclass
class UTR(Exon):
    type: str = None      # "5'" or "3'"

All three inherit Locus’s UID / overlap / distance methods, so they participate in every interval API.


Copyright © 2024–2026 Umut Berkay Altintas. MIT Licensed.

This site uses Just the Docs, a documentation theme for Jekyll.