def set_brackets(pathway):
    """
    Function defines levels of all brackets in expression. The output will be used by function <check_brackets>
    Example 1:
        expression: A B (C,D)
        levels:  -1,-1,-1,-1,0,-1,-1,-1,0
    Example 2:
        expression: (A B (C,D))
        levels:  0,-1,-1,-1,-1,1,-1,-1,-1,1,0
    :param pathway: string expression
    :return: levels of brackets
    """
    levels_brackets = []
    cur_open = []
    num = -1
    for c in pathway:
        if c == '(':
            num += 1
            cur_open.append(num)
            levels_brackets.append(num)
        elif c == ')':
            levels_brackets.append(cur_open[len(cur_open)-1])
            cur_open.pop()
        else:
            levels_brackets.append(-1)
    return levels_brackets