The unmapped.bam file up until at least Tophat 2.1.1 is broken in various
    ways, see https://github.com/cbrueffer/tophat-recondition for details.
    Run TopHat-Recondition to fix these issues.

def _fix_unmapped(mapped_file, unmapped_file, data):
    """
    The unmapped.bam file up until at least Tophat 2.1.1 is broken in various
    ways, see https://github.com/cbrueffer/tophat-recondition for details.
    Run TopHat-Recondition to fix these issues.
    """
    out_file = os.path.splitext(unmapped_file)[0] + "_fixup.bam"
    if file_exists(out_file):
        return out_file

    assert os.path.dirname(mapped_file) == os.path.dirname(unmapped_file)

    cmd = config_utils.get_program("tophat-recondition", data)
    cmd += " -q"
    tophat_out_dir = os.path.dirname(mapped_file)
    tophat_logfile = os.path.join(tophat_out_dir, 'tophat-recondition.log')

    with file_transaction(data, tophat_logfile) as tx_logfile:
        cmd += ' --logfile %s' % tx_logfile
        cmd += " -m %s" % mapped_file
        cmd += " -u %s" % unmapped_file
        cmd += " %s" % tophat_out_dir
        do.run(cmd, "Fixing unmapped reads with Tophat-Recondition.", None)

    return out_file