def readTable(infile,
              as_rows=True,
              with_header=True,
              ignore_incomplete=False,
              dialect="excel-tab"):
    """read a table from infile

    Arguments
    ---------
    infile : File
       File or list of lines
    as_rows : bool
       If true, return table as a list of rows. Otherwise,
       return as a list of columns.
    ignore_incomplete : bool
       If true, incomplete rows are ignored.
    dialect : string
       CSV dialect.

    Returns
    -------
    fields : list
        List of field names
    rows : list
        List of rows
    """

    lines = [x for x in infile if x[0] != "#"]

    if len(lines) == 0:
        return [], []

    if with_header:
        fields = lines[0][:-1].split("\t")
        del lines[0]
    else:
        fields = lines[0][:-1].split("\t")
        fields = map(str, range(len(fields)))

    nfields = len(fields)

    try:
        reader = csv.reader(lines.__iter__(),
                            dialect=dialect)
    except __HOLE__:
        reader = csv.reader(lines.__iter__())

    table = list(reader)

    if ignore_incomplete:
        table = [x for x in table if len(x) == nfields]
    else:
        for r, row in enumerate(table):
            if len(row) != nfields:
                if not ignore_incomplete:
                    raise ValueError(
                        "missing elements in line %s, received=%s, "
                        "expected=%s" %
                        (r, str(row),  str(fields)))

                raise ValueError

    if not as_rows:
        table = zip(*table)

    return fields, table
dataset/ETHPy150Open CGATOxford/cgat/CGAT/CSV.py/readTable