perl 和python 翻译序列

Posted 01说

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了perl 和python 翻译序列相关的知识,希望对你有一定的参考价值。

把人的P53的cDNA序列转录为RNA,再翻译为蛋白质;

perl

use strict;open IN,"c:/Users/11852/Desktop/human_TP53_cDNA.fasta";my $cdna;
while (my $line=<IN>){ chomp $line; if ($line=~ ">"){ next; } $cdna.=$line; }print "the length of cdna\t".length($cdna)."\n".$cdna."\n";
$cdna=~ tr/T/U/;close IN;
open IN,"c:/Users/11852/Desktop/codon_table.txt";my %codon_dic;while (my$line =<IN>){ chomp $line; my @li=split(/\t/,$line); my$codon=$li[0]; $codon=~tr/T/U/; $codon_dic{$codon}=$li[1];}my $protein;for (my$i=0;$i<length($cdna);$i+=3){ my$j=substr($cdna,$i,3); my$a= $codon_dic{$j}; if ($a eq "Stop"){ next; } $protein .= $a;}print $protein;

python

fin=open("data/human_TP53_cDNA.fasta")tp53_cdna=""tp53_mrna=""tp53_protein=""for line in fin: if line[0]==">": continue tp53_cdna+=line.strip()print("TP53 cDNA sequence (Length: ", len(tp53_cdna), "): ",  tp53_cdna, sep="") tp53_mrna=tp53_cnda.replace("T","U")print("TP53 mRNA sequence (Length: ", len(tp53_mrna), "): ",  tp53_mrna, sep="")codon_dic={}f_codon=open("data/codon_table.txt","rt")for line in f_codon: sp=line.strip().split("\t") codon=sp[0].replace("T","U") aa=sp[1] codon_dic[codon]=aafor i in range(0,len(tp53_mrna),3): aa=codon_dic[tp53_mrna[i:i+3]] if aa=="Stop": break tp53_protein+=aaprint("TP53 protein sequence (Length: ", len( tp53_protein), "): ", tp53_protein, sep="")fin.close()f_codon.close()


以上是关于perl 和python 翻译序列的主要内容,如果未能解决你的问题,请参考以下文章

如何有条件地将 C 代码片段编译到我的 Perl 模块?

perl 将函数解包到 python

伪代码翻译?

如何将 shell 脚本翻译成 Perl?

如何将此 JavaScript 代码片段翻译成 Parenscript?

关于语言翻译的问题