这篇文章主要介绍了怎么使用python求已知DNA模板的互补DNA序列的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇怎么使用python求已知DNA模板的互补DNA序列文章都会有所收获,下面我们一起来看看吧。
DNA序列
ACTGATCGATTACGTATAGTATTTGCTATCATACATATATATCGATGCGTTCAT
求其互补DNA序列。
在生物上DNA互补序列简述表达可以表示为:A与T,C与G互补,可以理解为将上述序列中现有的A用T代替,C用G代替,T用A代替,G用C代替,则其互补序列为:
TGACTAGCTAATGCATATCATAAACGATAGTATGTATATATAGCTACGCAAGTA
根据上述表述,我可以利用replace()函数进行替换,将A用T替换,T用A替换,C用G替换,G用C替换,
简述其代码
my_dna = "ACTGATCGATTACGTATAGTATTTGCTATCATACATATATATCGATGCGTTCAT" # replace A with T sequence1 = my_dna.replace('A', 'T') # replace T with A sequence2 = sequence1.replace('T', 'A') # replace C with G sequence3 = sequence2.replace('C', 'G') # replace G with C sequence4 = sequence3.replace('G', 'C') # print the result of the final replacement print(sequence1) print(sequence2) print(sequence3) print(sequence4)
其输出结果如下:
TCTGTTCGTTTTCGTTTTGTTTTTGCTTTCTTTCTTTTTTTTCGTTGCGTTCTT
ACAGAACGAAAACGAAAAGAAAAAGCAAACAAACAAAAAAAACGAAGCGAACAA
AGAGAAGGAAAAGGAAAAGAAAAAGGAAAGAAAGAAAAAAAAGGAAGGGAAGAA
ACACAACCAAAACCAAAACAAAAACCAAACAAACAAAAAAAACCAACCCAACAA
原始序列上进行替换
显然结果是不正确的,我们在sequence1到sequence2中就已经出现错误,误把sequence1中A被替换之后变为T的序列,在sequence2中又被替换掉了,因此我们要转变思路,保持只替换原本的序列,不进行多次替换,避免错误,我们可以尝试每次只在原始序列上进行替换,尝试代码如下:
my_dna = "ACTGATCGATTACGTATAGTATTTGCTATCATACATATATATCGATGCGTTCAT" # replace A with T sequence = my_dna.replace('A', 'T') # replace T with A sequence2 = my_dna.replace('T', 'A') # replace C with G sequence3 = my_dna.replace('C', 'G') # replace G with C sequence4 = my_dna.replace('G', 'C') print(sequence1) print(sequence2) print(sequence3) print(sequence4)
其输出结果如下:
TCTGTTCGTTTTCGTTTTGTTTTTGCTTTCTTTCTTTTTTTTCGTTGCGTTCTT
ACAGAACGAAAACGAAAAGAAAAAGCAAACAAACAAAAAAAACGAAGCGAACAA
AGTGATGGATTAGGTATAGTATTTGGTATGATAGATATATATGGATGGGTTGAT
ACTCATCCATTACCTATACTATTTCCTATCATACATATATATCCATCCCTTCAT
显然结果也是不正确的,因此,我们要引入中间变量,最后再把它做一个回环,
也就是说引入四个临时字母,然后每个变换2次,最后把最终结果输出,其代码可以为:
my_dna = "ACTGATCGATTACGTATAGTATTTGCTATCATACATATATATCGATGCGTTCAT" sequence1 = my_dna.replace('A', 'H') sequence2 = sequence1.replace('T', 'J') sequence3 = sequence2.replace('C', 'K') sequence4 = sequence3.replace('G', 'L') sequence5 = sequence4.replace('H', 'T') sequence6 = sequence5.replace('J', 'A') sequence7 = sequence6.replace('K', 'G') sequence8 = sequence7.replace('L', 'C') print(sequence8)
其结果为:
TGACTAGCTAATGCATATCATAAACGATAGTATGTATATATAGCTACGCAAGTA
利用upper()输出大写结果
至此得到了我们想要的结果,但这种方法显然是有些复杂了,我们可以利用字符的大小写来完成我们的工作,也就是利用小写字母为临时变量,最终利用upper()输出大写的结果就行了,其代码和结果如下:
my_dna = "ACTGATCGATTACGTATAGTATTTGCTATCATACATATATATCGATGCGTTCAT" sequence1 = my_dna.replace('A', 't') print(sequence1) sequence2 = sequence1.replace('T', 'a') print(sequence2) sequence3 = sequence2.replace('C', 'g') print(sequence3) sequence4 = sequence3.replace('G', 'c') print(sequence4) print(sequence4.upper())
其结果为:
tCTGtTCGtTTtCGTtTtGTtTTTGCTtTCtTtCtTtTtTtTCGtTGCGTTCtT
tCaGtaCGtaatCGatatGataaaGCataCtatCtatatataCGtaGCGaaCta
tgaGtagGtaatgGatatGataaaGgatagtatgtatatatagGtaGgGaagta
tgactagctaatgcatatcataaacgatagtatgtatatatagctacgcaagta
TGACTAGCTAATGCATATCATAAACGATAGTATGTATATATAGCTACGCAAGTA
关于“怎么使用python求已知DNA模板的互补DNA序列”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“怎么使用python求已知DNA模板的互补DNA序列”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注恰卡网行业资讯频道。