def translate(self):
'''
make alignments of translations.
'''
from Bio.Seq import CodonTable
codon_table = CodonTable.ambiguous_dna_by_name['Standard'].forward_table
self.translations={}
if not hasattr(self, "proteins"): # ensure dictionary to hold annotation
self.proteins={}
# add a default translation of the entire sequence unless otherwise specified
if len(self.proteins)==0:
self.proteins.update({'cds':FeatureLocation(start=0,
end=self.aln.get_alignment_length(), strand=1)})
# loop over all proteins and create one MSA for each
for prot in self.proteins:
aa_seqs = []
for seq in self.aln:
tmpseq = self.proteins[prot].extract(seq)
translated_seq, translation_exception = safe_translate(str(tmpseq.seq), report_exceptions=True)
if translation_exception:
self.log.notify("Trouble translating because of invalid codons %s" % seq.id)
tmpseq.seq = Seq(translated_seq)
# copy attributes
tmpseq.attributes = seq.attributes
aa_seqs.append(tmpseq)
self.translations[prot] = MultipleSeqAlignment(aa_seqs)
评论列表
文章目录