############################################### #####Adding GDI values to a list of genes###### ############################################### metrics_dictionary = {} #a dictionary containing all human genes, with their GDI values (raw and Phred) #####Loading GDI into memory##### file1 = open("GDI_full.txt", 'r') for line1 in file1: #Loop through all genes line11 = line1.rstrip("\n") words1 = line11.split("\t") gene = words1[0] #extracting gene name metrics = words1[1] + "\t" + words1[2] #adding metrics values to gene metrics_dictionary[gene] = metrics #adding gene and values to dictionary file1.close() file2 = open("GDI_output.txt", 'w') #output file name #####Adding metrics values to user's gene list##### file1 = open("gene_list.txt", 'r') #input file name header = 'Gene\tGDI-raw\tGDI-Phred\n' file2.write(header) print "\nAdding GDI values to genes:\n" for line1 in file1: #Loop through all genes line11 = line1.rstrip() gene = line11.rstrip('\r') #input file gene name if (gene not in metrics_dictionary): #gene not found in dictionary to_write = gene + "\tNA\tNA\n" else: #gene found in dictionary to_write = gene + "\t" + metrics_dictionary[gene] + "\n" print to_write file2.write(to_write) #write gene and values into tab separated text file file1.close() file2.close()