def rreplace(s, old, new, occurrence, only_if_not_followed_by=None):
    """replaces occurences of character, counted from last to first, with new 
    character. 
    Arguments:
    s - string
    old - character/string to be replaced
    new - character/string to replace old with
    occurence - nth occurence up to which instances should be replaced, counting 
    from end to beginning. e.g. if set to 2, the two last instances of "old" 
    will be replaced
    only_if_not_followed_by - if this is set to a string, [old] is only replaced
    by [new] if [old] is not followed by [only_if_not_followed_by] in [s]. Useful
    for gene names like abc-1.d, in that case we do not want to replace the dash.
    Returns:
    string with replaced character
    """
    if old not in s:
        return s
    elif only_if_not_followed_by != None:
        # test if latest instance of old is followed by [only_if_not_followed_by]
        last_inst_old = s.rfind(old)
        last_inst_oinfb = s.rfind(only_if_not_followed_by)
        if last_inst_oinfb > last_inst_old:
            return s
    li = s.rsplit(old, occurrence)
    return new.join(li)