def position_distance(a, b, g_length):
    """
    Calculate the shortest distance between two positions on a circular genome.
    :param a: index of first position
    :param b: index of second position
    :param g_length: total genome length in basepairs
    :return: the calculated distance
    """
    diff = abs(a - b)
    return min(diff, g_length - diff)
