def ReadBinarySparseMatrix(filename,
                           separator="\t",
                           numeric_type=numpy.float,
                           is_symmetric=None):

    lines = map(lambda x: string.split(x[:-1], separator)[:2],
                filter(lambda x: x[0] != "#", open(filename, "r").readlines()))

    data = map(lambda x: (string.atoi(x[0]), string.atoi(x[1])), lines)

    num_rows = max(map(lambda x: x[0], data))
    num_cols = max(map(lambda x: x[1], data))

    if (is_symmetric):
        num_rows = max(num_rows, num_cols)
        num_cols = max(num_rows, num_cols)
    matrix = numpy.zeros((num_rows, num_cols), numeric_type)

    for row, col in data:
        matrix[row - 1, col - 1] = 1

    if is_symmetric:
        for col, row in data:
            matrix[row - 1, col - 1] = 1

    return matrix
read sparse matrix.
dataset/ETHPy150Open CGATOxford/cgat/CGAT/MatlabTools.py/ReadBinarySparseMatrix