def write_output(file_obj, diffSolution, solution, filenames, cutoff, showOrig
    ):
    """ Write output to the given file object (expected to be open for writing)

    This function writes a list of "<reaction> <difference>" pairs to the given
    file object, sorted in order of decreasing difference. Differences below
    cutoff are not reported. If cutoff is zero, all differences are reported.
    If showOrig is True, the original flux values are listed in addition to the
    absolute differences.

    Keyword arguments:
    file_obj     -- the file object (open for writing; may also be sys.stdout)
    diffSolution -- MetabolicFlux of absolute flux differences
    solution     -- pair (or list) of solutions (flux distributions),
                    as MetabolicFlux
    filenames    -- pair (or list) of solution filenames, in original order
    cutoff       -- cutoff below which differences are not reported
    showOrig     -- if True, also show original values, else only the difference

    Returns:
    True if any difference is above cutoff, False else
    """
    maxlen = len(max(list(diffSolution.fluxDict.keys()), key=len))
    len0 = max(len(filenames[0]), 12)
    len1 = max(len(filenames[1]), 12)
    first = True
    for rea in sorted(diffSolution.fluxDict, key=diffSolution.fluxDict.get,
        reverse=True):
        value = diffSolution[rea]
        if value < cutoff:
            break
        if first:
            s = 'REACTION'.ljust(maxlen) + 'DIFFERENCE'.rjust(12)
            if showOrig:
                s += '  ' + filenames[0].rjust(len0) + '  ' + filenames[1
                    ].rjust(len1)
            file_obj.write(s + '\n')
            first = False
        s = rea.ljust(maxlen) + ('%.6g' % value).rjust(12)
        in2 = rea in solution[1]
        if rea in solution[0]:
            if showOrig:
                s += '  ' + ('% .6g' % solution[0][rea]).rjust(len0)
            notPresent = -1
        else:
            notPresent = 0
            if showOrig and in2:
                s += ' ' * (len0 + 2)
        if in2:
            if showOrig:
                s += '  ' + ('% .6g' % solution[1][rea]).rjust(len1)
        else:
            notPresent = 1
        if notPresent >= 0:
            s += ' # not present in ' + filenames[notPresent]
        file_obj.write(s + '\n')
    return not first
