def mergeGenomeLogFiles(outPrefix, nbSet):
    """Merge genome and log files together.

    :param outPrefix: the prefix of the output files.
    :param nbSet: The number of set of files to merge together.

    :type outPrefix: str
    :type nbSet: int

    :returns: the name of the output file (the ``genome`` file).

    After merging, the files are deleted to save space.

    """
    outputFile = None
    try:
        outputFile = open(outPrefix + ".genome", "w")
        outputLog = open(outPrefix + ".log", "w")
    except IOError:
        msg = "%s or %s: can't write file" % (outPrefix + ".genome",
                                              outPrefix + ".log")
        raise ProgramError(msg)

    for i in xrange(1, nbSet + 1):
        for j in xrange(i, nbSet + 1):
            fileName = outPrefix + "_output.sub.%(i)d.%(j)d.genome" % locals()

            printHeader = False
            if (i == 1) and (j == 1):
                # This is the first file we open
                printHeader = True

            # Read file here
            try:
                with open(fileName, 'r') as inputFile:
                    for nbLine, line in enumerate(inputFile):
                        if nbLine == 0:
                            if printHeader:
                                outputFile.write(line)
                        else:
                            outputFile.write(line)
            except IOError:
                msg = "%(fileName)s: no such file" % locals()
                raise ProgramError(msg)

            # Deleting the file
            try:
                os.remove(fileName)
            except IOError:
                msg = "%(fileName)s: can't delete the file" % locals()
                raise ProgramError(msg)

            # Read file here
            fileName = outPrefix + "_output.sub.%(i)d.%(j)d.log" % locals()
            try:
                with open(fileName, 'r') as inputFile:
                    for line in inputFile:
                        outputLog.write(line)
            except IOError:
                msg = "%(fileName)s: no such file" % locals()
                raise ProgramError(msg)

            # Deleting the file
            try:
                os.remove(fileName)
            except IOError:
                msg = "%(fileName)s: can't delete the file" % locals()
                raise ProgramError(msg)

    # Removing the tmp.list* files
    try:
        for fileName in glob.glob(outPrefix + "_tmp.list*"):
            os.remove(fileName)
    except IOError:
        msg = "can't delete the tmp.list* files"
        raise ProgramError(msg)

    # Removing the output.sub.*
    try:
        for fileName in glob.glob(outPrefix + "_output.sub.*"):
            os.remove(fileName)
    except IOError:
        msg = "can't delete the output.sub.* files"
        raise ProgramError(msg)

    # Closing the output files
    outputFile.close()
    outputLog.close()

    return outPrefix + ".genome"
Merge genome and log files together.

    :param outPrefix: the prefix of the output files.
    :param nbSet: The number of set of files to merge together.

    :type outPrefix: str
    :type nbSet: int

    :returns: the name of the output file (the ``genome`` file).

    After merging, the files are deleted to save space.