def reorder_dataframe_columns(dataframe, cols, front=True):
    """Takes a dataframe and a subsequence of its columns,
       returns dataframe with seq as first columns if "front" is True,
       and seq as last columns if "front" is False.
       taken from https://stackoverflow.com/questions/12329853/how-to-rearrange-pandas-column-sequence

    Parameters
    ----------
    df : pd.DataFrame
        original dataframe
    cols : list
        List of cols to put first or last.
    front : bool
        Whether to put the columns at the front or the back.

    Usage
    -----
    df = reorder_dataframe_columns(df, ["TMD_start", "database", "whatever other col I want first"])
    """
    for col in cols:
        if col not in dataframe.columns:
            cols.remove(col)
    cols_to_place_first = cols[:]
    for existing_col in dataframe.columns:
        if existing_col not in cols_to_place_first:
            if front:
                cols_to_place_first.append(existing_col)
            else:
                cols_to_place_first.insert(0, existing_col)
    return dataframe[cols_to_place_first]
