# print trans # if str(trans) == str(TolC): # print 'congrats, you reinvented the wheel' # else: # print 'you still suck' def reverse_translate_amino_acid(self, amino_acid): codon_options = self.amino_acid_to_codon_map[amino_acid] # Somehow make a choice. For now, just first one. codon = codon_options[0] # Return the one we chose. return codon if __name__ == '__main__': my_codon_table = CodonTable('standard_usage.txt') print my_codon_table.translate_codon('AAA') print my_codon_table.translate_sequence('ATGAAGAAATTGCTCCCCATT') #print len(my_codon_table.codon_to_amino_acid_map) #print my_codon_table.amino_acid_to_codon_map #print len(my_codon_table.amino_acid_to_codon_map) #print my_codon_table.amino_acid_to_codon_map['A'] #print my_codon_table.amino_acid_to_weight_map #print my_codon_table.translate_codon('AAA') #print my_codon_table.reverse_translate_amino_acid('F') #my_second_codon_table = CodonTable('weird_usage.txt')
def run_script(args): #open the input file, which should be args.scriptinput #send to the correct function based on the choice # print args.scriptinput scriptinput = open(args.scriptinput[0]) outputfh = open(args.output[0],'w') output = csv.writer(outputfh)#output.txt','w') my_codon_table = CodonTable('rEcoli-codon-usage.txt') my_rare_codon_table = CodonTable('rEcoli-codon-usage-1st20.txt') scriptinputreader = csv.reader(scriptinput) if args.mode[0] == 'translate': for row in scriptinputreader: line = row[1] # print line codonseq = '' ti = 0 line = line.replace('T','U') while ti + 2 < len(line): codon = line[ti] + line[ti+1] + line[ti+2] codonseq += my_codon_table.translate_codon(codon) ti += 3 output.writerow([row[0]] + [codonseq]) elif args.mode[0] == 'revtranslate': for row in scriptinputreader: line = row[1] # print line codonseq = '' ti = 0 for character in line: if ti < 20: table = my_rare_codon_table else: table = my_codon_table codonseq += table.reverse_translate_codon(character) ti += 1 #print ti codonseq = codonseq.replace('U','T') output.writerow([row[0]] + [codonseq]) elif args.mode[0] == 'transcribe': for row in scriptinputreader: line = row[1] # print line codonseq = '' codonseq = line.replace('T','U') output.writerow([row[0]] + [codonseq]) # else: # print args.mode elif args.mode[0] == 'calCUT': calCUT = {} for row in scriptinputreader: line = row[1] ti = 0 while ti + 2 < len(line): codon = line[ti] + line[ti+1] + line[ti+2] #print codon if not codon in calCUT: calCUT[codon] = 0 calCUT[codon] += 1 ti += 3 #print ti for codon in calCUT: count = calCUT[codon] cudun = codon.replace('T','U') AA = my_codon_table.translate_codon(cudun) output.writerow([codon] + [AA] + [count]) # print codonseq # if str(codonseq) == str(TolC): # print "nice" # else: # print "you suck" outputfh.close()