def get_quantile(pos, percentile=0.5):
    """provided a list of (positions,coverage) pairs, return the median position"""
    total = sum(cov for _, cov in pos)
    n = 0
    for p, cov in sorted(pos, key=lambda x: x[0]):
        n += cov
        if n >= total * percentile:
            return p
    raise ValueError(f"cannot find {percentile} percentile of {pos}")