您好,登錄后才能下訂單哦!
這篇文章主要介紹了怎么使用python求已知DNA模板的互補(bǔ)DNA序列的相關(guān)知識(shí),內(nèi)容詳細(xì)易懂,操作簡(jiǎn)單快捷,具有一定借鑒價(jià)值,相信大家閱讀完這篇怎么使用python求已知DNA模板的互補(bǔ)DNA序列文章都會(huì)有所收獲,下面我們一起來(lái)看看吧。
ACTGATCGATTACGTATAGTATTTGCTATCATACATATATATCGATGCGTTCAT
求其互補(bǔ)DNA序列。
在生物上DNA互補(bǔ)序列簡(jiǎn)述表達(dá)可以表示為:A與T,C與G互補(bǔ),可以理解為將上述序列中現(xiàn)有的A用T代替,C用G代替,T用A代替,G用C代替,則其互補(bǔ)序列為:
TGACTAGCTAATGCATATCATAAACGATAGTATGTATATATAGCTACGCAAGTA
根據(jù)上述表述,我可以利用replace()函數(shù)進(jìn)行替換,將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)
其輸出結(jié)果如下:
TCTGTTCGTTTTCGTTTTGTTTTTGCTTTCTTTCTTTTTTTTCGTTGCGTTCTT
ACAGAACGAAAACGAAAAGAAAAAGCAAACAAACAAAAAAAACGAAGCGAACAA
AGAGAAGGAAAAGGAAAAGAAAAAGGAAAGAAAGAAAAAAAAGGAAGGGAAGAA
ACACAACCAAAACCAAAACAAAAACCAAACAAACAAAAAAAACCAACCCAACAA
顯然結(jié)果是不正確的,我們?cè)趕equence1到sequence2中就已經(jīng)出現(xiàn)錯(cuò)誤,誤把sequence1中A被替換之后變?yōu)門的序列,在sequence2中又被替換掉了,因此我們要轉(zhuǎn)變思路,保持只替換原本的序列,不進(jìn)行多次替換,避免錯(cuò)誤,我們可以嘗試每次只在原始序列上進(jìn)行替換,嘗試代碼如下:
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)
其輸出結(jié)果如下:
TCTGTTCGTTTTCGTTTTGTTTTTGCTTTCTTTCTTTTTTTTCGTTGCGTTCTT
ACAGAACGAAAACGAAAAGAAAAAGCAAACAAACAAAAAAAACGAAGCGAACAA
AGTGATGGATTAGGTATAGTATTTGGTATGATAGATATATATGGATGGGTTGAT
ACTCATCCATTACCTATACTATTTCCTATCATACATATATATCCATCCCTTCAT
顯然結(jié)果也是不正確的,因此,我們要引入中間變量,最后再把它做一個(gè)回環(huán),
也就是說(shuō)引入四個(gè)臨時(shí)字母,然后每個(gè)變換2次,最后把最終結(jié)果輸出,其代碼可以為:
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)
其結(jié)果為:
TGACTAGCTAATGCATATCATAAACGATAGTATGTATATATAGCTACGCAAGTA
至此得到了我們想要的結(jié)果,但這種方法顯然是有些復(fù)雜了,我們可以利用字符的大小寫來(lái)完成我們的工作,也就是利用小寫字母為臨時(shí)變量,最終利用upper()輸出大寫的結(jié)果就行了,其代碼和結(jié)果如下:
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())
其結(jié)果為:
tCTGtTCGtTTtCGTtTtGTtTTTGCTtTCtTtCtTtTtTtTCGtTGCGTTCtT
tCaGtaCGtaatCGatatGataaaGCataCtatCtatatataCGtaGCGaaCta
tgaGtagGtaatgGatatGataaaGgatagtatgtatatatagGtaGgGaagta
tgactagctaatgcatatcataaacgatagtatgtatatatagctacgcaagta
TGACTAGCTAATGCATATCATAAACGATAGTATGTATATATAGCTACGCAAGTA
關(guān)于“怎么使用python求已知DNA模板的互補(bǔ)DNA序列”這篇文章的內(nèi)容就介紹到這里,感謝各位的閱讀!相信大家對(duì)“怎么使用python求已知DNA模板的互補(bǔ)DNA序列”知識(shí)都有一定的了解,大家如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。