def getMatrixFromEdges(lines, options,
                       in_map_token2row={},
                       in_map_token2col={}):

    # remove comments
    lines = filter(lambda x: x[0] != "#" and len(x[:-1]) > 0, lines)

    if in_map_token2row:
        map_token2row = in_map_token2row
    else:
        map_token2row = {}

    if in_map_token2col:
        map_token2col = in_map_token2col
    else:
        map_token2col = {}

    if options.format == "string":

        has_row_names = len(map_token2row) > 0
        has_col_names = len(map_token2col) > 0

        # if either row/column names are not given:
        if not map_token2row or not map_token2col:

            row_tokens = map(lambda x: string.split(x[:-1], "\t")[0], lines)
            col_tokens = map(lambda x: string.split(x[:-1], "\t")[1], lines)

            if options.is_numeric:
                row_tokens = map(float, row_tokens)
                col_tokens = map(float, col_tokens)
                row_tokens.sort()
                col_tokens.sort()
                row_tokens = map(str, row_tokens)
                col_tokens = map(str, col_tokens)
            else:
                row_tokens.sort()
                col_tokens.sort()

            if not has_row_names:
                for row_token in row_tokens:
                    if row_token not in map_token2row:
                        map_token2row[row_token] = len(map_token2row)
            if not has_col_names:
                for col_token in col_tokens:
                    if col_token not in map_token2col:
                        map_token2col[col_token] = len(map_token2col)

        if not options.asymmetric:
            for col_token in map_token2col.keys():
                if col_token not in map_token2row:
                    map_token2row[col_token] = len(map_token2row)
            map_token2col = map_token2row

        matrix = [[options.default for j in range(len(map_token2col))] for i in range(
            len(map_token2row))]

        if len(map_token2col) == len(map_token2row):
            for j in range(len(map_token2col)):
                matrix[j][j] = options.default_diagonal

        # return matrix
        m = Matrix()

        if options.input_format == "row-col-weight":
            for line in lines:
                row_token, col_token, weight = string.split(
                    line[:-1], "\t")[:3]
                matrix[map_token2row[row_token]][
                    map_token2col[col_token]] = weight
                if not options.asymmetric:
                    matrix[map_token2col[col_token]][
                        map_token2row[row_token]] = weight

        elif options.input_format == "row-col-weight-replicates":
            replicates = [[0 for j in range(len(map_token2col))]
                          for i in range(len(map_token2row))]
            for line in lines:
                row_token, col_token, weight, n = string.split(
                    line[:-1], "\t")[:4]
                matrix[map_token2row[row_token]][
                    map_token2col[col_token]] = weight
                replicates[map_token2row[row_token]][
                    map_token2col[col_token]] = int(n)
                if not options.asymmetric:
                    matrix[map_token2col[col_token]][
                        map_token2row[row_token]] = weight
                    replicates[map_token2col[col_token]][
                        map_token2row[row_token]] = int(n)
            m.mReplicates = replicates

        col_tokens = map_token2col.items()
        col_tokens.sort(lambda x, y: cmp(x[1], y[1]))
        row_tokens = map_token2row.items()
        row_tokens.sort(lambda x, y: cmp(x[1], y[1]))

        m.mMatrix = matrix
        m.mMapRow2Token = row_tokens
        m.mMapCol2Token = col_tokens
        m.mMapToken2Row = map_token2row
        m.mMapToken2Col = map_token2col

    return matrix
read matrix from lines
dataset/ETHPy150Open CGATOxford/cgat/CGAT/MatrixTools.py/getMatrixFromEdges