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[0]) == len(data[1]) - 1: data[0].insert(0, " ") utilities.writeMatrixToFile(utilities.transposeMatrix(data), outFilePath)
inFilePath = sys.argv[1] classFilePath = sys.argv[2] ignorePatientID = sys.argv[3] includeIDs = sys.argv[4] == "True" outFilePath = sys.argv[5] patientClassDict = {} for line in file(classFilePath): if line.startswith("#"): continue lineItems = line.rstrip().split("\t") patientClassDict[lineItems[0]] = lineItems[1] if os.path.exists(inFilePath): data = utilities.transposeMatrix(utilities.readMatrixFromFile(inFilePath)) features = data.pop(0) features.pop(0) else: data = [[patientID] for patientID in patientClassDict.keys()] features = [] outFile = open(outFilePath, "w") outFile.write("@relation data\n\n") if includeIDs: outFile.write("@attribute id string\n") for feature in features: outFile.write("@attribute %s numeric\n" % feature.replace("'", "prime"))
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)
inFilePath = sys.argv[1] classFilePath = sys.argv[2] ignorePatientID = sys.argv[3] includeIDs = sys.argv[4] == "True" outFilePath = sys.argv[5] patientClassDict = {} for line in file(classFilePath): if line.startswith("#"): continue lineItems = line.rstrip().split("\t") patientClassDict[lineItems[0]] = lineItems[1] if os.path.exists(inFilePath): data = utilities.transposeMatrix(utilities.readMatrixFromFile(inFilePath)) features = data.pop(0) features.pop(0) else: data = [[patientID] for patientID in patientClassDict.keys()] features = [] outFile = open(outFilePath, 'w') outFile.write("@relation data\n\n") if includeIDs: outFile.write("@attribute id string\n") for feature in features: outFile.write("@attribute %s numeric\n" % feature.replace("'", "prime"))