Trees | Indices | Help |
---|
|
1 import string 2 from Bio import Alphabet, Seq 3 from Bio.Data import CodonTable 4985 86 unambiguous_dna_by_name = {} 87 for key, value in CodonTable.unambiguous_dna_by_name.items(): 88 unambiguous_dna_by_name[key] = Translator(value) 89 unambiguous_dna_by_id = {} 90 for key, value in CodonTable.unambiguous_dna_by_id.items(): 91 unambiguous_dna_by_id[key] = Translator(value) 92 93 unambiguous_rna_by_name = {} 94 for key, value in CodonTable.unambiguous_rna_by_name.items(): 95 unambiguous_rna_by_name[key] = Translator(value) 96 unambiguous_rna_by_id = {} 97 for key, value in CodonTable.unambiguous_rna_by_id.items(): 98 unambiguous_rna_by_id[key] = Translator(value) 99 100 # XXX Ambiguous - can be done the same except for stop codons! 101 ambiguous_dna_by_name = {} 102 for key, value in CodonTable.ambiguous_dna_by_name.items(): 103 ambiguous_dna_by_name[key] = Translator(value) 104 ambiguous_dna_by_id = {} 105 for key, value in CodonTable.ambiguous_dna_by_id.items(): 106 ambiguous_dna_by_id[key] = Translator(value) 107 108 ambiguous_rna_by_name = {} 109 for key, value in CodonTable.ambiguous_rna_by_name.items(): 110 ambiguous_rna_by_name[key] = Translator(value) 111 ambiguous_rna_by_id = {} 112 for key, value in CodonTable.ambiguous_rna_by_id.items(): 113 ambiguous_rna_by_id[key] = Translator(value) 11411 return "Translator object\n" + str(self.table)1214 assert seq.alphabet == self.table.nucleotide_alphabet, \ 15 "cannot translate from the given alphabet (%s)" % seq.alphabet 16 s = seq.data 17 letters = [] 18 append = letters.append 19 table = self.table 20 get = table.forward_table.get 21 n = len(seq) 22 for i in range(0, n-n%3, 3): 23 append(get(s[i:i+3], stop_symbol)) 24 25 # return with the correct alphabet encoding (cache the encoding) 26 try: 27 alphabet = self._encoded[stop_symbol] 28 except KeyError: 29 alphabet = Alphabet.HasStopCodon(table.protein_alphabet) 30 self._encoded[stop_symbol] = alphabet 31 32 return Seq.Seq(string.join(letters, ""), alphabet)3335 # This doesn't have a stop encoding 36 assert seq.alphabet == self.table.nucleotide_alphabet, \ 37 "cannot translate from given alphabet (have %s, need %s)" %\ 38 (seq.alphabet, self.table.nucleotide_alphabet) 39 s = seq.data 40 letters = [] 41 append = letters.append 42 table = self.table.forward_table 43 n = len(seq) 44 try: 45 for i in range(0, n-n%3, 3): 46 append(table[s[i:i+3]]) 47 except KeyError: 48 # Stop at the first codon failure 49 pass 50 return Seq.Seq(string.join(letters, ""), self.table.protein_alphabet)5153 # includes the stop codon 54 if not isinstance(seq.alphabet, Alphabet.HasStopCodon): 55 return self._back_translate_no_stop(seq) 56 assert seq.alphabet.alphabet == self.table.protein_alphabet, \ 57 "cannot back translate from the given alphabet (%s)" % \ 58 seq.alphabet.alphabet 59 s = seq.data 60 letter = seq.alphabet.stop_symbol 61 letters = [] 62 append = letters.append 63 table = self.table.back_table 64 for c in seq.data: 65 if c == letter: 66 append(table[None]) 67 else: 68 append(table[c]) 69 return Seq.Seq(string.join(letters, ""), 70 self.table.nucleotide_alphabet)7173 # does not allow a stop codon 74 assert seq.alphabet == self.table.protein_alphabet, \ 75 "cannot back translate from the given alphabet (%s)" % \ 76 seq.alphabet 77 s = seq.data 78 letters = [] 79 append = letters.append 80 table = self.table.back_table 81 for c in seq.data: 82 append(table[c]) 83 return Seq.Seq(string.join(letters, ""), 84 self.table.nucleotide_alphabet)
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Thu Feb 7 11:51:31 2008 | http://epydoc.sourceforge.net |