def count_sep(specstr, sep=','):
    """Count number of specified separators (default = ',') in given string,
    avoiding occurrences of the separator inside nested braces"""

    num_seps = 0
    brace_depth = 0
    for s in specstr:
        if s == sep and brace_depth == 0:
            num_seps += 1
        elif s == '(':
            brace_depth += 1
        elif s == ')':
            brace_depth -= 1
    return num_seps