#this version was NOT used. laptop version was used because of directory listing consistency #script to add multiple SdA models' predictions to a directory of existing feature files import os import sys files = [] predDir = sys.argv[1] #should contain directories only named integers (1, 2, 3, etc) with .pred files inside. will all be combined and placed in outDir #note. all .pred files for the same target should have the same number of lines featsDir = sys.argv[2] #the original features that will have the sda predictions added to them. ".feat" files only targetName_etc.feat outDir = sys.argv[3] numDirs = 5 #the number of directories that continain models. shou targetList = [] #will hold all the target names of the files (should be first characters before '_') if not outDir.endswith('/'): outDir = outDir + '/' if not predDir.endswith('/'): predDir = predDir + '/' """ for file in os.listdir(featsDir): if not file.endswith(".feat"): continue n = file[:file.find('_')] if n not in targetList: targetList.append(n) """ targetList = ['T0759', 'T0761', 'T0767', 'T0769', 'T0770', 'T0771', 'T0772', 'T0773', 'T0774', 'T0775', 'T0776', 'T0777', 'T0778', 'T0779', 'T0780', 'T0781', 'T0782', 'T0783', 'T0784', 'T0785', 'T0786', 'T0787', 'T0788', 'T0789', 'T0790', 'T0791', 'T0792', 'T0793', 'T0794', 'T0795', 'T0796', 'T0797', 'T0798', 'T0799', 'T0800', 'T0801', 'T0802', 'T0803', 'T0804', 'T0805', 'T0806', 'T0807', 'T0808', 'T0809', 'T0810', 'T0811', 'T0812', 'T0813', 'T0814', 'T0815', 'T0816', 'T0817', 'T0818', 'T0819', 'T0820', 'T0821', 'T0822', 'T0823', 'T0824', 'T0826', 'T0828', 'T0829', 'T0831', 'T0832', 'T0833', 'T0834', 'T0835', 'T0836', 'T0837', 'T0838', 'T0839', 'T0841', 'T0842', 'T0843', 'T0844', 'T0845', 'T0846', 'T0847', 'T0848', 'T0849', 'T0850', 'T0851', 'T0852', 'T0853', 'T0854', 'T0855', 'T0856', 'T0857'] for tar in targetList: pickedPreds = [] for path, subdirs, files in os.walk(predDir): for name in files: if tar in name and name.endswith('.pred'): pickedPreds.append(open(os.path.join(path,name), 'r')) outN = outDir + tar + '.combinedPred' outF = open(outN, 'w') fLoopControl = True while True: line = "" for f in pickedPreds: tarL = f.readline().rstrip() if tarL == '': fLoopControl = False continue #reached end of file. items = tarL.split() if 'e' in items[0]: items[0] = '0.0' if 'e' in items[1]: items[1] = '0.0' line = line + items[0] + ' ' + items[1] + ' ' if fLoopControl == False: break outF.write(line + '\n')