def _summarize_type(df, value1, value2, total):
    """Helper function for calculating a codon pair reference
    """
    value1_count = df[[value1, total]].groupby(value1).sum()
    value2_count = df[[value2, total]].groupby(value2).sum()
    value_count = value1_count.add(value2_count, fill_value=0)
    value_count.columns = [value1 + '_cnt']
    df = df.merge(value_count, how='left', left_on=value1, right_index=True,
        copy=False)
    value_count.columns = [value2 + '_cnt']
    return df.merge(value_count, how='left', left_on=value2, right_index=
        True, copy=False)
