def _gene_distance(insertion, gene):
    """Calculates distance between insertion and gene."""

    position = insertion.position
    gene_start = gene.start
    gene_end = gene.end

    if gene_start <= position < gene_end:
        return 0
    elif position < gene_start:
        return gene_start - position
    else:
        return position - gene_end