@@ -5,65 +5,68 @@ class CodonOptimizer:
55 base class of codon optimizer.
66 methods for loading tables are implemented here
77 '''
8-
8+
99 def __init__ (self , cuSource , cuTarget ):
1010 '''
1111 initialize with 2 codon usage tables
1212 '''
1313 self .aa_table = dict ()
1414 self .src_table = dict ()
1515 self .trg_table = dict ()
16-
16+
1717 for l in cuSource .split ("\n " ):
1818 ls = l .split (" " ) # split line into: codon, aa, relative usage, ...
19-
19+
2020 self .aa_table [ls [0 ]] = ls [1 ] # map codon->aa constructed from source table
21-
21+
2222 # create map aa->(codon, usage) for source organism
2323 if (ls [1 ] in self .src_table .keys ()):
2424 self .src_table [ls [1 ]].append ((ls [0 ],ls [2 ]))
2525 else :
2626 self .src_table [ls [1 ]] = list ()
2727 self .src_table [ls [1 ]].append ((ls [0 ],ls [2 ]))
28-
29-
28+
29+
3030 for l in cuTarget .split ("\n " ):
3131 ls = l .split (" " ) # split line into: codon, aa, relative usage, ...
32-
32+
3333 # create map aa->(codon, usage) for source organism
3434 if (ls [1 ] in self .trg_table .keys ()):
3535 self .trg_table [ls [1 ]].append ((ls [0 ],ls [2 ]))
3636 else :
3737 self .trg_table [ls [1 ]] = list ()
3838 self .trg_table [ls [1 ]].append ((ls [0 ],ls [2 ]))
39-
39+
4040class MostUsedCodonOptimizer (CodonOptimizer ):
4141 '''
4242 optimize sequence to use only the most used codons in target organism
43- '''
43+ '''
4444 def optimize (self , codon ):
4545 aa = self .aa_table [codon ]
4646 target_codons = self .trg_table [aa ] #codons for same aa in target
47- codons_sorted = sorted (target_codons , reverse = True , key = lambda x : (x [1 ]))
47+ codons_sorted = sorted (target_codons , reverse = True , key = lambda x : (x [1 ]))
4848 return (codons_sorted [0 ][0 ])
49-
49+
5050class RelativeUsageCodonOptimizer (CodonOptimizer ):
5151 '''
5252 optimize sequence to minimize the difference (percent-wise) between relative usage in source and target organism.
5353 '''
5454 def optimize (self , codon ):
5555 aa = self .aa_table [codon ]
56-
56+
5757 for c in self .src_table [aa ]:
5858 if c [0 ] == codon :
5959 srcUsage = float (c [1 ])
60-
60+
6161 # create list of possible codons (codon, rel.usage difference (max/min))
6262 targetCodons = list ()
6363 for c in self .trg_table [aa ]:
64- if (srcUsage < float (c [1 ])):
64+ if (srcUsage == 0 or float (c [1 ]) == 0 ):
65+ # codon is not used at all in one of the species -> worst possible score
66+ targetCodons .append (c [0 ], float ('inf' ))
67+ elif (srcUsage < float (c [1 ])):
6568 targetCodons .append ((c [0 ], float (c [1 ])/ srcUsage ))
6669 else :
6770 targetCodons .append ((c [0 ], srcUsage / float (c [1 ])))
68-
69- return (sorted (targetCodons , key = lambda x : (x [1 ]))[0 ][0 ])
71+
72+ return (sorted (targetCodons , key = lambda x : (x [1 ]))[0 ][0 ])
0 commit comments