Write down the provided matrix in the specified outputfile.
    :arg outputfile, name of the outputfile in which the QTLs found are
        written.
    :arg matrix, the list of lists of data to write.

def write_matrix(outputfile, matrix):
    """ Write down the provided matrix in the specified outputfile.
    :arg outputfile, name of the outputfile in which the QTLs found are
        written.
    :arg matrix, the list of lists of data to write.
    """

    try:
        stream = open(outputfile, 'w')
        for row in matrix:
            if isinstance(row, list) or isinstance(row, tuple):
                row = [str(el).strip() for el in row]
                stream.write(','.join(row) + '\n')
            else:
                stream.write(row + '\n')
    except IOError as err:  # pragma: no cover
        LOG.info('An error occured while writing the file %s'
                 % outputfile)
        LOG.debug("Error: %s" % err)
    finally:
        stream.close()
    LOG.info('Wrote QTLs in file %s' % outputfile)