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