def get_consensus(out_fn, trim_margin):
    """ Extract consensus sequence from output of spoa.

    Parameters
    ----------
    out_fn : str (output from spoa)
    trim_margin : int (number of bp to trim on each end of the consensus, as the consensus sequence
    is more likely to be erroneous on the ends)

    Returns
    -------
    consensus : str (consensus sequence)

    """
    fh = open(out_fn, 'rb')
    lines = fh.readlines()
    if len(lines) == 0:
        return ''
    consensus = lines[-1][:-1]
    consensus = consensus[trim_margin:len(consensus) - trim_margin]
    fh.close()
    return consensus