Skip to content

coordmath

Methods for coordinate-based math and interval manipulation.

Contains the following public methods:

Functions

get_closed_end

get_closed_end(start: int, length: int) -> int

Get the closed end of an interval given its start and length.

Parameters:

Name Type Description Default
start int

The start position of the interval.

required
length int

The length of the interval.

required

Returns:

Type Description
int

The closed end of the interval.

Example

get_closed_end(start=10, length=5) 14

Source code in prymer/api/coordmath.py
def get_closed_end(start: int, length: int) -> int:
    """
    Get the closed end of an interval given its start and length.

    Args:
        start: The start position of the interval.
        length: The length of the interval.

    Returns:
        The closed end of the interval.

    Example:
        >>> get_closed_end(start=10, length=5)
        14
    """
    return start + length - 1

get_locus_string

get_locus_string(record: Interval) -> str

Get the locus-string for an interval.

The output string will have the format <refname>:<start>-<end> No conversion on coordinates is performed, so the output is 0-based, open-ended.

Parameters:

Name Type Description Default
record Interval

The interval to get the locus-string for.

required

Returns:

Type Description
str

A locus-string for the interval.

Source code in prymer/api/coordmath.py
def get_locus_string(record: Interval) -> str:
    """
    Get the locus-string for an interval.

    The output string will have the format `<refname>:<start>-<end>`
    No conversion on coordinates is performed, so the output is 0-based, open-ended.

    Args:
        record: The interval to get the locus-string for.

    Returns:
        A locus-string for the interval.
    """
    return f"{record.refname}:{record.start}-{record.end}"

require_same_refname

require_same_refname(*intervals: Interval) -> None

Require that the input intervals all have the same refname.

Parameters:

Name Type Description Default
intervals Interval

one or more intervals

()

Raises:

Type Description
ValueError

if the intervals do not all have the same refname.

Source code in prymer/api/coordmath.py
def require_same_refname(*intervals: Interval) -> None:
    """
    Require that the input intervals all have the same refname.

    Args:
        intervals: one or more intervals

    Raises:
        ValueError: if the intervals do not all have the same refname.
    """

    refnames = set(i.refname for i in intervals)
    if len(refnames) != 1:
        raise ValueError(f"`intervals` must have exactly one refname\n Found {sorted(refnames)}")