def parse_flag_str(flag_str):
    """ Parse a dq flag query string

    Parameters
    ----------
    flag_str: str
        String to be parsed

    Returns
    -------
    flags: list of strings
        List of reduced name strings which can be passed to lower level
        query commands
    signs: dict
        Dict of bools indicating if the flag should add positively to the
        segmentlist
    ifos: dict
        Ifo specified for the given flag
    bounds: dict
        The boundary of a given flag
    padding: dict
        Any padding that should be applied to the segments for a given flag
    """
    flags = flag_str.replace(' ', '').strip().split(',')
    signs = {}
    ifos = {}
    bounds = {}
    padding = {}
    bflags = []
    for flag in flags:
        if not (flag[0] == '+' or flag[0] == '-'):
            err_msg = "DQ flags must begin with a '+' or a '-' character. "
            err_msg += 'You provided {}.'.format(flag)
            err_msg += (
                'See http://pycbc.org/pycbc/latest/html/workflow/segments.html'
                )
            err_msg += ' for more information.'
            raise ValueError(err_msg)
        sign = flag[0] == '+'
        flag = flag[1:]
        ifo = pad = bound = None
        if len(flag.split(':')[0]) == 2:
            ifo = flag.split(':')[0]
            flag = flag[3:]
        if '<' in flag:
            popt = flag.split('<')[1].split('>')[0]
            spad, epad = popt.split(':')
            pad = float(spad), float(epad)
            flag = flag.replace(popt, '').replace('<>', '')
        if '[' in flag:
            bopt = flag.split('[')[1].split(']')[0]
            start, end = bopt.split(':')
            bound = int(start), int(end)
            flag = flag.replace(bopt, '').replace('[]', '')
        if ifo:
            ifos[flag] = ifo
        if pad:
            padding[flag] = pad
        if bound:
            bounds[flag] = bound
        bflags.append(flag)
        signs[flag] = sign
    return bflags, signs, ifos, bounds, padding
