def average_barcodes(df, sequence_label="label", out_prefix=None):
    """Average RNA/DNA barcode counts for each sequence within replicates.

    Parameters
    ----------
    df : pd.DataFrame
        Index is the barcode, one column must have the key sequence_label, the rest are assumed to be RNA/DNA counts
        for each replicate.
    sequence_label : str
        Name of the column in df containing the sequence IDs
    out_prefix : str
        If specified, save the df to file with this prefix.

    Returns
    -------
    expression_df : pd.DataFrame
        Average RNA/DNA counts for each sequence in each replicate. Index is now the sequence label, column is the
        replicate.
    """
    expression_df = df.groupby(sequence_label).mean()
    if out_prefix:
        expression_df.to_csv(f"{out_prefix}AverageExpressionPerReplicate.txt", sep="\t", na_rep="NaN")

    return expression_df