@@ -31,19 +31,30 @@ def csv_string_to_codons_dict(csv_string):
3131 result [aa ][codon ] = float (freq )
3232 return result
3333
34+ def table_with_U_replaced_by_T (table ):
35+ return {
36+ aa : {
37+ codon .replace ('U' , 'T' ): freq
38+ for codon , freq in aa_data .items ()
39+ }
40+ for aa , aa_data in table .items ()
41+ }
3442@lru_cache (maxsize = 128 )
35- def get_codons_table (table_name ):
43+ def get_codons_table (table_name , replace_U_by_T = True ):
3644 """Get data from one of this package's builtin codon usage tables.
3745
3846 Returns a dict {"*": {'UAA': 0.64...}, 'K': {'AAA': 0.76...}, ...}
39-
47+
4048 The table_name argument very flexible on purpose, it can be either an
4149 integer representing a taxonomic ID (which will be downloaded from
4250 the kazusa database), or a string "12245" representing a TaxID, or a string
4351 "e_coli_316407" referring to a builtin table of python_codon_optimization,
4452 or a short form "e_coli" which will be automatically extended to
4553 "e_coli_316407" (at your own risks).
4654 """
55+ if replace_U_by_T :
56+ table = get_codons_table (table_name , replace_U_by_T = False )
57+ return table_with_U_replaced_by_T (table )
4758 if isinstance (table_name , int ) or str .isdigit (table_name ):
4859 return download_codons_table (taxid = table_name )
4960 if table_name in available_codon_tables_shortnames :
0 commit comments