import bz2
import gzip


def open_output(output, opts):
    """Open output file with right compression library
    """
    if opts.bzip:
        return bz2.open(output, 'wt')
    elif opts.gzip:
        return gzip.open(output, 'wt')
    else:
        return open(output, 'w')