def readTable(file,
              separator="\t",
              numeric_type=numpy.float,
              take="all",
              has_headers=True,
              truncate=None,
              missing_value=-99999,
              color=None,
              ):
    """read a matrix.

    There probably is a routine for this in Numpy, which I haven't found yet.
    Uses the MA module to deal with missing values.
    """

    lines = filter(lambda x: x[0] != "#", file.readlines())

    if len(lines) == 0:
        raise ValueError("no data")

    if take == "all":
        num_cols = len(string.split(lines[0][:-1], "\t"))
        take = range(0, num_cols)
    else:
        num_cols = len(take)

    colors = None
    if color > None:
        take = [x for x in take if x != color]
        num_cols = len(take)
        colors = []

    if has_headers:
        headers = lines[0][:-1].split("\t")
        headers = map(lambda x: headers[x], take)
        del lines[0]
    else:
        headers = None

    num_rows = len(lines)

    matrix = numpy.zeros((num_rows, num_cols), numeric_type)

    nrow = 0
    if truncate:
        min_val, max_val = truncate

    for l in lines:
        data = l[:-1].split("\t")

        if color is not None:
            colors.append(float(data[color]))

        try:
            data = map(lambda x: data[x], take)
        except IndexError:
            continue

        # try conversion. Unparseable fields set to missing_value
        for x in range(len(data)):
            try:
                data[x] = float(data[x])
            except ValueError:
                data[x] = missing_value

        if truncate:
            if data[0] < min_val or data[0] > max_val:
                continue

        matrix[nrow] = data
        nrow += 1

    if truncate is not None:
        # truncate matrix
        matrix = matrix[0:nrow + 1, 0:num_cols]

    return MA.masked_values(matrix, missing_value), headers, colors
dataset/ETHPy150Open CGATOxford/cgat/scripts/plot_data.py/readTable/operator `is not` -> `>`