def correlationMatrix(outf, inf, method = pcorrelation):
    """Takes a tab file and cross-correlates the columns"""
    
    outData = dict()
    inData = mData.rCRSData(inf)
    inCols = inData.keys()
    inRows = inData[inCols[0]].keys()
    for i in inCols:
        outData[i] = dict()
        outData[i][i] = 1.0
    for i in range(len(inCols)-1):
        list1 = []
        for k in inRows:
            list1.append(inData[inCols[i]][k])
        for j in range(i+1, len(inCols)):
            list2 = []
            for k in inRows:
                list2.append(inData[inCols[j]][k])
            value = method(list1, list2)
            outData[inCols[i]][inCols[j]] = value
            outData[inCols[j]][inCols[i]] = value
    mData.wCRSData(outf, outData)       
def correlationMatrix(outf, inf, method=pcorrelation):
    """Takes a tab file and cross-correlates the columns"""

    outData = dict()
    inData = mData.rCRSData(inf)
    inCols = inData.keys()
    inRows = inData[inCols[0]].keys()
    for i in inCols:
        outData[i] = dict()
        outData[i][i] = 1.0
    for i in range(len(inCols) - 1):
        list1 = []
        for k in inRows:
            list1.append(inData[inCols[i]][k])
        for j in range(i + 1, len(inCols)):
            list2 = []
            for k in inRows:
                list2.append(inData[inCols[j]][k])
            value = method(list1, list2)
            outData[inCols[i]][inCols[j]] = value
            outData[inCols[j]][inCols[i]] = value
    mData.wCRSData(outf, outData)
        )
    f.close()

    ## summarize pathways
    if iplMatrix is not None:
        pathwayVals = {}
        pathwayScores = {}
        (iplData, iplSamples, iplFeatures) = mData.rCRSData(iplMatrix, retFeatures=True)
        f = open(re.split("/", sifFile)[-2] + ".members.output", "r")
        for line in f:
            line = line.rstrip("\n\r")
            pline = re.split("\t", line)
            if pline[1] in statsMap:
                if pline[1] not in pathwayVals:
                    pathwayVals[pline[1]] = {}
                    for sample in iplSamples:
                        pathwayVals[pline[1]][sample] = []
                if pline[0] in iplFeatures:
                    for sample in iplSamples:
                        pathwayVals[pline[1]][sample].append(abs(float(iplData[sample][pline[0]])))
        f.close()
        for pathwayName in pathwayVals.keys():
            pathwayScores[pathwayName] = {}
            for sample in iplSamples:
                pathwayScores[pathwayName][sample] = mData.mean(pathwayVals[pathwayName][sample])
        mData.wCRSData(re.split("/", sifFile)[-2] + ".score", pathwayScores)


if __name__ == "__main__":
    main(sys.argv[1:])
Beispiel #4
0
    ## summarize pathways
    if iplMatrix is not None:
        pathwayVals = {}
        pathwayScores = {}
        (iplData, iplSamples, iplFeatures) = mData.rCRSData(iplMatrix,
                                                            retFeatures=True)
        f = open(re.split("/", sifFile)[-2] + ".members.output", "r")
        for line in f:
            line = line.rstrip("\n\r")
            pline = re.split("\t", line)
            if pline[1] in statsMap:
                if pline[1] not in pathwayVals:
                    pathwayVals[pline[1]] = {}
                    for sample in iplSamples:
                        pathwayVals[pline[1]][sample] = []
                if pline[0] in iplFeatures:
                    for sample in iplSamples:
                        pathwayVals[pline[1]][sample].append(
                            abs(float(iplData[sample][pline[0]])))
        f.close()
        for pathwayName in pathwayVals.keys():
            pathwayScores[pathwayName] = {}
            for sample in iplSamples:
                pathwayScores[pathwayName][sample] = mData.mean(
                    pathwayVals[pathwayName][sample])
        mData.wCRSData(re.split("/", sifFile)[-2] + ".score", pathwayScores)


if __name__ == "__main__":
    main(sys.argv[1:])