def readPValues(infile, synonyms={}):
    '''read pvalues and optionally fold changes from infile.'''
    term2pvalue, term2log2fold = {}, collections.defaultdict(float)

    def _parse2(data):
        goid = synonyms.get(data[0], data[0])
        term2pvalue[goid] = float(data[1])

    def _parse3(data):
        goid = synonyms.get(data[0], data[0])
        term2pvalue[goid] = float(data[1])
        term2log2fold[goid] = math.log(float(data[2]), 2)

    def _parseGO(data):
        '''parse output from GO.py'''
        if len(data) < 14:
            return
        goid = synonyms.get(data[11], data[11])
        term2pvalue[goid] = float(data[8])
        term2log2fold[goid] = math.log(float(data[7]) + 0.0000001, 2)

    parser = None
    for line in infile:
        if line.startswith("code"):
            parser = _parseGO
            continue
        elif line.startswith("goid"):
            data = line[:-1].split("\t")
            if len(data) == 2:
                parser = _parse2
            else:
                parser = _parse3
            continue
        if parser is None:
            raise ValueError(
                "don't know how to parse this file at line %s" % line)

        parser(line[:-1].split())

    return term2pvalue, term2log2fold
dataset/ETHPy150Open CGATOxford/cgat/scripts/revigo.py/readPValues/original