From headerfield object, this generates a full header as a list, ready
    to write to a TSV file
    E.g:
    headerfield = {precusroquant: {HEADER_AREA: OD([(set1, set1_HEAD), (set2,
    set2_HEAD), etc])}}

def generate_general_header(headerfields, fieldtypes, firstfield, oldheader,
                            group_by_field):
    """From headerfield object, this generates a full header as a list, ready
    to write to a TSV file
    E.g:
    headerfield = {precusroquant: {HEADER_AREA: OD([(set1, set1_HEAD), (set2,
    set2_HEAD), etc])}}"""
    if not oldheader:
        header = [firstfield]
    else:
        header = [firstfield] + oldheader[1:]
    poolfields = OrderedDict()
    poolfields[None] = []  # Have non-pool/set columns come before pool-columns
    if group_by_field:
        header.extend(poolfields[None])
    for fieldtype in fieldtypes:
        try:
            fields = headerfields[fieldtype]
        except KeyError:
            continue
        if type(fields) == list:
            header.extend(fields)
        elif group_by_field:
            pfmatrix = [list(x.values()) for k, x in fields.items()
                        if not HEADER_NO_PSMS_SUFFIX in k]
            header.extend([x for y in transpose(pfmatrix) for x in y])
            if fieldtype == 'isoquant':
                pfmatrix = [list(x.values()) for k, x in fields.items()
                            if HEADER_NO_PSMS_SUFFIX in k]
                header.extend([x for y in transpose(pfmatrix) for x in y])
        else:
            for pool_field in fields.values():
                for pool, field in pool_field.items():
                    try:
                        poolfields[pool].append(field)
                    except KeyError:
                        poolfields[pool] = [field]
    if poolfields and not group_by_field:
        for fields in poolfields.values():
            header.extend(fields)
    return header