def handle_hotmaps_results(permutation_result):
    """Takes in output from multiprocess_permutation function and converts to
    a better formatted dataframe.

    Parameters
    ----------
    permutation_result : list
        output from multiprocess_permutation

    Returns
    -------
    permutation_df : pd.DataFrame
        formatted output suitable to save
    """
    if len(permutation_result[0])  == 6:
        mycols = ['gene', 'window length', 'codon position', 'mutation count',
                  'windowed sum', 'p-value']
    else:
        mycols = ['gene', 'window length', 'codon position', 'index', 'mutation count',
                  'windowed sum', 'p-value']

    permutation_df = pd.DataFrame(permutation_result, columns=mycols)

    # get benjamani hochberg adjusted p-values
    permutation_df['q-value'] = 1
    for w in permutation_df['window length'].unique():
        is_window = permutation_df['window length'] == w
        permutation_df.loc[is_window, 'q-value'] = mypval.bh_fdr(permutation_df.loc[is_window, 'p-value'])
    #permutation_df['q-value'] = mypval.bh_fdr(permutation_df['p-value'])

    # order output
    #permutation_df = permutation_df.set_index('gene', drop=False)  # make sure genes are indices
    col_order = mycols + ['q-value']
    permutation_df = permutation_df.sort_values(by=['window length', 'p-value'])
    return permutation_df[col_order]