用 python 实现如下:
1 #!/usr/bin/python 2 # Complementing DNA 3 4 my_dna = "ACTGATCGATTACGTATAGTATTTGCTATCATACATATATATCGATGCGTTCAT" 5 # 由于python 区分大小写,所以先替换成小写可以有效避免后面重复替换的问题。 6 complement_AT = my_dna.replace("A","t") 7 complement_TA = complement_AT.replace("T","a") 8 complement_GC = complement_TA.replace("G","c") 9 complement_CG = complement_GC.replace("C","g") 10 # 把所以小写变为大写即可。 11 complement_DNA = complement_CG.upper() 12 reverse_complement_DNA = complement_DNA[::-1] # str[::-1] used to reverse the string 13 14 print(complement_DNA) 15 print(reverse_complement_DNA)
运行结果:
ubuntu$ python3 complement_py3.py TGACTAGCTAATGCATATCATAAACGATAGTATGTATATATAGCTACGCAAGTA ATGAACGCATCGATATATATGTATGATAGCAAATACTATACGTAATCGATCAGT
时间: 2024-10-12 04:02:13