The July 2012 issue of Mensa Newsletter has an article called Digital Brain. In it, the author connects the human brain with basic calculations. This is a pretty interesting and funny article with a tip at the end. This invitation asks the reader to convert the Cytosine Guanine Adenine Guanine Adenine Guanine to a base number of 10, using the fact that the cytosine cytosine Guanine Cytosine Adenine Guanine is 2011 (the first set of codons is short and the second is ccgcag for short.) you need to convert base number 64 to base 10 using the table in the article, which displays all possible codons in the correct order with aug = 0, uuu = 1, uuc = 2, ..., gga == 61, ggg = 62, uag = 63. I decided to do this and decided to write a python program to convert codon numbers to base 10 and base 10 numbers codons. After writing a quick algorithm for both, I ran it. The program did not give any errors and made codons for my numbers and vice versa. However, they were wrong numbers! I donβt seem to see what is going wrong, and I really appreciate any help.
Without any noise code:
codons = ['aug', 'uuu', 'uuc', 'uua', 'uug', 'ucu', 'ucc', 'uca', 'ucg', 'uau', 'uac', 'uaa', 'ugu', 'ugc', 'uga', 'ugg', 'cuu', 'cuc', 'cua', 'cug', 'ccu', 'ccc', 'cca', 'ccg', 'cau', 'cac', 'caa', 'cag', 'cgu', 'cgc', 'cga', 'cgg', 'auu', 'auc', 'aua', 'acu', 'acc', 'aca', 'acg', 'aau', 'aac', 'aaa', 'aag', 'agu', 'agc', 'aga', 'agg', 'guu', 'guc', 'gua', 'gug', 'gcu', 'gcc', 'gca', 'gcg', 'gau', 'gac', 'gaa', 'gag', 'ggu', 'ggc', 'gga', 'ggg', 'uag' ] def codonNumToBase10 ( codonValue ) : numberOfChars = len( codonValue ) # check to see if contains sets of threes if len( codonValue ) % 3 != 0 : return -1 # check to see if it contains the correct characters for i in range(0, numberOfChars ) : if codonValue[i] != 'a' : if codonValue[i] != 'u' : if codonValue[i] != 'c' : if codonValue[i] != 'g' : return -2 # populate an array with decimal versions of each codon in the input codonNumbers = [] base10Value = 0 numberOfCodons = int(numberOfChars / 3 ) for i in range(0, numberOfCodons) : charVal = codonValue[ 0 + (i*3) ] + codonValue[ 1 + (i*3) ] + codonValue[ 2 + (i*3) ] val = 0 for j in codons : if j == charVal : codonNumbers.append( val ) break val += 1 base10Value += ( pow( 64, numberOfCodons - i - 1 ) ) * codonNumbers[i] return base10Value def base10ToCodonNum ( number ) : codonNumber = '' hitZeroCount = 0 while( 1==1 ) : val = number % 64 number = int( number / 64 ) codonNumber = codons[val] + codonNumber if number == 0 : if hitZeroCount > 0: break hitZeroCount += 1 return codonNumber val_2011 = 'ccgcag' val_unknown = 'cgagag' print( base10ToCodonNum( codonNumToBase10( val_2011 ) ), '::', codonNumToBase10( val_2011 ) ) print( base10ToCodonNum( codonNumToBase10( val_unknown ) ), '::', codonNumToBase10( val_unknown ) )
EDIT 1: The values ββI get are 1499 for ccgcag and 1978 for cgagag.
EDIT 2: base10ToCodonNum function fixed thanks to Ashwini Chaudhary.