def tss_distances(peak,feature):
    """
    Return distances between peak edges and feature TSS

    Arguments:
      peak (Peak): peak instance
      feature (Feature): feature instance

    Returns:
      tuple: a pair of distances, the first being the
        smallest distance between an edge of the peak
        region to the TSS of the feature region, and
        the second being the distance from the other peak
        edge to the TSS.
        If the TSS position is entirely contained within
        the peak then the smallest distance is returned as
        zero, the second is the average of the distances
        to the two peak edges from the TSS.

    """
    # TSS is considered as a point
    if (feature.tss >= peak.start and
        feature.tss <= peak.end):
        # TSS entirely contained in the peak
        # Rank using the average distance of the peak
        # edges from the TSS
        return (0,(abs(feature.tss - peak.start) +
                   abs(feature.tss - peak.end))/2)
    # Possible distances to TSS
    d_tss = [abs(feature.tss - peak.start),
             abs(feature.tss - peak.end)]
    d_tss.sort()
    return tuple(d_tss)