def readPathways():

    fh = file(
        gidgetConfigVars['TCGAFMP_BIOINFORMATICS_REFERENCES'] + "/nci_pid/only_NCI_Nature_ver4.tab", 'r')

    pwDict = {}

    for aLine in fh:
        aLine = aLine.strip()
        aLine = aLine.upper()
        tokenList = aLine.split('\t')
        if (len(tokenList) != 3):
            continue
        if (tokenList[0] == "pathway"):
            continue

        longPathwayName = tokenList[0]
        shortPathwayName = tokenList[1]

        geneTokens = tokenList[2].strip()
        geneList = geneTokens.split(',')
        geneList.sort()

        if (len(geneList) > 0):
            while (geneList[0] == ''):
                geneList = geneList[1:]
                if (len(geneList) == 0):
                    continue

        if (len(geneList) == 0):
            continue

        pathwayName = cleanUpName(shortPathwayName)

        if (pathwayName not in pwDict.keys()):
            # print " adding pathway %s (%d) " % ( pathwayName, len(geneList) )
            pwDict[pathwayName] = geneList
        else:
            if (len(pwDict[pathwayName]) < len(geneList)):
                # print " substituting shorter list of genes for %s (%d) " % (
                # pathwayName, len(geneList) )
                pwDict[pathwayName] = geneList
            # else:
                # print " NOT substituing list for %s " % pathwayName

    fh.close()

    print " "
    print " have pathway dictionary with %d pathways " % len(pwDict)
    print "     --> now looking for duplicate pathways ... "
    pwList = pwDict.keys()
    pwList.sort()
    delList = []
    pairDict = {}

    for ii in range(len(pwList) - 1):
        iiName = pwList[ii]
        iiLen = len(pwDict[iiName])
        for jj in range(ii + 1, len(pwList)):
            jjName = pwList[jj]
            jjLen = len(pwDict[jjName])
            if (jjLen != iiLen):
                continue

            if (pwDict[iiName] == pwDict[jjName]):
                print "\n\n SAME !!! "
                print iiName, iiLen
                print pwDict[iiName]
                print jjName, jjLen
                print pwDict[jjName]

                iiSplit = iiName.split('__')
                jjSplit = jjName.split('__')

                if (iiSplit[1] <= jjSplit[1]):
                    pairNames = (iiSplit[1], jjSplit[1])
                else:
                    pairNames = (jjSplit[1], iiSplit[1])
                if (pairNames in pairDict.keys()):
                    pairDict[pairNames] += 1
                else:
                    pairDict[pairNames] = 1

                if (iiSplit[1] == jjSplit[1]):
                    if (len(iiName) <= len(jjName)):
                        delList += [jjName]
                    else:
                        delList += [iiName]

                else:

                    if (iiSplit[1] == "NCI-NATURE"):
                        delList += [jjName]
                    elif (jjSplit[1] == "NCI-NATURE"):
                        delList += [iiName]

                    elif (iiSplit[1] == "PID"):
                        delList += [jjName]
                    elif (jjSplit[1] == "PID"):
                        delList += [iiName]

                    elif (iiSplit[1] == "KEGG"):
                        delList += [jjName]
                    elif (jjSplit[1] == "KEGG"):
                        delList += [iiName]

                    elif (iiSplit[1] == "PWCOMMONS"):
                        delList += [jjName]
                    elif (jjSplit[1] == "PWCOMMONS"):
                        delList += [iiName]

                    elif (iiSplit[1] == "REACTOME"):
                        delList += [jjName]
                    elif (jjSplit[1] == "REACTOME"):
                        delList += [iiName]

                    elif (iiSplit[1] == "WIKIPATHWAYS"):
                        delList += [jjName]
                    elif (jjSplit[1] == "WIKIPATHWAYS"):
                        delList += [iiName]

                    elif (iiSplit[1] == "WIKIPW"):
                        delList += [jjName]
                    elif (jjSplit[1] == "WIKIPW"):
                        delList += [iiName]

                    elif (iiSplit[1] == "SMPDB"):
                        delList += [jjName]
                    elif (jjSplit[1] == "SMPDB"):
                        delList += [iiName]

                    elif (iiSplit[1] == "HUMANCYC"):
                        delList += [jjName]
                    elif (jjSplit[1] == "HUMANCYC"):
                        delList += [iiName]

                    else:
                        sys.exit(-1)

    for aName in delList:
        try:
            del pwDict[aName]
        except:
            doNothing = 1

    print " "
    print " returning pathway dictionary with %d pathways " % len(pwDict)
    print " "
    for aKey in pairDict.keys():
        print aKey, pairDict[aKey]
    print " "
    print " "

    return (pwDict)