import os, sys, glob, math import utilities from operator import itemgetter, attrgetter inFilePath = sys.argv[1] expression = sys.argv[2] reverse = sys.argv[3] == "reverse" numHeaderRows = int(sys.argv[4]) outFilePath = sys.argv[5] data = utilities.readMatrixFromFile(inFilePath) headerRows = [] for i in range(numHeaderRows): headerRows.append(data.pop(0)) data = map(lambda x: eval("x + [" + expression + "]"), data) data.sort(key=itemgetter(len(data[0])-1), reverse=reverse) data = [x[:-1] for x in data] utilities.writeMatrixToFile(headerRows + data, outFilePath)
numPlaces = sys.argv[4] outFilePath = sys.argv[5] numberFormatOption = "g" if len(sys.argv) > 6: numberFormatOption = sys.argv[6] data = utilities.readMatrixFromFile(inFilePath) def isNumber(x): try: float(x) return True except: return False for i in range(numHeaderRows, len(data)): if isNumber(data[i][colIndex]): modValue = ("%." + numPlaces + numberFormatOption) % float( data[i][colIndex]) else: modValue = data[i][colIndex] if len(data[i][colIndex]) > int(numPlaces): modValue = data[i][colIndex][:int(numPlaces)] + "..." data[i][colIndex] = modValue utilities.writeMatrixToFile(data, outFilePath)
import os, sys, glob, math import utilities from TransformFunctions import * inFilePath = sys.argv[1] hasHeaderRow = sys.argv[2] == "True" transformFunction = getattr(sys.modules[__name__], sys.argv[3]) outFilePath = sys.argv[4] data = utilities.readMatrixFromFile(inFilePath) if hasHeaderRow: headerRow = data.pop(0) rowNames = [x[0] for x in data] data = [x[1:] for x in data] data = utilities.transposeMatrix(data) data = [transformFunction([y for y in x]) for x in data] data = utilities.transposeMatrix(data) data = [[rowNames[i]] + data[i] for i in range(len(data))] if hasHeaderRow: data.insert(0, headerRow) utilities.writeMatrixToFile(data, outFilePath)
import os, sys import utilities inFilePath = sys.argv[1] outFilePath = sys.argv[2] data = utilities.readMatrixFromFile(inFilePath) if len(data) > 1 and len(data[0]) == len(data[1]) - 1: data[0].insert(0, " ") utilities.writeMatrixToFile(utilities.transposeMatrix(data), outFilePath)
import os, sys import utilities inFilePath = sys.argv[1] outFilePath = sys.argv[2] data = utilities.readMatrixFromFile(inFilePath) if len(data[0]) == len(data[1]) - 1: data[0].insert(0, " ") utilities.writeMatrixToFile(utilities.transposeMatrix(data), outFilePath)
numNonMuts2 = int(dataDict2[descriptor][-3]) numMuts2 = int(dataDict2[descriptor][-2]) mutFreq2 = float(dataDict2[descriptor][-1]) if (numNonMuts1 == 0 and numNonMuts2 == 0) or (numMuts1 == 0 and numMuts2 == 0): fisherP = "NaN" else: fisherP = calculateFisherExact(numNonMuts1, numMuts1, numNonMuts2, numMuts2) metaInfo1 = dataDict1[descriptor][1] metaInfo2 = dataDict2[descriptor][1] # meta = "" # if len(set([metaInfo1] + [metaInfo2])) == 1: # meta = ([metaInfo1] + [metaInfo2])[0] # elif len(set([metaInfo1] + [metaInfo2])) > 1: meta = ";".join(list([metaInfo1, metaInfo2])) outData.append([ descriptor, meta, numNonMuts1, numMuts1, numNonMuts2, numMuts2, mutFreq1, mutFreq2, fisherP ]) inFile2.close() inFile1.close() outData.sort(key=itemgetter(-1)) utilities.writeMatrixToFile(outHeader + outData, outFilePath)
for descriptor in (set(dataDict1.keys()) | set(dataDict2.keys())): numNonMuts1 = int(dataDict1[descriptor][-3]) numMuts1 = int(dataDict1[descriptor][-2]) mutFreq1 = float(dataDict1[descriptor][-1]) numNonMuts2 = int(dataDict2[descriptor][-3]) numMuts2 = int(dataDict2[descriptor][-2]) mutFreq2 = float(dataDict2[descriptor][-1]) if (numNonMuts1== 0 and numNonMuts2 == 0) or (numMuts1 == 0 and numMuts2 == 0): fisherP = "NaN" else: fisherP = calculateFisherExact(numNonMuts1, numMuts1, numNonMuts2, numMuts2) metaInfo1 = dataDict1[descriptor][1] metaInfo2 = dataDict2[descriptor][1] # meta = "" # if len(set([metaInfo1] + [metaInfo2])) == 1: # meta = ([metaInfo1] + [metaInfo2])[0] # elif len(set([metaInfo1] + [metaInfo2])) > 1: meta = ";".join(list([metaInfo1, metaInfo2])) outData.append([descriptor, meta, numNonMuts1, numMuts1, numNonMuts2, numMuts2, mutFreq1, mutFreq2, fisherP]) inFile2.close() inFile1.close() outData.sort(key=itemgetter(-1)) utilities.writeMatrixToFile(outHeader + outData, outFilePath)
import os, sys, glob, math import utilities from operator import itemgetter, attrgetter inFilePath = sys.argv[1] expression = sys.argv[2] reverse = sys.argv[3] == "reverse" numHeaderRows = int(sys.argv[4]) outFilePath = sys.argv[5] data = utilities.readMatrixFromFile(inFilePath) headerRows = [] for i in range(numHeaderRows): headerRows.append(data.pop(0)) data = map(lambda x: eval("x + [" + expression + "]"), data) data.sort(key=itemgetter(len(data[0]) - 1), reverse=reverse) data = [x[:-1] for x in data] utilities.writeMatrixToFile(headerRows + data, outFilePath)
outPositionsRow.append(geneInfoSingle[2]) outPositionsRow.append(geneInfoSingle[3]) outExonBedRows.append([chromosome, geneInfoSingle[2], geneInfoSingle[3], geneID]) else: outPositionsRow.append(",".join([str(x[2]) for x in transcribedInfo])) outPositionsRow.append(",".join([str(x[3]) for x in transcribedInfo])) for i in range(len(transcribedInfo)): outExonBedRows.append([chromosome, str(transcribedInfo[i][2]), str(transcribedInfo[i][3]), "%s_%i" % (geneID, i)]) # Add transcription start site if len(cdsInfo) == 0: if len(transcribedInfo) > 0: outPositionsRow.append(",".join([str(x[2]) for x in transcribedInfo])) outPositionsRow.append(",".join([str(x[3]) for x in transcribedInfo])) else: outPositionsRow.append(geneInfoSingle[2]) outPositionsRow.append(geneInfoSingle[3]) else: outPositionsRow.append(",".join([str(x[2]) for x in cdsInfo])) outPositionsRow.append(",".join([str(x[3]) for x in cdsInfo])) utilities.writeMatrixToOpenFile([outPositionsRow], outPositionsFile) utilities.writeMatrixToOpenFile([[geneID, geneInfoSingle[4]]], outStrandFile) utilities.writeMatrixToFile(outExonBedRows, outExonBedFilePath) outPositionsFile.close() outStrandFile.close()
keys = set() for line in file(inFilePath): keys.add(line.rstrip().split("\t")[0]) summedDict = {} for key in keys: summedDict[key] = [] for line in file(inFilePath): values = line.rstrip().split("\t") key = values.pop(0) summedDict[key].extend(values) outLines = [] for key in summedDict.keys(): out = [key] values = [x for x in summedDict[key] if x != ""] if len(values) == 0: out.append("NA") elif len(values) == 1: out.append(values[0]) else: out.append(summarizeFunction(values)[0]) outLines.append(out) utilities.writeMatrixToFile(outLines, outFilePath)